a
    ãIþfí-  ã                   @   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   ú%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   Z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   rP   r   r.   rR   r   r   r   r2   {   s8    	


ÿ
zDialog.__init__c                 C   s   d| _ t | ¡ dS )zDestroy the windowN)rS   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   rR   º   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$   rL   )r   rM   rN   ÚCancel)r   rW   r   r   z<Escape>N)r!   r)   ÚokZACTIVEr    r*   r#   r%   )r   ZboxÚwr   r   r   rT   Ã   s    zDialog.buttonboxc                 C   sJ   |   ¡ s| j ¡  d S |  ¡  |  ¡  z|  ¡  W |  ¡  n
|  ¡  0 d S r   )ÚvalidaterS   rU   r6   r8   Úapplyr#   rF   r   r   r   rY   Ø   s    

z	Dialog.okc                 C   s    | j d ur| j  ¡  |  ¡  d S r   )rP   rU   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)rH   rI   rJ   Ú__doc__r2   rB   rR   rT   rY   r#   r[   r\   r   r   r   r   rK   t   s   
7	


	rK   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::MacWindowStyleZstyleZmoveableModalr   Zx11z-typeZdialog)Z_windowingsystemZtkZcallZwm_attributes)rZ   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ÚinitialvaluerK   r2   )r   r   r_   rb   r`   ra   rP   r   r   r   r2     s
    z_QueryDialog.__init__c                 C   s   d | _ t | ¡ d S r   )ÚentryrK   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   rL   )ÚrowrM   Zstickyrc   )Únamer	   )ZLabelr_   r*   ZgridÚWZEntryrc   ÚErb   ÚinsertZselect_rangeZEND)r   r.   rZ   r   r   r   rR      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)rP   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Úerrormessager`   ra   rQ   )r   rQ   r   r   r   r[   .  s:    ýÿüÿüz_QueryDialog.validate)NNNN)rH   rI   rJ   r2   rB   rR   r[   r   r   r   r   r^     s      ý
r^   c                   @   s   e Zd ZdZdd„ ZdS )Ú_QueryIntegerzNot an integer.c                 C   s   |   | j ¡ ¡S r   )Zgetintrc   ÚgetrC   r   r   r   ri   S  s    z_QueryInteger.getresultN©rH   rI   rJ   rl   ri   r   r   r   r   rm   P  s   rm   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
    )rm   rQ   ©r   r_   ÚkwÚdr   r   r   Ú
askintegerW  s    rs   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	getdoublerc   rn   rC   r   r   r   ri   i  s    z_QueryFloat.getresultNro   r   r   r   r   rt   f  s   rt   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
    )rt   rQ   rp   r   r   r   Úaskfloatm  s    ru   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__showr^   r2   )r   Úargsrq   r   r   r   r2   }  s
    
z_QueryString.__init__c                 C   s(   t  | |¡}| jd ur$|j| jd |S )N)rw   )r^   rR   rx   Z	configure)r   r.   rc   r   r   r   rR   …  s    
z_QueryString.bodyc                 C   s
   | j  ¡ S r   )rc   rn   rC   r   r   r   ri   ‹  s    z_QueryString.getresultN)rH   rI   rJ   r2   rR   ri   r   r   r   r   rv   |  s   rv   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
    )rv   rQ   rp   r   r   r   Ú	askstring  s    rz   Ú__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NorX   r   é   zTest Dialog)r   r/   r$   r#   r   ZSpamz	Egg counté   )rb   zEgg weight
(in tons)r	   éd   )r`   ra   z	Egg label)r   ÚprintrD   rs   ru   rz   )r   rr   r   r   r   Údoit¢  s    ÷

ÿztest.<locals>.doitZTestr   ZQuit)ZTkr)   r    rG   rA   )r   r€   ÚtÚqr   r   r   Útest   s    rƒ   N)r]   Ztkinterr   r   r   r   rK   r   r^   rm   rs   rt   ru   rv   rz   rH   rƒ   r   r   r   r   Ú<module>   s    V 
C