Exemplo n.º 1
0
class CT_Path2D(BaseOxmlElement):
    """`a:path` custom element class."""

    close = ZeroOrMore("a:close", successors=())
    lnTo = ZeroOrMore("a:lnTo", successors=())
    moveTo = ZeroOrMore("a:moveTo", successors=())
    w = OptionalAttribute("w", ST_PositiveCoordinate)
    h = OptionalAttribute("h", ST_PositiveCoordinate)

    def add_close(self):
        """Return a newly created `a:close` element.

        The new `a:close` element is appended to this `a:path` element.
        """
        return self._add_close()

    def add_lnTo(self, x, y):
        """Return a newly created `a:lnTo` subtree with end point *(x, y)*.

        The new `a:lnTo` element is appended to this `a:path` element.
        """
        lnTo = self._add_lnTo()
        pt = lnTo._add_pt()
        pt.x, pt.y = x, y
        return lnTo

    def add_moveTo(self, x, y):
        """Return a newly created `a:moveTo` subtree with point *(x, y)*.

        The new `a:moveTo` element is appended to this `a:path` element.
        """
        moveTo = self._add_moveTo()
        pt = moveTo._add_pt()
        pt.x, pt.y = x, y
        return moveTo
Exemplo n.º 2
0
class CT_RelativeRect(BaseOxmlElement):
    """`a:srcRect` element and perhaps others."""

    l = OptionalAttribute("l", ST_Percentage, default=0.0)  # noqa
    t = OptionalAttribute("t", ST_Percentage, default=0.0)
    r = OptionalAttribute("r", ST_Percentage, default=0.0)
    b = OptionalAttribute("b", ST_Percentage, default=0.0)
Exemplo n.º 3
0
class CT_TableCellProperties(BaseOxmlElement):
    """`a:tcPr` custom element class"""

    eg_fillProperties = ZeroOrOneChoice(
        (
            Choice("a:noFill"),
            Choice("a:solidFill"),
            Choice("a:gradFill"),
            Choice("a:blipFill"),
            Choice("a:pattFill"),
            Choice("a:grpFill"),
        ),
        successors=("a:headers", "a:extLst"),
    )
    _tag_seq = ('a:lnL', 'a:lnR', 'a:lnT', 'a:lnB', 'a:solidFill')
    lnL = ZeroOrOne(nsptagname=_tag_seq[0], successors=_tag_seq[1:])
    lnR = ZeroOrOne(nsptagname=_tag_seq[1], successors=_tag_seq[2:])
    lnT = ZeroOrOne(nsptagname=_tag_seq[2], successors=_tag_seq[3:])
    lnB = ZeroOrOne(nsptagname=_tag_seq[3], successors=_tag_seq[4:])
    del _tag_seq

    anchor = OptionalAttribute("anchor", MSO_VERTICAL_ANCHOR)
    marL = OptionalAttribute("marL", ST_Coordinate32)
    marR = OptionalAttribute("marR", ST_Coordinate32)
    marT = OptionalAttribute("marT", ST_Coordinate32)
    marB = OptionalAttribute("marB", ST_Coordinate32)

    def _new_gradFill(self):
        return CT_GradientFillProperties.new_gradFill()
Exemplo n.º 4
0
class CT_LineTailEnd(BaseOxmlElement):
    """
    ''<a:tailEnd>''
    """
    type = RequiredAttribute('type', ST_LineEndType)
    w = OptionalAttribute('w', ST_ReletiveSize)
    len = OptionalAttribute('len', ST_ReletiveSize)
Exemplo n.º 5
0
class CT_Placeholder(BaseOxmlElement):
    """
    ``<p:ph>`` custom element class.
    """

    type = OptionalAttribute("type", PP_PLACEHOLDER, default=PP_PLACEHOLDER.OBJECT)
    orient = OptionalAttribute("orient", ST_Direction, default=ST_Direction.HORZ)
    sz = OptionalAttribute("sz", ST_PlaceholderSize, default=ST_PlaceholderSize.FULL)
    idx = OptionalAttribute("idx", XsdUnsignedInt, default=0)
