a ze-@sdZddlTddlmZmZGdddZGdddeZdd ZGd d d eZGd d d eZ ddZ GdddeZ ddZ GdddeZ ddZedkrddZedS)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 )*) messagebox_get_default_rootc@sLeZdZdgddddfddZdddZd d Zd d Zd dZddZdS) SimpleDialogNc Cs|rt||d|_n t||_|r:|j||j|t|jt|j|dd|_|jjdtdt |j|_ |j ||_ ||_ ||_ |jd|jtt|D]L}||} t|j | ||fddd } ||kr| jtd d | jttdd q|jd |j||dS)N)class_i)textZaspect)expandfillcSs ||SN)doneselfnumrH/opt/bitninja-python-dojo/embedded/lib/python3.9/tkinter/simpledialog.py8z'SimpleDialog.__init__..rcommand)ZreliefZ borderwidth)sider r WM_DELETE_WINDOW)ToplevelroottitleZiconname _setup_dialogZMessagemessagepackZBOTHFrameframercanceldefaultbind return_eventrangelenButtonZconfigZRIDGELEFTprotocolwm_delete_window_set_transient) rmasterrbuttonsr$r#rrrsbrrr__init__ s2       zSimpleDialog.__init__?333333?c Cs|j}|||||rJ|}|}|}|}n| }| }d}}| } | } ||| |} ||| |} | | | kr| | } n | dkrd} | | | kr| | } n | dkrd} | d| | f|dS)Nr+%d+%d)rwithdraw transientupdate_idletasksZwinfo_ismappedZ winfo_widthZ winfo_height winfo_rootx winfo_rootyZwinfo_screenwidthZwinfo_screenheightZwinfo_reqwidthZwinfo_reqheightgeometry deiconify) rr.ZrelxZrelyZwidgetZm_widthZm_heightZm_xZm_yZw_widthZw_heightxyrrrr-?s4  zSimpleDialog._set_transientcCs.|j|j|j|j|jSr )rwait_visibilitygrab_setmainloopdestroyrrrrrgo\s     zSimpleDialog.gocCs&|jdur|jn ||jdSr )r$rbellrreventrrrr&cs  zSimpleDialog.return_eventcCs&|jdur|jn ||jdSr )r#rrErrCrrrr,is  zSimpleDialog.wm_delete_windowcCs||_|jdSr )rrquitrrrrroszSimpleDialog.done)r3r4) __name__ __module__ __qualname__r2r-rDr&r,rrrrrrs  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 NcCs|}|std}t||||dur>|r>|||rL||t|||_d|_ t |}| ||_ |j ddd||j s||_ |d|j|dur|d|d|df||j ||||dS)zInitialize a dialog. Arguments: parent -- a parent window (the application window) title -- the dialog title zcreate dialog windowN)padxpadyrr52)rrr2r6Zwinfo_viewabler7rrparentresultr!body initial_focusr buttonboxr+r#r;r9r:r< focus_setr?r@Z wait_window)rrQrr.rSrrrr2{s8       zDialog.__init__cCsd|_t|dS)zDestroy the windowN)rTrrBrCrrrrBszDialog.destroycCsdS)zcreate dialog body. return widget that should have initial focus. This method should be overridden, and is called by the __init__ method. Nr)rr.rrrrSsz Dialog.bodycCsvt|}t|dd|jtd}|jtdddt|dd|jd}|jtddd|d|j|d |j|d S) z[add standard button box. override if you do not want the standard buttons ZOK )rwidthrr$rM)rrNrOCancel)rrXrr zN)r!r)okZACTIVEr r*r#r%)rZboxwrrrrUszDialog.buttonboxcCsJ|s|jdS||z|W|n |0dSr )validaterTrVr6r8applyr#rFrrrrZs  z Dialog.okcCs |jdur|j|dSr )rQrVrBrFrrrr#s  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 rrCrrrr\szDialog.validatecCsdS)zprocess the data This method is called automatically to process the data, *after* the dialog is destroyed. By default, it does nothing. NrrCrrrr]sz Dialog.apply)N)N)N) rIrJrK__doc__r2rBrSrUrZr#r\r]rrrrrLts 7    rLcCs:|jdkr |jdd|ddn|jdkr6|dddS) NZaquaz!::tk::unsupported::MacWindowStylestyleZ moveableModalrZx11z-typeZdialog)Z_windowingsystemZtkcallZ wm_attributes)r[rrrrs    rc@s.eZdZd ddZddZddZdd ZdS) _QueryDialogNcCs*||_||_||_||_t|||dSr )promptminvaluemaxvalue initialvaluerLr2)rrrbrercrdrQrrrr2s z_QueryDialog.__init__cCsd|_t|dSr )entryrLrBrCrrrrBsz_QueryDialog.destroycCsrt||jtd}|jddtdt|dd|_|jjddttd|jdurl|j d|j|j dt |jS)N)rZjustifyrrM)rowrNZstickyrf)namer ) ZLabelrbr*ZgridWZEntryrfEreinsertZ select_rangeZEND)rr.r[rrrrS s z_QueryDialog.bodycCsz |}Wn*ty6tjd|jd|dYdS0|jdurf||jkrftjdd|j|ddS|jdur||jkrtjdd|j|ddS||_d S) Nz Illegal valuez Please try again)rQrz 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 errormessagercrdrR)rrRrrrr\.s:  z_QueryDialog.validate)NNNN)rIrJrKr2rBrSr\rrrrra s rac@seZdZdZddZdS) _QueryIntegerzNot an integer.cCs||jSr )ZgetintrfgetrCrrrrlSsz_QueryInteger.getresultNrIrJrKrorlrrrrrpPsrpcKst||fi|}|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 )rprRrrbkwdrrr askintegerWs rvc@seZdZdZddZdS) _QueryFloatzNot a floating point value.cCs||jSr )Z getdoublerfrqrCrrrrlisz_QueryFloat.getresultNrrrrrrrwfsrwcKst||fi|}|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 )rwrRrsrrraskfloatms rxc@s$eZdZddZddZddZdS) _QueryStringcOs<d|vr|d|_|d=nd|_tj|g|Ri|dS)Nshow)_QueryString__showrar2)rargsrtrrrr2}s  z_QueryString.__init__cCs(t||}|jdur$|j|jd|S)N)rz)rarSr{Z configure)rr.rfrrrrSs  z_QueryString.bodycCs |jSr )rfrqrCrrrrlsz_QueryString.getresultN)rIrJrKr2rSrlrrrrry|srycKst||fi|}|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 )ryrRrsrrr askstrings r}__main__cCsLt}|fdd}t|d|d}|t|d|jd}||dS)NcSs\t|dgddddd}t|ttddd d ttdd d d dttdddS)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?)ZYesZNorYrz Test Dialog)rr/r$r#rZSpamz Egg count)rezEgg weight (in tons)r d)rcrdz Egg label)rprintrDrvrxr})rrurrrdoits  ztest..doitZTestrZQuit)ZTkr)r rHrA)rrtqrrrtests rN)r^tkinterrrrrrLrrarprvrwrxryr}rIrrrrr s V C