Beispiel #1
0
    def startElementNS(self, tag, qname, attrs):
        if tag in self.triggers:
            self.parse = True
        if self.doc._parsing != "styles.xml" and tag == (OFFICENS,
                                                         'font-face-decls'):
            self.parse = False
        if self.parse == False:
            return

        self.level = self.level + 1
        # Add any accumulated text content
        content = ''.join(self.data)
        if content:
            self.parent.addText(content, check_grammar=False)
            self.data = []
        # Create the element
        attrdict = {}
        for (att, value) in attrs.items():
            attrdict[att] = value
        try:
            e = Element(qname=tag, qattributes=attrdict, check_grammar=False)
            self.curr = e
        except AttributeError as v:
            print("Error: %s" % v)

        if tag == (OFFICENS, 'automatic-styles'):
            e = self.doc.automaticstyles
        elif tag == (OFFICENS, 'body'):
            e = self.doc.body
        elif tag == (OFFICENS, 'master-styles'):
            e = self.doc.masterstyles
        elif tag == (OFFICENS, 'meta'):
            e = self.doc.meta
        elif tag == (OFFICENS, 'scripts'):
            e = self.doc.scripts
        elif tag == (OFFICENS, 'settings'):
            e = self.doc.settings
        elif tag == (OFFICENS, 'styles'):
            e = self.doc.styles
        elif self.doc._parsing == "styles.xml" and tag == (OFFICENS,
                                                           'font-face-decls'):
            e = self.doc.fontfacedecls
        elif hasattr(self, 'parent'):
            self.parent.addElement(e, check_grammar=False)
        self.parent = e
def main():
    doc = OpenDocumentText()
    p = P(text=u'text')
    df = odf.draw.Frame(zindex=0, anchortype='as-char')
    p.addElement(df)
    doc.text.addElement(p)

    formula = u'c=sqrt(a^2+b^2)'
    math = Math()
    annot = Element(qname=(MATHNS, u'annotation'))
    annot.addText(formula, check_grammar=False)
    annot.setAttribute((MATHNS, 'encoding'),
                       'StarMath 5.0',
                       check_grammar=False)
    math.addElement(annot)
    do = odf.draw.Object()
    do.addElement(math)
    df.addElement(do)

    outputfile = u'result'
    doc.save(outputfile, True)
Beispiel #3
0
def StyleRefElement(stylename=None, classnames=None, **args):
    qattrs = {}
    if stylename is not None:
        f = stylename.getAttrNS(STYLENS, 'family')
        if f == 'graphic':
            qattrs[(DRAWNS, u'style-name')] = stylename
        elif f == 'presentation':
            qattrs[(PRESENTATIONNS, u'style-name')] = stylename
        else:
            raise ValueError(
                "Style's family must be either 'graphic' or 'presentation'")
    if classnames is not None:
        f = classnames[0].getAttrNS(STYLENS, 'family')
        if f == 'graphic':
            qattrs[(DRAWNS, u'class-names')] = classnames
        elif f == 'presentation':
            qattrs[(PRESENTATIONNS, u'class-names')] = classnames
        else:
            raise ValueError(
                "Style's family must be either 'graphic' or 'presentation'")
    return Element(qattributes=qattrs, **args)
Beispiel #4
0
def EventListener(**args):
    return Element(qname=(SCRIPTNS, 'event-listener'), **args)
Beispiel #5
0
def DataPilotGroup(**args):
    return Element(qname=(TABLENS, 'data-pilot-group'), **args)
Beispiel #6
0
def DataPilotField(**args):
    return Element(qname=(TABLENS, 'data-pilot-field'), **args)
Beispiel #7
0
def CutOffs(**args):
    return Element(qname=(TABLENS, 'cut-offs'), **args)
Beispiel #8
0
def ContentValidations(**args):
    return Element(qname=(TABLENS, 'content-validations'), **args)
Beispiel #9
0
def ChangeTrackTableCell(**args):
    return Element(qname=(TABLENS, 'change-track-table-cell'), **args)
Beispiel #10
0
def TableRows(**args):
    return Element(qname=(TABLENS, 'table-rows'), **args)
Beispiel #11
0
def TableRowGroup(**args):
    return Element(qname=(TABLENS, 'table-row-group'), **args)
Beispiel #12
0
def TableHeaderRows(**args):
    return Element(qname=(TABLENS, 'table-header-rows'), **args)
Beispiel #13
0
def TableHeaderColumns(**args):
    return Element(qname=(TABLENS, 'table-header-columns'), **args)
Beispiel #14
0
def TableColumns(**args):
    return Element(qname=(TABLENS, 'table-columns'), **args)
Beispiel #15
0
def TableColumnGroup(**args):
    return Element(qname=(TABLENS, 'table-column-group'), **args)
Beispiel #16
0
def CellRangeSource(**args):
    args.setdefault('type', 'simple')
    return Element(qname=(TABLENS, 'cell-range-source'), **args)
Beispiel #17
0
def ChangeDeletion(**args):
    return Element(qname=(TABLENS, 'change-deletion'), **args)
Beispiel #18
0
def TableSource(**args):
    args.setdefault('type', 'simple')
    return Element(qname=(TABLENS, 'table-source'), **args)
Beispiel #19
0
def Consolidation(**args):
    return Element(qname=(TABLENS, 'consolidation'), **args)
Beispiel #20
0
def TableTemplate(**args):
    return Element(qname=(TABLENS, 'table-template'), **args)
Beispiel #21
0
def CoveredTableCell(**args):
    return Element(qname=(TABLENS, 'covered-table-cell'), **args)
Beispiel #22
0
def TargetRangeAddress(**args):
    return Element(qname=(TABLENS, 'target-range-address'), **args)
Beispiel #23
0
def DataPilotDisplayInfo(**args):
    return Element(qname=(TABLENS, 'data-pilot-display-info'), **args)
Beispiel #24
0
def CellContentChange(**args):
    return Element(qname=(TABLENS, 'cell-content-change'), **args)
Beispiel #25
0
def DataPilotFieldReference(**args):
    return Element(qname=(TABLENS, 'data-pilot-field-reference'), **args)
Beispiel #26
0
def Title(**args):
    return Element(qname=(TABLENS, 'title'), **args)
Beispiel #27
0
def DataPilotGroupMember(**args):
    return Element(qname=(TABLENS, 'data-pilot-group-member'), **args)
Beispiel #28
0
def TrackedChanges(**args):
    return Element(qname=(TABLENS, 'tracked-changes'), **args)
Beispiel #29
0
def Math(**args):
    return Element(qname = (MATHNS,'math'), **args)
Beispiel #30
0
def CellContentDeletion(**args):
    return Element(qname=(TABLENS, 'cell-content-deletion'), **args)