Exemplo n.º 6
0
class CT_OleObject(BaseOxmlElement):
    """`<p:oleObj>` element, container for an OLE object (e.g. Excel file).

    An OLE object can be either linked or embedded (hence the name).
    """

    progId = OptionalAttribute("progId", XsdString)
    rId = OptionalAttribute("r:id", XsdString)
    showAsIcon = OptionalAttribute("showAsIcon", XsdBoolean, default=False)

    @property
    def is_embedded(self):
        """True when this OLE object is embedded, False when it is linked."""
        return True if len(self.xpath("./p:embed")) > 0 else False
Exemplo n.º 7
0
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
Exemplo n.º 8
0
class CT_TableCellProperties(BaseOxmlElement):
    """`a:tcPr` custom element class"""

    eg_fillProperties = ZeroOrOneChoice(
        (Choice('a:noFill'), Choice('a:solidFill'), Choice('a:gradFill'),
         Choice('a:blipFill'), Choice('a:pattFill'), Choice('a:grpFill')),
        successors=('a:headers', 'a:extLst'))
    anchor = OptionalAttribute('anchor', MSO_VERTICAL_ANCHOR)
    marL = OptionalAttribute('marL', ST_Coordinate32)
    marR = OptionalAttribute('marR', ST_Coordinate32)
    marT = OptionalAttribute('marT', ST_Coordinate32)
    marB = OptionalAttribute('marB', ST_Coordinate32)

    def _new_gradFill(self):
        return CT_GradientFillProperties.new_gradFill()
Exemplo n.º 9
0
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
Exemplo n.º 10
0
class CT_NonVisualDrawingShapeProps(BaseShapeElement):
    """
    ``<p:cNvSpPr>`` custom element class
    """

    spLocks = ZeroOrOne("a:spLocks")
    txBox = OptionalAttribute("txBox", XsdBoolean)
Exemplo n.º 11
0
class CT_LayoutMode(BaseOxmlElement):
    """
    Used for ``<c:xMode>``, ``<c:yMode>``, ``<c:wMode>``, and ``<c:hMode>``
    child elements of CT_ManualLayout.
    """

    val = OptionalAttribute("val", ST_LayoutMode, default=ST_LayoutMode.FACTOR)
Exemplo n.º 12
0
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
Exemplo n.º 13
0
class CT_TextNormalAutofit(BaseOxmlElement):
    """
    <a:normAutofit> element specifying fit text to shape font reduction, etc.
    """
    fontScale = OptionalAttribute('fontScale',
                                  ST_TextFontScalePercentOrPercentString,
                                  default=100.0)
Exemplo n.º 14
0
class CT_NumFmt(BaseOxmlElement):
    """
    ``<c:numFmt>`` element specifying the formatting for number labels on a
    tick mark or data point.
    """
    formatCode = RequiredAttribute('formatCode', XsdString)
    sourceLinked = OptionalAttribute('sourceLinked', XsdBoolean)
Exemplo n.º 15
0
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
Exemplo n.º 16
0
class CT_Orientation(BaseOxmlElement):
    """`c:xAx/c:scaling/c:orientation` element, defining category order.

    Used to reverse the order categories appear in on a bar chart so they start at the
    top rather than the bottom. Because we read top-to-bottom, the default way looks odd
    to many and perhaps most folks. Also applicable to value and date axes.
    """

    val = OptionalAttribute("val",
                            ST_Orientation,
                            default=ST_Orientation.MIN_MAX)
Exemplo n.º 17
0
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)
    del _tag_seq
Exemplo n.º 18
0
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)

    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
Exemplo n.º 19
0
class CT_TableProperties(BaseOxmlElement):
    """
    ``<a:tblPr>`` custom element class
    """
    bandRow = OptionalAttribute('bandRow', XsdBoolean, default=False)
    bandCol = OptionalAttribute('bandCol', XsdBoolean, default=False)
    firstRow = OptionalAttribute('firstRow', XsdBoolean, default=False)
    firstCol = OptionalAttribute('firstCol', XsdBoolean, default=False)
    lastRow = OptionalAttribute('lastRow', XsdBoolean, default=False)
    lastCol = OptionalAttribute('lastCol', XsdBoolean, default=False)
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
class CT_Boolean_Explicit(BaseOxmlElement):
    """Always spells out the `val` attribute, e.g. `val=1`.

    At least one boolean element is improperly interpreted by one or more
    versions of PowerPoint. The `c:overlay` element is interpreted as |False|
    when no `val` attribute is present, contrary to the behavior described in
    the schema. A remedy for this is to interpret a missing `val` attribute
    as |True| (consistent with the spec), but always write the attribute
    whenever there is occasion for changing the element.
    """
    _val = OptionalAttribute('val', XsdBoolean, default=True)

    @property
    def val(self):
        return self._val

    @val.setter
    def val(self, value):
        val_str = '1' if bool(value) is True else '0'
        self.set('val', val_str)
