o
    `TT                     @   s   d Z ddlmZmZmZ G dd deZG dd deZG dd deZG d	d
 d
eZ	G dd deZ
G dd deZG dd deZG dd deZdd Zdd ZG dd deZG dd deZdS )z!
Objects shared by docx modules.
    )absolute_importprint_functionunicode_literalsc                   @   st   e Zd ZdZdZdZdZdZdZdd Z	e
d	d
 Ze
dd Ze
dd Ze
dd Ze
dd Ze
dd ZdS )Lengtha  
    Base class for length constructor classes Inches, Cm, Mm, Px, and Emu.
    Behaves as an int count of English Metric Units, 914,400 to the inch,
    36,000 to the mm. Provides convenience unit conversion methods in the form
    of read-only properties. Immutable.
    i i@~ i  i1  i{  c                 C   s   t | |S N)int__new__clsemu r   ;D:\Projects\ConvertPro\env\Lib\site-packages\docx\shared.pyr      s   zLength.__new__c                 C      | t | j S )zI
        The equivalent length expressed in centimeters (float).
        )float_EMUS_PER_CMselfr   r   r   cm      z	Length.cmc                 C   s   | S )zP
        The equivalent length expressed in English Metric Units (int).
        r   r   r   r   r   r   !   s   z
Length.emuc                 C   r   )zD
        The equivalent length expressed in inches (float).
        )r   _EMUS_PER_INCHr   r   r   r   inches(   r   zLength.inchesc                 C   r   )zI
        The equivalent length expressed in millimeters (float).
        )r   _EMUS_PER_MMr   r   r   r   mm/   r   z	Length.mmc                 C   r   )z1
        Floating point length in points
        )r   _EMUS_PER_PTr   r   r   r   pt6   r   z	Length.ptc                 C   s   t t| t| j S )zA
        The equivalent length expressed in twips (int).
        )r   roundr   _EMUS_PER_TWIPr   r   r   r   twips=   s   zLength.twipsN)__name__
__module____qualname____doc__r   r   r   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   
   s(    




r   c                   @      e Zd ZdZdd ZdS )IncheszY
    Convenience constructor for length in inches, e.g.
    ``width = Inches(0.5)``.
    c                 C      t |tj }t| |S r   )r   r   r   r   )r
   r   r   r   r   r   r   J      zInches.__new__Nr   r   r    r!   r   r   r   r   r   r$   E       r$   c                   @   r#   )CmzZ
    Convenience constructor for length in centimeters, e.g.
    ``height = Cm(12)``.
    c                 C   r%   r   )r   r   r   r   )r
   r   r   r   r   r   r   T   r&   z
Cm.__new__Nr'   r   r   r   r   r)   O   r(   r)   c                   @   r#   )Emuzg
    Convenience constructor for length in English Metric Units, e.g.
    ``width = Emu(457200)``.
    c                 C   s   t | t|S r   )r   r   r   r	   r   r   r   r   ^   s   zEmu.__new__Nr'   r   r   r   r   r*   Y   r(   r*   c                   @   r#   )Mmz\
    Convenience constructor for length in millimeters, e.g.
    ``width = Mm(240.5)``.
    c                 C   r%   r   )r   r   r   r   )r
   r   r   r   r   r   r   g   r&   z
Mm.__new__Nr'   r   r   r   r   r+   b   r(   r+   c                   @   r#   )PtzC
    Convenience value class for specifying a length in points
    c                 C   r%   r   )r   r   r   r   )r
   Zpointsr   r   r   r   r   p   r&   z
Pt.__new__Nr'   r   r   r   r   r,   l   s    r,   c                   @   r#   )Twipsz
    Convenience constructor for length in twips, e.g. ``width = Twips(42)``.
    A twip is a twentieth of a point, 635 EMU.
    c                 C   r%   r   )r   r   r   r   )r
   r   r   r   r   r   r   z   r&   zTwips.__new__Nr'   r   r   r   r   r-   u   r(   r-   c                       s<   e Zd ZdZ fddZdd Zdd Zedd	 Z  Z	S )
RGBColorzA
    Immutable value object defining a particular RGB color.
    c                    sN   d}|||fD ]}t |tr|dk s|dkrt|qtt| | |||fS )Nz+RGBColor() takes three integer values 0-255r      )
isinstancer   
ValueErrorsuperr.   r   )r
   rgbmsgval	__class__r   r   r      s   zRGBColor.__new__c                 C      d|  S )Nz RGBColor(0x%02x, 0x%02x, 0x%02x)r   r   r   r   r   __repr__   s   zRGBColor.__repr__c                 C   r:   )z>
        Return a hex string rgb value, like '3C2F80'
        z%02X%02X%02Xr   r   r   r   r   __str__   s   zRGBColor.__str__c                 C   sB   t |dd d}t |dd d}t |dd d}| |||S )zW
        Return a new instance from an RGB color hex string like ``'3C2F80'``.
        N         )r   )r
   Zrgb_hex_strr3   r4   r5   r   r   r   from_string   s   zRGBColor.from_string)
r   r   r    r!   r   r;   r<   classmethodr@   __classcell__r   r   r8   r   r.      s    r.   c                    s*   dj   j} fdd}t||dS )z
    @lazyprop decorator. Decorated method will be called only on first access
    to calculate a cached property value. After that, the cached value is
    returned.
    z_%sc                    s8   zt |  W S  ty   | }t|  | | Y S w r   )getattrAttributeErrorsetattr)objvalueZcache_attr_namefr   r   get_prop_value   s   z$lazyproperty.<locals>.get_prop_value)doc)r   r!   r"   )rI   	docstringrJ   r   rH   r   lazyproperty   s   
rM   c                 C   s   | j }t| |dS )z
    @write_only_property decorator. Creates a property (descriptor attribute)
    that accepts assignment, but not getattr (use in an expression).
    )fsetrK   )r!   r"   )rI   rL   r   r   r   write_only_property   s   rO   c                   @   sF   e Zd ZdZdZdddZdd Zdd	 Zed
d Z	edd Z
dS )ElementProxya0  
    Base class for lxml element proxy classes. An element proxy class is one
    whose primary responsibilities are fulfilled by manipulating the
    attributes and child elements of an XML element. They are the most common
    type of class in python-docx other than custom element (oxml) classes.
    _element_parentNc                 C   s   || _ || _d S r   rQ   )r   elementparentr   r   r   __init__   s   
zElementProxy.__init__c                 C   s   t |tsdS | j|ju S )a\  
        Return |True| if this proxy object refers to the same oxml element as
        does *other*. ElementProxy objects are value objects and should
        maintain no mutable local state. Equality for proxy objects is
        defined as referring to the same XML element, whether or not they are
        the same proxy object instance.
        Fr0   rP   rR   r   otherr   r   r   __eq__   s   
zElementProxy.__eq__c                 C   s   t |tsdS | j|juS )NTrW   rX   r   r   r   __ne__   s   
zElementProxy.__ne__c                 C   s   | j S )z:
        The lxml element proxied by this object.
        )rR   r   r   r   r   rT      s   zElementProxy.elementc                 C      | j jS z9
        The package part containing this object
        rS   partr   r   r   r   r_         zElementProxy.partr   )r   r   r    r!   	__slots__rV   rZ   r[   r"   rT   r_   r   r   r   r   rP      s    

rP   c                       s,   e Zd ZdZ fddZedd Z  ZS )Parentedz
    Provides common services for document elements that occur below a part
    but may occasionally require an ancestor object to provide a service,
    such as add or drop a relationship. Provides ``self._parent`` attribute
    to subclasses.
    c                    s   t t|   || _d S r   )r2   rb   rV   rS   )r   rU   r8   r   r   rV      s   
zParented.__init__c                 C   r\   r]   r^   r   r   r   r   r_      r`   zParented.part)r   r   r    r!   rV   r"   r_   rB   r   r   r8   r   rb      s
    rb   N)r!   Z
__future__r   r   r   r   r   r$   r)   r*   r+   r,   r-   tupler.   rM   rO   objectrP   rb   r   r   r   r   <module>   s   ;

	
	

.