
    ,h6                         d Z ddlmZmZmZmZ ddlmZ ddlm	c 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  G d de      Z G d de      Z G d de      Z G d de      Zy)z7Autoshape-related objects such as Shape and Adjustment.    )absolute_importdivisionprint_functionunicode_literals)NumberN)
FillFormat
LineFormat)MSO_AUTO_SHAPE_TYPEMSO_SHAPE_TYPE)	BaseShapeautoshape_types)	TextFrame)lazypropertyc                        e Zd ZdZd fd	Zed        Zej                  d        Zed        Z	ed        Z
ed        Z xZS )	
Adjustmenta=  
    An adjustment value for an autoshape.

    An adjustment value corresponds to the position of an adjustment handle on
    an auto shape. Adjustment handles are the small yellow diamond-shaped
    handles that appear on certain auto shapes and allow the outline of the
    shape to be adjusted. For example, a rounded rectangle has an adjustment
    handle that allows the radius of its corner rounding to be adjusted.

    Values are |float| and generally range from 0.0 to 1.0, although the value
    can be negative or greater than 1.0 in certain circumstances.
    c                 T    t         t        |           || _        || _        || _        y N)superr   __init__namedef_valactual)selfr   r   r   	__class__s       W/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pptx/shapes/autoshape.pyr   zAdjustment.__init__!   s%    j$(*	    c                 X    | j                   }|| j                  }| j                  |      S )a  
        Read/write |float| representing normalized adjustment value for this
        adjustment. Actual values are a large-ish integer expressed in shape
        coordinates, nominally between 0 and 100,000. The effective value is
        normalized to a corresponding value nominally between 0.0 and 1.0.
        Intuitively this represents the proportion of the width or height of
        the shape at which the adjustment value is located from its starting
        point. For simple shapes such as a rounded rectangle, this intuitive
        correspondence holds. For more complicated shapes and at more extreme
        shape proportions (e.g. width is much greater than height), the value
        can become negative or greater than 1.0.
        )r   r   
_normalize)r   	raw_values     r   effective_valuezAdjustment.effective_value'   s+     KK	Iy))r   c                 p    t        |t              sd}t        ||z        | j                  |      | _        y )Nz*adjustment value must be numeric, got '%s')
isinstancer   
ValueError_denormalizer   )r   valuetmpls      r   r"   zAdjustment.effective_value:   s2    %(?DTE\**''.r   c                     t        | dz        S )z
        Return integer corresponding to normalized *raw_value* on unit basis
        of 100,000. See Adjustment.normalize for additional details.
             j@)int)r'   s    r   r&   zAdjustment._denormalizeA   s     58#$$r   c                     | dz  S )a.  
        Return normalized value for *raw_value*. A normalized value is a
        |float| between 0.0 and 1.0 for nominal raw values between 0 and
        100,000. Raw values less than 0 and greater than 100,000 are valid
        and return values calculated on the same unit basis of 100,000.
        r*    )r!   s    r   r    zAdjustment._normalizeI   s     8##r   c                 J    | j                   | j                   S | j                  S )zw
        Denormalized effective value (expressed in shape coordinates),
        suitable for using in the XML.
        )r   r   r   s    r   valzAdjustment.valS   s      #kk5t{{G4<<Gr   r   )__name__
__module____qualname____doc__r   propertyr"   setterstaticmethodr&   r    r0   __classcell__r   s   @r   r   r      sy     * *$ / / % % $ $ H Hr   r   c                   `     e Zd ZdZ fdZd Zd Zd Zd Ze	d        Z
ed        Zd	 Z xZS )
AdjustmentCollectionz
    Sequence of |Adjustment| instances for an auto shape, each representing
    an available adjustment for a shape of its type. Supports ``len()`` and
    indexed access, e.g. ``shape.adjustments[1] = 0.15``.
    c                 d    t         t        |           | j                  |      | _        || _        y r   )r   r;   r   _initialized_adjustments_adjustments_	_prstGeom)r   prstGeomr   s     r   r   zAdjustmentCollection.__init__c   s+    "D24!::8D!r   c                 4    | j                   |   j                  S )z1Provides indexed access, (e.g. 'adjustments[9]').)r>   r"   )r   keys     r   __getitem__z AdjustmentCollection.__getitem__h   s    !!#&666r   c                 L    || j                   |   _        | j                          y)z
        Provides item assignment via an indexed expression, e.g.
        ``adjustments[9] = 999.9``. Causes all adjustment values in
        collection to be written to the XML.
        N)r>   r"   _rewrite_guides)r   rB   r'   s      r   __setitem__z AdjustmentCollection.__setitem__l   s#     383/r   c                     |g S t         j                  |j                        }|D cg c]  \  }}t        ||       }}}| j	                  ||j
                         |S c c}}w )zm
        Return an initialized list of adjustment values based on the contents
        of *prstGeom*
        )AutoShapeTypedefault_adjustment_valuesprstr    _update_adjustments_with_actualsgd_lst)r   r@   davsr   r   adjustmentss         r   r=   z-AdjustmentCollection._initialized_adjustmentsu   sa    
 I66x}}EFJK]T7z$0KK--k8??K Ls   A c                     | j                   D cg c]  }|j                  |j                  f }}| j                  j	                  |       yc c}w )z
        Write ``<a:gd>`` elements to the XML, one for each adjustment value.
        Any existing guide elements are overwritten.
        N)r>   r   r0   r?   rewrite_guides)r   adjguidess      r   rE   z$AdjustmentCollection._rewrite_guides   sB    
 261C1CD#388SWW%DD%%f- Es   Ac                     t        d | D              }|D ]3  }|j                  }t        |j                  dd       }	 ||   }||_        5 y# t        $ r Y Bw xY w)z
        Update |Adjustment| instances in *adjustments* with actual values
        held in *guides*, a list of ``<a:gd>`` elements. Guides with a name
        that does not match an adjustment object are skipped.
        c              3   8   K   | ]  }|j                   |f  y wr   )r   ).0rQ   s     r   	<genexpr>zHAdjustmentCollection._update_adjustments_with_actuals.<locals>.<genexpr>   s     "JsCHHc?"Js      N)dictr   r+   fmlaKeyErrorr   )rN   rR   adjustments_by_namegdr   r   
adjustments          r   rK   z5AdjustmentCollection._update_adjustments_with_actuals   ss     #"Jk"JJ 	'B77D%F06
 !'J	' 	  s   A	AAc                 ,    t        | j                        S )zt
        Sequence containing direct references to the |Adjustment| objects
        contained in collection.
        )tupler>   r/   s    r   _adjustmentsz!AdjustmentCollection._adjustments   s     T''((r   c                 ,    t        | j                        S )z!Implement built-in function len())lenr>   r/   s    r   __len__zAdjustmentCollection.__len__   s    4%%&&r   )r1   r2   r3   r4   r   rC   rF   r=   rE   r7   rK   r5   r`   rc   r8   r9   s   @r   r;   r;   \   sN    "
7
.  " ) )'r   r;   c                        e Zd ZdZi Z fdZd Zed        Zed        Z	e
d        Zed        Ze
d        Zed	        Z xZS )
rH   a  
    Return an instance of |AutoShapeType| containing metadata for an auto
    shape of type identified by *autoshape_type_id*. Instances are cached, so
    no more than one instance for a particular auto shape type is in memory.

    Instances provide the following attributes:

    .. attribute:: autoshape_type_id

       Integer uniquely identifying this auto shape type. Corresponds to a
       value in ``pptx.constants.MSO`` like ``MSO_SHAPE.ROUNDED_RECTANGLE``.

    .. attribute:: basename

       Base part of shape name for auto shapes of this type, e.g. ``Rounded
       Rectangle`` becomes ``Rounded Rectangle 99`` when the distinguishing
       integer is added to the shape name.

    .. attribute:: prst

       String identifier for this auto shape type used in the ``<a:prstGeom>``
       element.

    .. attribute:: desc

       Informal string description of auto shape.

    c                     || j                   vr"t        t        |   |       }|| j                   |<   | j                   |   S )zs
        Only create new instance on first call for content_type. After that,
        use cached instance.
        )
_instancesr   rH   __new__)clsautoshape_type_idinstr   s      r   rg   zAutoShapeType.__new__   sA     CNN24S9D04CNN,-~~/00r   c                     t        | d      ry|t        vrt        d|z        t        |   }|| _        |d   | _        d| _        y)z7Initialize attributes from constant values in pptx.spec_loadedNz;no autoshape type with id '%s' in pptx.spec.autoshape_typesbasenameT)hasattrr   rZ   _autoshape_type_id	_basenamerl   )r   ri   autoshape_types      r   r   zAutoShapeType.__init__   sY     4#O3M#$ 
 )):;"3'
3r   c                     | j                   S )zP
        MSO_AUTO_SHAPE_TYPE enumeration value for this auto shape type
        )ro   r/   s    r   ri   zAutoShapeType.autoshape_type_id   s    
 &&&r   c                 F    t        j                  | j                  ddi      S )aw  Base of shape name for this auto shape type.

        A shape name is like "Rounded Rectangle 7" and appears as an XML attribute for
        example at `p:sp/p:nvSpPr/p:cNvPr{name}`. This basename value is the name less
        the distinguishing integer. This value is escaped because at least one
        autoshape-type name includes double quotes ('"No" Symbol').
        "z&quot;)saxutilsescaperp   r/   s    r   rm   zAutoShapeType.basename   s     t~~X??r   c                     t         |   d   S )z
        Return sequence of name, value tuples representing the adjustment
        value defaults for the auto shape type identified by *prst*.
        avLstr   rh   rJ   s     r   rI   z'AutoShapeType.default_adjustment_values   s     t$W--r   c                     | j                   S )z,Informal description of this auto shape type)_descr/   s    r   desczAutoShapeType.desc   s     zzr   c                 ,    t        j                  |      S )z~
        Return auto shape id (e.g. ``MSO_SHAPE.RECTANGLE``) corresponding to
        preset geometry keyword *prst*.
        )r   from_xmlry   s     r   id_from_prstzAutoShapeType.id_from_prst  s     #++D11r   c                 @    t        j                  | j                        S )z
        Preset geometry identifier string for this auto shape. Used in the
        ``prst`` attribute of ``<a:prstGeom>`` element to specify the geometry
        to be used in rendering the shape, for example ``'roundRect'``.
        )r   to_xmlro   r/   s    r   rJ   zAutoShapeType.prst  s     #))$*A*ABBr   )r1   r2   r3   r4   rf   rg   r   r5   ri   rm   classmethodrI   r|   r   rJ   r8   r9   s   @r   rH   rH      s    : J
1" ' ' @ @ . .   2 2 C Cr   rH   c                        e Zd ZdZ fdZed        Zed        Zed        Z	d Z
ed        Zed        Zed	        Zed
        Zed        Zej                   d        Zed        Z xZS )ShapezA shape that can appear on a slide.

    Corresponds to the ``<p:sp>`` element that can appear in any of the slide-type parts
    (slide, slideLayout, slideMaster, notesPage, notesMaster, handoutMaster).
    c                 <    t         t        |   ||       || _        y r   )r   r   r   _sp)r   spparentr   s      r   r   zShape.__init__  s    eT#B/r   c                 @    t        | j                  j                        S )z_
        Read-only reference to |AdjustmentCollection| instance for this
        shape
        )r;   r   r@   r/   s    r   rN   zShape.adjustments!  s     $DHH$5$566r   c                 p    | j                   j                  st        d      | j                   j                  S )z
        Enumeration value identifying the type of this auto shape, like
        ``MSO_SHAPE.ROUNDED_RECTANGLE``. Raises |ValueError| if this shape is
        not an auto shape.
        zshape is not an auto shape)r   is_autoshaper%   rJ   r/   s    r   auto_shape_typezShape.auto_shape_type)  s+     xx$$9::xx}}r   c                 T    t        j                  | j                  j                        S )zw
        |FillFormat| instance for this shape, providing access to fill
        properties such as fill color.
        )r   from_fill_parentr   spPrr/   s    r   fillz
Shape.fill4  s     **488==99r   c                 6    | j                   j                         S )zq
        Return the ``<a:ln>`` element containing the line format properties
        XML for this shape.
        )r   get_or_add_lnr/   s    r   r   zShape.get_or_add_ln<  s    
 xx%%''r   c                      y)z`
        |True| if this shape can contain text. Always |True| for an
        AutoShape.
        Tr-   r/   s    r   has_text_framezShape.has_text_frameC  s     r   c                     t        |       S )zw
        |LineFormat| instance for this shape, providing access to line
        properties such as line color.
        r	   r/   s    r   linez
