Sindbad~EG File Manager
3
\�8�@sdZddlTddlmZddlmZddlZddlZiZGdd�d�ZGdd �d e�Z Gd
d�de�Z
Gdd
�d
ej�ZGdd�de�ZGdd�de�Z
Gdd�dej�Zdd�Zdd�Zdd�Zd'dd�Zd(dd�Zd)d d!�Zd"d#�Zd$d%�Zed&k�re�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.
�)�*)�Dialog)�commondialogNc@s�eZdZdZdZd$dd�Zejdddfdd �Zd%d
d�Z dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd&dd�Zdd�Zdd�Zd'dd�Zd d!�Zd"d#�ZdS)(�
FileDialoga�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.)
zFile Selection DialogNcCs�|dkr|j}||_d|_t|�|_|jj|�|jj|�t|j�|_|jjt t
d�t|j�|_|jjt t
d�|jj
d|j�t|j�|_|jjtt
d�|jj
d|j�t|j�|_|jjttd�t|j�|_|jjttd�t|jd|jdfd�|_|jjtttd�|jj�}|jj|dd�|dd��|jj
d |j�|jj
d
|j�|jj|jdfd�t|j�|_|jjt td�t|jd|jdfd�|_!|j!jt ttd�|jj|j!dfd�|j!j�}|j!j|dd�|dd��|j!j
d |j"�|j!j
d
|j#�t$|jd
|j%d�|_&|j&jt d�t$|jd|jd�|_'|j'jt td�t$|jd|j(d�|_)|j)jtd�|jj*d|j(�|jj
d|j(�|jj
d|j(�dS)N)�side�fillz<Return>)�expandrr�set)ZexportselectionZyscrollcommand)rrr�z<ButtonRelease-1>z<Double-ButtonRelease-1>Zyview)�commandZOK)�textr)rZFilter)rr�CancelZWM_DELETE_WINDOWz<Alt-w>z<Alt-W>)+�title�master� directoryZToplevel�topZiconnameZFrameZbotframeZpackZBOTTOM�XZEntry� selectionZbind�ok_event�filterZTOP�filter_commandZmidframeZYESZBOTHZ ScrollbarZfilesbarZRIGHT�YZListbox�filesZbindtags�files_select_event�files_double_event�configZdirsbarZLEFT�dirs�dirs_select_event�dirs_double_eventZButton�
ok_commandZ ok_buttonZ
filter_button�cancel_commandZ
cancel_buttonZprotocol)�selfrrZbtags�r"�*/usr/lib64/python3.6/tkinter/filedialog.py�__init__3sh
zFileDialog.__init__r�cCs�|r|tkrt|\|_}n2tjj|�}tjj|�r<||_ntjj|�\|_}|j|j|�|j|�|j �|j
j�|jj
�|jj�d|_|jj�|r�|j�\}}|jr�tjj|j�}||ft|<|jj�|jS)N)�dialogstatesr�os�path�
expanduser�isdir�split�
set_filter�
set_selectionrrZ focus_setrZwait_visibilityZgrab_set�howrZmainloop�
get_filter�dirnameZdestroy)r!Zdir_or_file�pattern�default�keyrr"r"r#�gors*
z
FileDialog.gocCs||_|jj�dS)N)r.r�quit)r!r.r"r"r#r5�szFileDialog.quitcCs|j�dS)N)r)r!�eventr"r"r#r�szFileDialog.dirs_double_eventcCs@|j�\}}|jjd�}tjjtjj|j|��}|j||�dS)N�active) r/r�getr'r(�normpath�joinrr,)r!r6�dir�patZsubdirr"r"r#r�szFileDialog.dirs_select_eventcCs|j�dS)N)r)r!r6r"r"r#r�szFileDialog.files_double_eventcCs|jjd�}|j|�dS)Nr7)rr8r-)r!r6�filer"r"r#r�szFileDialog.files_select_eventcCs|j�dS)N)r)r!r6r"r"r#r�szFileDialog.ok_eventcCs|j|j��dS)N)r5�
get_selection)r!r"r"r#r�szFileDialog.ok_commandcCs0|j�\}}ytj|�}Wntk
r8|jj�dSX||_|j||�|j�tj g}g}xH|D]@}tj
j||�}tj
j|�r�|j
|�qftj||�rf|j
|�qfW|jjdt�x|D]}|jjt|�q�W|jjdt�x|D]}|jjt|�q�Wtj
j|j��\} }
|
tjk�r"d}
|j|
�dS)Nrr%)r/r'�listdir�OSErrorr�bellrr,�sort�pardirr(r:r*�append�fnmatchr�delete�END�insertrr+r>�curdirr-)r!r6r;r<�namesZsubdirsZ
matchingfiles�name�fullname�head�tailr"r"r#r�s6
zFileDialog.filter_commandcCsN|jj�}tjj|�}|dd�tjks4tjj|�rBtjj|d�}tjj|�S)Nr
r���) rr8r'r(r)�sepr*r:r+)r!rr"r"r#r/�s
zFileDialog.get_filtercCs|jj�}tjj|�}|S)N)rr8r'r(r))r!r=r"r"r#r>�s
zFileDialog.get_selectioncCs|j�dS)N)r5)r!r6r"r"r#r �szFileDialog.cancel_commandc
Cs�tjj|�sPytj�}Wntk
r0d}YnX|rPtjj||�}tjj|�}|jjdt �|jj
t tjj|pttj|pzd��dS)Nrr)r'r(�isabs�getcwdr@r:r9rrFrGrHrI)r!r;r<�pwdr"r"r#r,�s
zFileDialog.set_filtercCs,|jjdt�|jjttjj|j|��dS)Nr)rrFrGrHr'r(r:r)r!r=r"r"r#r-�szFileDialog.set_selection)N)N)N)N)�__name__�
__module__�__qualname__�__doc__rr$r'rIr4r5rrrrrrrr/r>r r,r-r"r"r"r#rs"
?
rc@seZdZdZdZdd�ZdS)�LoadFileDialogz8File selection dialog which checks that the file exists.zLoad File Selection DialogcCs.|j�}tjj|�s |jj�n
|j|�dS)N)r>r'r(�isfilerrAr5)r!r=r"r"r#r�szLoadFileDialog.ok_commandN)rTrUrVrWrrr"r"r"r#rX�srXc@seZdZdZdZdd�ZdS)�SaveFileDialogz@File selection dialog which checks that the file may be created.zSave File Selection DialogcCs�|j�}tjj|�rZtjj|�r.|jj�dSt|jdd|fddd d�}|j dkr�dSn*tjj
|�\}}tjj|�s�|jj�dS|j|�dS)
Nz Overwrite Existing File QuestionzOverwrite existing file %r?Z questheadr
�Yesr
)rrZbitmapr2Zstringsr)r[r
)r>r'r(�existsr*rrArrZnumr+r5)r!r=�drMrNr"r"r#r�s$
zSaveFileDialog.ok_commandN)rTrUrVrWrrr"r"r"r#rZ�srZc@seZdZdd�Zdd�ZdS)�_DialogcCs2yt|jd�|jd<Wntk
r,YnXdS)N� filetypes)�tuple�options�KeyError)r!r"r"r#�_fixoptions+sz_Dialog._fixoptionscCsR|rHy
|j}Wntk
r"YnXtjj|�\}}||jd<||jd<||_|S)N�
initialdirZinitialfile)�string�AttributeErrorr'r(r+ra�filename)r!�widget�resultr(r=r"r"r#�
_fixresult2s
z_Dialog._fixresultN)rTrUrVrcrjr"r"r"r#r^)sr^c@seZdZdZdZdd�ZdS)�OpenzAsk for a filename to openZtk_getOpenFilecCszt|t�rBtdd�|D��}|r>tjj|d�\}}||jd<|S|jj�rld|jkrl|j||jj |��St
j|||�S)NcSsg|]}t|d|��qS)re)�getattr)�.0�rr"r"r#�
<listcomp>Msz#Open._fixresult.<locals>.<listcomp>rrd�multiple)�
isinstancer`r'r(r+raZtkZwantobjectsrjZ splitlistr^)r!rhrir(r=r"r"r#rjJs
zOpen._fixresultN)rTrUrVrWrrjr"r"r"r#rkEsrkc@seZdZdZdZdS)�SaveAszAsk for a filename to save asZtk_getSaveFileN)rTrUrVrWrr"r"r"r#rrXsrrc@seZdZdZdZdd�ZdS)� DirectoryzAsk for a directoryZtk_chooseDirectorycCs8|r.y
|j}Wntk
r"YnX||jd<||_|S)Nrd)rerfrar)r!rhrir"r"r#rjds
zDirectory._fixresultN)rTrUrVrWrrjr"r"r"r#rs_srscKstf|�j�S)zAsk for a filename to open)rk�show)rar"r"r#�askopenfilenametsrucKstf|�j�S)zAsk for a filename to save as)rrrt)rar"r"r#�asksaveasfilenameysrvcKsd|d<tf|�j�S)ztAsk for multiple filenames to open
Returns a list of filenames or empty list if
cancel button selected
r
rp)rkrt)rar"r"r#�askopenfilenames~srwrncKs tf|�j�}|rt||�SdS)z8Ask for a filename to open, and returned the opened fileN)rkrt�open)�moderargr"r"r#�askopenfile�s
rzcKs8tf|�}|r4g}x|D]}|jt||��qW|}|S)z�Ask for multiple filenames and return the open file
objects
returns a list of open file objects or an empty list if
cancel selected
)rwrDrx)ryrarZofilesrgr"r"r#�askopenfiles�s
r{�wcKs tf|�j�}|rt||�SdS)z;Ask for a filename to save as, and returned the opened fileN)rrrtrx)ryrargr"r"r#�
asksaveasfile�s
r}cKstf|�j�S)z-Ask for a directory, and return the file name)rsrt)rar"r"r#�askdirectory�sr~c
Cs�t�}|j�t|�}|jdd�}t|�}|jdd�}t||�d}ddl}y&ddl}|j|j d�|j
|j�}Wntt
fk
r�YnXtdgd �}yt|d
�}|j�Wn$td�t|j�d�YnXtd
|j|��t�} td| j|��dS)zSimple test program.�test)r3zutf-8rNr%� all filesr)r_rnzCould not open File: r
rxZsaveas)r�r)ZTkZwithdrawrXr4rZ�print�sys�locale� setlocale�LC_ALL�nl_langinfo�CODESET�ImportErrorrfrurx�close�exc_info�encoderv)
�root�fdZloadfileZsavefile�encr�r�Zopenfilename�fpZsaveasfilenamer"r"r#r�s2
r�__main__)rn)rn)r|)rWZtkinterZtkinter.dialogrrr'rEr&rrXrZr^rkrrrsrurvrwrzr{r}r~rrTr"r"r"r#�<module>
s0H:
+
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists