a
    ]j)                     @  s   d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
mZmZmZmZ dd 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S )z2Custom element classes related to the styles part.    )annotations)WD_STYLE_TYPE)ST_DecimalNumberST_OnOff	ST_String)BaseOxmlElementOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOnec                 C  s*   ddddddddd	d
d
 | | ddS )zlReturn the style id corresponding to `name`, taking into account special-case
    names such as 'Heading 1'.ZCaptionZHeading1ZHeading2ZHeading3ZHeading4ZHeading5ZHeading6ZHeading7ZHeading8ZHeading9)
captionz	heading 1z	heading 2z	heading 3z	heading 4z	heading 5z	heading 6z	heading 7z	heading 8z	heading 9  )getreplace)name r   L/var/www/html/assistant/venv/lib/python3.9/site-packages/docx/oxml/styles.pystyleId_from_name   s    r   c                   @  sp   e Zd ZdZedddZedeZede	Z
ede	Zede	Zed	eZed
e	Zdd Zdd Zdd ZdS )CT_LatentStylesz`w:latentStyles` element, defining behavior defaults for latent styles and
    containing `w:lsdException` child elements that each override those defaults for a
    named latent style.zw:lsdExceptionr   
successorszw:countzw:defLockedStatezw:defQFormatzw:defSemiHiddenzw:defUIPriorityzw:defUnhideWhenUsedc                 C  s   t | |}|du rdS |S )z`Return the boolean value of the attribute having `attr_name`, or |False| if
        not present.NFgetattrself	attr_namevaluer   r   r   	bool_prop/   s    
zCT_LatentStyles.bool_propc                 C  s   |  d| }|sdS |d S )zHReturn the `w:lsdException` child having `name`, or |None| if not found.zw:lsdException[@w:name="%s"]Nr   xpath)r   r   foundr   r   r   get_by_name7   s    zCT_LatentStyles.get_by_namec                 C  s   t | |t| dS z7Set the on/off attribute having `attr_name` to `value`.N)setattrboolr   r   r   r   set_bool_prop>   s    zCT_LatentStyles.set_bool_propN)__name__
__module____qualname____doc__r
   ZlsdExceptionr   r   countr   ZdefLockedStateZ
defQFormatZdefSemiHiddenZdefUIPriorityZdefUnhideWhenUsedr   r"   r&   r   r   r   r   r   !   s   





r   c                   @  sd   e Zd ZdZedeZedeZ	edeZ
edeZedeZedeZdd	 Zd
d Zdd ZdS )CT_LsdExceptionzb``<w:lsdException>`` element, defining override visibility behaviors for a named
    latent style.w:lockedw:name	w:qFormatw:semiHiddenw:uiPriorityw:unhideWhenUsedc                 C  s   |   |  dS )z;Remove this `w:lsdException` element from the XML document.N	getparentremover   r   r   r   deleteN   s    zCT_LsdException.deletec                 C  s
   t | |S )z_Return the boolean value of the attribute having `attr_name`, or |None| if
        not present.r   )r   r   r   r   r   on_off_propR   s    zCT_LsdException.on_off_propc                 C  s   t | || dS r#   )r$   r   r   r   r   set_on_off_propW   s    zCT_LsdException.set_on_off_propN)r'   r(   r)   r*   r   r   lockedr	   r   r   qFormat
semiHiddenr   
uiPriorityunhideWhenUsedr7   r8   r9   r   r   r   r   r,   C   s   





r,   c                   @  s  e Zd ZU dZdZededd dZededd dZed	ed
d dZededd dZ	ededd dZ
ededd dZededd dZededd dZededd dZededd dZ[edeZded< edeZded< edeZed eZed!d" Zejd#d" Zed$d% Z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d0d1 Z!e!jd2d1 Z!ed3d4 Z"e"jd5d4 Z"ed6d7 Z#e#jd8d7 Z#ed9d: Z$e$jd;d: Z$dS )<CT_Stylez9A ``<w:style>`` element, representing a style definition.)r.   z	w:aliases	w:basedOnw:nextzw:linkzw:autoRedefinezw:hiddenr1   r0   r2   r/   r-   z
w:personalzw:personalComposezw:personalReplyzw:rsidw:pPrw:rPrzw:tblPrzw:trPrzw:tcPrzw:tblStylePrr.      Nr   r@      rA      r1      r0   	   r2   
   r/      r-      rB      rC      zw:typezWD_STYLE_TYPE | Nonetypez	w:styleIdz
str | NonestyleIdz	w:defaultzw:customStylec                 C  s   | j }|du rdS |jS )z5Value of `w:basedOn/@w:val` or |None| if not present.N)basedOnval)r   rP   r   r   r   basedOn_val   s    zCT_Style.basedOn_valc                 C  s    |d u r|    n
||  _d S N)Z_remove_basedOnZget_or_add_basedOnrQ   r   r   r   r   r   rR      s    
c                 C  s6   | j }|du rdS |  }||j}|du r2dS |S )zkSibling CT_Style element this style is based on or |None| if no base style or
        base style not found.N)rP   r4   	get_by_idrQ   )r   rP   styles
base_styler   r   r   rW      s    zCT_Style.base_stylec                 C  s   |   |  dS )zARemove this `w:style` element from its parent `w:styles` element.Nr3   r6   r   r   r   r7      s    zCT_Style.deletec                 C  s   | j }|du rdS |jS )z5Value of `w:locked/@w:val` or |False| if not present.NF)r:   rQ   )r   r:   r   r   r   
locked_val   s    zCT_Style.locked_valc                 C  s&   |    t|du r"|  }||_d S NT)Z_remove_lockedr%   Z_add_lockedrQ   )r   r   r:   r   r   r   rX      s    c                 C  s   | j }|du rdS |jS )z5Value of ``<w:name>`` child or |None| if not present.N)r   rQ   )r   r   r   r   r   name_val   s    zCT_Style.name_valc                 C  s"   |    |d ur|  }||_d S rS   )Z_remove_nameZ	_add_namerQ   )r   r   r   r   r   r   rZ      s    c                 C  s&   | j }|du rdS |  }||jS )zSibling CT_Style element identified by the value of `w:name/@w:val` or |None|
        if no value is present or no style with that style id is found.N)nextr4   rU   rQ   )r   r[   rV   r   r   r   
next_style   s
    zCT_Style.next_stylec                 C  s   | j }|du rdS |jS )z6Value of `w:qFormat/@w:val` or |False| if not present.NF)r;   rQ   )r   r;   r   r   r   qFormat_val   s    zCT_Style.qFormat_valc                 C  s   |    t|r|   d S rS   )Z_remove_qFormatr%   Z_add_qFormatrT   r   r   r   r]      s    c                 C  s   | j }|du rdS |jS )z<Value of ``<w:semiHidden>`` child or |False| if not present.NF)r<   rQ   )r   r<   r   r   r   semiHidden_val   s    zCT_Style.semiHidden_valc                 C  s&   |    t|du r"|  }||_d S rY   )Z_remove_semiHiddenr%   Z_add_semiHiddenrQ   )r   r   r<   r   r   r   r^      s    c                 C  s   | j }|du rdS |jS )z;Value of ``<w:uiPriority>`` child or |None| if not present.N)r=   rQ   )r   r=   r   r   r   uiPriority_val   s    zCT_Style.uiPriority_valc                 C  s"   |    |d ur|  }||_d S rS   )Z_remove_uiPriorityZ_add_uiPriorityrQ   )r   r   r=   r   r   r   r_      s    c                 C  s   | j }|du rdS |jS )z=Value of `w:unhideWhenUsed/@w:val` or |False| if not present.NF)r>   rQ   )r   r>   r   r   r   unhideWhenUsed_val   s    zCT_Style.unhideWhenUsed_valc                 C  s&   |    t|du r"|  }||_d S rY   )Z_remove_unhideWhenUsedr%   Z_add_unhideWhenUsedrQ   )r   r   r>   r   r   r   r`     s    )%r'   r(   r)   r*   _tag_seqr   r   rP   r[   r=   r<   r>   r;   r:   ZpPrZrPrr   r   rN   __annotations__r   rO   r   defaultcustomStylepropertyrR   setterrW   r7   rX   rZ   r\   r]   r^   r_   r`   r   r   r   r   r?   \   sl   










	






