o
    7 h4                     @  s  d Z ddlmZ ddlZddlZddlmZmZmZm	Z	m
Z
mZ ddlmZmZ ddlmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlm Z m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z: ddl;m<Z<m=Z= erddl>m?Z? ddl@mAZA ddlBmCZC ddlmDZDmEZE ddlFmGZG ddlHmIZI ddlJmKZK ddlLmMZM ddlNmOZO dd lPmQZQmRZR dd!lSmTZT dd"l;mUZU G d#d$ d$e:ZVG d%d& d&eVZWG d'd( d(eWZXG d)d* d*eWZYG d+d, d,eVZZG d-d. d.eVZ[G d/d0 d0eVZ\G d1d2 d2eVZ]G d3d4 d4e]Z^G d5d6 d6e]Z_G d7d8 d8e_Z`G d9d: d:e:ZadQdAdBZbdQdCdDZcdQdEdFZddQdGdHZedRdIdJZfdQdKdLZgG dMdN dNehZiG dOdP dPehZjdS )Sz:The shape tree, the structure that holds a slide's shapes.    )annotationsN)IOTYPE_CHECKINGCallableIterableIteratorcast)PP_PLACEHOLDERPROG_ID)SPEAKER_IMAGE_BYTESVideo)CONTENT_TYPE)qn)CT_Shape)CT_GraphicalObjectFrame)
CT_Picture)ST_Direction)AutoShapeTypeShape)	BaseShape)	Connector)FreeformBuilder)GraphicFrame)
GroupShape)MoviePicture)	ChartPlaceholderLayoutPlaceholderMasterPlaceholderNotesSlidePlaceholderPicturePlaceholderPlaceholderGraphicFramePlaceholderPictureSlidePlaceholderTablePlaceholder)ParentedElementProxy)Emulazyproperty)Chart)	ChartData)XL_CHART_TYPE)MSO_CONNECTOR_TYPE	MSO_SHAPE)ShapeElement)CT_Connector)CT_GroupShape)	ImagePart)	SlidePart)SlideSlideLayout)ProvidesPart)Lengthc                      s   e Zd ZdZd1 fddZd2ddZd3ddZd4ddZd5ddZd6ddZ	e
d7ddZejd8d!dZed9d$d%Zd:d'd(Zd;d+d,Ze
d4d-d.Zd<d/d0Z  ZS )=_BaseShapeszBase class for a shape collection appearing in a slide-type object.

    Subclasses include Slide, SlideLayout, and SlideMaster. Provides common methods.
    spTreer/   parentr4   c                   s"   t t| || || _d | _d S N)superr6   __init___spTree_cached_max_shape_id)selfr7   r8   	__class__ ]/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/pptx/shapes/shapetree.pyr;   S   s   
z_BaseShapes.__init__idxintreturnr   c                 C  s:   t |  }z|| }W n ty   tdw | |S )z4Return shape at `idx` in sequence, e.g. `shapes[2]`.zshape index out of range)list_iter_member_elms
IndexError_shape_factory)r>   rC   
shape_elms	shape_elmrA   rA   rB   __getitem__X   s   
z_BaseShapes.__getitem__Iterator[BaseShape]c                 c  s     |   D ]}| |V  qdS )zBGenerate a reference to each shape in the collection, in sequence.N)rG   rI   r>   rK   rA   rA   rB   __iter__a   s   z_BaseShapes.__iter__c                 C  s   t |  }t|S )zReturn count of shapes in this shape tree.

        A group shape contributes 1 to the total, without regard to the number of shapes contained
        in the group.
        )rF   rG   len)r>   rJ   rA   rA   rB   __len__f   s   z_BaseShapes.__len__placeholderr   Nonec           	      C  sP   |j }|j|j|j|jf\}}}}| j}| |||}| j|||||| dS )z3Add a new placeholder shape based on `placeholder`.N)	elementph_type	ph_orientph_szph_idx_next_shape_id_next_ph_namer<   add_placeholder)	r>   rR   sprU   orientszrC   id_namerA   rA   rB   clone_placeholdero   s
   z_BaseShapes.clone_placeholderrU   r	   strc                 C  sb   t jdt jdt jdt jdt jdt jdt jdt jdt j	d	t j
d
t jdt jdt jdt jdt jdi| S )a  Return the base name for a placeholder of `ph_type` in this shape collection.

        There is some variance between slide types, for example a notes slide uses a different
        name for the body placeholder, so this method can be overriden by subclasses.
        zClipArt PlaceholderzText PlaceholderTitlezChart PlaceholderDate PlaceholderFooter PlaceholderHeader PlaceholderzMedia PlaceholderzContent PlaceholderzSmartArt PlaceholderzPicture PlaceholderSlide Number PlaceholderSubtitlezTable Placeholder)r	   BITMAPBODYCENTER_TITLECHARTDATEFOOTERHEADER
MEDIA_CLIPOBJECT	ORG_CHARTPICTURESLIDE_NUMBERSUBTITLETABLETITLEr>   rU   rA   rA   rB   ph_basenamew   s$   z_BaseShapes.ph_basenameboolc                 C  s
   | j duS )a  True if "turbo-add" mode is enabled. Read/Write.

        EXPERIMENTAL: This feature can radically improve performance when adding large numbers
        (hundreds of shapes) to a slide. It works by caching the last shape ID used and
        incrementing that value to assign the next shape id. This avoids repeatedly searching all
        shape ids in the slide each time a new ID is required.

        Performance is not noticeably improved for a slide with a relatively small number of
        shapes, but because the search time rises with the square of the shape count, this option
        can be useful for optimizing generation of a slide composed of many shapes.

        Shape-id collisions can occur (causing a repair error on load) if more than one |Slide|
        object is used to interact with the same slide in the presentation. Note that the |Slides|
        collection creates a new |Slide| object each time a slide is accessed (e.g. `slide =
        prs.slides[0]`, so you must be careful to limit use to a single |Slide| object.
        N)r=   r>   rA   rA   rB   turbo_add_enabled   s   
