U
    cqeF  ã                   @   sD   d Z ddlmZmZ ddlmZ G dd„ deƒZG dd„ deƒZdS )	zTabstop-related proxy types.é    )ÚWD_TAB_ALIGNMENTÚWD_TAB_LEADER)ÚElementProxyc                       sZ   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Ze	j
ejfdd„Zdd„ Z‡  ZS )ÚTabStopsa6  A sequence of |TabStop| objects providing access to the tab stops of a paragraph
    or paragraph style.

    Supports iteration, indexed access, del, and len(). It is accesed using the
    :attr:`~.ParagraphFormat.tab_stops` property of ParagraphFormat; it is not intended
    to be constructed directly.
    c                    s   t t| ƒ |d ¡ || _d S ©N)Úsuperr   Ú__init__Ú_pPr©ÚselfÚelement©Ú	__class__© ú6/tmp/pip-unpacked-wheel-gx5hpqp3/docx/text/tabstops.pyr      s    zTabStops.__init__c              	   C   sX   | j j}z| || ¡ W n  ttfk
r:   tdƒ‚Y nX t|ƒdkrT| j  |¡ dS )z0Remove the tab at offset `idx` in this sequence.ztab index out of ranger   N)r	   ÚtabsÚremoveÚAttributeErrorÚ
IndexErrorÚlen)r   Úidxr   r   r   r   Ú__delitem__   s    zTabStops.__delitem__c                 C   s*   | j j}|dkrtdƒ‚|j| }t|ƒS )z#Enables list-style access by index.NzTabStops object is empty)r	   r   r   Útab_lstÚTabStop)r   r   r   Útabr   r   r   Ú__getitem__   s
    
zTabStops.__getitem__c                 c   s*   | j j}|dk	r&|jD ]}t|ƒV  qdS )zXGenerate a TabStop object for each of the w:tab elements, in XML document
        order.N)r	   r   r   r   )r   r   r   r   r   r   Ú__iter__'   s    
zTabStops.__iter__c                 C   s   | j j}|d krdS t|jƒS )Nr   )r	   r   r   r   )r   r   r   r   r   Ú__len__/   s    zTabStops.__len__c                 C   s    | j  ¡ }| |||¡}t|ƒS )aõ  Add a new tab stop at `position`, a |Length| object specifying the location
        of the tab stop relative to the paragraph edge.

        A negative `position` value is valid and appears in hanging indentation. Tab
        alignment defaults to left, but may be specified by passing a member of the
        :ref:`WdTabAlignment` enumeration as `alignment`. An optional leader character
        can be specified by passing a member of the :ref:`WdTabLeader` enumeration as
        `leader`.
        )r	   Zget_or_add_tabsÚinsert_tab_in_orderr   )r   ÚpositionÚ	alignmentÚleaderr   r   r   r   r   Úadd_tab_stop5   s    
zTabStops.add_tab_stopc                 C   s   | j  ¡  dS )zRemove all custom tab stops.N)r	   Z_remove_tabs©r   r   r   r   Ú	clear_allE   s    zTabStops.clear_all)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   ÚLEFTr   ZSPACESr"   r$   Ú__classcell__r   r   r   r   r      s    ÿ
r   c                       sn   e Zd ZdZ‡ fdd„Zedd„ ƒZejdd„ ƒZedd„ ƒZejd	d„ ƒZed
d„ ƒZ	e	jdd„ ƒZ	‡  Z
S )r   z…An individual tab stop applying to a paragraph or style.

    Accessed using list semantics on its containing |TabStops| object.
    c                    s   t t| ƒ |d ¡ || _d S r   )r   r   r   Ú_tabr
   r   r   r   r   P   s    zTabStop.__init__c                 C   s   | j jS )z{A member of :ref:`WdTabAlignment` specifying the alignment setting for this
        tab stop.

        Read/write.
        ©r+   Úvalr#   r   r   r   r    T   s    zTabStop.alignmentc                 C   s   || j _d S r   r,   ©r   Úvaluer   r   r   r    ]   s    c                 C   s   | j jS )zúA member of :ref:`WdTabLeader` specifying a repeating character used as a
        "leader", filling in the space spanned by this tab.

        Assigning |None| produces the same result as assigning `WD_TAB_LEADER.SPACES`.
        Read/write.
        ©r+   r!   r#   r   r   r   r!   a   s    zTabStop.leaderc                 C   s   || j _d S r   r0   r.   r   r   r   r!   k   s    c                 C   s   | j jS )z¦A |Length| object representing the distance of this tab stop from the inside
        edge of the paragraph.

        May be positive or negative. Read/write.
        )r+   Úposr#   r   r   r   r   o   s    zTabStop.positionc                 C   s0   | j }| ¡ }| ||j|j¡| _ | |¡ d S r   )r+   Z	getparentr   r-   r!   r   )r   r/   r   r   r   r   r   r   x   s    )r%   r&   r'   r(   r   Úpropertyr    Úsetterr!   r   r*   r   r   r   r   r   J   s   


	

r   N)r(   Zdocx.enum.textr   r   Zdocx.sharedr   r   r   r   r   r   r   Ú<module>   s   C