r?   c                   @  sn   e Zd ZdZdZededd dZedddZ[d	d
 Z	dd Z
dddddZdddddZdd ZdS )	CT_StyleszK``<w:styles>`` element, the root element of a styles part, i.e. styles.xml.)zw:docDefaultsw:latentStylesw:stylerh      Nr   ri   r   c                 C  s0   |   }||_|rdnd|_t||_||_|S )zReturn a newly added `w:style` element having `name` and `style_type`.

        `w:style/@customStyle` is set based on the value of `builtin`.
        NT)Z	add_stylerN   rd   r   rO   rZ   )r   r   
style_typebuiltinstyler   r   r   add_style_of_type  s    
zCT_Styles.add_style_of_typec                   s&    fdd|   D }|sdS |d S )zEReturn `w:style[@w:type="*{style_type}*][-1]` or |None| if not found.c                   s    g | ]}|j  kr|jr|qS r   )rN   rc   ).0srk   r   r   
<listcomp>&  s   z)CT_Styles.default_for.<locals>.<listcomp>N)_iter_styles)r   rk   Zdefault_styles_for_typer   rq   r   default_for$  s    
zCT_Styles.default_forstrzCT_Style | None)rO   returnc                 C  s    d| d}t t| |dS )zR`w:style` child where @styleId = `styleId`.

        |None| if not found.
        zw:style[@w:styleId="z"]Nr[   iterr    )r   rO   r    r   r   r   rU   .  s    zCT_Styles.get_by_id)r   rw   c                 C  s   d| }t t| |dS )zd`w:style` child with `w:name` grandchild having value `name`.

        |None| if not found.
        zw:style[w:name/@w:val="%s"]Nrx   )r   r   r    r   r   r   r"   6  s    zCT_Styles.get_by_namec                 C  s   dd |  dD S )z@Generate each of the `w:style` child elements in document order.c                 s  s   | ]
}|V  qd S rS   r   )ro   rm   r   r   r   	<genexpr>@      z)CT_Styles._iter_styles.<locals>.<genexpr>ri   r   r6   r   r   r   rt   >  s    zCT_Styles._iter_styles)r'   r(   r)   r*   ra   r   ZlatentStylesr
   rm   rn   ru   rU   r"   rt   r   r   r   r   rg     s   
rg   N)r*   
__future__r   Zdocx.enum.styler   Zdocx.oxml.simpletypesr   r   r   Zdocx.oxml.xmlchemyr   r   r	   r
   r   r   r   r,   r?   rg   r   r   r   r   <module>   s   	" 5