z_BaseShapes.turbo_add_enabledvaluec                 C  s$   t |}|r| jj| _d S d | _d S r9   )rz   r<   max_shape_idr=   )r>   r}   enablerA   rA   rB   r|      s   rK   r-   c                 C     dS )zSReturn true if `shape_elm` represents a member of this collection, False otherwise.TrA   rK   rA   rA   rB   _is_member_elm   s   z_BaseShapes._is_member_elmIterator[ShapeElement]c                 c  s&    | j  D ]
}| |r|V  qdS )zGenerate each child of the `p:spTree` element that corresponds to a shape.

        Items appear in XML document order.
        N)r<   iter_shape_elmsr   rN   rA   rA   rB   rG      s   
z_BaseShapes._iter_member_elmsidr]   c                 C  sV   |  |}|tjkrd| }|d }| jd}	 d||f }||vr&	 |S |d7 }q)a  Next unique placeholder name for placeholder shape of type `ph_type`.

        Usually will be standard placeholder root name suffixed with id-1, e.g.
        _next_ph_name(ST_PlaceholderType.TBL, 4, 'horz') ==> 'Table Placeholder 3'. The number is
        incremented as necessary to make the name unique within the collection. If `orient` is
        `'vert'`, the placeholder name is prefixed with `'Vertical '`.
        zVertical %s   z//p:cNvPr/@nameT%s %d)ry   r   VERTr<   xpath)r>   rU   r   r]   basenameZnumpartnamesr`   rA   rA   rB   rZ      s   

z_BaseShapes._next_ph_namec                 C  s*   | j dur|  j d7  _ | j S | jjd S )zReturn a unique shape id suitable for use with a new shape.

        The returned id is 1 greater than the maximum shape id used so far. In practice, the
        minimum id is 2 because the spTree element is always assigned id="1".
        Nr   )r=   r<   r~   r{   rA   rA   rB   rY      s   
z_BaseShapes._next_shape_idc                 C  
   t || S HReturn an instance of the appropriate shape proxy class for `shape_elm`.)BaseShapeFactoryrN   rA   rA   rB   rI         
z_BaseShapes._shape_factory)r7   r/   r8   r4   )rC   rD   rE   r   )rE   rM   rE   rD   )rR   r   rE   rS   rU   r	   rE   rb   )rE   rz   )r}   rz   rK   r-   rE   rz   )rE   r   )rU   r	   r   rD   r]   rb   rE   rb   rK   r-   rE   r   )__name__
__module____qualname____doc__r;   rL   rO   rQ   ra   ry   propertyr|   setterstaticmethodr   rG   rZ   rY   rI   __classcell__rA   rA   r?   rB   r6   M   s&    

	

	


	r6   c                      s   e Zd ZU dZded< ded< dh fd	d
ZdiddZdjdd Zdkdld%d&Z	'	'	'	'	'dmdnd6d7Z		'	'dodpd:d;Z
dqd?d@ZdrdAdBZ	DdsdtdKdLZdudPdQZdvdTdUZdwdWdXZdxd\d]ZdydadbZdzdcddZd{dfdgZ  ZS )|_BaseGroupShapesz/Base class for shape-trees that can add shapes.r1   partr/   _elementgrpSpr8   r4   c                   s   t t| || || _d S r9   )r:   r   r;   _grpSp)r>   r   r8   r?   rA   rB   r;      s   
z_BaseGroupShapes.__init__
chart_typer*   xr5   ycxcy
chart_datar)   rE   r(   c           	      C  s8   | j ||}| |||||}|   td| |S )aB  Add a new chart of `chart_type` to the slide.

        The chart is positioned at (`x`, `y`), has size (`cx`, `cy`), and depicts `chart_data`.
        `chart_type` is one of the :ref:`XlChartType` enumeration values. `chart_data` is a
        |ChartData| object populated with the categories and series values for the chart.

        Note that a |GraphicFrame| shape object is returned, not the |Chart| object contained in
        that graphic frame shape. The chart object may be accessed using the :attr:`chart`
        property of the returned |GraphicFrame| object.
        r(   )r   add_chart_part_add_chart_graphicFrame_recalculate_extentsr   rI   )	r>   r   r   r   r   r   r   rIdgraphicFramerA   rA   rB   	add_chart   s   z_BaseGroupShapes.add_chartconnector_typer+   begin_xbegin_yend_xend_yr   c                 C  s*   |  |||||}|   tt| |S )a@  Add a newly created connector shape to the end of this shape tree.

        `connector_type` is a member of the :ref:`MsoConnectorType` enumeration and the end-point
        values are specified as EMU values. The returned connector is of type `connector_type` and
        has begin and end points as specified.
        )
_add_cxnSpr   r   r   rI   )r>   r   r   r   r   r   cxnSprA   rA   rB   add_connector  s   z_BaseGroupShapes.add_connectorrA   shapesIterable[BaseShape]r   c                 C  sF   t |}| j }|D ]	}||jd q|r|  tt| |S )a  Return a |GroupShape| object newly appended to this shape tree.

        The group shape is empty and must be populated with shapes using methods on its shape
        tree, available on its `.shapes` property. The position and extents of the group shape are
        determined by the shapes it contains; its position and extents are recalculated each time
        a shape is added to it.
        zp:extLst)tupler   	add_grpSpinsert_element_beforerecalculate_extentsr   r   rI   )r>   r   r   shaperA   rA   rB   add_group_shape  s   
