3 ^,@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@sLeZdZdgddddfddZdddZd d Zd d Zd dZddZdS) SimpleDialogNc 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)expandfillzcSs |j|S)N)done)selfnumr,/usr/lib64/python3.6/tkinter/simpledialog.py6sz'SimpleDialog.__init__..)rcommand)ZreliefZ borderwidth)sider r WM_DELETE_WINDOW)ToplevelroottitleZiconnameZMessagemessagepackZBOTHFrameframer canceldefaultbind return_eventrangelenButtonconfigZRIDGELEFTprotocolwm_delete_window_set_transient) r masterrbuttonsrrrrr sbrrr__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)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.gocCs&|jdkr|jjn |j|jdS)N)rrbellr )r eventrrrras  zSimpleDialog.return_eventcCs&|jdkr|jjn |j|jdS)N)rrr=r )r rrrr&gs  zSimpleDialog.wm_delete_windowcCs||_|jjdS)N)r rquit)r r rrrr mszSimpleDialog.done)r-r.) __name__ __module__ __qualname__r,r'r<rr&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)padxpadyrz+%d+%d2)rr,r/Zwinfo_viewabler0rparentresultrbody initial_focusr buttonboxr%rr4r2r3r5 focus_setr8r9Z wait_window)r rHrrJrrrr,ys.      zDialog.__init__cCsd|_tj|dS)zDestroy the windowN)rKrr;)r rrrr;szDialog.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(rrrrJsz 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 ZOK )rwidthrrrD)rrErFCancel)rrOrzzN)rr"okZACTIVErr$rr)r ZboxwrrrrLszDialog.buttonboxc CsB|js|jjdS|j|jz |jWd|jXdS)N)validaterKrMr/r1applyr)r r>rrrrQs  z Dialog.okcCs |jdk r|jj|jdS)N)rHrMr;)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. rr)r rrrrSszDialog.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 rrrrTsz Dialog.apply)N)N)N) r@rArB__doc__r,r;rJrLrQrrSrTrrrrrCrs 2    rCc@s.eZdZd ddZddZddZdd ZdS) _QueryDialogNcCs4|s tj}||_||_||_||_tj|||dS)N)tkinterZ _default_rootpromptminvaluemaxvalue initialvaluerCr,)r rrXr[rYrZrHrrrr,sz_QueryDialog.__init__cCsd|_tj|dS)N)entryrCr;)r rrrr;sz_QueryDialog.destroycCsrt||jtd}|jddtdt|dd|_|jjddttd|jdk rl|jj d|j|jj dt |jS)N)rZjustifyrrD)rowrEZstickyr\)namer) ZLabelrXr$ZgridWZEntryr\Er[insertZ select_rangeZEND)r r(rRrrrrJs 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)rHrz 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 errormessagerYrZrI)r rIrrrrS#s0 z_QueryDialog.validate)NNNN)r@rArBr,r;rJrSrrrrrVs  rVc@seZdZdZddZdS) _QueryIntegerzNot an integer.cCs|j|jjS)N)Zgetintr\get)r rrrrbGsz_QueryInteger.getresultN)r@rArBrerbrrrrrfEsrfcKst||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 )rfrI)rrXkwdrrr askintegerJs rjc@seZdZdZddZdS) _QueryFloatzNot a floating point value.cCs|j|jjS)N)Z getdoubler\rg)r rrrrbZsz_QueryFloat.getresultN)r@rArBrerbrrrrrkXsrkcKst||f|}|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 )rkrI)rrXrhrirrraskfloat]s rlc@s$eZdZddZddZddZdS) _QueryStringcOs6d|kr|d|_|d=nd|_tj|f||dS)Nshow)_QueryString__showrVr,)r argsrhrrrr,ls  z_QueryString.__init__cCs(tj||}|jdk r$|j|jd|S)N)rn)rVrJroZ configure)r r(r\rrrrJts  z_QueryString.bodycCs |jjS)N)r\rg)r rrrrbzsz_QueryString.getresultN)r@rArBr,rJrbrrrrrmksrmcKst||f|}|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 )rmrI)rrXrhrirrr askstring}s rq__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?ZYesZNorPrz Test Dialog)rr)rrrZSpamz Egg count )r[zEgg weight (in tons)rd)rYrZz Egg label)rprintr<rjrlrq)rrirrrdoits   ztest..doitZTest)rrZQuit)ZTkr"rr?r:)rrxtqrrrtests r{)rUrWrrrrCrVrfrjrkrlrmrqr@r{rrrrs  SF