a
    ãzeí-  ã                   @   s´   d Z ddlT ddlmZmZ G dd„ dƒZG dd„ deƒZdd	„ ZG d
d„ deƒZG dd„ deƒZ	dd„ Z
G dd„ deƒZdd„ ZG dd„ deƒZdd„ Zedkr°dd„ Zeƒ  dS )a&  This modules handles dialog boxes.

It contains the following public symbols:

SimpleDialog -- A simple but flexible modal dialog box

Dialog -- a base class for dialogs

askinteger -- get an integer from the user

askfloat -- get a float from the user

askstring -- get a string from the user
é    )Ú*)Ú
messageboxÚ_get_default_rootc                   @   sL   e Zd Zdg ddddfdd„Zddd„Zd	d
„ Zdd„ Zdd„ Zdd„ ZdS )ÚSimpleDialogÚ Nc                 C   s  |rt ||d| _n
t |ƒ| _|r:| j |¡ | j |¡ t| jƒ t| j|dd| _| jjdtd t	| jƒ| _
| j
 ¡  || _|| _|| _| j d| j¡ tt|ƒƒD ]L}|| }	t| j
|	| |fdd„d	}
||kræ|
jtd
d |
jttdd qª| j d| j¡ |  |¡ d S )N)Úclass_i  )ÚtextZaspecté   )ÚexpandÚfillú<Return>c                 S   s
   |   |¡S ©N)Údone©ÚselfÚnum© r   ú*/usr/lib/python3.9/tkinter/simpledialog.pyÚ<lambda>8   ó    z'SimpleDialog.__init__.<locals>.<lambda>©r   Úcommandé   )ZreliefZborderwidth)Úsider   r
   ÚWM_DELETE_WINDOW)ÚToplevelÚrootÚtitleZiconnameÚ_setup_dialogZMessageÚmessageÚpackZBOTHÚFrameÚframer   ÚcancelÚdefaultÚbindÚreturn_eventÚrangeÚlenÚButtonZconfigZRIDGEÚLEFTÚprotocolÚwm_delete_windowÚ_set_transient)r   Úmasterr   Úbuttonsr$   r#   r   r   r   ÚsÚbr   r   r   Ú__init__    s2    


ÿzSimpleDialog.__init__ç      à?ç333333Ó?c                 C   s  | j }| ¡  | |¡ | ¡  | ¡ rJ| ¡ }| ¡ }| ¡ }| ¡ }n| 	¡ }| 
¡ }d }}| ¡ }	| ¡ }
|||	 |  }|||
 |  }||	 | 	¡ kr°| 	¡ |	 }n|dk r¼d}||
 | 
¡ krÚ| 
¡ |
 }n|dk ræd}| d||f ¡ | ¡  d S )Nr   ú+%d+%d)r   ÚwithdrawÚ	transientÚupdate_idletasksZwinfo_ismappedZwinfo_widthZwinfo_heightÚwinfo_rootxÚwinfo_rootyZwinfo_screenwidthZwinfo_screenheightZwinfo_reqwidthZwinfo_reqheightÚgeometryÚ	deiconify)r   r.   ZrelxZrelyZwidgetZm_widthZm_heightZm_xZm_yZw_widthZw_heightÚxÚyr   r   r   r-   ?   s4    

zSimpleDialog._set_transientc                 C   s.   | j  ¡  | j  ¡  | j  ¡  | j  ¡  | jS r   )r   Úwait_visibilityÚgrab_setÚmainloopÚdestroyr   ©r   r   r   r   Úgo\   s
    



zSimpleDialog.goc                 C   s&   | j d u r| j ¡  n|  | j ¡ d S r   )r$   r   Úbellr   ©r   Úeventr   r   r   r&   c   s    
zSimpleDialog.return_eventc                 C   s&   | j d u r| j ¡  n|  | j ¡ d S r   )r#   r   rE   r   rC   r   r   r   r,   i   s    
zSimpleDialog.wm_delete_windowc                 C   s   || _ | j ¡  d S r   )r   r   Úquitr   r   r   r   r   o   s    zSimpleDialog.done)r3   r4   )	Ú__name__Ú
__module__Ú__qualname__r2   r-   rD   r&   r,   r   r   r   r   r   r      s   þ