z _BaseGroupShapes.add_group_shapeNobject_filestr | IO[bytes]prog_idrb   lefttopwidthLength | Noneheight	icon_filestr | IO[bytes] | None
icon_widthicon_heightr   c
                 C  sD   t | | j|||||||||	}
| j|
 |   tt| |
S )aq  Return newly-created GraphicFrame shape embedding `object_file`.

        The returned graphic-frame shape contains `object_file` as an embedded OLE object. It is
        displayed as an icon at `left`, `top` with size `width`, `height`. `width` and `height`
        may be omitted when `prog_id` is a member of `PROG_ID`, in which case the default icon
        size is used. This is advised for best appearance where applicable because it avoids an
        icon with a "stretched" appearance.

        `object_file` may either be a str path to a file or file-like object (such as
        `io.BytesIO`) containing the bytes of the object to be embedded (such as an Excel file).

        `prog_id` can be either a member of `pptx.enum.shapes.PROG_ID` or a str value like
        `"Adobe.Exchange.7"` determined by inspecting the XML generated by PowerPoint for an
        object of the desired type.

        `icon_file` may either be a str path to an image file or a file-like object containing the
        image. The image provided will be displayed in lieu of the OLE object; double-clicking on
        the image opens the object (subject to operating-system limitations). The image file can
        be any supported image file. Those produced by PowerPoint itself are generally EMF and can
        be harvested from a PPTX package that embeds such an object. PNG and JPG also work fine.

        `icon_width` and `icon_height` are `Length` values (e.g. Emu() or Inches()) that describe
        the size of the icon image within the shape. These should be omitted unless a custom
        `icon_file` is provided. The dimensions must be discovered by inspecting the XML.
        Automatic resizing of the OLE-object shape can occur when the icon is double-clicked if
        these values are not as set by PowerPoint. This behavior may only manifest in the Windows
        version of PowerPoint.
        )	_OleObjectElementCreatorr   rY   r<   appendr   r   r   rI   )r>   r   r   r   r   r   r   r   r   r   r   rA   rA   rB   add_ole_object(  s    (z_BaseGroupShapes.add_ole_object
image_filer   c           	      C  s<   | j |\}}| ||||||}|   tt| |S )a3  Add picture shape displaying image in `image_file`.

        `image_file` can be either a path to a file (a string) or a file-like object. The picture
        is positioned with its top-left corner at (`top`, `left`). If `width` and `height` are
        both |None|, the native size of the image is used. If only one of `width` or `height` is
        used, the unspecified dimension is calculated to preserve the aspect ratio of the image.
        If both are specified, the picture is stretched to fit, without regard to its native
        aspect ratio.
        )r   get_or_add_image_part_add_pic_from_image_partr   r   r   rI   )	r>   r   r   r   r   r   
image_partr   picrA   rA   rB   add_picturea  s   z_BaseGroupShapes.add_pictureautoshape_type_idr,   r   c                 C  s2   t |}| |||||}|   tt| |S )a  Return new |Shape| object appended to this shape tree.

        `autoshape_type_id` is a member of :ref:`MsoAutoShapeType` e.g. `MSO_SHAPE.RECTANGLE`
        specifying the type of shape to be added. The remaining arguments specify the new shape's
        position and size.
        )r   _add_spr   r   r   rI   )r>   r   r   r   r   r   autoshape_typer\   rA   rA   rB   	add_shapew  s   	z_BaseGroupShapes.add_shapec                 C  s(   |  ||||}|   tt| |S )zReturn newly added text box shape appended to this shape tree.

        The text box is of the specified size, located at the specified position on the slide.
        )_add_textbox_spr   r   r   rI   )r>   r   r   r   r   r\   rA   rA   rB   add_textbox  s   z_BaseGroupShapes.add_textboxr         ?start_xfloatstart_yscaletuple[float, float] | floatr   c                 C  s,   t |tr|n||f\}}t| ||||S )a  Return |FreeformBuilder| object to specify a freeform shape.

        The optional `start_x` and `start_y` arguments specify the starting pen position in local
        coordinates. They will be rounded to the nearest integer before use and each default to
        zero.

        The optional `scale` argument specifies the size of local coordinates proportional to
        slide coordinates (EMU). If the vertical scale is different than the horizontal scale
        (local coordinate units are "rectangular"), a pair of numeric values can be provided as
        the `scale` argument, e.g. `scale=(1.0, 2.0)`. In this case the first number is
        interpreted as the horizontal (X) scale and the second as the vertical (Y) scale.

        A convenient method for calculating scale is to divide a |Length| object by an equivalent
        count of local coordinate units, e.g. `scale = Inches(1)/1000` for 1000 local units per
        inch.
        )
isinstancer   r   new)r>   r   r   r   Zx_scaleZy_scalerA   rA   rB   build_freeform  s   z_BaseGroupShapes.build_freeformr   r   rD   c                 C  s   t | j }||jS )zxReturn the index of `shape` in this sequence.

        Raises |ValueError| if `shape` is not in the collection.
        )rF   r   r   indexrT   )r>   r   rJ   rA   rA   rB   r     s   z_BaseGroupShapes.indexr   r   c           	   	   C  s8   | j }d|d  }t|||||||}| j| |S )zReturn new `p:graphicFrame` element appended to this shape tree.

        The `p:graphicFrame` element has the specified position and size and refers to the chart
        part identified by `rId`.
        zChart %dr   )rY   r   new_chart_graphicFramer<   r   )	r>   r   r   r   r   r   shape_idr`   r   rA   rA   rB   r     s   z(_BaseGroupShapes._add_chart_graphicFramer.   c                 C  sp   | j }d|d  }||k||k}}	t||t||}
}t|| t|| }}| j||||
|||||		S )zReturn a newly-added `p:cxnSp` element as specified.

        The `p:cxnSp` element is for a connector of `connector_type` beginning at (`begin_x`,
        `begin_y`) and extending to (`end_x`, `end_y`).
        zConnector %dr   )rY   minabsr   	add_cxnSp)r>   r   r   r   r   r   r_   r`   flipHflipVr   r   r   r   rA   rA   rB   r     s   z_BaseGroupShapes._add_cxnSpr   r0   r   c              
   C  sF   | j }|||\}}	d|d  }
