o
    7 h5                     @  s   d 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mZ dd	lmZ dd
lmZ ddlmZ ddlmZ er`ddlmZmZmZ ddlmZ ddlmZ G dd dZ G dd dZ!G dd dZ"G dd deZ#dS )z7Autoshape-related objects such as Shape and Adjustment.    )annotations)Number)TYPE_CHECKINGIterable)saxutils)
FillFormat
LineFormat)MSO_AUTO_SHAPE_TYPEMSO_SHAPE_TYPE)	BaseShapeautoshape_types)	TextFrame)lazyproperty)CT_GeomGuideCT_PresetGeometry2DCT_Shape)AdjustmentValue)ProvidesPartc                      sl   e Zd ZdZdd fd	d
ZedddZejdddZedddZ	edddZ
edddZ  ZS )
Adjustmenta4  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.
    Nnamestrdef_valintactual
int | Nonec                   s$   t t|   || _|| _|| _d S N)superr   __init__r   r   r   )selfr   r   r   	__class__ ]/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/pptx/shapes/autoshape.pyr   #   s   
zAdjustment.__init__returnfloatc                 C  s    | j dur| j n| 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.
        N)r   r   
_normalize)r    	raw_valuer#   r#   r$   effective_value)   s   
zAdjustment.effective_valuevaluec                 C  s,   t |tstdt| | || _d S )Nz&adjustment value must be numeric, got )
isinstancer   
ValueErrorrepr_denormalizer   )r    r*   r#   r#   r$   r)   8   s   
c                 C  s   t | d S )zReturn integer corresponding to normalized `raw_value` on unit basis of 100,000.

        See Adjustment.normalize for additional details.
             j@)r   )r*   r#   r#   r$   r.   >   s   zAdjustment._denormalizer(   c                 C  s   | d 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#   )r(   r#   r#   r$   r'   F   s   zAdjustment._normalizec                 C  s   | j dur| j S | jS )zvDenormalized effective value.

        Expressed in shape coordinates, this is suitable for using in the XML.
        N)r   r   r    r#   r#   r$   valP   s   zAdjustment.valr   )r   r   r   r   r   r   )r%   r&   )r*   r&   )r*   r&   r%   r   )r(   r   r%   r&   )r%   r   )__name__
__module____qualname____doc__r   propertyr)   setterstaticmethodr.   r'   r1   __classcell__r#   r#   r!   r$   r      s    	r   c                      sl   e Zd ZdZd  fddZd!d
dZd"ddZd#ddZdd Ze	d$ddZ
ed%ddZdd Z  ZS )&AdjustmentCollectionzSequence of |Adjustment| instances for an auto shape.

    Each represents an available adjustment for a shape of its type. Supports `len()` and indexed
    access, e.g. `shape.adjustments[1] = 0.15`.
    prstGeomr   c                   s$   t t|   | || _|| _d S r   )r   r:   r   _initialized_adjustments_adjustments_	_prstGeom)r    r;   r!   r#   r$   r   `   s   