r   c                   @   sV   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zddd„Zddd„Z	dd„ Z
dd„ ZdS )ÚDialogzZClass to open dialogs.

    This class is intended as a base class for custom dialogs
    Nc                 C   sþ   |}|st dƒ}t | |¡ |  ¡  |dur>| ¡ r>|  |¡ |rL|  |¡ t| ƒ || _d| _	t
| ƒ}|  |¡| _|jddd |  ¡  | js–| | _|  d| j¡ |durÎ|  d| ¡ d | ¡ d f ¡ |  ¡  | j ¡  |  ¡  |  ¡  |  | ¡ dS )z˜Initialize a dialog.

        Arguments:

            parent -- a parent window (the application window)

            title -- the dialog title
        zcreate dialog windowNé   )ÚpadxÚpadyr   r5   é2   )r   r   r2   r6   Zwinfo_viewabler7   r   r   ÚparentÚresultr!   ÚbodyÚinitial_focusr    Ú	buttonboxr+   r#   r;   r9   r:   r<   Ú	focus_setr?   r@   Zwait_window)r   rQ   r   r.   rS   r   r   r   r2   {   s8    	


ÿ
zDialog.__init__c                 C   s   d| _ t | ¡ dS )zDestroy the windowN)rT   r   rB   rC   r   r   r   rB   ²   s    zDialog.destroyc                 C   s   dS )z«create dialog body.

        return widget that should have initial focus.
        This method should be overridden, and is called
        by the __init__ method.
        Nr   )r   r.   r   r   r   rS   º   s    zDialog.bodyc                 C   sv   t | ƒ}t|dd| jtd}|jtddd t|dd| jd}|jtddd |  d| j¡ |  d	| j¡ | ¡  d
S )z[add standard button box.

        override if you do not want the standard buttons
        ZOKé
   )r   Úwidthr   r$   rM   )r   rN   rO   ÚCancel)r   rX   r   r   z<Escape>N)r!   r)   ÚokZACTIVEr    r*   r#   r%   )r   ZboxÚwr   r   r   rU   Ã   s    zDialog.buttonboxc                 C   sJ   |   ¡ s| j ¡  d S |  ¡  |  ¡  z|  ¡  W |  ¡  n
|  ¡  0 d S r   )ÚvalidaterT   rV   r6   r8   Úapplyr#   rF   r   r   r   rZ   Ø   s    

z	Dialog.okc                 C   s    | j d ur| j  ¡  |  ¡  d S r   )rQ   rV   rB   rF   r   r   r   r#   æ   s    

zDialog.cancelc                 C   s   dS )z¨validate the data

        This method is called automatically to validate the data before the
        dialog is destroyed. By default, it always validates OK.
        r	   r   rC   r   r   r   r\   ð   s    zDialog.validatec                 C   s   dS )z¡process the data

        This method is called automatically to process the data, *after*
        the dialog is destroyed. By default, it does nothing.
        Nr   rC   r   r   r   r]   ù   s    zDialog.apply)N)N)N)rI   rJ   rK   Ú__doc__r2   rB   rS   rU   rZ   r#   r\   r]   r   r   r   r   rL   t   s   
7	


	rL   c                 C   s:   | j dkr | j dd| dd¡ n| j dkr6|  dd¡ d S )	NZaquaz!::tk::unsupported::MacWindowStyleÚstyleZmoveableModalr   Zx11z-typeZdialog)Z_windowingsystemZtkÚcallZwm_attributes)r[   r   r   r   r     s    

ÿ
r   c                   @   s.   e Zd Zd
dd„Zdd„ Zdd„ Zdd	„ ZdS )Ú_QueryDialogNc                 C   s*   || _ || _|| _|| _t | ||¡ d S r   )ÚpromptÚminvalueÚmaxvalueÚinitialvaluerL   r2   )r   r   rb   re   rc   rd   rQ   r   r   r   r2     s
    z_QueryDialog.__init__c                 C   s   d | _ t | ¡ d S r   )ÚentryrL   rB   rC   r   r   r   rB     s    z_QueryDialog.destroyc                 C   sr   t || jtd}|jddtd t|dd| _| jjddtt d | jd url| j 	d| j¡ | j 