|j}| j||
||||||	}|S )a1  Return a newly appended `p:pic` element as specified.

        The `p:pic` element displays the image in `image_part` with size and position specified by
        `x`, `y`, `cx`, and `cy`. The element is appended to the shape tree, causing it to be
        displayed first in z-order on the slide.
        z
Picture %dr   )rY   r   descr   add_pic)r>   r   r   r   r   r   r   r_   	scaled_cx	scaled_cyr`   r   r   rA   rA   rB   r     s   z)_BaseGroupShapes._add_pic_from_image_partr   r   r   c           	   	   C  s6   | j }d|j|d f }| j|||j||||}|S )zReturn newly-added `p:sp` element as specified.

        `p:sp` element is of `autoshape_type` at position (`x`, `y`) and of size (`cx`, `cy`).
        r   r   )rY   r   r   add_autoshapeprst)	r>   r   r   r   r   r   r_   r`   r\   rA   rA   rB   r     s   z_BaseGroupShapes._add_spc                 C  s,   | j }d|d  }| j||||||}|S )zvReturn newly-appended textbox `p:sp` element.

        Element has position (`x`, `y`) and size (`cx`, `cy`).
        z
TextBox %dr   )rY   r<   r   )r>   r   r   r   r   r_   r`   r\   rA   rA   rB   r     s   z _BaseGroupShapes._add_textbox_sprS   c                 C  r   zAdjust position and size to incorporate all contained shapes.

        This would typically be called when a contained shape is added, removed, or its position
        or size updated.
        NrA   r{   rA   rA   rB   r     s   z%_BaseGroupShapes._recalculate_extents)r   r/   r8   r4   )r   r*   r   r5   r   r5   r   r5   r   r5   r   r)   rE   r(   )r   r+   r   r5   r   r5   r   r5   r   r5   rE   r   )rA   )r   r   rE   r   )NNNNN)r   r   r   rb   r   r5   r   r5   r   r   r   r   r   r   r   r   r   r   rE   r   )NN)r   r   r   r5   r   r5   r   r   r   r   rE   r   )r   r,   r   r5   r   r5   r   r5   r   r5   rE   r   )
r   r5   r   r5   r   r5   r   r5   rE   r   )r   r   r   )r   r   r   r   r   r   rE   r   )r   r   rE   rD   )r   rb   r   r5   r   r5   r   r5   r   r5   rE   r   )r   r+   r   r5   r   r5   r   r5   r   r5   rE   r.   )r   r0   r   rb   r   r5   r   r5   r   r   r   r   rE   r   )r   r   r   r5   r   r5   r   r5   r   r5   rE   r   )
r   r5   r   r5   r   r5   r   r5   rE   r   rE   rS   )r   r   r   r   __annotations__r;   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rA   rA   r?   rB   r      s8   
 

>









r   c                   @  s   e Zd ZdZdddZdS )GroupShapeszThe sequence of child shapes belonging to a group shape.

    Note that this collection can itself contain a group shape, making this part of a recursive,
    tree data structure (acyclic graph).
    rE   rS   c                 C  s   | j   dS r   )r   r   r{   rA   rA   rB   r        z GroupShapes._recalculate_extentsNr   )r   r   r   r   r   rA   rA   rA   rB   r   
      r   c                   @  sz   e Zd ZU dZded< dejfd4ddZd5ddZd6ddZ	e
d7dd Ze
d8d"d#Zd9d)d*Zd:d-d.Zd;d2d3ZdS )<SlideShapeszSequence of shapes appearing on a slide.

    The first shape in the sequence is the backmost in z-order and the last shape is topmost.
    Supports indexed access, len(), index(), and iteration.
    r2   r8   N
movie_filer   r   r5   r   r   r   poster_frame_imager   	mime_typerb   rE   r   c           	      C  sB   t | | j|||||||	}| j| | | tt| |S )a  Return newly added movie shape displaying video in `movie_file`.

        **EXPERIMENTAL.** This method has important limitations:

        * The size must be specified; no auto-scaling such as that provided by :meth:`add_picture`
          is performed.
        * The MIME type of the video file should be specified, e.g. 'video/mp4'. The provided
          video file is not interrogated for its type. The MIME type `video/unknown` is used by
          default (and works fine in tests as of this writing).
        * A poster frame image must be provided, it cannot be automatically extracted from the
          video file. If no poster frame is provided, the default "media loudspeaker" image will
          be used.

        Return a newly added movie shape to the slide, positioned at (`left`, `top`), having size
        (`width`, `height`), and containing `movie_file`. Before the video is started,
        `poster_frame_image` is displayed as a placeholder for the video.
        )	_MoviePicElementCreatornew_movie_picrY   r<   r   _add_video_timingr   r   rI   )	r>   r   r   r   r   r   r   r   Z	movie_picrA   rA   rB   	add_movie#  s   
zSlideShapes.add_movierowsrD   colsc                 C  s$   |  ||||||}tt| |S )a  Add a |GraphicFrame| object containing a table.

        The table has the specified number of `rows` and `cols` and the specified position and
        size. `width` is evenly distributed between the columns of the new table. Likewise,
        `height` is evenly distributed between the rows. Note that the `.table` property on the
        returned |GraphicFrame| shape must be used to access the enclosed |Table| object.
        )"_add_graphicFrame_containing_tabler   r   rI   )r>   r   r   r   r   r   r   r   rA   rA   rB   	add_tableM  s   
zSlideShapes.add_tableslide_layoutr3   rS   c                 C  s   |  D ]}| | qdS )zAdd placeholder shapes based on those in `slide_layout`.

        Z-order of placeholders is preserved. Latent placeholders (date, slide number, and footer)
        are not cloned.
        N)iter_cloneable_placeholdersra   )r>   r  rR   rA   rA   rB   clone_layout_placeholdersZ  s   z%SlideShapes.clone_layout_placeholdersSlidePlaceholdersc                 C     | j jS )z-Sequence of placeholder shapes in this slide.)r8   placeholdersr{   rA   rA   rB   r  c     zSlideShapes.placeholdersShape | Nonec                 C  s2   | j  D ]}|jdkrtt| |  S qdS )ziThe title placeholder shape on the slide.

        |None| if the slide has no title placeholder.
        r   N)r<   iter_ph_elmsrX   r   r   rI   )r>   elmrA   rA   rB   titleh  s
   
zSlideShapes.titler   r   r   r   r   c           
   
   C  s0   | j }d|d  }| j||||||||}	|	S )zNReturn a newly added `p:graphicFrame` element containing a table as specified.zTable %dr   )rY   r<   r  )
r>   r   r   r   r   r   r   _idr`   r   rA   rA   rB   r   s  s   z.SlideShapes._add_graphicFrame_containing_tabler   r   c                 C  s(   | j dd }| }||j dS )zAdd a `p:video` element under `p:sld/p:timing`.

        The element will refer to the specified `pic` element by its shape id, and cause the video
        play controls to appear for that video.
        z/p:sldr   N)r<   r   get_or_add_childTnLst	add_videor   )r>   r   sld
