
+c`,                 @   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   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  |  |  _ | rS |  j j |  |  j j |  t |  j d | d d |  _ |  j j d d d t  t |  j  |  _	 |  j	 j   | |  _
 | |  _ | |  _ |  j j d |  j  x t t |   D]u } | | }	 t |  j	 d |	 d	 |  | d
 d  }
 | | k rF|
 j d t d d  |
 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.5/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Frame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   sb  |  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 } | |
 | j
   k r+| j
   |
 } n | d k  r=d } | 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   r9   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%   r8   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   s1  t  j |  |  |  j   | j   r3 |  j |  | rF |  j |  | |  _ d |  _ t |   } |  j	 |  |  _
 | j d d d d  |  j   |  j
 s |  |  _
 |  j d |  j  |  j d k	 r |  j d | j   d | j   d f  |  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   r0   r.   r/   r1   	focus_setr4   r5   Zwait_window)r   rD   r   rF   r   r   r   r*   y   s.    

		
		


zDialog.__init__c             C   s   d |  _  t j |   d S)zDestroy the windowN)rG   r   r7   )r   r   r   r   r7      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   rF      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@   rA   rB   Cancelz<Return>z<Escape>N)r   r!   okZACTIVEr   r"   r   r   )r   Zboxwr   r   r   rH      s    '!zDialog.buttonboxc          
   C   sQ   |  j    s |  j j   d  S|  j   |  j   z |  j   Wd  |  j   Xd  S)N)validaterG   rI   r+   r-   applyr   )r   r:   r   r   r   rM      s    

z	Dialog.okc             C   s*   |  j  d  k	 r |  j  j   |  j   d  S)N)rD   rI   r7   )r   r:   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   rO      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   rP      s    zDialog.apply)r<   r=   r>   __doc__r*   r7   rF   rH   rM   r   rO   rP   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   sJ   | s t  j } | |  _ | |  _ | |  _ | |  _ t j |  | |  d  S)N)tkinterZ_default_rootpromptminvaluemaxvalueinitialvaluer?   r*   )r   r   rT   rW   rU   rV   rD   r   r   r   r*     s    					z_QueryDialog.__init__c             C   s   d  |  _  t j |   d  S)N)entryr?   r7   )r   r   r   r   r7     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  |  j S)Nr   Zjustifyrowr   r@   rA   ZstickynamerX   r	   )ZLabelrT   r"   ZgridWZEntryrX   ErW   insertZselect_rangeZEND)r   r&   rN   r   r   r   rF     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 againrD   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errormessagerU   rV   rE   )r   rE   r   r   r   rO   #  s0    	

	z_QueryDialog.validate)r<   r=   r>   r*   r7   rF   rO   r   r   r   r   rR      s   rR   c               @   s"   e  Z d  Z d Z d d   Z d S)_QueryIntegerzNot an integer.c             C   s   |  j  |  j j    S)N)ZgetintrX   get)r   r   r   r   r^   G  s    z_QueryInteger.getresultN)r<   r=   r>   ra   r^   r   r   r   r   rb   E  s   rb   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
    )rb   rE   )r   rT   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   |  j  |  j j    S)N)Z	getdoublerX   rc   )r   r   r   r   r^   Z  s    z_QueryFloat.getresultN)r<   r=   r>   ra   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   rE   )r   rT   rd   re   r   r   r   askfloat]  s    rh   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__showrR   r*   )r   argsrd   r   r   r   r*   l  s
    
	z_QueryString.__init__c             C   s8   t  j |  |  } |  j d  k	 r4 | j d |  j  | S)Nrj   )rR   rF   rk   Z	configure)r   r&   rX   r   r   r   rF   t  s    z_QueryString.bodyc             C   s   |  j  j   S)N)rX   rc   )r   r   r   r   r^   z  s    z_QueryString.getresultN)r<   r=   r>   r*   rF   r^   r   r   r   r   ri   k  s   ri   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
    )ri   rE   )r   rT   rd   re   r   r   r   	askstring}  s    rm   __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NorL   r   r   r      r   zTest DialogZSpamz	Egg countrW      zEgg weight
(in tons)rU   r	   rV   d   z	Egg label   )r   printr8   rf   rh   rm   )r   re   r   r   r   doit  s    		
ztest.<locals>.doitr   ZTestr
   ZQuit)ZTkr!   r   r;   r6   )r   rt   tqr   r   r   test  s    	

rw   )rQ   rS   r   r   r   r?   rR   rb   rf   rg   rh   ri   rm   r<   rw   r   r   r   r   <module>   s   
SF