Python elementtree.ElementTree.SubElement() Examples
The following are 30
code examples of elementtree.ElementTree.SubElement().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
elementtree.ElementTree
, or try the search function
.
Example #1
Source File: __init__.py From faces with GNU General Public License v2.0 | 6 votes |
def visit_colspec(self, node): self.column_count += 1 colspec_name = self.rststyle( '%s%%d.%%s' % TABLESTYLEPREFIX, (self.table_count, chr(self.column_count), ) ) colwidth = node['colwidth'] / 12.0 el1 = SubElement(self.automatic_styles, 'style:style', attrib={ 'style:name': colspec_name, 'style:family': 'table-column', }, nsdict=SNSD) el1_1 = SubElement(el1, 'style:table-column-properties', attrib={ 'style:column-width': '%.4fin' % colwidth }, nsdict=SNSD) el2 = self.append_child('table:table-column', attrib={ 'table:style-name': colspec_name, }) self.table_width += colwidth
Example #2
Source File: __init__.py From faces with GNU General Public License v2.0 | 6 votes |
def visit_inline(self, node): styles = node.attributes.get('classes', ()) if styles: el = self.current_element for inline_style in styles: el = SubElement(el, 'text:span', attrib={'text:style-name': self.rststyle(inline_style)}) count = len(styles) else: # No style was specified so use a default style (old code # crashed if no style was given) el = SubElement(self.current_element, 'text:span') count = 1 self.set_current_element(el) self.inline_style_count_stack.append(count)
Example #3
Source File: __init__.py From bash-lambda-layer with MIT License | 6 votes |
def attach_page_style(self, el): """Attach the default page style. Create an automatic-style that refers to the current style of this element and that refers to the default page style. """ current_style = el.get('text:style-name') style_name = 'P1003' el1 = SubElement( self.automatic_styles, 'style:style', attrib={ 'style:name': style_name, 'style:master-page-name': "rststyle-pagedefault", 'style:family': "paragraph", }, nsdict=SNSD) if current_style: el1.set('style:parent-style-name', current_style) el.set('text:style-name', style_name)
Example #4
Source File: __init__.py From deepWordBug with Apache License 2.0 | 6 votes |
def visit_colspec(self, node): self.column_count += 1 colspec_name = self.rststyle( '%s%%d.%%s' % TABLESTYLEPREFIX, (self.table_count, chr(self.column_count), ) ) colwidth = node['colwidth'] / 12.0 el1 = SubElement(self.automatic_styles, 'style:style', attrib={ 'style:name': colspec_name, 'style:family': 'table-column', }, nsdict=SNSD) el1_1 = SubElement(el1, 'style:table-column-properties', attrib={ 'style:column-width': '%.4fin' % colwidth }, nsdict=SNSD) el2 = self.append_child('table:table-column', attrib={ 'table:style-name': colspec_name, }) self.table_width += colwidth
Example #5
Source File: makeOvModel.py From sequitur-g2p with GNU General Public License v2.0 | 6 votes |
def changeSyntaticToPhonetic(xml): lexicon = xml.getroot() for lemma in lexicon.getiterator('lemma'): if lemma.get('special'): continue phon = lemma.find('phon') if phon is not None: phon = phon.text.split() phon.append('#1') synt = lemma.find('synt') if synt is None: synt = SubElement(lemma, 'synt') else: synt.clear() synt.tail = '\n ' if phon: for ph in phon: SubElement(synt, 'tok').text = ph # ===========================================================================
Example #6
Source File: __init__.py From faces with GNU General Public License v2.0 | 6 votes |
def visit_enumerated_list(self, node): el1 = self.current_element if self.blockstyle == self.rststyle('blockquote'): el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle('blockquote-enumlist'), }) self.list_style_stack.append(self.rststyle('blockquote-enumitem')) elif self.blockstyle == self.rststyle('highlights'): el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle('highlights-enumlist'), }) self.list_style_stack.append(self.rststyle('highlights-enumitem')) elif self.blockstyle == self.rststyle('epigraph'): el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle('epigraph-enumlist'), }) self.list_style_stack.append(self.rststyle('epigraph-enumitem')) else: liststylename = 'enumlist-%s' % (node.get('enumtype', 'arabic'), ) el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle(liststylename), }) self.list_style_stack.append(self.rststyle('enumitem')) self.set_current_element(el2)
Example #7
Source File: makeOvModel.py From sequitur-g2p with GNU General Public License v2.0 | 6 votes |
def addGraphonesToLexicon(xml, graphones): lexicon = xml.getroot() for letters, phonemes in graphones: lemma = SubElement(lexicon, 'lemma') lemma.text = '\n ' orth = SubElement(lemma, 'orth') orth.text = '_' + ''.join(letters) + '_' orth.tail = '\n ' phon = SubElement(lemma, 'phon') phon.text = ' '.join(phonemes) phon.tail = '\n ' synt = SubElement(lemma, 'synt') SubElement(synt, 'tok').text = lmToken(letters, phonemes) synt.tail = '\n' # synt.tail = '\n ' # eval = SubElement(lemma, 'eval') # SubElement(eval, 'tok').text = '[UNKNOWN]' # eval.tail = '\n' lemma.tail = '\n'
Example #8
Source File: __init__.py From deepWordBug with Apache License 2.0 | 6 votes |
def generate_admonition(self, node, label, title=None): if hasattr(self.language, 'labels'): translated_label = self.language.labels[label] else: translated_label = label el1 = SubElement(self.current_element, 'text:p', attrib={ 'text:style-name': self.rststyle( 'admon-%s-hdr', (label, )), }) if title: el1.text = title else: el1.text = '%s!' % (translated_label.capitalize(), ) s1 = self.rststyle('admon-%s-body', (label, )) self.paragraph_style_stack.append(s1) # # Roles (e.g. subscript, superscript, strong, ... #
Example #9
Source File: __init__.py From deepWordBug with Apache License 2.0 | 6 votes |
def visit_inline(self, node): styles = node.attributes.get('classes', ()) if styles: el = self.current_element for inline_style in styles: el = SubElement(el, 'text:span', attrib={'text:style-name': self.rststyle(inline_style)}) count = len(styles) else: # No style was specified so use a default style (old code # crashed if no style was given) el = SubElement(self.current_element, 'text:span') count = 1 self.set_current_element(el) self.inline_style_count_stack.append(count)
Example #10
Source File: __init__.py From deepWordBug with Apache License 2.0 | 6 votes |
def attach_page_style(self, el): """Attach the default page style. Create an automatic-style that refers to the current style of this element and that refers to the default page style. """ current_style = el.get('text:style-name') style_name = 'P1003' el1 = SubElement( self.automatic_styles, 'style:style', attrib={ 'style:name': style_name, 'style:master-page-name': "rststyle-pagedefault", 'style:family': "paragraph", }, nsdict=SNSD) if current_style: el1.set('style:parent-style-name', current_style) el.set('text:style-name', style_name)
Example #11
Source File: __init__.py From bash-lambda-layer with MIT License | 6 votes |
def visit_enumerated_list(self, node): el1 = self.current_element if self.blockstyle == self.rststyle('blockquote'): el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle('blockquote-enumlist'), }) self.list_style_stack.append(self.rststyle('blockquote-enumitem')) elif self.blockstyle == self.rststyle('highlights'): el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle('highlights-enumlist'), }) self.list_style_stack.append(self.rststyle('highlights-enumitem')) elif self.blockstyle == self.rststyle('epigraph'): el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle('epigraph-enumlist'), }) self.list_style_stack.append(self.rststyle('epigraph-enumitem')) else: liststylename = 'enumlist-%s' % (node.get('enumtype', 'arabic'), ) el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle(liststylename), }) self.list_style_stack.append(self.rststyle('enumitem')) self.set_current_element(el2)
Example #12
Source File: __init__.py From deepWordBug with Apache License 2.0 | 6 votes |
def visit_enumerated_list(self, node): el1 = self.current_element if self.blockstyle == self.rststyle('blockquote'): el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle('blockquote-enumlist'), }) self.list_style_stack.append(self.rststyle('blockquote-enumitem')) elif self.blockstyle == self.rststyle('highlights'): el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle('highlights-enumlist'), }) self.list_style_stack.append(self.rststyle('highlights-enumitem')) elif self.blockstyle == self.rststyle('epigraph'): el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle('epigraph-enumlist'), }) self.list_style_stack.append(self.rststyle('epigraph-enumitem')) else: liststylename = 'enumlist-%s' % (node.get('enumtype', 'arabic'), ) el2 = SubElement(el1, 'text:list', attrib={ 'text:style-name': self.rststyle(liststylename), }) self.list_style_stack.append(self.rststyle('enumitem')) self.set_current_element(el2)
Example #13
Source File: __init__.py From faces with GNU General Public License v2.0 | 6 votes |
def attach_page_style(self, el): """Attach the default page style. Create an automatic-style that refers to the current style of this element and that refers to the default page style. """ current_style = el.get('text:style-name') style_name = 'P1003' el1 = SubElement( self.automatic_styles, 'style:style', attrib={ 'style:name': style_name, 'style:master-page-name': "rststyle-pagedefault", 'style:family': "paragraph", }, nsdict=SNSD) if current_style: el1.set('style:parent-style-name', current_style) el.set('text:style-name', style_name)
Example #14
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def visit_strong(self, node): el = SubElement(self.current_element, 'text:span', attrib={'text:style-name': self.rststyle('strong')}) self.set_current_element(el)
Example #15
Source File: __init__.py From bash-lambda-layer with MIT License | 5 votes |
def visit_footnote_reference(self, node): if self.footnote_level <= 0: id = node.attributes['ids'][0] refid = node.attributes.get('refid') if refid is None: refid = '' if self.settings.endnotes_end_doc: note_class = 'endnote' else: note_class = 'footnote' el1 = self.append_child('text:note', attrib={ 'text:id': '%s' % (refid, ), 'text:note-class': note_class, }) note_auto = str(node.attributes.get('auto', 1)) if isinstance(node, docutils.nodes.citation_reference): citation = '[%s]' % node.astext() el2 = SubElement(el1, 'text:note-citation', attrib={ 'text:label': citation, }) el2.text = citation elif note_auto == '1': el2 = SubElement(el1, 'text:note-citation', attrib={ 'text:label': node.astext(), }) el2.text = node.astext() elif note_auto == '*': if self.footnote_chars_idx >= len( ODFTranslator.footnote_chars): self.footnote_chars_idx = 0 footnote_char = ODFTranslator.footnote_chars[ self.footnote_chars_idx] self.footnote_chars_idx += 1 el2 = SubElement(el1, 'text:note-citation', attrib={ 'text:label': footnote_char, }) el2.text = footnote_char self.footnote_ref_dict[id] = el1 raise nodes.SkipChildren()
Example #16
Source File: __init__.py From bash-lambda-layer with MIT License | 5 votes |
def visit_comment(self, node): el = self.append_p('textbody') el1 = SubElement(el, 'office:annotation', attrib={}) el2 = SubElement(el1, 'dc:creator', attrib={}) s1 = os.environ.get('USER', '') el2.text = s1 el2 = SubElement(el1, 'text:p', attrib={}) el2.text = node.astext()
Example #17
Source File: __init__.py From bash-lambda-layer with MIT License | 5 votes |
def visit_classifier(self, node): els = self.current_element.getchildren() if len(els) > 0: el = els[-1] el1 = SubElement(el, 'text:span', attrib={'text:style-name': self.rststyle('emphasis') }) el1.text = ' (%s)' % (node.astext(), )
Example #18
Source File: __init__.py From bash-lambda-layer with MIT License | 5 votes |
def visit_emphasis(self, node): el = SubElement(self.current_element, 'text:span', attrib={'text:style-name': self.rststyle('emphasis')}) self.set_current_element(el)
Example #19
Source File: __init__.py From bash-lambda-layer with MIT License | 5 votes |
def depart_label(self, node): if isinstance(node.parent, docutils.nodes.footnote): pass elif self.citation_id is not None: if self.settings.create_links: el = self.append_child('text:reference-mark-end', attrib={ 'text:name': '%s' % (self.citation_id, ), }) el0 = SubElement(self.current_element, 'text:span') el0.text = ']' else: self.current_element.text += ']' self.set_to_parent()
Example #20
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def update_toc_add_numbers(self, collection): for level, el1 in collection: if (el1.tag == 'text:p' and el1.text != 'Table of Contents'): el2 = SubElement(el1, 'text:tab') el2.tail = '9999'
Example #21
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def generate_table_of_content_entry_template(self, el1): for idx in range(1, 11): el2 = SubElement(el1, 'text:table-of-content-entry-template', attrib={ 'text:outline-level': "%d" % (idx, ), 'text:style-name': self.rststyle('contents-%d' % (idx, )), }) el3 = SubElement(el2, 'text:index-entry-chapter') el3 = SubElement(el2, 'text:index-entry-text') el3 = SubElement(el2, 'text:index-entry-tab-stop', attrib={ 'style:leader-char': ".", 'style:type': "right", }) el3 = SubElement(el2, 'text:index-entry-page-number')
Example #22
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def visit_classifier(self, node): els = self.current_element.getchildren() if len(els) > 0: el = els[-1] el1 = SubElement(el, 'text:span', attrib={'text:style-name': self.rststyle('emphasis') }) el1.text = ' (%s)' % (node.astext(), )
Example #23
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def visit_rubric(self, node): style_name = self.rststyle('rubric') classes = node.get('classes') if classes: class1 = classes[0] if class1: style_name = class1 el = SubElement(self.current_element, 'text:h', attrib = { #'text:outline-level': '%d' % section_level, #'text:style-name': 'Heading_20_%d' % section_level, 'text:style-name': style_name, }) text = node.astext() el.text = self.encode(text)
Example #24
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def visit_description(self, node): el = self.append_child('table:table-cell', attrib={ 'table:style-name': 'Table%d.B2' % self.table_count, 'office:value-type': 'string', }) el1 = SubElement(el, 'text:p', attrib={ 'text:style-name': 'Table_20_Contents'}) el1.text = node.astext() raise nodes.SkipChildren()
Example #25
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def visit_line(self, node): style = 'lineblock%d' % self.line_indent_level el1 = SubElement(self.current_element, 'text:p', attrib={ 'text:style-name': self.rststyle(style), }) self.current_element = el1
Example #26
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def depart_label(self, node): if isinstance(node.parent, docutils.nodes.footnote): pass elif self.citation_id is not None: if self.settings.create_links: el = self.append_child('text:reference-mark-end', attrib={ 'text:name': '%s' % (self.citation_id, ), }) el0 = SubElement(self.current_element, 'text:span') el0.text = ']' else: self.current_element.text += ']' self.set_to_parent()
Example #27
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def visit_label(self, node): if isinstance(node.parent, docutils.nodes.footnote): raise nodes.SkipChildren() elif self.citation_id is not None: el = self.append_p('textbody') self.set_current_element(el) if self.settings.create_links: el0 = SubElement(el, 'text:span') el0.text = '[' el1 = self.append_child('text:reference-mark-start', attrib={ 'text:name': '%s' % (self.citation_id, ), }) else: el.text = '['
Example #28
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def visit_footnote_reference(self, node): if self.footnote_level <= 0: id = node.attributes['ids'][0] refid = node.attributes.get('refid') if refid is None: refid = '' if self.settings.endnotes_end_doc: note_class = 'endnote' else: note_class = 'footnote' el1 = self.append_child('text:note', attrib={ 'text:id': '%s' % (refid, ), 'text:note-class': note_class, }) note_auto = str(node.attributes.get('auto', 1)) if isinstance(node, docutils.nodes.citation_reference): citation = '[%s]' % node.astext() el2 = SubElement(el1, 'text:note-citation', attrib={ 'text:label': citation, }) el2.text = citation elif note_auto == '1': el2 = SubElement(el1, 'text:note-citation', attrib={ 'text:label': node.astext(), }) el2.text = node.astext() elif note_auto == '*': if self.footnote_chars_idx >= len( ODFTranslator.footnote_chars): self.footnote_chars_idx = 0 footnote_char = ODFTranslator.footnote_chars[ self.footnote_chars_idx] self.footnote_chars_idx += 1 el2 = SubElement(el1, 'text:note-citation', attrib={ 'text:label': footnote_char, }) el2.text = footnote_char self.footnote_ref_dict[id] = el1 raise nodes.SkipChildren()
Example #29
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def visit_emphasis(self, node): el = SubElement(self.current_element, 'text:span', attrib={'text:style-name': self.rststyle('emphasis')}) self.set_current_element(el)
Example #30
Source File: __init__.py From deepWordBug with Apache License 2.0 | 5 votes |
def visit_comment(self, node): el = self.append_p('textbody') el1 = SubElement(el, 'office:annotation', attrib={}) el2 = SubElement(el1, 'dc:creator', attrib={}) s1 = os.environ.get('USER', '') el2.text = s1 el2 = SubElement(el1, 'text:p', attrib={}) el2.text = node.astext()