childTnLstrA   rA   rB   r   |  s   zSlideShapes._add_video_timingrK   r-   r   c                 C  r   r   SlideShapeFactoryrN   rA   rA   rB   rI     r   zSlideShapes._shape_factory)r   r   r   r5   r   r5   r   r5   r   r5   r   r   r   rb   rE   r   )r   rD   r   rD   r   r5   r   r5   r   r5   r   r5   rE   r   )r  r3   rE   rS   )rE   r  )rE   r	  )r   rD   r   rD   r   r5   r   r5   r   r5   r   r5   rE   r   )r   r   rE   rS   r   )r   r   r   r   r   CTVIDEOr   r  r  r   r  r  r   r   rI   rA   rA   rA   rB   r     s   
 	
*
	


	
r   c                   @     e Zd ZdZd	ddZdS )
LayoutShapeszSequence of shapes appearing on a slide layout.

    The first shape in the sequence is the backmost in z-order and the last shape is topmost.
    Supports indexed access, len(), index(), and iteration.
    rK   r-   rE   r   c                 C  r   r   _LayoutShapeFactoryrN   rA   rA   rB   rI     r   zLayoutShapes._shape_factoryNr   r   r   r   r   rI   rA   rA   rA   rB   r    r   r  c                   @  r  )
MasterShapeszSequence of shapes appearing on a slide master.

    The first shape in the sequence is the backmost in z-order and the last shape is topmost.
    Supports indexed access, len(), and iteration.
    rK   r-   rE   r   c                 C  r   r   )_MasterShapeFactoryrN   rA   rA   rB   rI     r   zMasterShapes._shape_factoryNr   r  rA   rA   rA   rB   r    r   r  c                   @  s$   e Zd ZdZdddZdddZdS )NotesSlideShapeszSequence of shapes appearing on a notes slide.

    The first shape in the sequence is the backmost in z-order and the last shape is topmost.
    Supports indexed access, len(), index(), and iteration.
    rU   r	   rE   rb   c                 C  s,   t jdt jdt jdt jdt jdt jdi| S )a  Return the base name for a placeholder of `ph_type` in this shape collection.

        A notes slide uses a different name for the body placeholder and has some unique
        placeholder types, so this method overrides the default in the base class.
        zNotes Placeholderrd   re   rf   zSlide Image Placeholderrg   )r	   rj   rm   rn   ro   SLIDE_IMAGErt   rx   rA   rA   rB   ry     s   zNotesSlideShapes.ph_basenamerK   r-   r   c                 C  r   )zKReturn appropriate shape object for `shape_elm` appearing on a notes slide.)_NotesSlideShapeFactoryrN   rA   rA   rB   rI     r   zNotesSlideShapes._shape_factoryNr   r   )r   r   r   r   ry   rI   rA   rA   rA   rB   r    s    
r  c                   @  s   e Zd ZdZed	ddZdS )
BasePlaceholdersa  Base class for placeholder collections.

    Subclasses differentiate behaviors for a master, layout, and slide. By default, placeholder
    shapes are constructed using |BaseShapeFactory|. Subclasses should override
    :method:`_shape_factory` to use custom placeholder classes.
    rK   r-   rE   rz   c                 C     | j S )z<True if `shape_elm` is a placeholder shape, False otherwise.)
has_ph_elmr   rA   rA   rB   r     s   zBasePlaceholders._is_member_elmNr   )r   r   r   r   r   r   rA   rA   rA   rB   r     s    r   c                   @  s0   e Zd ZU dZded< ddd
dZdddZdS )LayoutPlaceholderszVSequence of |LayoutPlaceholder| instance for each placeholder shape on a slide layout.z)Callable[[], Iterator[LayoutPlaceholder]]rO   NrC   rD   defaultLayoutPlaceholder | NonerE   c                 C  s"   | D ]}|j j|kr|  S q|S )zQThe first placeholder shape with matching `idx` value, or `default` if not found.)rT   rX   )r>   rC   r$  rR   rA   rA   rB   get  s
   zLayoutPlaceholders.getrK   r-   r   c                 C  r   r   r  rN   rA   rA   rB   rI     r   z!LayoutPlaceholders._shape_factoryr9   )rC   rD   r$  r%  rE   r%  r   r   r   r   r   r   r&  rI   rA   rA   rA   rB   r#    s
   
 r#  c                   @  s0   e Zd ZU dZded< ddd	d
ZdddZdS )MasterPlaceholderszTSequence of MasterPlaceholder representing the placeholder shapes on a slide master.z)Callable[[], Iterator[MasterPlaceholder]]rO   NrU   r	   r$  MasterPlaceholder | Nonec                 C  s    | D ]}|j |kr|  S q|S )zReturn the first placeholder shape with type `ph_type` (e.g. 'body').

        Returns `default` if no such placeholder shape is present in the collection.
        )rU   )r>   rU   r$  rR   rA   rA   rB   r&    s
   
zMasterPlaceholders.getplaceholder_elmr   rE   r   c                 C     t tt|| S r   )r   r   r  r>   r*  rA   rA   rB   rI        z!MasterPlaceholders._shape_factoryr9   )rU   r	   r$  r)  )r*  r   rE   r   r'  rA   rA   rA   rB   r(    s
   
 
r(  c                   @  s$   e Zd ZU dZded< ddd	Zd
S )NotesSlidePlaceholdersz0Sequence of placeholder shapes on a notes slide.z-Callable[[], Iterator[NotesSlidePlaceholder]]rO   r*  r   rE   r   c                 C  r+  )zTReturn an instance of the appropriate placeholder proxy class for `placeholder_elm`.)r   r   r  r,  rA   rA   rB   rI     r-  z%NotesSlidePlaceholders._shape_factoryN)r*  r   rE   r   )r   r   r   r   r   rI   rA   rA   rA   rB   r.    s   
 r.  c                   @  s6   e Zd ZU dZded< dddZdd	 ZdddZdS )r  zCollection of placeholder shapes on a slide.

    Supports iteration, :func:`len`, and dictionary-style lookup on the `idx` value of the
    placeholders it contains.
    r/   r   rC   rD   c                 C  s4   | j  D ]}|j|krt||   S qtd| )zAccess placeholder shape having `idx`.

        Note that while this looks like list access, idx is actually a dictionary key and will
        raise |KeyError| if no placeholder with that idx value is in the collection.
        z+no placeholder on this slide with idx == %d)r   r
  rX   r  KeyError)r>   rC   erA   rA   rB   rL     s
   
zSlidePlaceholders.__getitem__c                   s2   t dd  j D dd d} fdd|D S )z+Generate placeholder shapes in `idx` order.c                 S  s   g | ]}|qS rA   rA   .0r0  rA   rA   rB   
<listcomp>  s    z.SlidePlaceholders.__iter__.<locals>.<listcomp>c                 S  r!  r9   )rX   )r0  rA   rA   rB   <lambda>  s    z,SlidePlaceholders.__iter__.<locals>.<lambda>)keyc                 3  s    | ]}t | V  qd S r9   r  r1  r{   rA   rB   	<genexpr>  s    z-SlidePlaceholders.__iter__.<locals>.<genexpr>)sortedr   r
  )r>   ph_elmsrA   r{   rB   rO     s    zSlidePlaceholders.__iter__rE   c                 C  s   t t| j S )z#Return count of placeholder shapes.)rP   rF   r   r
  r{   rA   rA   rB   rQ     s   zSlidePlaceholders.__len__N)rC   rD   r   )r   r   r   r   r   rL   rO   rQ   rA   rA   rA   rB   r    s   
 
r  rK   r-   r8   r4   rE   r   c                 C  sh   | j }t| tr| d}|rt| |S t| |S tdttdttdt	tdt
i|t}|| |S )r   z./p:nvPicPr/p:nvPr/a:videoFilezp:cxnSpzp:grpSpp:spp:graphicFrame)tagr   r   r   r   r   r   r   r   r   r   r&  r   )rK   r8   r;  Z
videoFilesZ	shape_clsrA   rA   rB   r   #  s   




r   c                 C  $   t | tr| jrt| |S t| |S )zBReturn appropriate shape object for `shape_elm` on a slide layout.)r   r   r"  r   r   rK   r8   rA   rA   rB   r  7     

r  c                 C  r<  )zBReturn appropriate shape object for `shape_elm` on a slide master.)r   r   r"  r   r   r=  rA   rA   rB   r  >  r>  r  c                 C  r<  )zAReturn appropriate shape object for `shape_elm` on a notes slide.)r   r   r"  r   r   r=  rA   rA   rB   r  E  r>  r  c                 C  sl   | j }|tdkrtjttjttjttjt	i
| jt}n|tdkr&t}n|tdkr/t}nt}|| |S )zCReturn a placeholder shape of the appropriate type for `shape_elm`.r9  r:  zp:pic)r;  r   r	   ri   r    rl   r   rs   rv   r$   r&  rU   r#   r!   r"   r   )rK   r8   r;  ZConstructorrA   rA   rB   _SlidePlaceholderFactoryL  s   

r?  c                 C  s   | j rt| |S t| |S )z;Return appropriate shape object for `shape_elm` on a slide.)r"  r?  r   r=  rA   rA   rB   r  _  s   

