def add_paragraph(self): """ Return new |_Paragraph| instance appended to the sequence of paragraphs contained in this text frame. """ # <a:p> elements are last in txBody, so can simply append new one p = _Element("a:p", namespaces("a")) self.__txBody.append(p) return _Paragraph(p)
def add_paragraph(self): """ Return new |_Paragraph| instance appended to the sequence of paragraphs contained in this text frame. """ # <a:p> elements are last in txBody, so can simply append new one p = _Element('a:p', namespaces('a')) self.__txBody.append(p) return _Paragraph(p)
def font(self): """ |_Font| object containing run-level character properties for the text in this run. Character properties can and perhaps most often are inherited from parent objects such as the paragraph and slide layout the run is contained in. Only those specifically assigned at the run level are contained in the |_Font| object. """ if not hasattr(self.__r, "rPr"): self.__r.insert(0, _Element("a:rPr", namespaces("a"))) return _Font(self.__r.rPr)
def add_run(self): """Return a new run appended to the runs in this paragraph.""" r = _Element("a:r", namespaces("a")) _SubElement(r, "a:t") # work out where to insert it, ahead of a:endParaRPr if there is one endParaRPr = _child(self.__p, "a:endParaRPr") if endParaRPr is not None: endParaRPr.addprevious(r) else: self.__p.append(r) return _Run(r)
def font(self): """ |_Font| object containing run-level character properties for the text in this run. Character properties can and perhaps most often are inherited from parent objects such as the paragraph and slide layout the run is contained in. Only those specifically assigned at the run level are contained in the |_Font| object. """ if not hasattr(self.__r, 'rPr'): self.__r.insert(0, _Element('a:rPr', namespaces('a'))) return _Font(self.__r.rPr)
def add_run(self): """Return a new run appended to the runs in this paragraph.""" r = _Element('a:r', namespaces('a')) _SubElement(r, 'a:t') # work out where to insert it, ahead of a:endParaRPr if there is one endParaRPr = _child(self.__p, 'a:endParaRPr') if endParaRPr is not None: endParaRPr.addprevious(r) else: self.__p.append(r) return _Run(r)
def _set_level(self, level): """ Set indentation level of this paragraph to *level*, an integer value between 0 and 8 inclusive. """ if not isinstance(level, int) or level < 0 or level > 8: msg = "paragraph level must be integer between 0 and 8 inclusive" raise ValueError(msg) if not hasattr(self.__p, "pPr"): pPr = _Element("a:pPr", namespaces("a")) self.__p.insert(0, pPr) self.__p.pPr.set("lvl", str(level))
def _set_level(self, level): """ Set indentation level of this paragraph to *level*, an integer value between 0 and 8 inclusive. """ if not isinstance(level, int) or level < 0 or level > 8: msg = "paragraph level must be integer between 0 and 8 inclusive" raise ValueError(msg) if not hasattr(self.__p, 'pPr'): pPr = _Element('a:pPr', namespaces('a')) self.__p.insert(0, pPr) self.__p.pPr.set('lvl', str(level))
def font(self): """ |_Font| object containing default character properties for the runs in this paragraph. These character properties override default properties inherited from parent objects such as the text frame the paragraph is contained in and they may be overridden by character properties set at the run level. """ # A _Font instance is created on first access if it doesn't exist. # This can cause "litter" <a:pPr> and <a:defRPr> elements to be # included in the XML if the _Font element is referred to but not # populated with values. if not hasattr(self.__p, "pPr"): pPr = _Element("a:pPr", namespaces("a")) self.__p.insert(0, pPr) if not hasattr(self.__p.pPr, "defRPr"): _SubElement(self.__p.pPr, "a:defRPr") return _Font(self.__p.pPr.defRPr)
def font(self): """ |_Font| object containing default character properties for the runs in this paragraph. These character properties override default properties inherited from parent objects such as the text frame the paragraph is contained in and they may be overridden by character properties set at the run level. """ # A _Font instance is created on first access if it doesn't exist. # This can cause "litter" <a:pPr> and <a:defRPr> elements to be # included in the XML if the _Font element is referred to but not # populated with values. if not hasattr(self.__p, 'pPr'): pPr = _Element('a:pPr', namespaces('a')) self.__p.insert(0, pPr) if not hasattr(self.__p.pPr, 'defRPr'): _SubElement(self.__p.pPr, 'a:defRPr') return _Font(self.__p.pPr.defRPr)
# module globals ------------------------------------------------------------- def absjoin(*paths): return os.path.abspath(os.path.join(*paths)) thisdir = os.path.split(__file__)[0] test_file_dir = absjoin(thisdir, 'test_files') test_image_path = absjoin(test_file_dir, 'python-icon.jpeg') test_bmp_path = absjoin(test_file_dir, 'python.bmp') new_image_path = absjoin(test_file_dir, 'monty-truth.png') test_pptx_path = absjoin(test_file_dir, 'test.pptx') images_pptx_path = absjoin(test_file_dir, 'with_images.pptx') nsmap = namespaces('a', 'r', 'p') def _sldLayout1(): path = os.path.join(thisdir, 'test_files/slideLayout1.xml') sldLayout = oxml_parse(path).getroot() return sldLayout def _sldLayout1_shapes(): sldLayout = _sldLayout1() spTree = sldLayout.xpath('./p:cSld/p:spTree', namespaces=nsmap)[0] shapes = _ShapeCollection(spTree) return shapes
Classes that implement PowerPoint shapes such as picture, textbox, and table. """ from numbers import Number from pptx.constants import MSO from pptx.oxml import _get_or_add, qn, _Element, _SubElement, CT_GraphicalObjectFrame, CT_Picture, CT_Shape from pptx.spec import autoshape_types, namespaces, ParagraphAlignment, slide_ph_basenames, VerticalAnchor from pptx.spec import PH_ORIENT_HORZ, PH_ORIENT_VERT, PH_SZ_FULL, PH_TYPE_DT, PH_TYPE_FTR, PH_TYPE_OBJ, PH_TYPE_SLDNUM from pptx.util import Collection # import logging # log = logging.getLogger('pptx.shapes') # default namespace map for use in lxml calls _nsmap = namespaces("a", "r", "p") def _child(element, child_tagname, nsmap=None): """ Return direct child of *element* having *child_tagname* or |None| if no such child element is present. """ # use default nsmap if not specified if nsmap is None: nsmap = _nsmap xpath = "./%s" % child_tagname matching_children = element.xpath(xpath, namespaces=nsmap) return matching_children[0] if len(matching_children) else None
from numbers import Number from pptx.constants import MSO from pptx.oxml import (_get_or_add, qn, _Element, _SubElement, CT_GraphicalObjectFrame, CT_Picture, CT_Shape) from pptx.spec import (autoshape_types, namespaces, ParagraphAlignment, slide_ph_basenames, VerticalAnchor) from pptx.spec import (PH_ORIENT_HORZ, PH_ORIENT_VERT, PH_SZ_FULL, PH_TYPE_DT, PH_TYPE_FTR, PH_TYPE_OBJ, PH_TYPE_SLDNUM) from pptx.util import Collection # import logging # log = logging.getLogger('pptx.shapes') # default namespace map for use in lxml calls _nsmap = namespaces('a', 'r', 'p') def _child(element, child_tagname, nsmap=None): """ Return direct child of *element* having *child_tagname* or |None| if no such child element is present. """ # use default nsmap if not specified if nsmap is None: nsmap = _nsmap xpath = './%s' % child_tagname matching_children = element.xpath(xpath, namespaces=nsmap) return matching_children[0] if len(matching_children) else None