Exemplo n.º 22
0
class CT_TextBodyProperties(BaseOxmlElement):
    """
    <a:bodyPr> custom element class
    """

    eg_textAutoFit = ZeroOrOneChoice(
        (Choice("a:noAutofit"), Choice("a:normAutofit"),
         Choice("a:spAutoFit")),
        successors=("a:scene3d", "a:sp3d", "a:flatTx", "a:extLst"),
    )
    lIns = OptionalAttribute("lIns", ST_Coordinate32, default=Emu(91440))
    tIns = OptionalAttribute("tIns", ST_Coordinate32, default=Emu(45720))
    rIns = OptionalAttribute("rIns", ST_Coordinate32, default=Emu(91440))
    bIns = OptionalAttribute("bIns", ST_Coordinate32, default=Emu(45720))
    anchor = OptionalAttribute("anchor", MSO_VERTICAL_ANCHOR)
    wrap = OptionalAttribute("wrap", ST_TextWrappingType)

    @property
    def autofit(self):
        """
        The autofit setting for the text frame, a member of the
        ``MSO_AUTO_SIZE`` enumeration.
        """
        if self.noAutofit is not None:
            return MSO_AUTO_SIZE.NONE
        if self.normAutofit is not None:
            return MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE
        if self.spAutoFit is not None:
            return MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT
        return None

    @autofit.setter
    def autofit(self, value):
        if value is not None and value not in MSO_AUTO_SIZE._valid_settings:
            raise ValueError(
                "only None or a member of the MSO_AUTO_SIZE enumeration can "
                "be assigned to CT_TextBodyProperties.autofit, got %s" % value)
        self._remove_eg_textAutoFit()
        if value == MSO_AUTO_SIZE.NONE:
            self._add_noAutofit()
        elif value == MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE:
            self._add_normAutofit()
        elif value == MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT:
            self._add_spAutoFit()
Exemplo n.º 23
0
class CT_Blip(BaseOxmlElement):
    """
    <a:blip> element
    """
    rEmbed = OptionalAttribute('r:embed', ST_RelationshipId)
Exemplo n.º 24
0
class CT_Boolean(BaseOxmlElement):
    """
    Common complex type used for elements having a True/False value.
    """
    val = OptionalAttribute('val', XsdBoolean, default=True)
Exemplo n.º 25
0
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)
    baseline = OptionalAttribute("baseline", BaseIntType)
    u = OptionalAttribute("u", MSO_TEXT_UNDERLINE_TYPE)

    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
