Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/lib-tk/FileDialog.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@s�dZddlTddlmZddlZddlZiZdd
d��YZdefd��YZd	efd
��YZd�Z	e
dkr�e	�ndS(sZFile selection dialog classes.

Classes:

- FileDialog
- LoadFileDialog
- SaveFileDialog

i�(t*(tDialogNt
FileDialogcBs�eZdZdZdd�Zejdddd�Zdd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zdd
�Zd�Zd�Zdd�Zd�Zd�ZRS(s�Standard 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.)

    sFile Selection DialogcCs�|dkr|j}n||_d|_t|�|_|jj|�|jj|�t|j�|_|jj	dt
dt�t|j�|_
|j
j	dt
dt�|j
jd|j�t|j�|_|jj	dtdt�|jjd|j�t|j�|_|jj	dtdt�t|j�|_|jj	dtdt�t|jddd|jdf�|_|jj	dtdtdt�|jj�}|jj|d	|d	 �|jjd
|j�|jjd|j�|jjd|jd
f�t|j�|_ |j j	dt!dt�t|jddd|j df�|_"|j"j	dt!dtdt�|j jd|j"d
f�|j"j�}|j"j|d	|d	 �|j"jd
|j#�|j"jd|j$�t%|jddd|j&�|_'|j'j	dt!�t%|jddd|j�|_(|j(j	dt!dt�t%|jddd|j)�|_*|j*j	dt�|jj+d|j)�|jjd|j)�|jjd|j)�dS(Ntsidetfills<Return>texpandtexportselectionityscrollcommandtsetis<ButtonRelease-1>s<Double-ButtonRelease-1>tcommandtyviewttexttOKtFiltertCanceltWM_DELETE_WINDOWs<Alt-w>s<Alt-W>(,tNonettitletmastert	directorytToplevelttopticonnametFrametbotframetpacktBOTTOMtXtEntryt	selectiontbindtok_eventtfiltertTOPtfilter_commandtmidframetYEStBOTHt	ScrollbartfilesbartRIGHTtYtListboxtfilestbindtagstfiles_select_eventtfiles_double_eventtconfigtdirsbartLEFTtdirstdirs_select_eventtdirs_double_eventtButtont
ok_commandt	ok_buttont
filter_buttontcancel_commandt
cancel_buttontprotocol(tselfRRtbtags((s'/sys/lib/python2.7/lib-tk/FileDialog.pyt__init__.sh		RtcCs:|r(|tkr(t|\|_}nKtjj|�}tjj|�rX||_ntjj|�\|_}|j|j|�|j|�|j	�|j
j�|jj
�|jj�d|_|jj�|r&|j�\}}|jrtjj|j�}n||ft|<n|jj�|jS(N(tdialogstatesRtostpatht
expandusertisdirtsplitt
set_filtert
set_selectionR"Rt	focus_setRtwait_visibilitytgrab_setRthowRtmainloopt
get_filtertdirnametdestroy(R<tdir_or_filetpatterntdefaulttkeyR((s'/sys/lib/python2.7/lib-tk/FileDialog.pytgoms*




	
	
cCs||_|jj�dS(N(RKRtquit(R<RK((s'/sys/lib/python2.7/lib-tk/FileDialog.pyRU�s	cCs|j�dS(N(R"(R<tevent((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR4�scCs\|j�\}}|jjd�}tjjtjj|j|��}|j||�dS(Ntactive(	RMR2tgetRARBtnormpathtjoinRRF(R<RVtdirtpattsubdir((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR3�s$cCs|j�dS(N(R6(R<RV((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR.�scCs#|jjd�}|j|�dS(NRW(R+RXRG(R<RVtfile((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR-�scCs|j�dS(N(R6(R<RV((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR�scCs|j|j��dS(N(RUt
get_selection(R<((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR6�scCs�|j�\}}ytj|�}Wn"tjk
rI|jj�dSX||_|j||�|j�tj	g}g}xg|D]_}tj
j||�}tj
j|�r�|j
|�q�tj||�r�|j
|�q�q�W|jjdt�x!|D]}|jjt|�qW|jjdt�x!|D]}|jjt|�q:Wtj
j|j��\}	}
|
tjkr�d}
n|j|
�dS(NiR?(RMRAtlistdirterrorRtbellRRFtsorttpardirRBRZRDtappendtfnmatchR2tdeletetENDtinsertR+RER_tcurdirRG(R<RVR[R\tnamestsubdirst
matchingfilestnametfullnametheadttail((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR"�s6
	



	cCsn|jj�}tjj|�}|dtjksFtjj|�r^tjj|d�}ntjj|�S(Ni�R(	R RXRARBRCtsepRDRZRE(R<R ((s'/sys/lib/python2.7/lib-tk/FileDialog.pyRM�s
%cCs%|jj�}tjj|�}|S(N(RRXRARBRC(R<R^((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR_�scCs|j�dS(N(RU(R<RV((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR9�scCs�tjj|�srytj�}Wntjk
r>d}nX|rrtjj||�}tjj|�}qrn|jj	dt
�|jjt
tjj|p�tj|p�d��dS(NiR(
RARBtisabstgetcwdRaRRZRYR RgRhRiRj(R<R[R\tpwd((s'/sys/lib/python2.7/lib-tk/FileDialog.pyRF�s
cCs<|jjdt�|jjttjj|j|��dS(Ni(RRgRhRiRARBRZR(R<R^((s'/sys/lib/python2.7/lib-tk/FileDialog.pyRG�sN(t__name__t
__module__t__doc__RRR>RARjRTRUR4R3R.R-RR6R"RMR_R9RFRG(((s'/sys/lib/python2.7/lib-tk/FileDialog.pyRs"?									tLoadFileDialogcBseZdZdZd�ZRS(s8File selection dialog which checks that the file exists.sLoad File Selection DialogcCs?|j�}tjj|�s.|jj�n
|j|�dS(N(R_RARBtisfileRRbRU(R<R^((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR6�s(RvRwRxRR6(((s'/sys/lib/python2.7/lib-tk/FileDialog.pyRy�stSaveFileDialogcBseZdZdZd�ZRS(s@File selection dialog which checks that the file may be created.sSave File Selection Dialogc
Cs�|j�}tjj|�r�tjj|�rA|jj�dSt|jdddd|fddddd	d
�}|j	dkr�dSn;tjj
|�\}}tjj|�s�|jj�dS|j|�dS(NRs Overwrite Existing File QuestionRsOverwrite existing file %r?tbitmapt	questheadRRitstringstYesRi(RsCancel(R_RARBtexistsRDRRbRRtnumRERU(R<R^tdRpRq((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR6�s$

	
(RvRwRxRR6(((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR{�scCs\t�}|j�t|�}|jdd�}t|�}|jdd�}|G|GHdS(sSimple test program.RSttestN(tTktwithdrawRyRTR{(troottfdtloadfiletsavefile((s'/sys/lib/python2.7/lib-tk/FileDialog.pyR�s	
t__main__((RxtTkinterRRARfR@RRyR{R�Rv(((s'/sys/lib/python2.7/lib-tk/FileDialog.pyt<module>	s
�	

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].