
[[\,                 @   s   d  Z  d d l Td d l m Z d d l Z Gd d   d  Z Gd d   d e  Z Gd	 d
   d
 e  Z Gd d   d e  Z d d   Z Gd d   d e  Z	 d d   Z
 Gd d   d e  Z d d   Z e d k r d d   Z e   n  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
    )*)
messageboxNc               @   sp   e  Z d  Z d g  d d d d d d  Z d 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  |  |  _ | rV |  j j |  |  j j |  n  t |  j d | d d |  _ |  j j d d d t  t |  j  |  _	 |  j	 j   | |  _
 | |  _ | |  _ |  j j d |  j  x t t |   D]x } | | }	 t |  j	 d |	 d	 |  | d
 d  }
 | | k rL|
 j d t d d  n  |
 j d t d t d d  q W|  j j d |  j  |  j |  d  S)Nclass_textZaspecti  expand   Zfillz<Return>commandc             S   s   |  j  |  S)N)done)selfnum r   */usr/lib/python3.4/tkinter/simpledialog.py<lambda>6   s    z'SimpleDialog.__init__.<locals>.<lambda>ZreliefZborderwidth   sideWM_DELETE_WINDOW)ToplevelroottitleZiconnameZMessagemessagepackZBOTHFrameZ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__!   s.    			
 zSimpleDialog.__init__g      ?g333333?c             C   sh  |  j  } | j   | j |  | j   | j   ri | j   } | j   } | j   } | j   } n" | j	   } | j
   } d } } | j   }	 | j   }
 | | |	 | } | | |
 | } | |	 | j	   k r | j	   |	 } n | d k  rd } n  | |
 | j
   k r.| j
   |
 } n | d k  rCd } n  | j d | | f  | j   d  S)Nr   z+%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  j   |  j  j   |  j S)N)r   wait_visibilitygrab_setmainloopdestroyr   )r   r   r   r   goZ   s
    zSimpleDialog.goc             C   s3   |  j  d  k r |  j j   n |  j |  j   d  S)N)r   r   bellr   )r   eventr   r   r   r   a   s    zSimpleDialog.return_eventc             C   s3   |  j  d  k r |  j j   n |  j |  j   d  S)N)r   r   r8   r   )r   r   r   r   r#   g   s    zSimpleDialog.wm_delete_windowc             C   s   | |  _  |  j j   d  S)N)r   r   quit)r   r   r   r   r   r   m   s    	zSimpleDialog.done)	__name__
__module____qualname__r)   r$   r7   r   r#   r   r   r   r   r   r      s   r   c               @   s   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=  t  j |  |  |  j   | j   r6 |  j |  n  | rL |  j |  n  | |  _ d |  _ t |   } |  j	 |  |  _
 | j d d d d  |  j   |  j
 s |  |  _
 n  |  j d |  j  |  j d k	 r|  j d | j   d | j   d f  n  |  j   |  j
 j   |  j   |  j   |  j |   d S)zInitialize a dialog.

        Arguments:

            parent -- a parent window (the application window)

            title -- the dialog title
        Npadx   padyr   z+%d+%d2   )r   r)   r*   Zwinfo_viewabler+   r   parentresultr   bodyinitial_focusr   	buttonboxr"   r   r/   r-   r.   r0   	focus_setr3   r4   Zwait_window)r   rC   r   rE   r   r   r   r)   y   s.    

		
	


zDialog.__init__c             C   s   d |  _  t j |   d S)zDestroy the windowN)rF   r   r6   )r   r   r   r   r6      s    	zDialog.destroyc             C   s   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   r%   r   r   r   rE      s    zDialog.bodyc          
   C   s   t  |   } t | d d d d d |  j d t } | j d t d d	 d
 d	  t | d d d d d |  j } | j d t d d	 d
 d	  |  j d |  j  |  j d |  j  | j   d S)z[add standard button box.

        override if you do not want the standard buttons
        r   ZOKwidth
   r
   r   r   r?   r@   rA   Cancelz<Return>z<Escape>N)r   r    okZACTIVEr   r!   r   r   )r   Zboxwr   r   r   rG      s    '!zDialog.buttonboxc          
   C   sQ   |  j    s |  j j   d  S|  j   |  j   z |  j   Wd  |  j   Xd  S)N)validaterF   rH   r*   r,   applyr   )r   r9   r   r   r   rL      s    

