3 ^,c@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 )Z*) messageboxNc@sLeZdZdgddddfddZdddZd d Zd d Zd dZddZdS) SimpleDialogZNc Cs|rt||d|_n t||_|r:|jj||jj|t|j|dd|_|jjdtdt|j|_ |j j||_ ||_ ||_ |jj d|jx\tt|D]L}||} t|j | ||fddd } ||kr| jtd d | jttdd qW|jjd |j|j|dS)N)class_i)textZaspect)expandfillcSs |j|SN)doneselfnumr,/usr/lib64/python3.6/tkinter/simpledialog.pyZ6sz'SimpleDialog.__init__..rcommandi)ZreliefZ borderwidth)siderrWM_DELETE_WINDOW)ToplevelroottitleZiconnameZMessageZmessagepackZBOTHFrameZframer canceldefaultbind return_eventZrangeZlenButtonZconfigZRIDGELEFTprotocolwm_delete_window_set_transient) r masterrbuttonsrrrrr ZsZbrrr__init__!s.     zSimpleDialog.__init__?333333?c Cs|j}|j|j||j|jrJ|j}|j}|j}|j}n|j }|j }d}}|j } |j } ||| |} ||| |} | | |j kr|j | } n | dkrd} | | |j kr|j | } n | dkrd} |j d| | f|jdS)Nr+%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_heightZxZyrrrr!=s4  zSimpleDialog._set_transientcCs.|jj|jj|jj|jj|jSr )rwait_visibilitygrab_setmainloopdestroyr r rrrgoZs     zSimpleDialog.gocC&|jdkr|jjn |j|jdSr )rrbellr r Zeventrrrra  zSimpleDialog.return_eventcCr5r )rrr6r r3rrrr gr8zSimpleDialog.wm_delete_windowcCs||_|jjdSr )r rquitr rrrr mzSimpleDialog.done)r%r&) __name__ __module__ __qualname__r$r!r4rr r rrrrrs rc@sVeZdZdZdddZddZddZd d Zdd d Zdd dZ ddZ ddZ dS)DialogzZClass to open dialogs. This class is intended as a base class for custom dialogs NcCstj|||j|jr&|j||r4|j|||_d|_t|}|j ||_ |j ddd|j |j sv||_ |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 N)padxpadyrr'i2)rr$r(Zwinfo_viewabler)rparentresultrbody initial_focusr buttonboxrrr-r+r,r. focus_setr/r0Z wait_window)r rBrrDrrrr$ys.      zDialog.__init__cCsd|_tj|dS)zDestroy the windowN)rErr2r3rrrr2szDialog.destroycCdS)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"rrrrDz Dialog.bodycCsvt|}t|dd|jtd}|jtdddt|dd|jd}|jtddd|jd|j|jd |j|jd S) z[add standard button box. override if you do not want the standard buttons ZOKi )rwidthrrr?)rr@rACancel)rrJrrzN)rrokZACTIVErrrr)r ZboxwrrrrFszDialog.buttonboxc CsB|js|jjdS|j|jz |jWd|jXdSr )validaterErGr(r*applyrr7rrrrLs  z Dialog.okcCs |jdk r|jj|jdSr )rBrGr2r7rrrrs  z Dialog.cancelcCrH)zvalidate the data This method is called automatically to validate the data before the dialog is destroyed. By default, it always validates OK. rrr3rrrrNrIzDialog.validatecCrH)zprocess the data This method is called automatically to process the data, *after* the dialog is destroyed. By default, it does nothing. Nrr3rrrrOrIz Dialog.applyr r r ) r;r<r=__doc__r$r2rDrFrLrrNrOrrrrr>rs 2    r>c@s.eZdZd ddZddZddZdd ZdS) _QueryDialogNcCs4|s tj}||_||_||_||_tj|||dSr )tkinterZ _default_rootpromptminvaluemaxvalue initialvaluer>r$)r rrSrVrTrUrBrrrr$sz_QueryDialog.__init__cCsd|_tj|dSr )entryr>r2r3rrrr2r:z_QueryDialog.destroycCsrt||jtd}|jddtdt|dd|_|jjddttd|jdk rl|jj d|j|jj dt |jS)N)rZjustifyrr?)Zrowr@ZstickyrW)Znamer) ZLabelrSrZgridZWZEntryrWZErVZinsertZ select_rangeZEND)r r"rMrrrrDs z_QueryDialog.bodyc Csy |j}Wn*tk r6tjd|jd|ddSX|jdk rf||jkrftjdd|j|ddS|jdk r||jkrtjdd|j|ddS||_d S) Nz Illegal valuez Please try again)rBrz Too smallz2The allowed minimum value is %s. Please try again.z Too largez2The allowed maximum value is %s. Please try again.r) getresultZ ValueErrorrZ showwarning errormessagerTrUrC)r rCrrrrN#s0 z_QueryDialog.validate)NNNN)r;r<r=r$r2rDrNrrrrrQs  rQc@eZdZdZddZdS) _QueryIntegerzNot an integer.cC|j|jjSr )ZgetintrWgetr3rrrrXGz_QueryInteger.getresultNr;r<r=rYrXrrrrr[Er[cKt||f|}|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 )r[rCrrSkwdrrr askintegerJ rec@rZ) _QueryFloatzNot a floating point value.cCr\r )Z getdoublerWr]r3rrrrXZr^z_QueryFloat.getresultNr_rrrrrgXr`rgcKra)zget a float from the user Arguments: title -- the dialog title prompt -- the label text **kw -- see SimpleDialog class Return value is a float )rgrCrbrrraskfloat]rfrhc@s$eZdZddZddZddZdS) _QueryStringcOs6d|kr|d|_|d=nd|_tj|f||dS)Nshow)_QueryString__showrQr$)r Zargsrcrrrr$ls  z_QueryString.__init__cCs(tj||}|jdk r$|j|jd|S)N)rj)rQrDrkZ configure)r r"rWrrrrDts  z_QueryString.bodycCs |jjSr )rWr]r3rrrrXzr^z_QueryString.getresultN)r;r<r=r$rDrXrrrrriksricKra)zget a string from the user Arguments: title -- the dialog title prompt -- the label text **kw -- see SimpleDialog class Return value is a string )rirCrbrrr askstring}rfrlZ__main__cCsLt}|fdd}t|d|d}|jt|d|jd}|j|jdS)NcSs^t|ddddgdddd}t|jttd d dd ttd d dddttd ddS)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?ZYesZNorKriz Test Dialog)rr#rrrZSpamz Egg counti )rVzEgg weight (in tons)rid)rTrUz Egg labeli)rZprintr4rerhrl)rrdrrrdoits   ztest..doitZTestrZQuit)ZTkrrr9r1)rrmZtZqrrrtests rn)rPrRrrrr>rQr[rergrhrirlr;rnrrrrZs  SF