当前位置: 首页>>代码示例>>Python>>正文


Python OdfParser.startElement方法代码示例

本文整理汇总了Python中appy.pod.odf_parser.OdfParser.startElement方法的典型用法代码示例。如果您正苦于以下问题:Python OdfParser.startElement方法的具体用法?Python OdfParser.startElement怎么用?Python OdfParser.startElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在appy.pod.odf_parser.OdfParser的用法示例。


在下文中一共展示了OdfParser.startElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: startElement

# 需要导入模块: from appy.pod.odf_parser import OdfParser [as 别名]
# 或者: from appy.pod.odf_parser.OdfParser import startElement [as 别名]
 def startElement(self, elem, attrs):
     e = OdfParser.startElement(self, elem, attrs)
     self.styleTag = '%s:style' % e.ns(e.NS_STYLE)
     if elem == self.styleTag:
         e.state = PARSING_STYLE
         nameAttr = '%s:name' % e.ns(e.NS_STYLE)
         familyAttr = '%s:family' % e.ns(e.NS_STYLE)
         classAttr = '%s:class' % e.ns(e.NS_STYLE)
         displayNameAttr = '%s:display-name' % e.ns(e.NS_STYLE)
         # Create the style
         style = Style(name=attrs[nameAttr], family=attrs[familyAttr])
         if classAttr in attrs:
             style.styleClass = attrs[classAttr]
         if displayNameAttr in attrs:
             style.displayName = attrs[displayNameAttr]
         # Record this style in the environment
         e.styles[style.name] = style
         e.currentStyle = style
         levelKey = '%s:default-outline-level' % e.ns(e.NS_STYLE)
         if levelKey in attrs and attrs[levelKey].strip():
             style.outlineLevel = int(attrs[levelKey])
     else:
         if e.state == PARSING_STYLE:
             # I am parsing tags within the style.
             if elem == ('%s:text-properties' % e.ns(e.NS_STYLE)):
                 fontSizeKey = '%s:font-size' % e.ns(e.NS_FO)
                 if fontSizeKey in attrs:
                     e.currentStyle.setFontSize(attrs[fontSizeKey])
开发者ID:PeterEymann,项目名称:appypod,代码行数:30,代码来源:styles_manager.py

示例2: startElement

# 需要导入模块: from appy.pod.odf_parser import OdfParser [as 别名]
# 或者: from appy.pod.odf_parser.OdfParser import startElement [as 别名]
 def startElement(self, elem, attrs):
     e = OdfParser.startElement(self, elem, attrs)
     ns = e.onStartElement()
     officeNs = ns[e.NS_OFFICE]
     textNs = ns[e.NS_TEXT]
     if elem in e.ignorableElements:
         e.state = e.IGNORING
     elif elem == ('%s:annotation' % officeNs):
         e.state = e.READING_STATEMENT
     elif (elem == ('%s:change-start' % textNs)) or \
          (elem == ('%s:conditional-text' % textNs)):
         e.state = e.READING_EXPRESSION
         e.exprHasStyle = False
     else:
         if e.state == e.IGNORING:
             pass
         elif e.state == e.READING_CONTENT:
             if elem in e.impactableElements:
                 if e.mode == e.ADD_IN_SUBBUFFER:
                     e.addSubBuffer()
                 e.currentBuffer.addElement(e.currentElem.name)
             e.currentBuffer.dumpStartElement(elem, attrs)
         elif e.state == e.READING_STATEMENT:
             pass
         elif e.state == e.READING_EXPRESSION:
             if (elem == ('%s:span' % textNs)) and \
                not e.currentContent.strip():
                 e.currentBuffer.dumpStartElement(elem, attrs)
                 e.exprHasStyle = True
     e.manageInserts()
开发者ID:a-iv,项目名称:appy,代码行数:32,代码来源:pod_parser.py

示例3: startElement

