o
    j%                     @  s   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 erPd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mZ G dd deZG dd deZdS )zDObjects related to mouse click and hover actions on a shape or text.    )annotations)TYPE_CHECKINGcast)	PP_ACTION)RELATIONSHIP_TYPE)Subshape)lazyproperty)CT_Hyperlink)CT_NonVisualDrawingProps)CT_TextCharacterProperties)	SlidePart)	BaseShape)SlideSlidesc                      s   e Zd ZdZ	d"d# fd	d
Zedd Zed$ddZed%ddZ	e	j
d&ddZ	dd Zed'ddZedd Zedd Zed(d d!Z  ZS ))ActionSettingzAProperties specifying how a shape or run reacts to mouse actions.FxPr5CT_NonVisualDrawingProps | CT_TextCharacterPropertiesparentr   hoverboolc                       t t| | || _|| _d S N)superr   __init___element_hoverselfr   r   r   	__class__ K/home/air/Certificate/back/venv/lib/python3.10/site-packages/pptx/action.pyr         
zActionSetting.__init__c              	   C  s~   | j }|du r
tjS |j}|dkr'|jd }tjtjtjtjtj	tj
d| S tjtjtjtjtjtjtjtjd|tjS )a  Member of :ref:`PpActionType` enumeration, such as `PP_ACTION.HYPERLINK`.

        The returned member indicates the type of action that will result when the
        specified shape or text is clicked or the mouse pointer is positioned over the
        shape during a slide show.

        If there is no click-action or the click-action value is not recognized (is not
        one of the official `MsoPpAction` values) then `PP_ACTION.NONE` is returned.
        Nhlinkshowjumpjump)
firstslide	lastslidelastslideviewed	nextslidepreviousslideendshow)Nhlinksldjump	hlinkpres	hlinkfile
customshowolemacroprogram)_hlinkr   NONEaction_verbaction_fieldsFIRST_SLIDE
LAST_SLIDELAST_SLIDE_VIEWED
NEXT_SLIDEPREVIOUS_SLIDEEND_SHOW	HYPERLINKNAMED_SLIDEPLAY	OPEN_FILENAMED_SLIDE_SHOWOLE_VERB	RUN_MACRORUN_PROGRAMget)r   hlinkr4   relative_targetr    r    r!   action'   s4   


	zActionSetting.actionreturn	Hyperlinkc                 C  s   t | j| j| jS )z
        A |Hyperlink| object representing the hyperlink action defined on
        this click or hover mouse event. A |Hyperlink| object is always
        returned, even if no hyperlink or other click action is defined.
        )rI   r   _parentr   r   r    r    r!   	hyperlinkO   s   zActionSetting.hyperlinkSlide | Nonec                 C  s   t jt jt jt jt jf}| j|vrdS | jt jkr| jd S | jt jkr)| jd S | jt jkrD| jd }|t	| jkr?t
d| j| S | jt jkr\| jd }|dk rWt
d| j| S | jt jkry| jdusiJ | jj}td| j|}|jS dS )a  
        A reference to the slide in this presentation that is the target of
        the slide jump action in this shape. Slide jump actions include
        `PP_ACTION.FIRST_SLIDE`, `LAST_SLIDE`, `NEXT_SLIDE`,
        `PREVIOUS_SLIDE`, and `NAMED_SLIDE`. Returns |None| for all other
        actions. In particular, the `LAST_SLIDE_VIEWED` action and the `PLAY`
        (start other presentation) actions are not supported.

        A slide object may be assigned to this property, which makes the
        shape an "internal hyperlink" to the assigened slide::

            slide, target_slide = prs.slides[0], prs.slides[1]
            shape = slide.shapes[0]
            shape.target_slide = target_slide

        Assigning |None| removes any slide jump action. Note that this is
        accomplished by removing any action present (such as a hyperlink),
        without first checking that it is a slide jump action.
        Nr      zno next slidezno previous slider   )r   r6   r7   r9   r:   r=   rG   _slides_slide_indexlen
ValueErrorr2   rIdr   partrelated_partslide)r   slide_jump_actionsnext_slide_idxprev_slide_idxrT   
slide_partr    r    r!   target_slideX   s8   






