o
    JAfé-  ã                   @   sÎ   d Z ddlT ddlmZmZ ddlmZ G dd„ dƒZG dd„ deƒZdd
d„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redd„ Zeƒ  d	S 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
é    )Ú*)Ú_get_temp_rootÚ_destroy_temp_root)Ú
messageboxc                   @   sB   e Zd Zdg ddddf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 ]&}|| }	t| j
|	| |fdd„d	}
||krs|
jtd
d |
jttdd qU| j d| j¡ | j |¡ t| j|ƒ d S )N)Úclass_i  )ÚtextZaspecté   )ÚexpandÚfillú<Return>c                 S   s
   |   |¡S ©N)Údone©ÚselfÚnum© r   ú+/usr/lib/python3.10/tkinter/simpledialog.pyÚ<lambda>9   s   
 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Ú	transientÚ_place_window)r   Úmasterr	   Úbuttonsr$   r#   r   r   r   ÚsÚbr   r   r   Ú__init__!   s4   


ÿzSimpleDialog.__init__c                 C   s.   | j  ¡  | j  ¡  | j  ¡  | j  ¡  | jS r   )r   Úwait_visibilityÚgrab_setÚmainloopÚdestroyr   ©r   r   r   r   ÚgoA   s
   



zSimpleDialog.goc                 C   ó(   | j d u r| j ¡  d S |  | j ¡ d S r   )r$   r   Úbellr   ©r   Úeventr   r   r   r&   H   ó   
zSimpleDialog.return_eventc                 C   r:   r   )r#   r   r;   r   r8   r   r   r   r,   N   r>   zSimpleDialog.wm_delete_windowc                 C   s   || _ | j ¡  d S r   )r   r   Úquitr   r   r   r   r   T   ó   zSimpleDialog.done)Ú__name__Ú
__module__Ú__qualname__r3   r9   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Ü   |}|du r	t ƒ }t | |¡ |  ¡  |dur | ¡ r |  |¡ |r'|  |¡ t| ƒ || _d| _	t
| ƒ}|  |¡| _|jddd |  ¡  | jdu rN| | _|  d| j¡ t| |ƒ | j ¡  |  ¡  |  ¡  |  | ¡ dS )z˜Initialize a dialog.

        Arguments:

            parent -- a parent window (the application window)

            title -- the dialog title
        Né   )ÚpadxÚpadyr   )r   r   r3   ÚwithdrawZwinfo_viewabler-   r   r   ÚparentÚresultr!   ÚbodyÚinitial_focusr    Ú	buttonboxr+   r#   r.   Ú	focus_setr4   r5   Zwait_window)r   rI   r   r/   rK   r   r   r   r3   `   s0   	




zDialog.__init__c                 C   s   d| _ t | ¡ t| jƒ dS )zDestroy the windowN)rL   r   r7   r   r/   r8   r   r   r   r7   “   s   
zDialog.destroyc                 C   ó   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   rK   œ   ó   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$   rE   )r   rF   rG   ÚCancel)r	   rR   r   r   z<Escape>N)r!   r)   ÚokZACTIVEr    r*   r#   r%   )r   ZboxÚwr   r   r   rM   ¥   s   zDialog.buttonboxc                 C   sH   |   ¡ s| j ¡  d S |  ¡  |  ¡  z|  ¡  W |  ¡  d S |  ¡  w r   )ÚvalidaterL   rN   rH   Úupdate_idletasksÚapplyr#   r<   r   r   r   rT   º   s   

z	Dialog.okc                 C   s    | j d ur
| j  ¡  |  ¡  d S r   )rI   rN   r7   r<   r   r   r   r#   È   s   

zDialog.cancelc                 C   rO   )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   r8   r   r   r   rV   Ò   rP   zDialog.validatec                 C   rO   )z¡process the data

        This method is called automatically to process the data, *after*
        the dialog is destroyed. By default, it does nothing.
        Nr   r8   r   r   r   rX   Û   rP   zDialog.applyr   )rA   rB   rC   Ú__doc__r3   r7   rK   rM   rT   r#   rV   rX   r   r   r   r   rD   Y   s    
3		


	rD   Nc           
      C   s  |   ¡  |  ¡  |  ¡ }|  ¡ }|  ¡ }|  ¡ }|d urg| ¡ rg| ¡ | ¡ | d  }| 	¡ | 