Shape.lineK  s     $r   c                 .    | j                   j                  S )z
        The ``<a:ln>`` element containing the line format properties such as
        line color and width. |None| if no ``<a:ln>`` element is present.
        )r   lnr/   s    r   r   zShape.lnS  s     xx{{r   c                 8   | j                   rt        j                  S | j                  j                  rt        j
                  S | j                  j                  rt        j                  S | j                  j                  rt        j                  S d}t        |      )zn
        Unique integer identifying the type of this shape, like
        ``MSO_SHAPE_TYPE.TEXT_BOX``.
        z)Shape instance of unrecognized shape type)is_placeholderr   PLACEHOLDERr   has_custom_geometryFREEFORMr   
AUTO_SHAPE
is_textboxTEXT_BOXNotImplementedError)r   msgs     r   
shape_typezShape.shape_type[  st     !---88''!***88  !,,,88!***9!#&&r   c                 .    | j                   j                  S )a  Read/write. Unicode (str in Python 3) representation of shape text.

        The returned string will contain a newline character (``"\n"``) separating each
        paragraph and a vertical-tab (``"\v"``) character for each line break (soft
        carriage return) in the shape's text.

        Assignment to *text* replaces all text previously contained in the shape, along
        with any paragraph or font formatting applied to it. A newline character
        (``"\n"``) in the assigned text causes a new paragraph to be started.
        A vertical-tab (``"\v"``) character in the assigned text causes a line-break
        (soft carriage-return) to be inserted. (The vertical-tab character appears in
        clipboard text copied from PowerPoint as its encoding of line-breaks.)

        Either bytes (Python 2 str) or unicode (Python 3 str) can be assigned. Bytes can
        be 7-bit ASCII or UTF-8 encoded 8-bit bytes. Bytes values are converted to
        unicode assuming UTF-8 encoding (which also works for ASCII).
        
text_frametextr/   s    r   r   z
Shape.textl  s    & ###r   c                 &    || j                   _        y r   r   )r   r   s     r   r   z
Shape.text  s    #r   c                 N    | j                   j                         }t        ||       S )z|TextFrame| instance for this shape.

        Contains the text of the shape and provides access to text formatting
        properties.
        )_elementget_or_add_txBodyr   )r   txBodys     r   r   zShape.text_frame  s#     002&&r   )r1   r2   r3   r4   r   r   rN   r5   r   r   r   r   r   r   r   r   r6   r   r8   r9   s   @r   r   r     s     7 7   : :(         ' '  $ $( 
[[$ $ ' 'r   r   )r4   
__future__r   r   r   r   numbersr   xml.sax.saxutilssaxru   pptx.dml.fillr   pptx.dml.liner
   pptx.enum.shapesr   r   pptx.shapes.baser   	pptx.specr   pptx.text.textr   	pptx.utilr   objectr   r;   rH   r   r-   r   r   <module>r      sm    > R R  # # $ $ @ & % $ "FH FHRI'6 I'XkCF kC\w'I w'r   