zActionSetting.target_sliderW   c                 C  s<   |    |d u r
d S | j }d|_| j|jtj|_d S )Nzppaction://hlinksldjump)	_clear_click_actionr   get_or_add_hlinkClickrG   rU   	relate_toRTSLIDErT   )r   rW   rE   r    r    r!   r\      s   
c                 C  8   | j }|du r	dS |j}|r| j| | j| dS )z!Remove any existing click action.Nr2   rT   rU   drop_relr   remover   rE   rT   r    r    r!   r]      s   z!ActionSetting._clear_click_actionCT_Hyperlink | Nonec                 C  s&   | j rt| jtsJ | jjS | jjS )z
        Reference to the `a:hlinkClick` or `a:hlinkHover` element for this
        click action. Returns |None| if the element is not present.
        )r   
isinstancer   r
   
hlinkHover
hlinkClickrK   r    r    r!   r2      s   zActionSetting._hlinkc                 C  s   | j jS )zW
        Reference to the slide containing the shape having this click action.
        )rU   rW   rK   r    r    r!   _slide   s   zActionSetting._slidec                 C  s   | j | jS )zv
        Position in the slide collection of the slide containing the shape
        having this click action.
        )rP   indexrk   rK   r    r    r!   rQ      s   zActionSetting._slide_indexr   c                 C  s   | j jjjjS )zJ
        Reference to the slide collection for this presentation.
        )rU   packagepresentation_partpresentationslidesrK   r    r    r!   rP      s   zActionSetting._slidesFr   r   r   r   r   r   )rH   rI   )rH   rM   )rW   rM   rH   rg   )rH   r   )__name__
__module____qualname____doc__r   propertyrG   r   rL   r\   setterr]   r2   rk   rQ   rP   __classcell__r    r    r   r!   r      s*    	
'3



r   c                      sd   e Zd ZdZ	dd fd	d
ZedddZejdddZdddZedddZ	dd Z
  ZS )rI   z5Represents a hyperlink action on a shape or text run.Fr   r   r   r   r   r   c                   r   r   )r   rI   r   r   r   r   r   r    r!   r      r"   zHyperlink.__init__rH   
str | Nonec                 C  s,   | j }|du r	dS |j}|sdS | j|S )an  Read/write. The URL of the hyperlink.

        URL can be on http, https, mailto, or file scheme; others may work. Returns |None| if no
        hyperlink is defined, including when another action such as `RUN_MACRO` is defined on the
        object. Assigning |None| removes any action defined on the object, whether it is a hyperlink
        action or not.
        N)r2   rT   rU   
target_refrf   r    r    r!   address   s   	zHyperlink.addressurlc                 C  s6   |    |r| jj|tjdd}|  }||_d S d S )NT)is_external)_remove_hlinkrU   r_   r`   r<   _get_or_add_hlinkrT   )r   r~   rT   rE   r    r    r!   r}      s   
r	   c                 C  s    | j rtd| j S | j S )zGet the `a:hlinkClick` or `a:hlinkHover` element for the Hyperlink object.

        The actual element depends on the value of `self._hover`. Create the element if not present.
        r
   )r   r   r   get_or_add_hlinkHoverr^   rK   r    r    r!   r      s   
zHyperlink._get_or_add_hlinkrg   c                 C  s   | j r
td| jjS | jjS )zReference to the `a:hlinkClick` or `h:hlinkHover` element for this click action.

        Returns |None| if the element is not present.
        r
   )r   r   r   ri   rj   rK   r    r    r!   r2      s   zHyperlink._hlinkc                 C  rb   )zmRemove the a:hlinkClick or a:hlinkHover element.

        Also drops any relationship it might have.
        Nrc   rf   r    r    r!   r     s   zHyperlink._remove_hlinkrq   rr   )rH   r{   )r~   r{   )rH   r	   rs   )rt   ru   rv   rw   r   rx   r}   ry   r   r2   r   rz   r    r    r   r!   rI      s    
			rI   N)rw   
__future__r   typingr   r   pptx.enum.actionr   pptx.opc.constantsr   r`   pptx.shapesr   	pptx.utilr   pptx.oxml.actionr	   pptx.oxml.shapes.sharedr
   pptx.oxml.textr   pptx.parts.slider   pptx.shapes.baser   
pptx.slider   r   r   rI   r    r    r    r!   <module>   s"     -