z	Dialog.okc             C   s-   |  j  d  k	 r |  j  j   n  |  j   d  S)N)rC   rH   r6   )r   r9   r   r   r   r      s    zDialog.cancelc             C   s   d S)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   rN      s    zDialog.validatec             C   s   d S)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   rO      s    zDialog.apply)r;   r<   r=   __doc__r)   r6   rE   rG   rL   r   rN   rO   r   r   r   r   r>   r   s   2	
	r>   c               @   sL   e  Z d  Z d d d d d d  Z d d   Z d d   Z d d	   Z d S)
_QueryDialogNc             C   sM   | s t  j } n  | |  _ | |  _ | |  _ | |  _ t j |  | |  d  S)N)tkinterZ_default_rootpromptminvaluemaxvalueinitialvaluer>   r)   )r   r   rS   rV   rT   rU   rC   r   r   r   r)     s    				z_QueryDialog.__init__c             C   s   d  |  _  t j |   d  S)N)entryr>   r6   )r   r   r   r   r6     s    	z_QueryDialog.destroyc             C   s   t  | d |  j d t } | j d d d d d t  t | d d	 |  _ |  j j d d
 d d d t t  |  j d  k	 r |  j j	 d |  j  |  j j
 d t  n  |  j S)Nr   Zjustifyrowr   r?   r@   ZstickynamerW   r	   )ZLabelrS   r!   ZgridWZEntryrW   ErV   insertZselect_rangeZEND)r   r%   rM   r   r   r   rE     s    #z_QueryDialog.bodyc             C   s   y |  j    } Wn3 t k
 rE t j d |  j d d |  d SYn X|  j d  k	 r | |  j k  r t j d d |  j d |  d S|  j d  k	 r | |  j k r t j d d |  j d |  d S| |  _ d	 S)
NzIllegal valuez
Please try againrC   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errormessagerT   rU   rD   )r   rD   r   r   r   rN   #  s0    	

	z_QueryDialog.validate)r;   r<   r=   r)   r6   rE   rN   r   r   r   r   rQ      s   rQ   c               @   s"   e  Z d  Z d Z d d   Z d S)_QueryIntegerzNot an integer.c             C   s   t  |  j j    S)N)intrW   get)r   r   r   r   r]   G  s    z_QueryInteger.getresultN)r;   r<   r=   r`   r]   r   r   r   r   ra   E  s   ra   c             K   s   t  |  | |  } | 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
    )ra   rD   )r   rS   kwdr   r   r   
askintegerJ  s    rf   c               @   s"   e  Z d  Z d Z d d   Z d S)_QueryFloatzNot a floating point value.c             C   s   t  |  j j    S)N)floatrW   rc   )r   r   r   r   r]   Z  s    z_QueryFloat.getresultN)r;   r<   r=   r`   r]   r   r   r   r   rg   X  s   rg   c             K   s   t  |  | |  } | 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
    )rg   rD   )r   rS   rd   re   r   r   r   askfloat]  s    ri   c               @   s4   e  Z d  Z d d   Z d d   Z d d   Z d S)_QueryStringc             O   sC   d | k r# | d |  _  | d =n	 d  |  _  t j |  | |  d  S)Nshow)_QueryString__showrQ   r)   )r   argsrd   r   r   r   r)   l  s
    
	z_QueryString.__init__c             C   s;   t  j |  |  } |  j d  k	 r7 | j d |  j  n  | S)Nrk   )rQ   rE   rl   Z	configure)r   r%   rW   r   r   r   rE   t  s    z_QueryString.bodyc             C   s   |  j  j   S)N)rW   rc   )r   r   r   r   r]   z  s    z_QueryString.getresultN)r;   r<   r=   r)   rE   r]   r   r   r   r   rj   k  s   rj   c             K   s   t  |  | |  } | 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
    )rj   rD   )r   rS   rd   re   r   r   r   	askstring}  s    rn   __main__c              C   sm   t    }  |  d d  } t |  d d d | } | j   t |  d d d | j } | j   | j   d  S)Nc             S   s   t  |  d d d d d d g d d d	 d
 d d } t | j    t t d d d d  t t d d d d d d  t t d d   d  S)Nr   zThis 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?r&   ZYesZNorK   r   r   r      r   zTest DialogZSpamz	Egg countrV      zEgg weight
(in tons)rT   r	   rU   d   z	Egg label   )r   printr7   rf   ri   rn   )r   re   r   r   r   doit  s    		
ztest.<locals>.doitr   ZTestr
   ZQuit)ZTkr    r   r:   r5   )r   ru   tqr   r   r   test  s    	

rx   )rP   rR   r   r   r   r>   rQ   ra   rf   rg   ri   rj   rn   r;   rx   r   r   r   r   <module>   s   
SF