o
    bc-                     @   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   +/usr/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 )zInitialize 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 )zcreate 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   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   )zvalidate 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   rc      rZ   zDialog.validatec                 C   rY   )zprocess 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   re      rZ   zDialog.applyr   )rI   rJ   rK   __doc__r;   r?   rT   rV   r_   r)   rc   re   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_withdrawrd   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)
rb   rR   minwidth	minheightmaxwidth	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 )	Nrh   z!::tk::unsupported::MacWindowStylestylemoveableModalr   x11z-typedialog)rx   tkcallwm_attributes)rb   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	   justifyr   rM   )rowrN   stickyr   )namer   )Labelr   r2   gridWEntryr   Er   insertselect_rangeEND)r   r7   rb   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   showwarningerrormessager   r   rS   )r   rS   r   r   r   rc   /  s<   z_QueryDialog.validate)NNNN)rI   rJ   rK   r;   r?   rT   rc   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 )zget 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   )zget 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   )zget 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 )NzThis 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?)YesNor^   r   rg   zTest Dialog)r	   r8   r*   r)   r    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>.doitTestr   Quit)Tkr/   r%   rG   r>   )r   r   tqr   r   r   test  s   r   r   )rf   tkinterr   r   r   r   r   rL   r6   r"   r   r   r   r   r   r   r   rI   r   r   r   r   r   <module>   s(   
: 

C
