o
    8U€jé-  ã                   @   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  )ÚtextÚaspecté   )ÚexpandÚfillú<Return>c                 S   s
   |   |¡S ©N)Údone©ÚselfÚnum© r   úf/home/user/.local/share/uv/python/cpython-3.10-linux-x86_64-gnu/lib/python3.10/tkinter/simpledialog.pyÚ<lambda>9   s   
 z'SimpleDialog.__init__.<locals>.<lambda>©r	   Úcommandé   )ÚreliefÚborderwidth)Úsider   r   ÚWM_DELETE_WINDOW)ÚToplevelÚrootÚtitleÚiconnameÚ_setup_dialogÚMessageÚmessageÚpackÚBOTHÚFrameÚframer   ÚcancelÚdefaultÚbindÚreturn_eventÚrangeÚlenÚButtonÚconfigÚ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   rB   r   )r)   r   rC   r   r@   r   r   r   r4   N   rF   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__r;   rA   r,   r4   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   r;   ÚwithdrawÚwinfo_viewabler5   r    r"   ÚparentÚresultr'   ÚbodyÚinitial_focusr%   Ú	buttonboxr3   r)   r6   Ú	focus_setr<   r=   Úwait_window)r   rR   r    r7   rT   r   r   r   r;   `   s0   	




zDialog.__init__c                 C   s   d| _ t | ¡ t| jƒ dS )zDestroy the windowN)rU   r   r?   r   r7   r@   r   r   r   r?   “   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   r7   r   r   r   rT   œ   ó   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
        ÚOKé
   )r	   Úwidthr   r*   rM   )r   rN   rO   ÚCancel)r	   r]   r   r   z<Escape>N)r'   r/   ÚokÚACTIVEr%   r2   r)   r+   )r   ZboxÚwr   r   r   rV   ¥   s   zDialog.buttonboxc                 C   sH   |   ¡ s| j ¡  d S |  ¡  |  ¡  z|  ¡  W |  ¡  d S |  ¡  w r   )ÚvalidaterU   rW   rP   Úupdate_idletasksÚapplyr)   rD   r   r   r   r_   º   s   

z	Dialog.okc                 C   s    | j d ur
| j  ¡  |  ¡  d S r   )rR   rW   r?   rD   r   r   r   r)   È   s   

zDialog.cancelc                 C   rY   )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   r@   r   r   r   rb   Ò   rZ   zDialog.validatec                 C   rY   )z¡process the data

        This method is called automatically to process the data, *after*
        the dialog is destroyed. By default, it does nothing.
        Nr   r@   r   r   r   rd   Û   rZ   zDialog.applyr   )rI   rJ   rK   Ú__doc__r;   r?   rT   rV   r_   r)   rb   rd   r   r   r   r   rL   Y   s    
3		


	rL   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)Úwm_withdrawrc   Úwinfo_reqwidthÚwinfo_reqheightÚwinfo_vrootwidthÚwinfo_vrootheightÚwinfo_ismappedÚwinfo_rootxÚwinfo_widthÚwinfo_rootyÚwinfo_heightÚwinfo_vrootxÚwinfo_vrootyÚminÚmaxÚ_windowingsystemÚwinfo_screenwidthÚwinfo_screenheightÚ
wm_maxsizeÚwm_geometryÚwm_deiconify)
ra   rR   ZminwidthZ	minheightZmaxwidthZ	maxheightÚxÚyÚvrootxÚvrootyr   r   r   r6   ç   s.   



€r6   c                 C   s@   | j dkr| j dd| dd¡ d S | j dkr|  dd¡ d S d S )	Nrg   z!::tk::unsupported::MacWindowStyleZstyleZmoveableModalr   Úx11z-typeÚdialog)rw   ÚtkÚcallÚwm_attributes)ra   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ÚinitialvaluerL   r;   )r   r    r‡   rŠ   rˆ   r‰   rR   r   r   r   r;     s
   z_QueryDialog.__init__c                 C   s   d | _ t | ¡ d S r   )ÚentryrL   r?   r@   r   r   r   r?     rH   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   rM   )ÚrowrN   Zstickyr‹   )Únamer   )ÚLabelr‡   r2   ÚgridÚWÚEntryr‹   ÚErŠ   ÚinsertÚselect_rangeÚEND)r   r7   ra   r   r   r   rT   !  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)rR   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   ZshowwarningÚerrormessagerˆ   r‰   rS   )r   rS   r   r   r   rb   /  s<   ýúÿüÿüz_QueryDialog.validate)NNNN)rI   rJ   rK   r;   r?   rT   rb   r   r   r   r   r†     s    
ýr†   c                   @   ó   e Zd ZdZdd„ ZdS )Ú_QueryIntegerzNot an integer.c                 C   ó   |   | j ¡ ¡S r   )Úgetintr‹   Úgetr@   r   r   r   r–   T  ó   z_QueryInteger.getresultN©rI   rJ   rK   r˜   r–   r   r   r   r   rš   Q  ó    rš   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
    )rš   rS   ©r    r‡   ÚkwÚdr   r   r   Ú
askintegerX  ó   r¥   c                   @   r™   )Ú_QueryFloatzNot a floating point value.c                 C   r›   r   )Ú	getdoubler‹   r   r@   r   r   r   r–   j  rž   z_QueryFloat.getresultNrŸ   r   r   r   r   r§   g  r    r§   c                 K   r¡   )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§   rS   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__showr†   r;   )r   Úargsr£   r   r   r   r;   ~  s
   
z_QueryString.__init__c                 C   s(   t  | |¡}| jd ur|j| jd |S )N)r«   )r†   rT   r¬   Ú	configure)r   r7   r‹   r   r   r   rT   †  s   
z_QueryString.bodyc                 C   s
   | j  ¡ S r   )r‹   r   r@   r   r   r   r–   Œ  s   
z_QueryString.getresultN)rI   rJ   rK   r;   rT   r–   r   r   r   r   rª   }  s    rª   c                 K   r¡   )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ª   rS   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?)ÚYesZNor^   r   rf   zTest Dialog)r	   r8   r*   r)   r    ZSpamz	Egg counté   )rŠ   zEgg weight
(in tons)r   éd   )rˆ   r‰   z	Egg label)r   ÚprintrA   r¥   r©   r¯   )r   r¤   r   r   r   Údoit£  s   ÷

ÿztest.<locals>.doitZTestr   ZQuit)ÚTkr/   r%   rG   r>   )r   rµ   ÚtÚqr   r   r   Útest¡  s   r¹   r   )re   Útkinterr   r   r   r   r   rL   r6   r"   r†   rš   r¥   r§   r©   rª   r¯   rI   r¹   r   r   r   r   Ú<module>   s(   
: 

C
æ