zAdjustmentCollection.__init__idxr   r%   r&   c                 C  s   | j | jS )z1Provides indexed access, (e.g. 'adjustments[9]').)r=   r)   )r    r?   r#   r#   r$   __getitem__e      z AdjustmentCollection.__getitem__r*   c                 C  s   || j | _|   dS )zProvides 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    r?   r*   r#   r#   r$   __setitem__i   s   z AdjustmentCollection.__setitem__CT_PresetGeometry2D | Nonelist[Adjustment]c                 C  s8   |du rg S t |j}dd |D }| ||j |S )zTReturn an initialized list of adjustment values based on the contents of `prstGeom`.Nc                 S  s   g | ]	\}}t ||qS r#   )r   ).0r   r   r#   r#   r$   
<listcomp>v   s    zAAdjustmentCollection._initialized_adjustments.<locals>.<listcomp>)AutoShapeTypedefault_adjustment_valuesprst _update_adjustments_with_actualsgd_lst)r    r;   Zdavsadjustmentsr#   r#   r$   r<   q   s   z-AdjustmentCollection._initialized_adjustmentsc                 C  s    dd | j D }| j| dS )zWrite `a:gd` elements to the XML, one for each adjustment value.

        Any existing guide elements are overwritten.
        c                 S  s   g | ]}|j |jfqS r#   )r   r1   rF   adjr#   r#   r$   rG      s    z8AdjustmentCollection._rewrite_guides.<locals>.<listcomp>N)r=   r>   rewrite_guides)r    guidesr#   r#   r$   rB   z   s   z$AdjustmentCollection._rewrite_guidesrM   Iterable[Adjustment]rQ   Iterable[CT_GeomGuide]c              	   C  s^   t dd | D }|D ]!}|j}t|jdd }z|| }W n	 ty(   Y qw ||_qdS )zUpdate |Adjustment| instances in `adjustments` with actual values held in `guides`.

        `guides` is a list of `a:gd` elements. Guides with a name that does not match an adjustment
        object are skipped.
        c                 s  s    | ]}|j |fV  qd S r   )r   rN   r#   r#   r$   	<genexpr>   s    zHAdjustmentCollection._update_adjustments_with_actuals.<locals>.<genexpr>   N)dictr   r   fmlaKeyErrorr   )rM   rQ   Zadjustments_by_namegdr   r   Z
adjustmentr#   r#   r$   rK      s   	z5AdjustmentCollection._update_adjustments_with_actualstuple[Adjustment, ...]c                 C  
   t | jS )z9Sequence of |Adjustment| objects contained in collection.)tupler=   r0   r#   r#   r$   _adjustments   s   
z!AdjustmentCollection._adjustmentsc                 C  r[   )z!Implement built-in function len())lenr=   r0   r#   r#   r$   __len__      
zAdjustmentCollection.__len__)r;   r   )r?   r   r%   r&   )r?   r   r*   r&   )r;   rD   r%   rE   )rM   rR   rQ   rS   )r%   rZ   )r2   r3   r4   r5   r   r@   rC   r<   rB   r8   rK   r6   r]   r_   r9   r#   r#   r!   r$   r:   Y   s    


	r:   c                      s~   e Zd ZU dZi Zded< d fddZdd	d
ZedddZ	edddZ
edddZedddZedd Z  ZS )rH   a  Provides access to 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.

    z(dict[MSO_AUTO_SHAPE_TYPE, AutoShapeType]
_instancesautoshape_type_idr
   r%   c                   s.   || j vrtt| | }|| j |< | j | S )zkOnly create new instance on first call for content_type.

        After that, use cached instance.
        )ra   r   rH   __new__)clsrb   instr!   r#   r$   rc      s   


zAutoShapeType.__new__c                 C  sD   t | drdS |tvrtd| t| }|| _|d | _d| _dS )z:Initialize attributes from constant values in `pptx.spec`._loadedNz;no autoshape type with id '%s' in pptx.spec.autoshape_typesbasenameT)hasattrr   rX   _autoshape_type_id	_basenamerf   )r    rb   autoshape_typer#   r#   r$   r      s   


zAutoShapeType.__init__c                 C  s   | j S )zHMSO_AUTO_SHAPE_TYPE enumeration member identifying this auto shape type.)ri   r0   r#   r#   r$   rb      s   zAutoShapeType.autoshape_type_idr   c                 C  s   t | 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;)r   escaperj   r0   r#   r#   r$   rg      s   	zAutoShapeType.basenamerJ   tuple[AdjustmentValue, ...]c                 C  s   t | d S )zSSequence of (name, value) pair adjustment value defaults for `prst` autoshape-type.avLstr   rd   rJ   r#   r#   r$   rI         z'AutoShapeType.default_adjustment_valuesc                 C  s
   t |S )zSelect auto shape type with matching `prst`.

        e.g. `MSO_SHAPE.RECTANGLE` corresponding to preset geometry keyword `"rect"`.
        )r
   from_xmlrp   r#   r#   r$   id_from_prst   s   
