Fa,@sdZddlTddlmZddlZGdddZGdddeZGd d d eZGd d d eZd dZGdddeZ ddZ GdddeZ ddZ e dkrddZedS)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@speZdZdgddddddZddddZd d Zd d Zd dZddZdS) SimpleDialogNc Cs|rt|d||_nt||_|rS|jj||jj|t|jd|dd|_|jjdddtt|j|_ |j j||_ ||_ ||_ |jj d|jxtt|D]u}||} t|j d| d ||d d } ||krF| jd td d| jdtdtddqW|jjd|j|j|dS)Nclass_textZaspectiexpandZfillzcommandcSs |j|S)N)done)selfnumr*/usr/lib/python3.5/tkinter/simpledialog.py6sz'SimpleDialog.__init__..ZreliefZ borderwidthsideWM_DELETE_WINDOW)ToplevelroottitleZiconnameZMessagemessagepackZBOTHFrameframer canceldefaultbind return_eventrangelenButtonZconfigZRIDGELEFTprotocolwm_delete_window_set_transient) r masterrbuttonsrrrrr sbrrr__init__!s.       zSimpleDialog.__init__g?g333333?c Csb|j}|j|j||j|jri|j}|j}|j}|j}n"|j }|j }d}}|j } |j } ||| |} ||| |} | | |j kr|j | } n| dkrd} | | |j kr+|j | } n| dkr=d} |j d| | f|jdS)Nrz+%d+%d)rwithdraw transientupdate_idletasksZwinfo_ismappedZ winfo_widthZ winfo_height winfo_rootx winfo_rootyZwinfo_screenwidthZwinfo_screenheightZwinfo_reqwidthZwinfo_reqheightgeometry deiconify) r r&ZrelxZrelyZwidgetZm_widthZm_heightZm_xZm_yZw_widthZw_heightxyrrrr%=s4               zSimpleDialog._set_transientcCs;|jj|jj|jj|jj|jS)N)rwait_visibilitygrab_setmainloopdestroyr )r rrrgoZs     zSimpleDialog.gocCs3|jdkr|jjn|j|jdS)N)rrbellr )r eventrrrraszSimpleDialog.return_eventcCs3|jdkr|jjn|j|jdS)N)rrr9r )r rrrr$gszSimpleDialog.wm_delete_windowcCs||_|jjdS)N)r rquit)r r rrrr ms zSimpleDialog.done) __name__ __module__ __qualname__r*r%r8rr$r rrrrrs     rc@seZdZdZdddZddZddZd d Zdd d Zdd dZ ddZ ddZ dS)DialogzZClass to open dialogs. This class is intended as a base class for custom dialogs NcCs1tj|||j|jr3|j||rF|j|||_d|_t|}|j ||_ |j dddd|j |j s||_ |j d|j|jdk r|jd|jd|jdf|j|j j|j|j|j|dS)zInitialize a dialog. Arguments: parent -- a parent window (the application window) title -- the dialog title Npadxpadyrz+%d+%d2)rr*r+Zwinfo_viewabler,rparentresultrbody initial_focusr buttonboxr#rr0r.r/r1 focus_setr4r5Z wait_window)r rDrrFrrrr*ys.               zDialog.__init__cCsd|_tj|dS)zDestroy the windowN)rGrr7)r rrrr7s zDialog.destroycCsdS)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&rrrrFsz Dialog.bodyc Cst|}t|ddddd|jdt}|jdtdd d d t|dd ddd|j}|jdtdd d d |jd |j|jd |j|jdS)z[add standard button box. override if you do not want the standard buttons rZOKwidth r rrr@rArBCancelzzN)rr!okZACTIVErr"rr)r ZboxwrrrrHs '!zDialog.buttonboxc CsQ|js|jjdS|j|jz|jWd|jXdS)N)validaterGrIr+r-applyr)r r:rrrrMs    z Dialog.okcCs*|jdk r|jj|jdS)N)rDrIr7)r r:rrrrs z Dialog.cancelcCsdS)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 rrrrOszDialog.validatecCsdS)zprocess the data This method is called automatically to process the data, *after* the dialog is destroyed. By default, it does nothing. Nr)r rrrrPsz Dialog.apply) r<r=r>__doc__r*r7rFrHrMrrOrPrrrrr?rs 2   r?c@sLeZdZddddddZddZddZdd ZdS) _QueryDialogNcCsJ|stj}||_||_||_||_tj|||dS)N)tkinterZ _default_rootpromptminvaluemaxvalue initialvaluer?r*)r rrTrWrUrVrDrrrr*s     z_QueryDialog.__init__cCsd|_tj|dS)N)entryr?r7)r rrrr7s z_QueryDialog.destroycCst|d|jdt}|jdddddtt|dd |_|jjdd dddtt|jdk r|jj d|j|jj dt |jS) NrZjustifyrowrr@rAZstickynamerXr ) ZLabelrTr"ZgridWZEntryrXErWinsertZ select_rangeZEND)r r&rNrrrrFs#z_QueryDialog.bodyc Csy|j}Wn3tk rEtjd|jdd|dSYnX|jdk r||jkrtjdd|jd|dS|jdk r||jkrtjdd|jd|dS||_d S) Nz Illegal valuez Please try againrDrz 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 errormessagerUrVrE)r rErrrrO#s0      z_QueryDialog.validate)r<r=r>r*r7rFrOrrrrrRs   rRc@s"eZdZdZddZdS) _QueryIntegerzNot an integer.cCs|j|jjS)N)ZgetintrXget)r rrrr^Gsz_QueryInteger.getresultN)r<r=r>rar^rrrrrbEs rbcKst|||}|jS)zget an integer from the user Arguments: title -- the dialog title prompt -- the label text **kw -- see SimpleDialog class Return value is an integer )rbrE)rrTkwdrrr askintegerJs rfc@s"eZdZdZddZdS) _QueryFloatzNot a floating point value.cCs|j|jjS)N)Z getdoublerXrc)r rrrr^Zsz_QueryFloat.getresultN)r<r=r>rar^rrrrrgXs rgcKst|||}|jS)zget a float from the user Arguments: title -- the dialog title prompt -- the label text **kw -- see SimpleDialog class Return value is a float )rgrE)rrTrdrerrraskfloat]s rhc@s4eZdZddZddZddZdS) _QueryStringcOsCd|kr#|d|_|d=n d|_tj|||dS)Nshow)_QueryString__showrRr*)r argsrdrrrr*ls     z_QueryString.__init__cCs8tj||}|jdk r4|jd|j|S)Nrj)rRrFrkZ configure)r r&rXrrrrFtsz_QueryString.bodycCs |jjS)N)rXrc)r rrrr^zsz_QueryString.getresultN)r<r=r>r*rFr^rrrrriks   ricKst|||}|jS)zget a string from the user Arguments: title -- the dialog title prompt -- the label text **kw -- see SimpleDialog class Return value is a string )rirE)rrTrdrerrr askstring}s rm__main__cCsmt}|dd}t|ddd|}|jt|ddd|j}|j|jdS)Nc Sst|ddddddgddd d d d }t|jttd dddttd dddddttd ddS)NrzThis 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'ZYesZNorLrrrrz Test DialogZSpamz Egg countrW zEgg weight (in tons)rUr rVdz Egg label)rprintr8rfrhrm)rrerrrdoits   ztest..doitrZTestr ZQuit)ZTkr!rr;r6)rrttqrrrtests   rw)rQrSrrrr?rRrbrfrgrhrirmr<rwrrrrs  SF