¡ | d  }|  ¡ }|  ¡ }	t||| | ƒ}t||ƒ}t||	| | ƒ}t||	ƒ}| jdkrft|dƒ}n|  ¡ | d }|  ¡ | d }|  ||¡ |  d||f ¡ |  ¡  d S )Né   Úaquaé   z+%d+%d)Zwm_withdrawrW   Zwinfo_reqwidthZwinfo_reqheightZwinfo_vrootwidthZwinfo_vrootheightZwinfo_ismappedZwinfo_rootxZwinfo_widthZwinfo_rootyZwinfo_heightZwinfo_vrootxZwinfo_vrootyÚminÚmaxÚ_windowingsystemZwinfo_screenwidthZwinfo_screenheightZ
wm_maxsizeZwm_geometryZwm_deiconify)
rU   rI   ZminwidthZ	minheightZmaxwidthZ	maxheightÚxÚyZvrootxZvrootyr   r   r   r.   ç   s.   



€r.   c                 C   s@   | j dkr| j dd| dd¡ d S | j dkr|  dd¡ d S d S )	Nr[   z!::tk::unsupported::MacWindowStyleÚstyleZmoveableModalr   Zx11z-typeZdialog)r_   ZtkÚcallZwm_attributes)rU   r   r   r   r     s   

ÿ
ÿr   c                   @   s4   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ÚinitialvaluerD   r3   )r   r   re   rh   rf   rg   rI   r   r   r   r3     s
   z_QueryDialog.__init__c                 C   s   d | _ t | ¡ d S r   )ÚentryrD   r7   r8   r   r   r   r7     r@   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r6| j 	d| j¡ | j 
dt¡ | jS )N)r	   Zjustifyr   rE   )ÚrowrF   Zstickyri   )Únamer
   )ZLabelre   r*   ZgridÚWZEntryri   ÚErh   ÚinsertZselect_rangeZEND)r   r/   rU   r   r   r   rK   !  s   
z_QueryDialog.bodyc                 C   sž   z|   ¡ }W n ty   tjd| jd | d Y dS w | jd ur3|| jk r3tjdd| j | d dS | jd urJ|| jkrJtjdd| j | d dS || _d	S )
NzIllegal valuez
Please try again)rI   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Úerrormessagerf   rg   rJ   )r   rJ   r   r   r   rV   /  s<   ýúÿüÿüz_QueryDialog.validate)NNNN)rA   rB   rC   r3   r7   rK   rV   r   r   r   r   rd     s    
ýrd   c                   @   ó   e Zd ZdZdd„ ZdS )Ú_QueryIntegerzNot an integer.c                 C   ó   |   | j ¡ ¡S r   )Zgetintri   Úgetr8   r   r   r   ro   T  ó   z_QueryInteger.getresultN©rA   rB   rC   rr   ro   r   r   r   r   rt   Q  ó    rt   c                 K   ó   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
    )rt   rJ   ©r   re   ÚkwÚdr   r   r   Ú
askintegerX  ó   r~   c                   @   rs   )Ú_QueryFloatzNot a floating point value.c                 C   ru   r   )Z	getdoubleri   rv   r8   r   r   r   ro   j  rw   z_QueryFloat.getresultNrx   r   r   r   r   r€   g  ry   r€   c                 K   rz   )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
    )r€   rJ   r{   r   r   r   Úaskfloatn  r   r   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__showrd   r3   )r   Úargsr|   r   r   r   r3   ~  s
   
z_QueryString.__init__c                 C   s(   t  | |¡}| jd ur|j| jd |S )N)rƒ   )rd   rK   r„   Z	configure)r   r/   ri   r   r   r   rK   †  s   
z_QueryString.bodyc                 C   s
   | j  ¡ S r   )ri   rv   r8   r   r   r   ro   Œ  s   
z_QueryString.getresultN)rA   rB   rC   r3   rK   ro   r   r   r   r   r‚   }  s    r‚   c                 K   rz   )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
    )r‚   rJ   r{   r   r   r   Ú	askstring  r   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NorS   r   rZ   zTest Dialog)r	   r0   r$   r#   r   ZSpamz	Egg counté   )rh   zEgg weight
(in tons)r
   éd   )rf   rg   z	Egg label)r   Úprintr9   r~   r   r†   )r   r}   r   r   r   Údoit£  s   ÷

ÿztest.<locals>.doitZTestr   ZQuit)ZTkr)   r    r?   r6   )r   r‹   ÚtÚqr   r   r   Útest¡  s   rŽ   r   )rY   Útkinterr   r   r   r   r   rD   r.   r   rd   rt   r~   r€   r   r‚   r†   rA   rŽ   r   r   r   r   Ú<module>   s(   
: 

C
æ