dt¡ | jS )N)r   Zjustifyr   rM   )ÚrowrN   Zstickyrf   )Únamer	   )ZLabelrb   r*   ZgridÚWZEntryrf   ÚEre   ÚinsertZselect_rangeZEND)r   r.   r[   r   r   r   rS      s    
z_QueryDialog.bodyc                 C   sž   z|   ¡ }W n* ty6   tjd| jd | d Y dS 0 | jd urf|| jk rftjdd| j | d dS | jd ur”|| jkr”tjdd| j | d dS || _d	S )
NzIllegal valuez
Please try again)rQ   r   z	Too smallz2The allowed minimum value is %s. Please try again.z	Too largez2The allowed maximum value is %s. Please try again.r	   )Ú	getresultÚ
ValueErrorr   ÚshowwarningÚerrormessagerc   rd   rR   )r   rR   r   r   r   r\   .  s:    ýÿüÿüz_QueryDialog.validate)NNNN)rI   rJ   rK   r2   rB   rS   r\   r   r   r   r   ra     s      ý
ra   c                   @   s   e Zd ZdZdd„ ZdS )Ú_QueryIntegerzNot an integer.c                 C   s   |   | j ¡ ¡S r   )Zgetintrf   ÚgetrC   r   r   r   rl   S  s    z_QueryInteger.getresultN©rI   rJ   rK   ro   rl   r   r   r   r   rp   P  s   rp   c                 K   s   t | |fi |¤Ž}|jS )z¼get an integer from the user

    Arguments:

        title -- the dialog title
        prompt -- the label text
        **kw -- see SimpleDialog class

    Return value is an integer
    )rp   rR   ©r   rb   ÚkwÚdr   r   r   Ú
askintegerW  s    rv   c                   @   s   e Zd ZdZdd„ ZdS )Ú_QueryFloatzNot a floating point value.c                 C   s   |   | j ¡ ¡S r   )Z	getdoublerf   rq   rC   r   r   r   rl   i  s    z_QueryFloat.getresultNrr   r   r   r   r   rw   f  s   rw   c                 K   s   t | |fi |¤Ž}|jS )z¶get a float from the user

    Arguments:

        title -- the dialog title
        prompt -- the label text
        **kw -- see SimpleDialog class

    Return value is a float
    )rw   rR   rs   r   r   r   Úaskfloatm  s    rx   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú_QueryStringc                 O   s<   d|v r|d | _ |d= nd | _ tj| g|¢R i |¤Ž d S )NÚshow)Ú_QueryString__showra   r2   )r   Úargsrt   r   r   r   r2   }  s
    
z_QueryString.__init__c                 C   s(   t  | |¡}| jd ur$|j| jd |S )N)rz   )ra   rS   r{   Z	configure)r   r.   rf   r   r   r   rS   …  s    
z_QueryString.bodyc                 C   s
   | j  ¡ S r   )rf   rq   rC   r   r   r   rl   ‹  s    z_QueryString.getresultN)rI   rJ   rK   r2   rS   rl   r   r   r   r   ry   |  s   ry   c                 K   s   t | |fi |¤Ž}|jS )z¸get a string from the user

    Arguments:

        title -- the dialog title
        prompt -- the label text
        **kw -- see SimpleDialog class

    Return value is a string
    )ry   rR   rs   r   r   r   Ú	askstring  s    r}   Ú__main__c                  C   sL   t ƒ } | fdd„}t| d|d}| ¡  t| d|jd}| ¡  | ¡  d S )Nc                 S   s\   t | dg d¢dddd}t| ¡ ƒ ttddd	d
ƒ ttdddddƒ ttddƒƒ d S )Nz‘This is a test dialog.  Would this have been an actual dialog, the buttons below would have been glowing in soft pink light.
Do you believe this?)ZYesZNorY   r   é   zTest Dialog)r   r/   r$   r#   r   ZSpamz	Egg counté   )re   zEgg weight
(in tons)r	   éd   )rc   rd   z	Egg label)r   ÚprintrD   rv   rx   r}   )r   ru   r   r   r   Údoit¢  s    ÷

ÿztest.<locals>.doitZTestr   ZQuit)ZTkr)   r    rH   rA   )r   rƒ   ÚtÚqr   r   r   Útest   s    r†   N)r^   Útkinterr   r   r   r   rL   r   ra   rp   rv   rw   rx   ry   r}   rI   r†   r   r   r   r   Ú<module>   s    V 
C