r  c                      s   e Zd ZdZd. fddZed/ddZed0ddZe	d1ddZ
e	d2ddZe	d0dd Zed0d!d"Zed3d$d%Ze	d4d'd(Ze	d5d*d+Zed0d,d-Z  ZS )6r   a  Functional service object for creating a new movie p:pic element.

    It's entire external interface is its :meth:`new_movie_pic` class method that returns a new
    `p:pic` element containing the specified video. This class is not intended to be constructed
    or an instance of it retained by the caller; it is a "one-shot" object, really a function
    wrapped in a object such that its helper methods can be organized here.
    r   r   r   rD   r   r   r   r5   r   r   r   poster_frame_filer   r   
str | Nonec
           
        sL   t t|   || _|| _|| _||||f\| _| _| _| _	|| _
|	| _d S r9   )r:   r   r;   _shapes	_shape_id_movie_file_x_y_cx_cy_poster_frame_file
_mime_type)
r>   r   r   r   r   r   r   r   r@  r   r?   rA   rB   r;   o  s   
z _MoviePicElementCreator.__init__r   rE   r   c
           
   
   C  s   | |||||||||		j S )zReturn a new `p:pic` element containing video in `movie_file`.

        If `mime_type` is None, 'video/unknown' is used. If `poster_frame_file` is None, the
        default "media loudspeaker" image is used.
        )_pic)
clsr   r   r   r   r   r   r   r   r   rA   rA   rB   r     s   z%_MoviePicElementCreator.new_movie_picrb   c                 C  
   | j d S )zReturn the rId of RT.MEDIA relationship to video part.

        For historical reasons, there are two relationships to the same part; one is the video rId
        and the other is the media rId.
        r   _video_part_rIdsr{   rA   rA   rB   
_media_rId     
z"_MoviePicElementCreator._media_rIdc                 C  s,   t | j| j| j| j| j| j| j| j	| j
	S )z5Return the new `p:pic` element referencing the video.)r   new_video_picrC  _shape_name
_video_rIdrP  _poster_frame_rIdrE  rF  rG  rH  r{   rA   rA   rB   rK    s   z_MoviePicElementCreator._picc                 C  s   | j }|du rttS |S )zReturn the image file for video placeholder image.

        If no poster frame file is provided, the default "media loudspeaker" image is used.
        N)rI  ioBytesIOr   )r>   r@  rA   rA   rB   _poster_frame_image_file  s   
z0_MoviePicElementCreator._poster_frame_image_filec                 C     | j | j\}}|S )zReturn the rId of relationship to poster frame image.

        The poster frame is the image used to represent the video before it's played.
        )_slide_partr   rX  )r>   _poster_frame_rIdrA   rA   rB   rU    s   z)_MoviePicElementCreator._poster_frame_rIdc                 C  r  )zReturn the appropriate shape name for the p:pic shape.

        A movie shape is named with the base filename of the video.
        )_videofilenamer{   rA   rA   rB   rS    s   z#_MoviePicElementCreator._shape_namer1   c                 C  r  )z8Return SlidePart object for slide containing this movie.rB  r   r{   rA   rA   rB   rZ    r  z#_MoviePicElementCreator._slide_partr   c                 C  s   t | j| jS )z2Return a |Video| object containing the movie file.)r   Zfrom_path_or_file_likerD  rJ  r{   rA   rA   rB   r]    s   z_MoviePicElementCreator._videotuple[str, str]c                 C  s   | j | j\}}||fS )zReturn the rIds for relationships to media part for video.

        This is where the media part and its relationships to the slide are actually created.
        )rZ  get_or_add_video_media_partr]  )r>   	media_rId	video_rIdrA   rA   rB   rO    s   z(_MoviePicElementCreator._video_part_rIdsc                 C  rM  )zReturn the rId of RT.VIDEO relationship to video part.

        For historical reasons, there are two relationships to the same part; one is the video rId
        and the other is the media rId.
        r   rN  r{   rA   rA   rB   rT    rQ  z"_MoviePicElementCreator._video_rId)r   r   r   rD   r   r   r   r5   r   r5   r   r5   r   r5   r@  r   r   rA  )r   r   r   rD   r   r   r   r5   r   r5   r   r5   r   r5   r   r   r   rA  rE   r   rE   rb   )rE   r   rE   r   rE   r1   )rE   r   )rE   r`  )r   r   r   r   r;   classmethodr   r   rP  r'   rK  rX  rU  rS  rZ  r]  rO  rT  r   rA   rA   r?   rB   r   f  s.    
r   c                   @  s   e Zd ZdZd3ddZed4ddZed5ddZed6ddZ	ed6ddZ
ed6d d!Zed7d"d#Zed8d%d&Zed6d'd(Zed8d)d*Zed8d+d,Zed8d-d.Zed9d0d1Zd2S ):r   a  Functional service object for creating a new OLE-object p:graphicFrame element.

    It's entire external interface is its :meth:`graphicFrame` class method that returns a new
    `p:graphicFrame` element containing the specified embedded OLE-object shape. This class is not
    intended to be constructed or an instance of it retained by the caller; it is a "one-shot"
    object, really a function wrapped in a object such that its helper methods can be organized
    here.
    r   r   r   rD   ole_object_filer   r   PROG_ID | strr   r5   r   r   r   r   r   r   r   r   c                 C  sF   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
d S r9   )rB  rC  _ole_object_file_prog_id_argrE  rF  _cx_arg_cy_arg_icon_file_arg_icon_width_arg_icon_height_arg)r>   r   r   rh  r   r   r   r   r   r   r   r   rA   rA   rB   r;     s   
z!_OleObjectElementCreator.__init__rE   r   c                 C  s   | |||||||||	|
|j S )zJReturn new `p:graphicFrame` element containing embedded `ole_object_file`.)_graphicFrame)rL  r   r   rh  r   r   r   r   r   r   r   r   rA   rA   rB   r     s   z%_OleObjectElementCreator.graphicFramec                 C  s4   t | j| j| j| j| j| j| j| j	| j
| j| jS )zGNewly-created `p:graphicFrame` element referencing embedded OLE-object.)r   new_ole_object_graphicFramerC  rS  _ole_object_rId_progId	_icon_rIdrE  rF  rG  rH  _icon_width_icon_heightr{   rA   rA   rB   rq  *  s   z&_OleObjectElementCreator._graphicFramec                 C  0   | j dur| j S t| jtrt| jjS tdS )zBEmu object specifying width of "show-as-icon" image for OLE shape.NP )rl  r   rk  r
   r&   r   r{   rA   rA   rB   rG  ;     
z_OleObjectElementCreator._cxc                 C  rx  )zCEmu object specifying height of "show-as-icon" image for OLE shape.N@M	 )rm  r   rk  r
   r&   r   r{   rA   rA   rB   rH  H  rz  z_OleObjectElementCreator._cyc                 C     | j dur| j S tdS )a  Vertical size of enclosed EMF icon within the OLE graphic-frame.

        This must be specified when a custom icon is used, to avoid stretching of the image and
        possible undesired resizing by PowerPoint when the OLE shape is double-clicked to open it.

        The correct size can be determined by creating an example PPTX using PowerPoint and then
        inspecting the XML of the OLE graphics-frame (p:oleObj.imgH).
        Nr{  )rp  r&   r{   rA   rA   rB   rw  U  s   
z%_OleObjectElementCreator._icon_heightc                 C  sR   | j dur| j S t| jtr| jjnd}tjtd }tj	tj
|dd|S )zReference to image file containing icon to show in lieu of this object.

        This can be either a str path or a file-like object (io.BytesIO typically).
        Nzgeneric-icon.emfr   z..	templates)rn  r   rk  r
   icon_filenameospathsplit__file__abspathjoin)r>   r~  _thisdirrA   rA   rB   _icon_image_filea  s   