Exemplo n.º 26
0
class CT_TextParagraphProperties(BaseOxmlElement):
    """
    <a:pPr> custom element class
    """

    _tag_seq = (
        "a:lnSpc",
        "a:spcBef",
        "a:spcAft",
        "a:buClrTx",
        "a:buClr",
        "a:buSzTx",
        "a:buSzPct",
        "a:buSzPts",
        "a:buFontTx",
        "a:buFont",
        "a:buNone",
        "a:buAutoNum",
        "a:buChar",
        "a:buBlip",
        "a:tabLst",
        "a:defRPr",
        "a:extLst",
    )
    lnSpc = ZeroOrOne("a:lnSpc", successors=_tag_seq[1:])
    spcBef = ZeroOrOne("a:spcBef", successors=_tag_seq[2:])
    spcAft = ZeroOrOne("a:spcAft", successors=_tag_seq[3:])
    defRPr = ZeroOrOne("a:defRPr", successors=_tag_seq[16:])
    lvl = OptionalAttribute("lvl", ST_TextIndentLevelType, default=0)
    algn = OptionalAttribute("algn", PP_PARAGRAPH_ALIGNMENT)
    del _tag_seq

    @property
    def line_spacing(self):
        """
        The spacing between baselines of successive lines in this paragraph.
        A float value indicates a number of lines. A |Length| value indicates
        a fixed spacing. Value is contained in `./a:lnSpc/a:spcPts/@val` or
        `./a:lnSpc/a:spcPct/@val`. Value is |None| if no element is present.
        """
        lnSpc = self.lnSpc
        if lnSpc is None:
            return None
        if lnSpc.spcPts is not None:
            return lnSpc.spcPts.val
        return lnSpc.spcPct.val

    @line_spacing.setter
    def line_spacing(self, value):
        self._remove_lnSpc()
        if value is None:
            return
        if isinstance(value, Length):
            self._add_lnSpc().set_spcPts(value)
        else:
            self._add_lnSpc().set_spcPct(value)

    @property
    def space_after(self):
        """
        The EMU equivalent of the centipoints value in
        `./a:spcAft/a:spcPts/@val`.
        """
        spcAft = self.spcAft
        if spcAft is None:
            return None
        spcPts = spcAft.spcPts
        if spcPts is None:
            return None
        return spcPts.val

    @space_after.setter
    def space_after(self, value):
        self._remove_spcAft()
        if value is not None:
            self._add_spcAft().set_spcPts(value)

    @property
    def space_before(self):
        """
        The EMU equivalent of the centipoints value in
        `./a:spcBef/a:spcPts/@val`.
        """
        spcBef = self.spcBef
        if spcBef is None:
            return None
        spcPts = spcBef.spcPts
        if spcPts is None:
            return None
        return spcPts.val

    @space_before.setter
    def space_before(self, value):
        self._remove_spcBef()
        if value is not None:
            self._add_spcBef().set_spcPts(value)
Exemplo n.º 27
0
class CT_PresetLineDashProperties(BaseOxmlElement):
    """`a:prstDash` custom element class"""

    val = OptionalAttribute("val", MSO_LINE_DASH_STYLE)
Exemplo n.º 28
0
class CT_RelativeRect(BaseOxmlElement):
    """`a:srcRect` element and perhaps others."""
    l = OptionalAttribute('l', ST_Percentage, default=0.0)
    t = OptionalAttribute('t', ST_Percentage, default=0.0)
    r = OptionalAttribute('r', ST_Percentage, default=0.0)
    b = OptionalAttribute('b', ST_Percentage, default=0.0)
