a zec:@sXdZgdZddlZddlZddlmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZddlmZddlmZddlmZiZGdd d ZGd d d eZGd d d eZGdddejZGdddeZGdddeZ GdddejZ!ddZ"ddZ#ddZ$d)ddZ%d*dd Z&d+d"d#Z'd$d%Z(d&d'Z)e*d(krTe)dS),aUFile selection dialog classes. Classes: - FileDialog - LoadFileDialog - SaveFileDialog This module also presents tk common file dialogues, it provides interfaces to the native file dialogues available in Tk 4.2 and newer, and the directory dialogue available in Tk 8.3 and newer. These interfaces were written by Fredrik Lundh, May 1997. ) FileDialogLoadFileDialogSaveFileDialogOpenSaveAs Directoryaskopenfilenameasksaveasfilenameaskopenfilenames askopenfile askopenfiles asksaveasfile askdirectoryN)FrameLEFTYESBOTTOMEntryTOPButtonTkXToplevelRIGHTYENDListboxBOTH Scrollbar)Dialog) commondialog) _setup_dialogc@seZdZdZdZd$ddZejdddfdd Zd%d d Z d d Z ddZ ddZ ddZ ddZddZd&ddZddZddZd'ddZd d!Zd"d#ZdS)(raStandard file selection dialog -- no checks on selected file. Usage: d = FileDialog(master) fname = d.go(dir_or_file, pattern, default, key) if fname is None: ...canceled... else: ...open file... All arguments to go() are optional. The 'key' argument specifies a key in the global dictionary 'dialogstates', which keeps track of the values for the directory and pattern arguments, overriding the values passed in (it does not keep track of the default argument!). If no key is specified, the dialog keeps no memory of previous state. Note that memory is kept even when the dialog is canceled. (All this emulates the behavior of the Macintosh file selection dialogs.) zFile Selection DialogNcCs|dur|j}||_d|_t||_|j||j|t|jt|j|_|jj t t dt |j|_ |j j t t d|j d|jt |j|_|jj tt d|jd|jt|j|_|jj ttdt|j|_|jj ttdt|jd|jdfd|_|jj tttd|j}|j|dd|dd|jd |j|jd |j|jj|jd fd t|j|_ |j j t!tdt|jd|j dfd|_"|j"j t!ttd|j j|j"d fd |j"}|j"|dd|dd|j"d |j#|j"d |j$t%|jd |j&d|_'|j'j t!dt%|jd|jd|_(|j(j t!tdt%|jd|j)d|_*|j*j td|j+d|j)|jd|j)|jd|j)dS)N)sidefillz)expandr#rset)ZexportselectionZyscrollcommand)r"r$r#zzZyview)commandZOK)textr')r"Filter)r"r$CancelZWM_DELETE_WINDOWzz),titlemaster directoryrtopZiconnamer!rZbotframepackrrr selectionbindok_eventfilterrfilter_commandZmidframerrrZfilesbarrrrfilesZbindtagsfiles_select_eventfiles_double_eventZconfigZdirsbarrdirsdirs_select_eventdirs_double_eventr ok_commandZ ok_buttonZ filter_buttoncancel_commandZ cancel_buttonprotocol)selfr,r+Zbtagsr?F/opt/bitninja-python-dojo/embedded/lib/python3.9/tkinter/filedialog.py__init__:sr              zFileDialog.__init__*cCs|r|tvrt|\|_}n2tj|}tj|r<||_ntj|\|_}||j|||| |j |j |j d|_|j|r|\}}|jrtj|j}||ft|<|j |jSN) dialogstatesr-ospath expanduserisdirsplit set_filter set_selectionr4r0Z focus_setr.Zwait_visibilityZgrab_sethowr,Zmainloop get_filterdirnameZdestroy)r>Z dir_or_filepatterndefaultkeyr-r?r?r@gozs*           z FileDialog.gocCs||_|jdSrD)rMr,quit)r>rMr?r?r@rTszFileDialog.quitcCs |dSrD)r4r>eventr?r?r@r:szFileDialog.dirs_double_eventcCs@|\}}|jd}tjtj|j|}|||dSNZactive) rNr8getrFrGnormpathjoinr-rK)r>rVdirpatZsubdirr?r?r@r9s  zFileDialog.dirs_select_eventcCs |dSrDr;rUr?r?r@r7szFileDialog.files_double_eventcCs|jd}||dSrW)r5rXrL)r>rVfiler?r?r@r6s zFileDialog.files_select_eventcCs |dSrDr]rUr?r?r@r2szFileDialog.ok_eventcCs||dSrD)rT get_selectionr>r?r?r@r;szFileDialog.ok_commandc Cs$|\}}zt|}Wnty8|jYdS0||_||||tj g}g}|D]@}tj ||}tj |r| |qdt||rd| |qd|jdt|D]}|jt|q|jdt|D]}|jt|qtj |\} } | tjkrd} || dS)NrrC)rNrFlistdirOSErrorr,bellr-rKsortpardirrGrZrIappendfnmatchr8deleterinsertr5rJr_curdirrL) r>rVr[r\namessubdirsZ matchingfilesnamefullnameheadtailr?r?r@r4s4        zFileDialog.filter_commandcCsN|j}tj|}|ddtjks4tj|rBtj|d}tj|S)NrB) r3rXrFrGrHseprIrZrJ)r>r3r?r?r@rNs   zFileDialog.get_filtercCs|j}tj|}|SrD)r0rXrFrGrHr>r^r?r?r@r_s  zFileDialog.get_selectioncCs |dSrD)rTrUr?r?r@r<szFileDialog.cancel_commandcCstj|sNz t}Wnty.d}Yn0|rNtj||}tj|}|jdt |j t tj|prtj |pxddS)NrrB) rFrGisabsgetcwdrbrZrYr3rhrrirj)r>r[r\pwdr?r?r@rKs     zFileDialog.set_filtercCs,|jdt|jttj|j|dS)Nr)r0rhrrirFrGrZr-rsr?r?r@rLszFileDialog.set_selection)N)N)N)N)__name__ __module__ __qualname____doc__r+rArFrjrSrTr:r9r7r6r2r;r4rNr_r<rKrLr?r?r?r@r!s" @    rc@seZdZdZdZddZdS)rz8File selection dialog which checks that the file exists.zLoad File Selection DialogcCs.|}tj|s |jn ||dSrD)r_rFrGisfiler,rcrTrsr?r?r@r;s  zLoadFileDialog.ok_commandNrwrxryrzr+r;r?r?r?r@rsrc@seZdZdZdZddZdS)rz@File selection dialog which checks that the file may be created.zSave File Selection DialogcCs|}tj|rZtj|r.|jdSt|jdd|fdddd}|j dkrdSn*tj |\}}tj|s|jdS| |dS)Nz Overwrite Existing File QuestionzOverwrite existing file %r?Z questheadr&)ZYesr*)r+r(ZbitmaprQstringsr) r_rFrGexistsrIr,rcrr.numrJrT)r>r^drorpr?r?r@r;s&      zSaveFileDialog.ok_commandNr|r?r?r?r@rsrc@seZdZddZddZdS)_DialogcCs0zt|jd|jd<Wnty*Yn0dS)N filetypes)tupleoptionsKeyErrorr`r?r?r@ _fixoptions2s z_Dialog._fixoptionscCsP|rFz |j}Wnty Yn0tj|\}}||jd<||jd<||_|S)N initialdirZ initialfile)stringAttributeErrorrFrGrJrfilenamer>widgetresultrGr^r?r?r@ _fixresult9s    z_Dialog._fixresultN)rwrxryrrr?r?r?r@r0src@seZdZdZdZddZdS)rAsk for a filename to openZtk_getOpenFilecCsxt|trBtdd|D}|r>tj|d\}}||jd<|S|jsjd|jvrj|||j |St |||S)NcSsg|]}t|d|qS)r)getattr).0rr?r?r@ Tz#Open._fixresult..rrmultiple) isinstancerrFrGrJrZtkZ wantobjectsrZ splitlistrrr?r?r@rQs  zOpen._fixresultNrwrxryrzr'rr?r?r?r@rLsrc@seZdZdZdZdS)rAsk for a filename to save asZtk_getSaveFileN)rwrxryrzr'r?r?r?r@r`src@seZdZdZdZddZdS)rzAsk for a directoryZtk_chooseDirectorycCs6|r,z |j}Wnty Yn0||jd<||_|S)Nr)rrrr-)r>rrr?r?r@rls   zDirectory._fixresultNrr?r?r?r@rgsrcKstfi|S)rrshowrr?r?r@r}srcKstfi|S)r)rrrr?r?r@rsrcKsd|d<tfi|S)ztAsk for multiple filenames to open Returns a list of filenames or empty list if cancel button selected r&rrrr?r?r@r sr rcKs$tfi|}|r t||SdS)z8Ask for a filename to open, and returned the opened fileN)rropenmoderrr?r?r@r s r cKs8tfi|}|r4g}|D]}|t||q|}|S)zAsk for multiple filenames and return the open file objects returns a list of open file objects or an empty list if cancel selected )r rfr)rrr5Zofilesrr?r?r@r sr wcKs$tfi|}|r t||SdS)z;Ask for a filename to save as, and returned the opened fileN)rrrrr?r?r@r s r cKstfi|S)z-Ask for a directory, and return the file name)rrrr?r?r@r sr c Cst}|t|}|jdd}t|}|jdd}t||d}ddl}z&ddl}||j d| |j }Wnt t fyYn0tdgd}zt|d }|Wn$td t|d Yn0td ||t} td | |dS)zSimple test program.test)rRzutf-8rNrC)z all filesrB)rrzCould not open File: r&rZsaveas)rZwithdrawrrSrprintsyslocale setlocaleLC_ALL nl_langinfoCODESET ImportErrorrrrcloseexc_infoencoder) rootfdZloadfileZsavefileencrrZ openfilenamefpZsaveasfilenamer?r?r@rs2      r__main__)r)r)r)+rz__all__rgrFtkinterrrrrrrrrrrrrrrrrZtkinter.dialogrr Ztkinter.simpledialogr!rErrrrrrrrrr r r r r rrwr?r?r?r@s4 H   I9  ,