zAutoShapeType.id_from_prstc                 C  s   t | 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_xmlri   r0   r#   r#   r$   rJ      s   zAutoShapeType.prst)rb   r
   r%   rH   )rb   r
   )r%   r
   r%   r   )rJ   r
   r%   rn   )rJ   r   r%   r
   )r2   r3   r4   r5   ra   __annotations__rc   r   r6   rb   rg   classmethodrI   rs   rJ   r9   r#   r#   r!   r$   rH      s   
 

rH   c                      s   e Zd ZdZd# fddZed$d
dZedd Zedd Z	dd Z
ed%ddZedd Zedd Zed&ddZed'ddZejd(d dZed!d" Z  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).
    spr   parentr   c                   s   t t| || || _d S r   )r   rx   r   _sp)r    ry   rz   r!   r#   r$   r     s   
zShape.__init__r%   r:   c                 C  s   t | jjS )zFRead-only reference to |AdjustmentCollection| instance for this shape.)r:   r{   r;   r0   r#   r#   r$   rM   
  rq   zShape.adjustmentsc                 C  s   | j jstd| j jS )zEnumeration 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   r0   r#   r#   r$   auto_shape_type  s   zShape.auto_shape_typec                 C  s   t | jjS )zn|FillFormat| instance for this shape.

        Provides access to fill properties such as fill color.
        )r   from_fill_parentr{   spPrr0   r#   r#   r$   fill  s   z
Shape.fillc                 C  s
   | j  S )zSReturn the `a:ln` element containing the line format properties XML for this shape.)r{   get_or_add_lnr0   r#   r#   r$   r   !  r`   zShape.get_or_add_lnboolc                 C  s   dS )zF|True| if this shape can contain text. Always |True| for an AutoShape.Tr#   r0   r#   r#   r$   has_text_frame%  s   zShape.has_text_framec                 C  s   t | S )zn|LineFormat| instance for this shape.

        Provides access to line properties such as line color.
        r   r0   r#   r#   r$   line*     z
Shape.linec                 C     | j jS )zThe `a:ln` element containing the line format properties such as line color and width.

        |None| if no `a:ln` element is present.
        )r{   lnr0   r#   r#   r$   r   2  r   zShape.lnr   c                 C  s>   | j rtjS | jjrtjS | jjrtjS | jjrtj	S t
d)zRUnique integer identifying the type of this shape, like `MSO_SHAPE_TYPE.TEXT_BOX`.z)Shape instance of unrecognized shape type)Zis_placeholderr   PLACEHOLDERr{   has_custom_geometryFREEFORMr|   
AUTO_SHAPE
is_textboxTEXT_BOXNotImplementedErrorr0   r#   r#   r$   
shape_type:  s   zShape.shape_typer   c                 C  r   )a  Read/write. Text in shape as a single string.

        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 any 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 str encoding of
        line-breaks.)
        
text_frametextr0   r#   r#   r$   r   G  s   z
Shape.textr   c                 C  s   || j _d S r   r   )r    r   r#   r#   r$   r   X  rA   c                 C  s   | j  }t|| S )z|TextFrame| instance for this shape.

        Contains the text of the shape and provides access to text formatting properties.
        )r{   get_or_add_txBodyr   )r    txBodyr#   r#   r$   r   \  s   

zShape.text_frame)ry   r   rz   r   )r%   r:   )r%   r   )r%   r   ru   )r   r   )r2   r3   r4   r5   r   r   rM   r6   r}   r   r   r   r   r   r   r   r7   r   r9   r#   r#   r!   r$   rx      s0    
	


rx   N)$r5   
__future__r   numbersr   typingr   r   Zxml.saxr   pptx.dml.fillr   pptx.dml.liner	   pptx.enum.shapesr
   r   pptx.shapes.baser   	pptx.specr   pptx.text.textr   	pptx.utilr   pptx.oxml.shapes.autoshaper   r   r   r   
pptx.typesr   r   r:   rH   rx   r#   r#   r#   r$   <module>   s(    BG_