Exemplo n.º 29
0
class CT_TableCell(BaseOxmlElement):
    """`a:tc` custom element class"""

    _tag_seq = ("a:txBody", "a:tcPr", "a:extLst")
    txBody = ZeroOrOne("a:txBody", successors=_tag_seq[1:])
    tcPr = ZeroOrOne("a:tcPr", successors=_tag_seq[2:])
    del _tag_seq

    gridSpan = OptionalAttribute("gridSpan", XsdInt, default=1)
    rowSpan = OptionalAttribute("rowSpan", XsdInt, default=1)
    hMerge = OptionalAttribute("hMerge", XsdBoolean, default=False)
    vMerge = OptionalAttribute("vMerge", XsdBoolean, default=False)

    @property
    def anchor(self):
        """
        String held in ``anchor`` attribute of ``<a:tcPr>`` child element of
        this ``<a:tc>`` element.
        """
        if self.tcPr is None:
            return None
        return self.tcPr.anchor

    @anchor.setter
    def anchor(self, anchor_enum_idx):
        """
        Set value of anchor attribute on ``<a:tcPr>`` child element
        """
        if anchor_enum_idx is None and self.tcPr is None:
            return
        tcPr = self.get_or_add_tcPr()
        tcPr.anchor = anchor_enum_idx

    def append_ps_from(self, spanned_tc):
        """Append `a:p` elements taken from *spanned_tc*.

        Any non-empty paragraph elements in *spanned_tc* are removed and
        appended to the text-frame of this cell. If *spanned_tc* is left with
        no content after this process, a single empty `a:p` element is added
        to ensure the cell is compliant with the spec.
        """
        source_txBody = spanned_tc.get_or_add_txBody()
        target_txBody = self.get_or_add_txBody()

        # ---if source is empty, there's nothing to do---
        if source_txBody.is_empty:
            return

        # ---a single empty paragraph in target is overwritten---
        if target_txBody.is_empty:
            target_txBody.clear_content()

        for p in source_txBody.p_lst:
            target_txBody.append(p)

        # ---neither source nor target can be left without ps---
        source_txBody.unclear_content()
        target_txBody.unclear_content()

    @property
    def col_idx(self):
        """Offset of this cell's column in its table."""
        # ---tc elements come before any others in `a:tr` element---
        return self.getparent().index(self)

    @property
    def is_merge_origin(self):
        """True if cell is top-left in merged cell range."""
        if self.gridSpan > 1 and not self.vMerge:
            return True
        if self.rowSpan > 1 and not self.hMerge:
            return True
        return False

    @property
    def is_spanned(self):
        """True if cell is in merged cell range but not merge origin cell."""
        return self.hMerge or self.vMerge

    @property
    def marT(self):
        """
        Read/write integer top margin value represented in ``marT`` attribute
        of the ``<a:tcPr>`` child element of this ``<a:tc>`` element. If the
        attribute is not present, the default value ``45720`` (0.05 inches)
        is returned for top and bottom; ``91440`` (0.10 inches) is the
        default for left and right. Assigning |None| to any ``marX``
        property clears that attribute from the element, effectively setting
        it to the default value.
        """
        return self._get_marX("marT", 45720)

    @marT.setter
    def marT(self, value):
        self._set_marX("marT", value)

    @property
    def marR(self):
        """
        Right margin value represented in ``marR`` attribute.
        """
        return self._get_marX("marR", 91440)

    @marR.setter
    def marR(self, value):
        self._set_marX("marR", value)

    @property
    def marB(self):
        """
        Bottom margin value represented in ``marB`` attribute.
        """
        return self._get_marX("marB", 45720)

    @marB.setter
    def marB(self, value):
        self._set_marX("marB", value)

    @property
    def marL(self):
        """
        Left margin value represented in ``marL`` attribute.
        """
        return self._get_marX("marL", 91440)

    @marL.setter
    def marL(self, value):
        self._set_marX("marL", value)

    @classmethod
    def new(cls):
        """Return a new `a:tc` element subtree."""
        xml = cls._tc_tmpl()
        tc = parse_xml(xml)
        return tc

    @property
    def row_idx(self):
        """Offset of this cell's row in its table."""
        return self.getparent().row_idx

    @property
    def tbl(self):
        """Table element this cell belongs to."""
        return self.xpath("ancestor::a:tbl")[0]

    @property
    def text(self):
        """str text contained in cell"""
        # ---note this shadows lxml _Element.text---
        txBody = self.txBody
        if txBody is None:
            return ""
        return "\n".join([p.text for p in txBody.p_lst])

    def _get_marX(self, attr_name, default):
        """
        Generalized method to get margin values.
        """
        if self.tcPr is None:
            return Emu(default)
        return Emu(int(self.tcPr.get(attr_name, default)))

    def _new_txBody(self):
        return CT_TextBody.new_a_txBody()

    def _set_marX(self, marX, value):
        """
        Set value of marX attribute on ``<a:tcPr>`` child element. If *marX*
        is |None|, the marX attribute is removed. *marX* is a string, one of
        ``('marL', 'marR', 'marT', 'marB')``.
        """
        if value is None and self.tcPr is None:
            return
        tcPr = self.get_or_add_tcPr()
        setattr(tcPr, marX, value)

    @classmethod
    def _tc_tmpl(cls):
        return (
            "<a:tc %s>\n"
            "  <a:txBody>\n"
            "    <a:bodyPr/>\n"
            "    <a:lstStyle/>\n"
            "    <a:p/>\n"
            "  </a:txBody>\n"
            "  <a:tcPr/>\n"
            "</a:tc>" % nsdecls("a")
        )
Exemplo n.º 30
0
class CT_HeadEndProperties(BaseOxmlElement):
    """`a:headEnd` custom element class"""
    type = OptionalAttribute('type', MSO_ARROWHEAD_STYLE)