a
    ]øjÅ  ã                   @  sâ   U d 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 ddlmZ erÂdd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dZde d< G dd„ deƒZ!d	S )z¾Block item container, used by body, cell, header, etc.

Block level items are things like paragraph and table, although there are a few other
specialized ones like structured document tags.
é    )Úannotations)ÚTYPE_CHECKINGÚIterator)Ú	TypeAlias)ÚCT_Tbl)ÚCT_P)Ú
StoryChild©Ú	ParagraphN)Ú
CT_Comment)ÚCT_Body)Ú	CT_HdrFtr)ÚCT_Tc)ÚLength)ÚParagraphStyle©ÚTablez(CT_Body | CT_Comment | CT_HdrFtr | CT_Tcr   ÚBlockItemElementc                      s~   e Zd ZdZdddœ‡ fdd„Zdd	d
ddœdd„Zdddddœdd„Zddœdd„Zedd„ ƒZ	edd„ ƒZ
dd„ Z‡  ZS ) ÚBlockItemContainera  Base class for proxy objects that can contain block items.

    These containers include _Body, _Cell, header, footer, footnote, endnote, comment,
    and text box objects. Provides the shared functionality to add a block item like a
    paragraph or table.
    r   zt.ProvidesStoryPart)ÚelementÚparentc                   s   t t| ƒ |¡ || _d S )N)Úsuperr   Ú__init__Ú_element)Úselfr   r   ©Ú	__class__© úI/var/www/html/assistant/venv/lib/python3.9/site-packages/docx/blkcntnr.pyr   )   s    zBlockItemContainer.__init__Ú NÚstrzstr | ParagraphStyle | Noner
   )ÚtextÚstyleÚreturnc                 C  s(   |   ¡ }|r| |¡ |dur$||_|S )a>  Return paragraph newly added to the end of the content in this container.

        The paragraph has `text` in a single run if present, and is given paragraph
        style `style`.

        If `style` is |None|, no paragraph style is applied, which has the same effect
        as applying the 'Normal' style.
        N)Ú_add_paragraphZadd_runr"   )r   r!   r"   Z	paragraphr   r   r   Úadd_paragraph-   s    	
z BlockItemContainer.add_paragraphÚintr   r   )ÚrowsÚcolsÚwidthr#   c                 C  s0   ddl m} t |||¡}| j |¡ ||| ƒS )zÞReturn table of `width` having `rows` rows and `cols` columns.

        The table is appended appended at the end of the content in this container.

        `width` is evenly distributed between the table columns.
        r   r   )Ú
docx.tabler   r   Znew_tblr   Z_insert_tbl)r   r'   r(   r)   r   Útblr   r   r   Ú	add_table=   s    zBlockItemContainer.add_tablezIterator[Paragraph | Table])r#   c                 c  s>   ddl m} | jjD ]$}t|tƒr,t|| ƒn||| ƒV  qdS )zIGenerate each `Paragraph` or `Table` in this container in document order.r   r   N)r*   r   r   Zinner_content_elementsÚ
isinstancer   r
   )r   r   r   r   r   r   Úiter_inner_contentJ   s    z%BlockItemContainer.iter_inner_contentc                   s   ‡ fdd„ˆ j jD ƒS )zcA list containing the paragraphs in this container, in document order.

        Read-only.
        c                   s   g | ]}t |ˆ ƒ‘qS r   r	   )Ú.0Úp©r   r   r   Ú
<listcomp>W   ó    z1BlockItemContainer.paragraphs.<locals>.<listcomp>)r   Zp_lstr1   r   r1   r   Ú
paragraphsQ   s    zBlockItemContainer.paragraphsc                   s$   ddl m‰  ‡ ‡fdd„ˆjjD ƒS )z_A list containing the tables in this container, in document order.

        Read-only.
        r   r   c                   s   g | ]}ˆ |ˆƒ‘qS r   r   )r/   r+   ©r   r   r   r   r2   a   r3   z-BlockItemContainer.tables.<locals>.<listcomp>)r*   r   r   Ztbl_lstr1   r   r5   r   ÚtablesY   s    zBlockItemContainer.tablesc                 C  s   t | j ¡ | ƒS )zIReturn paragraph newly added to the end of the content in this container.)r
   r   Zadd_pr1   r   r   r   r$   c   s    z!BlockItemContainer._add_paragraph)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r%   r,   r.   Úpropertyr4   r6   r$   Ú__classcell__r   r   r   r   r   !   s   

	r   )"r:   Ú
__future__r   Útypingr   r   Ztyping_extensionsr   Zdocx.oxml.tabler   Zdocx.oxml.text.paragraphr   Zdocx.sharedr   Zdocx.text.paragraphr
   Z
docx.typesÚtypesÚtZdocx.oxml.commentsr   Zdocx.oxml.documentr   Zdocx.oxml.sectionr   r   r   Zdocx.styles.styler   r*   r   r   Ú__annotations__r   r   r   r   r   Ú<module>   s$   