コード例 #1
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
 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)
コード例 #2
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
 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)
コード例 #3
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
 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)
コード例 #4
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
 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)
コード例 #5
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
 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)
コード例 #6
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
 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)
コード例 #7
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
 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))
コード例 #8
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
 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))
コード例 #9
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
 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)
コード例 #10
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
 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)
コード例 #11
0

# 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

コード例 #12
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
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

コード例 #13
0
ファイル: shapes.py プロジェクト: Gonzillaaa/python-pptx
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