# 需要导入模块: from appy.pod.odf_parser import OdfParser [as 别名]
# 或者: from appy.pod.odf_parser.OdfParser import startElement [as 别名]
 def startElement(self, elem, attrs):
     e = OdfParser.startElement(self, elem, attrs)
     ns = e.onStartElement()
     officeNs = ns[e.NS_OFFICE]
     textNs = ns[e.NS_TEXT]
     tableNs = ns[e.NS_TABLE]
     if elem in e.ignorableElems:
         e.state = e.IGNORING
     elif elem == e.tags['annotation']:
         # Be it in an ODT or ODS template, an annotation is considered to
         # contain a POD statement.
         e.state = e.READING_STATEMENT
     elif elem in e.exprStartElems:
         # Any track-changed text or being in a conditional or input field is
         # considered to be a POD expression.
         e.state = e.READING_EXPRESSION
         e.exprHasStyle = False
     elif (elem == e.tags['table-cell']) and \
          attrs.has_key(e.tags['formula']) and \
          attrs.has_key(e.tags['value-type']) and \
          (attrs[e.tags['value-type']] == 'string') and \
          attrs[e.tags['formula']].startswith('of:="'):
         # In an ODS template, any cell containing a formula of type "string"
         # and whose content is expressed as a string between double quotes
         # (="...") is considered to contain a POD expression. But here it
         # is a special case: we need to dump the cell; the expression is not
         # directly contained within this cell; the expression will be
         # contained in the next inner paragraph. So we must here dump the
         # cell, but without some attributes, because the "formula" will be
         # converted to the result of evaluating the POD expression.
         if e.mode == e.ADD_IN_SUBBUFFER:
             e.addSubBuffer()
         e.currentBuffer.addElement(e.currentElem.name)
         hook = e.currentBuffer.dumpStartElement(elem, attrs,
                  ignoreAttrs=(e.tags['formula'], e.tags['string-value'],
                               e.tags['value-type']),
                  hook=True)
         # We already have the POD expression: remember it on the env.
         e.currentOdsExpression = attrs[e.tags['string-value']]
         e.currentOdsHook = hook
     else:
         if e.state == e.IGNORING:
             pass
         elif e.state == e.READING_CONTENT:
             if elem in e.impactableElems:
                 if e.mode == e.ADD_IN_SUBBUFFER:
                     e.addSubBuffer()
                 e.currentBuffer.addElement(e.currentElem.name)
             e.currentBuffer.dumpStartElement(elem, attrs)
         elif e.state == e.READING_STATEMENT:
             pass
         elif e.state == e.READING_EXPRESSION:
             if (elem == (e.tags['span'])) and not e.currentContent.strip():
                 e.currentBuffer.dumpStartElement(elem, attrs)
                 e.exprHasStyle = True
     e.manageInserts()
开发者ID:tonibagur,项目名称:appy,代码行数:58,代码来源:pod_parser.py

示例4: startElement

# 需要导入模块: from appy.pod.odf_parser import OdfParser [as 别名]
# 或者: from appy.pod.odf_parser.OdfParser import startElement [as 别名]
    def startElement(self, elem, attrs):
        e = OdfParser.startElement(self, elem, attrs)
        ns = e.onStartElement()
        if elem == e.tags['style']:
            e.state = PARSING_STYLE
            # Create the style
            style = Style(name=attrs[e.tags['name']],
                          family=attrs[e.tags['family']])
            classAttr = e.tags['class']
            if attrs.has_key(classAttr): style.styleClass = attrs[classAttr]
            dnAttr = e.tags['display-name']
            if attrs.has_key(dnAttr): style.displayName = attrs[dnAttr]
            dolAttr = e.tags['default-outline-level']
            if attrs.has_key(dolAttr) and attrs[dolAttr].strip():
                style.outlineLevel = int(attrs[dolAttr])
            # Record this style in the environment
            e.styles[style.name] = style
            e.currentStyle = style

        elif elem == e.tags['page-layout']:
            e.state = PARSING_PAGE_LAYOUT
            pageLayout = PageLayout(attrs[e.tags['name']])
            # Record this page layout in the environment
            e.pageLayouts[pageLayout.name] = pageLayout
            e.currentPageLayout = pageLayout

        elif elem == e.tags['master-styles']:
            e.state = PARSING_MASTER_STYLES

        elif e.state == PARSING_STYLE:
            # Find properties within this style definition
            if elem == e.tags['text-properties']:
                fontSizeAttr = e.tags['font-size']
                if attrs.has_key(fontSizeAttr):
                    e.currentStyle.setFontSize(attrs[fontSizeAttr])

        elif e.state == PARSING_PAGE_LAYOUT:
            # Find properties within this page layout definition
            if elem == e.tags['page-layout-properties']:
                e.currentPageLayout.setProperties(e, attrs)

        elif e.state == PARSING_MASTER_STYLES:
            # I am parsing section "master-styles"
            if elem == e.tags['master-page']:
                plnAttr = e.tags['page-layout-name']
                if attrs.has_key(plnAttr):
                    e.masterLayoutName = attrs[plnAttr]
开发者ID:tonibagur,项目名称:appy,代码行数:49,代码来源:styles_manager.py

示例5: startElement

# 需要导入模块: from appy.pod.odf_parser import OdfParser [as 别名]
# 或者: from appy.pod.odf_parser.OdfParser import startElement [as 别名]
 def startElement(self, elem, attrs):
     e = OdfParser.startElement(self, elem, attrs)
     # Do we enter into an annotation ?
     if elem == "%s:annotation" % e.ns(e.NS_OFFICE):
         self.inAnnotation = True
         self.textEncountered = False
     elif elem == "%s:p" % e.ns(e.NS_TEXT):
         if self.inAnnotation:
             if not self.textEncountered:
                 self.textEncountered = True
             else:
                 self.ignore = True
     if not self.ignore:
         self.res += "<%s" % elem
         for attrName, attrValue in list(attrs.items()):
             self.res += ' %s="%s"' % (attrName, attrValue)
         self.res += ">"
开发者ID:PeterEymann,项目名称:appypod,代码行数:19,代码来源:Tester.py


注:本文中的appy.pod.odf_parser.OdfParser.startElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。