z)_OleObjectElementCreator._icon_image_filerb   c                 C  rY  )zHstr rId like "rId7" of rel to icon (image) representing OLE-object part.)rZ  r   r  )r>   r[  r   rA   rA   rB   ru  v  s   z"_OleObjectElementCreator._icon_rIdc                 C  r|  )a  Width of enclosed EMF icon within the OLE graphic-frame.

        This must be specified when a custom icon is used, to avoid stretching of the image and
        possible undesired resizing by PowerPoint when the OLE shape is double-clicked to open it.
        Nry  )ro  r&   r{   rA   rA   rB   rv  |  s   z$_OleObjectElementCreator._icon_widthc                 C  s   | j | j| jS )zstr rId like "rId6" of relationship to embedded ole_object part.

        This is where the ole_object part and its relationship to the slide are actually created.
        )rZ  add_embedded_ole_object_partrk  rj  r{   rA   rA   rB   rs    s   z(_OleObjectElementCreator._ole_object_rIdc                 C  s   | j }t|tr|jS |S )zstr like "Excel.Sheet.12" identifying program used to open object.

        This value appears in the `progId` attribute of the `p:oleObj` element for the object.
        )rk  r   r
   progId)r>   Zprog_id_argrA   rA   rB   rt    s   z _OleObjectElementCreator._progIdc                 C  s   d| j d  S )zstr name like "Object 1" for the embedded ole_object shape.

        The name is formed from the prefix "Object " and the shape-id decremented by 1.
        z	Object %dr   )rC  r{   rA   rA   rB   rS    r   z$_OleObjectElementCreator._shape_namer1   c                 C  r  )z SlidePart object for this slide.r_  r{   rA   rA   rB   rZ    r  z$_OleObjectElementCreator._slide_partN)r   r   r   rD   rh  r   r   ri  r   r5   r   r5   r   r   r   r   r   r   r   r   r   r   )r   r   r   rD   rh  r   r   ri  r   r5   r   r5   r   r   r   r   r   r   r   r   r   r   rE   r   )rE   r   )rE   r5   re  rd  rf  )r   r   r   r   r;   rg  r   r'   rq  rG  rH  rw  r  ru  rv  rs  rt  rS  rZ  rA   rA   rA   rB   r     s6    
		r   )rK   r-   r8   r4   rE   r   )rK   r-   r8   r4   )kr   
__future__r   rV  r  typingr   r   r   r   r   r   pptx.enum.shapesr	   r
   
pptx.mediar   r   pptx.opc.constantsr   r  pptx.oxml.nsr   pptx.oxml.shapes.autoshaper   pptx.oxml.shapes.graphfrmr   pptx.oxml.shapes.picturer   pptx.oxml.simpletypesr   Zpptx.shapes.autoshaper   r   Zpptx.shapes.baser   Zpptx.shapes.connectorr   Zpptx.shapes.freeformr   Zpptx.shapes.graphfrmr   Zpptx.shapes.groupr   Zpptx.shapes.picturer   r   pptx.shapes.placeholderr   r   r   r   r    r!   r"   r#   r$   pptx.sharedr%   	pptx.utilr&   r'   pptx.chart.chartr(   pptx.chart.datar)   pptx.enum.chartr*   r+   r,   Zpptx.oxml.shapesr-   pptx.oxml.shapes.connectorr.   pptx.oxml.shapes.groupshaper/   pptx.parts.imager0   pptx.parts.slider1   
pptx.slider2   r3   Z
pptx.typesr4   r5   r6   r   r   r   r  r  r  r   r#  r(  r.  r  r   r  r  r  r?  r  objectr   r   rA   rA   rA   rB   <module>   sx     ,   *q





 