
    3f-                         d Z ddl ddlmZmZ ddlmZ  G d d      Z G d de      Zdd
Zd Z	 G d de      Z
 G d de
      Zd Z G d de
      Zd Z G d de
      Zd Zedk(  rd Z e        y	y	)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                   8    e Zd Zdg ddddfdZd Zd Zd Zd Zy)SimpleDialog Nc                    |rt        ||      | _        nt        |      | _        |r6| j                  j                  |       | j                  j                  |       t	        | j                         t        | j                  |d      | _        | j                  j                  dt               t        | j                        | _
        | j                  j                          || _        || _        || _        | j                  j                  d| j                         t!        t#        |            D ][  }||   }	t%        | j                  |	| |fd      }
||k(  r|
j'                  t(        d	
       |
j                  t*        t        d       ] | j                  j-                  d| j.                         | j                  j1                  |       t3        | j                  |       y )N)class_i  )textaspect   )expandfill<Return>c                 $    | j                  |      S N)doneselfnums     +/usr/lib/python3.12/tkinter/simpledialog.py<lambda>z'SimpleDialog.__init__.<locals>.<lambda>9   s    499S>     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bs              r   __init__zSimpleDialog.__init__!   sj     7DI (DIIIOOE"IIu%dii tyytC@.499%


		z4#4#45W& 	3CAtzz,0c ILAg~15FF4F2	3 			-t/D/DE		F#dii(r   c                     | j                   j                          | j                   j                          | j                   j                          | j                   j	                          | j
                  S r   )r#   wait_visibilitygrab_setmainloopdestroyr   r   s    r   gozSimpleDialog.goA   sK    		!!#						xxr   c                     | j                   | j                  j                          y | j                  | j                          y r   )r.   r#   bellr   r   events     r   r0   zSimpleDialog.return_eventH   s*    <<IINNIIdll#r   c                     | j                   | j                  j                          y | j                  | j                          y r   )r-   r#   rH   r   rE   s    r   r8   zSimpleDialog.wm_delete_windowN   s*    ;;IINNIIdkk"r   c                 F    || _         | j                  j                          y r   )r   r#   quitr   s     r   r   zSimpleDialog.doneT   s    		r   )__name__
__module____qualname__r?   rF   r0   r8   r    r   r   r   r      s,     "d4D)@$#r   r   c                   F    e Zd ZdZddZd Zd Zd ZddZddZ	d	 Z
d
 Zy)DialogzZClass to open dialogs.

    This class is intended as a base class for custom dialogs
    Nc                    |}|
t               }t        j                  | |       | j                          |!|j	                         r| j                  |       |r| j                  |       t        |        || _        d| _	        t        |       }| j                  |      | _        |j                  dd       | j                          | j                  | | _        | j                  d| j                          t#        | |       | j                  j%                          | j'                          | j)                          | j+                  |        y)zInitialize a dialog.

        Arguments:

            parent -- a parent window (the application window)

            title -- the dialog title
        N   )padxpadyr!   )r   r"   r?   withdrawwinfo_viewabler9   r$   r&   parentresultr+   bodyinitial_focusr)   	buttonboxr7   r-   r:   	focus_setrA   rB   wait_window)r   rZ   r$   r;   r\   s        r   r?   zDialog.__init__`   s    >#%F$' &"7"7"9NN6"JJudT{!YYt_		qq	!%!%D($++6dF#$$& 	r   c                 f    d| _         t        j                  |        t        | j                         y)zDestroy the windowN)r]   r"   rD   r   r;   rE   s    r   rD   zDialog.destroy   s$    !4;;'r   c                      y)zcreate dialog body.

        return widget that should have initial focus.
        This method should be overridden, and is called
        by the __init__ method.
        NrQ   )r   r;   s     r   r\   zDialog.body        	r   c                 x   t        |       }t        |dd| j                  t              }|j	                  t
        dd       t        |dd| j                        }|j	                  t
        dd       | j                  d| j                         | j                  d	| j                         |j	                          y
)z[add standard button box.

        override if you do not want the standard buttons
        OK
   )r   widthr   r.   rU   )r    rV   rW   Cancel)r   rg   r   r   z<Escape>N)r+   r3   okACTIVEr)   r6   r-   r/   )r   boxws      r   r^   zDialog.buttonbox   s     Dk3TTWWfM	Dqq)3XRE	Dqq)		*dgg&		*dkk*
r   c                    | j                         s| j                  j                          y | j                          | j	                          	 | j                          | j                          y # | j                          w xY wr   )validater]   r_   rX   update_idletasksapplyr-   rI   s     r   ri   z	Dialog.ok   sV    }}((*	JJLKKMDKKMs   A. .B c                 p    | j                   | j                   j                          | j                          y r   )rZ   r_   rD   rI   s     r   r-   zDialog.cancel   s'     ;;"KK!!#r   c                      y)zvalidate the data

        This method is called automatically to validate the data before the
        dialog is destroyed. By default, it always validates OK.
        r   rQ   rE   s    r   rn   zDialog.validate   s     r   c                      y)zprocess the data

        This method is called automatically to process the data, *after*
        the dialog is destroyed. By default, it does nothing.
        NrQ   rE   s    r   rp   zDialog.apply   rc   r   r   )rN   rO   rP   __doc__r?   rD   r\   r^   ri   r-   rn   rp   rQ   r   r   rS   rS   Y   s0    
