class CT_NonVisualDrawingProps(BaseOxmlElement): """ ``<p:cNvPr>`` custom element class. """ _tag_seq = ("a:hlinkClick", "a:hlinkHover", "a:extLst") hlinkClick = ZeroOrOne("a:hlinkClick", successors=_tag_seq[1:]) hlinkHover = ZeroOrOne("a:hlinkHover", successors=_tag_seq[2:]) id = RequiredAttribute("id", ST_DrawingElementId) name = RequiredAttribute("name", XsdString) descr = OptionalAttribute("descr", XsdString, default="") hidden = OptionalAttribute("hidden", XsdBoolean, default=False ) title = OptionalAttribute("title", XsdString, default="") del _tag_seq
class CT_BlipFillProperties(BaseOxmlElement): """ Custom element class for <a:blipFill> element. """ _tag_seq = ("a:blip", "a:srcRect", "a:tile", "a:stretch") blip = ZeroOrOne("a:blip", successors=_tag_seq[1:]) srcRect = ZeroOrOne("a:srcRect", successors=_tag_seq[2:]) del _tag_seq def crop(self, cropping): """ Set `a:srcRect` child to crop according to *cropping* values. """ srcRect = self._add_srcRect() srcRect.l, srcRect.t, srcRect.r, srcRect.b = cropping
class CT_ChartLines(BaseOxmlElement): """Used for `c:majorGridlines` and `c:minorGridlines`. Specifies gridlines visual properties such as color and width. """ spPr = ZeroOrOne("c:spPr", successors=())
class CT_CommonSlideData(BaseOxmlElement): """`p:cSld` element.""" _tag_seq = ("p:bg", "p:spTree", "p:custDataLst", "p:controls", "p:extLst") bg = ZeroOrOne("p:bg", successors=_tag_seq[1:]) spTree = OneAndOnlyOne("p:spTree") del _tag_seq name = OptionalAttribute("name", XsdString, default="") def get_or_add_bgPr(self): """Return `p:bg/p:bgPr` grandchild. If no such grandchild is present, any existing `p:bg` child is first removed and a new default `p:bg` with noFill settings is added. """ bg = self.bg if bg is None or bg.bgPr is None: self._change_to_noFill_bg() return self.bg.bgPr def _change_to_noFill_bg(self): """Establish a `p:bg` child with no-fill settings. Any existing `p:bg` child is first removed. """ self._remove_bg() bg = self.get_or_add_bg() bg.add_noFill_bgPr() return bg
class CT_PresetGeometry2D(BaseOxmlElement): """ <a:prstGeom> custom element class """ avLst = ZeroOrOne("a:avLst") prst = RequiredAttribute("prst", MSO_AUTO_SHAPE_TYPE) @property def gd_lst(self): """ Sequence containing the ``gd`` element children of ``<a:avLst>`` child element, empty if none are present. """ avLst = self.avLst if avLst is None: return [] return avLst.gd_lst def rewrite_guides(self, guides): """ Remove any ``<a:gd>`` element children of ``<a:avLst>`` and replace them with ones having (name, val) in *guides*. """ self._remove_avLst() avLst = self._add_avLst() for name, val in guides: gd = avLst._add_gd() gd.name = name gd.fmla = "val %d" % val
class CT_ExternalData(BaseOxmlElement): """ `<c:externalData>` element, defining link to embedded Excel package part containing the chart data. """ autoUpdate = ZeroOrOne('c:autoUpdate') rId = RequiredAttribute('r:id', XsdString)
class CT_NonVisualDrawingShapeProps(BaseShapeElement): """ ``<p:cNvSpPr>`` custom element class """ spLocks = ZeroOrOne("a:spLocks") txBox = OptionalAttribute("txBox", XsdBoolean)
class CT_RegularTextRun(BaseOxmlElement): """`a:r` custom element class""" rPr = ZeroOrOne("a:rPr", successors=("a:t", )) t = OneAndOnlyOne("a:t") @property def text(self): """(unicode) str containing text of (required) `a:t` child""" text = self.t.text # t.text is None when t element is empty, e.g. '<a:t/>' return to_unicode(text) if text is not None else "" @text.setter def text(self, str): """*str* is unicode value to replace run text.""" self.t.text = self._escape_ctrl_chars(str) @staticmethod def _escape_ctrl_chars(s): """Return str after replacing each control character with a plain-text escape. For example, a BEL character (x07) would appear as "_x0007_". Horizontal-tab (x09) and line-feed (x0A) are not escaped. All other characters in the range x00-x1F are escaped. """ return re.sub(r"([\x00-\x08\x0B-\x1F])", lambda match: "_x%04X_" % ord(match.group(1)), s)
class CT_Layout(BaseOxmlElement): """ ``<c:layout>`` custom element class """ manualLayout = ZeroOrOne('c:manualLayout', successors=('c:extLst', )) @property def horz_offset(self): """ The float value in ./c:manualLayout/c:x when c:layout/c:manualLayout/c:xMode@val == "factor". 0.0 if that XPath expression finds no match. """ manualLayout = self.manualLayout if manualLayout is None: return 0.0 return manualLayout.horz_offset @horz_offset.setter def horz_offset(self, offset): """ Set the value of ./c:manualLayout/c:x@val to *offset* and ./c:manualLayout/c:xMode@val to "factor". Remove ./c:manualLayout if *offset* == 0. """ if offset == 0.0: self._remove_manualLayout() return manualLayout = self.get_or_add_manualLayout() manualLayout.horz_offset = offset
class CT_NotesSlide(BaseOxmlElement): """ ``<p:notes>`` element, root of a notesSlide part """ cSld = OneAndOnlyOne('p:cSld') clrMapOvr = ZeroOrOne('p:clrMapOvr', successors=('p:transition', 'p:timing', 'p:extLst')) @classmethod def new(cls): """ Return a new ``<p:notes>`` element configured as a base slide shape. """ return parse_xml(cls._notes_xml()) @staticmethod def _notes_xml(): """From http://msdn.microsoft.com/en-us/library/office/gg278319%28v=office.15%29.aspx#sectionSection4 """ return ( '<p:notes %s>\n' ' <p:cSld>\n' ' <p:spTree>\n' ' <p:nvGrpSpPr>\n' ' <p:cNvPr id="1"\n' ' name="" />\n' ' <p:cNvGrpSpPr />\n' ' <p:nvPr />\n' ' </p:nvGrpSpPr>\n' ' <p:grpSpPr>\n' ' <a:xfrm xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />\n' ' </p:grpSpPr>\n' ' <p:sp>\n' ' <p:nvSpPr>\n' ' <p:cNvPr id="2"\n' ' name="" />\n' ' <p:cNvSpPr>\n' ' <a:spLocks noGrp="1"\n' ' xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />\n' ' </p:cNvSpPr>\n' ' <p:nvPr>\n' ' <p:ph />\n' ' </p:nvPr>\n' ' </p:nvSpPr>\n' ' <p:spPr />\n' ' <p:txBody>\n' ' <a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />\n' ' <a:lstStyle xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />\n' ' <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">\n' ' <a:endParaRPr />\n' ' </a:p>\n' ' </p:txBody>\n' ' </p:sp>\n' ' </p:spTree>\n' ' </p:cSld>\n' ' <p:clrMapOvr>\n' ' <a:masterClrMapping xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />\n' ' </p:clrMapOvr>\n' '</p:notes>\n' % nsdecls('p', 'a', 'r'))
class CT_ApplicationNonVisualDrawingProps(BaseOxmlElement): """ ``<p:nvPr>`` element """ ph = ZeroOrOne('p:ph', successors=('a:audioCd', 'a:wavAudioFile', 'a:audioFile', 'a:videoFile', 'a:quickTimeFile', 'p:custDataLst', 'p:extLst'))
class CT_TextField(BaseOxmlElement): """ <a:fld> field element, for either a slide number or date field """ rPr = ZeroOrOne('a:rPr', successors=('a:pPr', 'a:t')) t = ZeroOrOne('a:t', successors=()) @property def text(self): """ The text of the ``<a:t>`` child element. """ t = self.t if t is None: return u'' text = t.text return to_unicode(text) if text is not None else u''
class CT_GroupShapeProperties(BaseOxmlElement): """ The ``<p:grpSpPr>`` element """ xfrm = ZeroOrOne('a:xfrm', successors=('a:noFill', 'a:solidFill', 'a:gradFill', 'a:blipFill', 'a:pattFill', 'a:grpFill', 'a:effectLst', 'a:effectDag', 'a:scene3d', 'a:extLst'))
class CT_GroupShapeProperties(BaseOxmlElement): """p:grpSpPr element """ _tag_seq = ( 'a:xfrm', 'a:noFill', 'a:solidFill', 'a:gradFill', 'a:blipFill', 'a:pattFill', 'a:grpFill', 'a:effectLst', 'a:effectDag', 'a:scene3d', 'a:extLst', ) xfrm = ZeroOrOne('a:xfrm', successors=_tag_seq[1:]) effectLst = ZeroOrOne('a:effectLst', successors=_tag_seq[8:]) del _tag_seq
class CT_SlideMaster(_BaseSlideElement): """ ``<p:sldMaster>`` element, root of a slide master part """ _tag_seq = ('p:cSld', 'p:clrMap', 'p:sldLayoutIdLst', 'p:transition', 'p:timing', 'p:hf', 'p:txStyles', 'p:extLst') cSld = OneAndOnlyOne('p:cSld') sldLayoutIdLst = ZeroOrOne('p:sldLayoutIdLst', successors=_tag_seq[3:]) del _tag_seq
class CT_Tx(BaseOxmlElement): """ ``<c:tx>`` element containing the text for a label on a data point or other chart item. """ strRef = ZeroOrOne('c:strRef') rich = ZeroOrOne('c:rich') def _new_rich(self): return parse_xml('<c:rich %s>' ' <a:bodyPr/>' ' <a:lstStyle/>' ' <a:p>' ' <a:pPr>' ' <a:defRPr/>' ' </a:pPr>' ' </a:p>' '</c:rich>' % nsdecls('c', 'a'))
class CT_TextParagraph(BaseOxmlElement): """ <a:p> custom element class """ pPr = ZeroOrOne('a:pPr', successors=('a:r', 'a:br', 'a:fld', 'a:endParaRPr')) r = ZeroOrMore('a:r', successors=('a:endParaRPr', )) br = ZeroOrMore('a:br', successors=('a:endParaRPr', )) endParaRPr = ZeroOrOne('a:endParaRPr', successors=()) def add_br(self): """ Return a newly appended <a:br> element. """ return self._add_br() def add_r(self, text=None): """ Return a newly appended <a:r> element. """ r = self._add_r() if text: r.t.text = text return r def append_text(self, text): """ Add *text* at the end of this paragraph element, translating line feed characters ('\n') into ``<a:br>`` elements. """ _ParagraphTextAppender.append_to_p_from_text(self, text) @property def content_children(self): """ A sequence containing the text-container child elements of this ``<a:p>`` element, i.e. (a:r|a:br|a:fld). """ text_types = (CT_RegularTextRun, CT_TextLineBreak, CT_TextField) return tuple(elm for elm in self if isinstance(elm, text_types)) def _new_r(self): r_xml = '<a:r %s><a:t/></a:r>' % nsdecls('a') return parse_xml(r_xml)
class CT_Tx(BaseOxmlElement): """ ``<c:tx>`` element containing the text for a label on a data point or other chart item. """ strRef = ZeroOrOne("c:strRef") rich = ZeroOrOne("c:rich") def _new_rich(self): return parse_xml("<c:rich %s>" " <a:bodyPr/>" " <a:lstStyle/>" " <a:p>" " <a:pPr>" " <a:defRPr/>" " </a:pPr>" " </a:p>" "</c:rich>" % nsdecls("c", "a"))
class CT_Background(BaseOxmlElement): """`p:bg` element.""" # ---these two are actually a choice, not a sequence, but simpler for # ---present purposes this way. _tag_seq = ('p:bgPr', 'p:bgRef') bgPr = ZeroOrOne('p:bgPr', successors=()) bgRef = ZeroOrOne('p:bgRef', successors=()) del _tag_seq def add_noFill_bgPr(self): """Return a new `p:bgPr` element with noFill properties.""" xml = ('<p:bgPr %s>\n' ' <a:noFill/>\n' ' <a:effectLst/>\n' '</p:bgPr>' % nsdecls('a', 'p')) bgPr = parse_xml(xml) self._insert_bgPr(bgPr) return bgPr
class CT_RegularTextRun(BaseOxmlElement): """`a:r` custom element class""" rPr = ZeroOrOne('a:rPr', successors=('a:t', )) t = OneAndOnlyOne('a:t') @property def text(self): """(unicode) str containing text of (required) `a:t` child""" text = self.t.text # t.text is None when t element is empty, e.g. '<a:t/>' return to_unicode(text) if text is not None else u''
class CT_TextLineBreak(BaseOxmlElement): """ <a:br> line break element """ rPr = ZeroOrOne('a:rPr', successors=()) @property def text(self): """ Unconditionally a single line feed character. A line break element can contain no text other than the implicit line feed it represents. """ return u'\n'
class CT_ManualLayout(BaseOxmlElement): """ ``<c:manualLayout>`` custom element class """ _tag_seq = ( "c:layoutTarget", "c:xMode", "c:yMode", "c:wMode", "c:hMode", "c:x", "c:y", "c:w", "c:h", "c:extLst", ) xMode = ZeroOrOne("c:xMode", successors=_tag_seq[2:]) x = ZeroOrOne("c:x", successors=_tag_seq[6:]) del _tag_seq @property def horz_offset(self): """ The float value in ./c:x@val when ./c:xMode@val == "factor". 0.0 when ./c:x is not present or ./c:xMode@val != "factor". """ x, xMode = self.x, self.xMode if x is None or xMode is None or xMode.val != ST_LayoutMode.FACTOR: return 0.0 return x.val @horz_offset.setter def horz_offset(self, offset): """ Set the value of ./c:x@val to *offset* and ./c:xMode@val to "factor". """ self.get_or_add_xMode().val = ST_LayoutMode.FACTOR self.get_or_add_x().val = offset
class CT_TextLineBreak(BaseOxmlElement): """`a:br` line break element""" rPr = ZeroOrOne("a:rPr", successors=()) @property def text(self): """Unconditionally a single vertical-tab character. A line break element can contain no text other than the implicit line feed it represents. """ return "\v"
class CT_Title(BaseOxmlElement): """`c:title` custom element class.""" _tag_seq = ("c:tx", "c:layout", "c:overlay", "c:spPr", "c:txPr", "c:extLst") tx = ZeroOrOne("c:tx", successors=_tag_seq[1:]) spPr = ZeroOrOne("c:spPr", successors=_tag_seq[4:]) del _tag_seq def get_or_add_tx_rich(self): """Return `c:tx/c:rich`, newly created if not present. Return the `c:rich` grandchild at `c:tx/c:rich`. Both the `c:tx` and `c:rich` elements are created if not already present. Any `c:tx/c:strRef` element is removed. (Such an element would contain a cell reference for the axis title text in the chart's Excel worksheet.) """ tx = self.get_or_add_tx() tx._remove_strRef() return tx.get_or_add_rich() @property def tx_rich(self): """Return `c:tx/c:rich` or |None| if not present.""" richs = self.xpath("c:tx/c:rich") if not richs: return None return richs[0] @staticmethod def new_title(): """Return "loose" `c:title` element containing default children.""" return parse_xml( "<c:title %s>" " <c:layout/>" ' <c:overlay val="0"/>' "</c:title>" % nsdecls("c") )
class CT_TextCharacterProperties(BaseOxmlElement): """`a:rPr, a:defRPr, and `a:endParaRPr` custom element class. 'rPr' is short for 'run properties', and it corresponds to the |Font| proxy class. """ eg_fillProperties = ZeroOrOneChoice( (Choice('a:noFill'), Choice('a:solidFill'), Choice('a:gradFill'), Choice('a:blipFill'), Choice('a:pattFill'), Choice('a:grpFill')), successors=('a:effectLst', 'a:effectDag', 'a:highlight', 'a:uLnTx', 'a:uLn', 'a:uFillTx', 'a:uFill', 'a:latin', 'a:ea', 'a:cs', 'a:sym', 'a:hlinkClick', 'a:hlinkMouseOver', 'a:rtl', 'a:extLst')) latin = ZeroOrOne('a:latin', successors=('a:ea', 'a:cs', 'a:sym', 'a:hlinkClick', 'a:hlinkMouseOver', 'a:rtl', 'a:extLst')) hlinkClick = ZeroOrOne('a:hlinkClick', successors=('a:hlinkMouseOver', 'a:rtl', 'a:extLst')) lang = OptionalAttribute('lang', MSO_LANGUAGE_ID) sz = OptionalAttribute('sz', ST_TextFontSize) b = OptionalAttribute('b', XsdBoolean) i = OptionalAttribute('i', XsdBoolean) u = OptionalAttribute('u', MSO_TEXT_UNDERLINE_TYPE) baseline = OptionalAttribute('baseline', XsdInt) def _new_gradFill(self): return CT_GradientFillProperties.new_gradFill() def add_hlinkClick(self, rId): """ Add an <a:hlinkClick> child element with r:id attribute set to *rId*. """ hlinkClick = self.get_or_add_hlinkClick() hlinkClick.rId = rId return hlinkClick
class CT_PatternFillProperties(BaseOxmlElement): """`a:pattFill` custom element class""" _tag_seq = ('a:fgClr', 'a:bgClr') fgClr = ZeroOrOne('a:fgClr', successors=_tag_seq[1:]) bgClr = ZeroOrOne('a:bgClr', successors=_tag_seq[2:]) del _tag_seq prst = OptionalAttribute('prst', MSO_PATTERN_TYPE) def _new_bgClr(self): """Override default to add minimum subtree.""" xml = ('<a:bgClr %s>\n' ' <a:srgbClr val="FFFFFF"/>\n' '</a:bgClr>\n') % nsdecls('a') bgClr = parse_xml(xml) return bgClr def _new_fgClr(self): """Override default to add minimum subtree.""" xml = ('<a:fgClr %s>\n' ' <a:srgbClr val="000000"/>\n' '</a:fgClr>\n') % nsdecls('a') fgClr = parse_xml(xml) return fgClr
class CT_GradientFillProperties(BaseOxmlElement): """`a:gradFill` custom element class.""" _tag_seq = ('a:gsLst', 'a:lin', 'a:path', 'a:tileRect') gsLst = ZeroOrOne('a:gsLst', successors=_tag_seq[1:]) lin = ZeroOrOne('a:lin', successors=_tag_seq[2:]) path = ZeroOrOne('a:path', successors=_tag_seq[3:]) del _tag_seq @classmethod def new_gradFill(cls): """Return newly-created "loose" default gradient subtree.""" return parse_xml( '<a:gradFill %s rotWithShape="1">\n' ' <a:gsLst>\n' ' <a:gs pos="0">\n' ' <a:schemeClr val="accent1">\n' ' <a:tint val="100000"/>\n' ' <a:shade val="100000"/>\n' ' <a:satMod val="130000"/>\n' ' </a:schemeClr>\n' ' </a:gs>\n' ' <a:gs pos="100000">\n' ' <a:schemeClr val="accent1">\n' ' <a:tint val="50000"/>\n' ' <a:shade val="100000"/>\n' ' <a:satMod val="350000"/>\n' ' </a:schemeClr>\n' ' </a:gs>\n' ' </a:gsLst>\n' ' <a:lin scaled="0"/>\n' '</a:gradFill>\n' % nsdecls('a') ) def _new_gsLst(self): """Override default to add minimum subtree.""" return CT_GradientStopList.new_gsLst()
class CT_LineProperties(BaseOxmlElement): """Custom element class for <a:ln> element""" _tag_seq = ('a:noFill', 'a:solidFill', 'a:gradFill', 'a:pattFill', 'a:prstDash', 'a:custDash', 'a:round', 'a:bevel', 'a:miter', 'a:headEnd', 'a:tailEnd', 'a:extLst') eg_lineFillProperties = ZeroOrOneChoice( (Choice('a:noFill'), Choice('a:solidFill'), Choice('a:gradFill'), Choice('a:pattFill')), successors=_tag_seq[4:]) prstDash = ZeroOrOne('a:prstDash', successors=_tag_seq[5:]) custDash = ZeroOrOne('a:custDash', successors=_tag_seq[6:]) del _tag_seq w = OptionalAttribute('w', ST_LineWidth, default=Emu(0)) @property def eg_fillProperties(self): """ Required to fulfill the interface used by dml.fill. """ return self.eg_lineFillProperties @property def prstDash_val(self): """Return value of `val` attribute of `a:prstDash` child. Return |None| if not present. """ prstDash = self.prstDash if prstDash is None: return None return prstDash.val @prstDash_val.setter def prstDash_val(self, val): self._remove_custDash() prstDash = self.get_or_add_prstDash() prstDash.val = val
class CT_RegularTextRun(BaseOxmlElement): """ Custom element class for <a:r> elements. """ rPr = ZeroOrOne('a:rPr', successors=('a:t', )) t = OneAndOnlyOne('a:t') @property def text(self): """ The text of the ``<a:t>`` child element. """ text = self.t.text # t.text is None when t element is empty, e.g. '<a:t/>' return to_unicode(text) if text is not None else u''
class CT_Parent(BaseOxmlElement): """ ``<p:parent>`` element, an invented element for use in testing. """ eg_zooChoice = ZeroOrOneChoice( (Choice('p:choice'), Choice('p:choice2')), successors=('p:oomChild', 'p:oooChild') ) oomChild = OneOrMore('p:oomChild', successors=( 'p:oooChild', 'p:zomChild', 'p:zooChild' )) oooChild = OneAndOnlyOne('p:oooChild') zomChild = ZeroOrMore('p:zomChild', successors=('p:zooChild',)) zooChild = ZeroOrOne('p:zooChild', successors=()) optAttr = OptionalAttribute('p:optAttr', ST_IntegerType) reqAttr = RequiredAttribute('reqAttr', ST_IntegerType)