1f(*r   rS   Nc                 <   | j                          | j                          | j                         }| j                         }| j	                         }| j                         }||j                         r|j                         |j                         |z
  dz  z   }|j                         |j                         |z
  dz  z   }| j                         }| j                         }	t        |||z   |z
        }t        ||      }t        ||	|z   |z
        }t        ||	      }| j                  dk(  r9t        |d      }n,| j!                         |z
  dz  }| j#                         |z
  dz  }| j%                  ||       | j'                  d||fz         | j)                          y )N   aqua   z+%d+%d)wm_withdrawro   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)
rl   rZ   minwidth	minheightmaxwidth	maxheightxyvrootxvrootys
             r   r:   r:      s|   MMO!H!!#I!!#H##%If335 F$6$6$88$C#II F$7$7$9I$E!#KK!!6H$x/06N6I%	126N'Ar
A  "X-!3!!#i/A5LL9%MM(aV#$NNr   c                     | j                   dk(  r | j                  j                  dd| dd       y | j                   dk(  r| j                  dd       y y )	Nrw   z!::tk::unsupported::MacWindowStylestylemoveableModalr	   x11z-typedialog)r   tkcallwm_attributes)rl   s    r   r&   r&     sM    V#			5w_b	*	
		u	$	* 
%r   c                   ,    e Zd Z	 	 	 ddZd Zd Zd Zy)_QueryDialogNc                 j    || _         || _        || _        || _        t        j                  | ||       y r   )promptminvaluemaxvalueinitialvaluerS   r?   )r   r$   r   r   r   r   rZ   s          r   r?   z_QueryDialog.__init__  s1    
   (fe,r   c                 <    d | _         t        j                  |        y r   )entryrS   rD   rE   s    r   rD   z_QueryDialog.destroy  s    
tr   c                    t        || j                  t              }|j                  ddt               t        |d      | _        | j                  j                  ddt        t        z          | j                  F| j                  j                  d| j                         | j                  j                  dt               | j                  S )N)r   justifyr   rU   )rowrV   stickyr   )namer   )Labelr   r6   gridWEntryr   Er   insertselect_rangeEND)r   r;   rl   s      r   r\   z_QueryDialog.body!  s    &t{{D9	11Q'60


AAac2(JJa!2!23JJ##As+zzr   c                    	 | j                         }| j
                  5|| j
                  k  r&t        j                  dd| j
                  z  |        y| j                  5|| j                  kD  r&t        j                  dd| j                  z  |        y|| _        y	# t        $ r( t        j                  d| j                  dz   |        Y yw xY w)
NzIllegal valuez
Please try again)rZ   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   r[   )r   r[   s     r   rn   z_QueryDialog.validate/  s    	^^%F ==$$--)?""$&*mm4	 ==$$--)?""$&*mm4	 9  	""!!$88
 	s   B .CC)NNNN)rN   rO   rP   r?   rD   r\   rn   rQ   r   r   r   r     s!     #-1-r   r   c                       e Zd ZdZd Zy)_QueryIntegerzNot an integer.c                 T    | j                  | j                  j                               S r   )getintr   getrE   s    r   r   z_QueryInteger.getresultT  s    {{4::>>+,,r   NrN   rO   rP   r   r   rQ   r   r   r   r   Q  s    $L-r   r   c                 4    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   r[   r$   r   kwds       r   
askintegerr   X  s     	eV*r*A88Or   c                       e Zd ZdZd Zy)_QueryFloatzNot a floating point value.c                 T    | j                  | j                  j                               S r   )	getdoubler   r   rE   s    r   r   z_QueryFloat.getresultj  s    ~~djjnn.//r   Nr   rQ   r   r   r   r   g  s    0L0r   r   c                 4    t        | |fi |}|j                  S )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   r[   r   s       r   askfloatr   n  s     	E6(R(A88Or   c                       e Zd Zd Zd Zd Zy)_QueryStringc                 h    d|v r|d   | _         |d= nd | _         t        j                  | g|i | y )Nshow)_QueryString__showr   r?   )r   argsr   s      r   r?   z_QueryString.__init__~  s:    R<V*DK6
DKd0T0R0r   c                     t         j                  | |      }| j                  |j                  | j                         |S )N)r   )r   r\   r   	configure)r   r;   r   s      r   r\   z_QueryString.body  s5    !!$/;;"OOO-r   c                 6    | j                   j                         S r   )r   r   rE   s    r   r   z_QueryString.getresult  s    zz~~r   N)rN   rO   rP   r?   r\   r   rQ   r   r   r   r   }  s    1 r   r   c                 4    t        | |fi |}|j                  S )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   r[   r   s       r   	askstringr     s     	UF)b)A88Or   __main__c                      t               } | fd}t        | d|      }|j                          t        | d|j                        }|j                          |j	                          y )Nc                     t        | dg dddd      }t        |j                                t        t        ddd	
             t        t	        dddd             t        t        dd             y )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Norh   r   rv   zTest Dialog)r   r<   r.   r-   r$   Spamz	Egg count   )r   zEgg weight
(in tons)r   d   )r   r   z	Egg label)r   printrF   r   r   r   )r#   r   s     r   doitztest.<locals>.doit  si    T5
 "9!" !,	.A !$$&M*V[uEF(6#:Q$') *)FK01r   Testr   Quit)Tkr3   r)   rM   rC   )r#   r   tqs       r   testr     sN    t 	2  4fd3	4faff5		

r   r   )rt   tkinterr   r   r   r   r"   rS   r:   r&   r   r   r   r   r   r   r   rN   r   rQ   r   r   <module>r      s     6 7 7tIX I\:+@6 @F-L -0, 0 <  & z0 	F5 r   