Sindbad~EG File Manager
�
&Μg[:���dZgd�ZddlZddlZddlmZmZmZmZm Z m
Z
mZmZm
Z
mZmZmZmZmZmZmZddlmZddlmZddlmZiZGd�d �ZGd
�de�ZGd�d
e�ZGd�dej,�ZGd�de�ZGd�de�Z Gd�dej,�Z!d�Z"d�Z#d�Z$dd�Z%dd�Z&d d�Z'd�Z(d�Z)e*dk(re)�yy)!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.
)
�
FileDialog�LoadFileDialog�SaveFileDialog�Open�SaveAs� Directory�askopenfilename�asksaveasfilename�askopenfilenames�askopenfile�askopenfiles�
asksaveasfile�askdirectory�N)�Frame�LEFT�YES�BOTTOM�Entry�TOP�Button�Tk�X�Toplevel�RIGHT�Y�END�Listbox�BOTH� Scrollbar)�Dialog)�commondialog)�
_setup_dialogc��eZdZdZdZdd�Zejdddfd�Zdd�Z d �Z
d
�Zd�Zd�Z
d
�Zd�Zdd�Zd�Zd�Zdd�Zd�Zd�Zy)ra�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 DialogNc�*�|�|j}||_d|_t|�|_|jj|�|jj|�t
|j�t|j�|_|jjtt��t|j�|_
|jjtt��|jjd|j�t|j�|_|j jt"t��|j jd|j$�t|j�|_|j&jt(t*��t-|j&�|_|j.jt0t2��t5|j&d|j.df��|_|j6jt0t(t*��|j6j9�}|j6j9|dd|ddz�|j6jd |j:�|j6jd
|j<�|j.j?|j6df��t-|j&�|_ |j@jtBt2��t5|j&d|j@df��|_"|jDjtBt(t*��|j@j?|jDdf��|jDj9�}|jDj9|dd|ddz�|jDjd |jF�|jDjd
|jH�tK|jd
|jL��|_'|jNjtB��tK|jd|j$��|_(|jPjtBt(��tK|jd|jR��|_*|jTjt0��|jjWd|jR�|jjd|jR�|jjd|jR�y)N)�side�fillz<Return>)�expandr&r�set)�exportselection�yscrollcommand)r%r'r&�z<ButtonRelease-1>z<Double-ButtonRelease-1>�yview)�command�OK)�textr-)r%�Filter)r%r'�Cancel�WM_DELETE_WINDOWz<Alt-w>z<Alt-W>),�title�master� directoryr�top�iconnamer"r�botframe�packrrr� selection�bind�ok_event�filterr�filter_command�midframerrr�filesbarrrr�files�bindtags�files_select_event�files_double_event�config�dirsbarr�dirs�dirs_select_event�dirs_double_eventr�
ok_command� ok_button�
filter_button�cancel_command�
cancel_button�protocol)�selfr4r3�btagss �//usr/local/lib/python3.12/tkinter/filedialog.py�__init__zFileDialog.__init__:s����=�$�*�*�%��������F�#��������u�������%� ��d�h�h���d�h�h���
��
�
����Q��/��t�x�x����������a��0������J��
�
�6��D�H�H�o��������c���*�������T�%8�%8�9��d�h�h���
��
�
���#�D��1�!�$�-�-�0��
��
�
����A��.��T�]�]�A�-1�]�]�E�,B�D��
��
�
���U�3�T��:��
�
�#�#�%���
�
���E�!�"�I��b�q� �1�2��
�
���+�T�-D�-D�E��
�
���2�D�4K�4K�L��
�
���d�j�j�'�%:��;� ����/��������t�!��,��D�M�M�1�,0�L�L�%�+@�B�� �� � ���D��4��8������T�Y�Y��$8��9�� � �"�"�$��� � ���5���9�u�R�a�y�0�1�� � ���*�D�,B�,B�C�� � ���1�4�3I�3I�J���
�
�&*�)-���:���
�������&�#�D�M�M�)1�,0�,?�,?�A���
�����T�#��6�#�D�M�M�)1�,0�,?�,?�A���
�����U��+������,�d�.A�.A�B����
�
�i��!4�!4�5����
�
�i��!4�!4�5��*�c�b�|r|tvrt|\|_}nmtjj |�}tjj|�r||_n'tjj
|�\|_}|j|j|�|j|�|j�|jj�|jj�|jj�d|_|j j#�|rS|j%�\}}|jr)tjj'|j�}||ft|<|jj)�|jS�N)�dialogstatesr5�os�path�
expanduser�isdir�split�
set_filter�
set_selectionr>r:� focus_setr6�wait_visibility�grab_set�howr4�mainloop�
get_filter�dirname�destroy)rP�dir_or_file�pattern�default�keyr5s rR�goz
FileDialog.gozs-���3�,�&�&2�3�&7�#�D�N�G��'�'�,�,�[�9�K��w�w�}�}�[�)�!,���*,�'�'�-�-��*D�'�����������0����7�#�������� � �"���� � �"�����������������!%���!2��I�w��x�x��G�G�O�O�D�H�H�5� � )�7� 2�L����������x�x�rTc�F�||_|jj�yrX)rdr4�quit)rPrds rRrozFileDialog.quit�s����������rTc�$�|j�yrX)r>�rP�events rRrIzFileDialog.dirs_double_event�s�����rTc��|j�\}}|jjd�}tjjtjj
|j|��}|j||�y�N�active) rfrG�getrZr[�normpath�joinr5r_)rPrr�dir�pat�subdirs rRrHzFileDialog.dirs_select_event�sY���?�?�$���S������x�(���g�g���r�w�w�|�|�D�N�N�F�C�D������S�!rTc�$�|j�yrX�rJrqs rRrDzFileDialog.files_double_event�������rTc�\�|jjd�}|j|�yrt)rArvr`)rPrr�files rRrCzFileDialog.files_select_event�s"���z�z�~�~�h�'�����4� rTc�$�|j�yrXr}rqs rRr<zFileDialog.ok_event�r~rTc�B�|j|j��yrX)ro�
get_selection�rPs rRrJzFileDialog.ok_command�s��� � �$�$�$�&�'rTc���|j�\}} tj|�}||_|j||�|j�tjg}g}|D]{}tjj||�}tjj|�r|j|��Ttj||�s�k|j|��}|jj!dt"�|D]"}|jj%t"|��$|j&j!dt"�|D]"}|j&j%t"|��$tjj)|j+��\} }
|
tj,k(rd}
|j/|
�y#t$r|jj�YywxYw)NrrV)rfrZ�listdir�OSErrorr4�bellr5r_�sort�pardirr[rxr]�append�fnmatchrG�deleter�insertrAr^r��curdirr`)rPrrryrz�names�subdirs�
matchingfiles�name�fullname�head�tails rRr>zFileDialog.filter_command�sq���?�?�$���S� ��J�J�s�O�E��������S�!�
�
�
���9�9�+���
��D��w�w�|�|�C��.�H��w�w�}�}�X�&����t�$�����s�+��$�$�T�*��
� � ����C� ��D��I�I���S�$�'���
�
���!�S�!�!�D��J�J���c�4�(�"��W�W�]�]�4�#5�#5�#7�8�
��d��2�9�9��R�d����4� ��-� ��K�K����� �s�G�#G1�0G1c�\�|jj�}tjj |�}|ddtj
k(stjj
|�r tjj|d�}tjj|�S)N���rU) r=rvrZr[r\�sepr]rxr^)rPr=s rRrfzFileDialog.get_filter�sn�������"�����#�#�F�+���"�#�;�"�&�&� �B�G�G�M�M�&�$9��W�W�\�\�&�#�.�F��w�w�}�}�V�$�$rTc�x�|jj�}tjj |�}|SrX)r:rvrZr[r\�rPr�s rRr�zFileDialog.get_selection�s-���~�~�!�!�#���w�w�!�!�$�'���rTc�$�|j�yrX)rorqs rRrMzFileDialog.cancel_command�s��� � �rTc��tjj|�sV tj�}|r?tjj||�}tjj
|�}|jjdt�|jjttjj|xstj|xsd��y#t$rd}Y��wxYw)NrrU)rZr[�isabs�getcwdr�rxrwr=r�rr�r�)rPryrz�pwds rRr_zFileDialog.set_filter�s����w�w�}�}�S�!�
��i�i�k����g�g�l�l�3��,���g�g�&�&�s�+�������1�c�"������3������S�-=�B�I�I�s�z�c� J�K��
�
���
�s�C+�+C9�8C9c���|jjdt�|jjttj
j
|j|��y)Nr)r:r�rr�rZr[rxr5r�s rRr`zFileDialog.set_selection�s=�������a��%������c�2�7�7�<�<�����#E�FrTrX)�__name__�
__module__�__qualname__�__doc__r3rSrZr�rmrorIrHrDrCr<rJr>rfr�rMr_r`�rTrRrr!sk���*
$�E�>6�@ �Y�Y��R�T��2��"��!��(�!�8%��
�
L�GrTrc��eZdZdZdZd�Zy)rz8File selection dialog which checks that the file exists.zLoad File Selection Dialogc��|j�}tjj|�s|jj�y|j
|�yrX)r�rZr[�isfiler4r�ror�s rRrJzLoadFileDialog.ok_command�s;���!�!�#���w�w�~�~�d�#��K�K�����I�I�d�OrTN�r�r�r�r�r3rJr�rTrRrr�s��B�(�E�rTrc��eZdZdZdZd�Zy)rz@File selection dialog which checks that the file may be created.zSave File Selection Dialogc��|j�}tjj|�ritjj |�r|j
j
�yt|jdd|�d�ddd��}|jdk7r]ytjj|�\}}tjj |�s|j
j
�y|j|�y) Nz Overwrite Existing File QuestionzOverwrite existing file �?� questheadr+)�Yesr1)r3r/�bitmaprk�stringsr)r�rZr[�existsr]r4r�r r6�numr^ro)rPr��dr�r�s rRrJzSaveFileDialog.ok_command�s����!�!�#��
�7�7�>�>�$���w�w�}�}�T�"���� � �"���t�x�x�?�=A�C�)� �0�2�A��u�u��z�������t�,�J�D�$��7�7�=�=��&���� � �"��� � �$�rTNr�r�rTrRrr�s��J�(�E�rTrc��eZdZd�Zd�Zy)�_Dialogc�n� t|jd�|jd<y#t$rYywxYw)N� filetypes)�tuple�options�KeyErrorr�s rR�_fixoptionsz_Dialog._fixoptions2s5�� �(-�d�l�l�;�.G�(H�D�L�L��%��� �� �s�%(� 4�4c���|rM |j}tjj |�\}}||j
d<||j
d<||_|S#t$rY�TwxYw)N�
initialdir�initialfile)�string�AttributeErrorrZr[r^r��filename)rP�widget�resultr[r�s rR�
_fixresultz_Dialog._fixresult9sg���
����������v�.�J�D�$�)-�D�L�L��&�*.�D�L�L��'���
��
��"�
��
�s�A� A%�$A%N)r�r�r�r�r�r�rTrRr�r�0s���
rTr�c��eZdZdZdZd�Zy)r�Ask for a filename to open�tk_getOpenFilec
��t|t�r\t|D�cgc]}t|d|���c}�}|r4tjj|d�\}}||jd<|S|jj�s9d|jvr+|j||jj|��Stj|||�Scc}w)Nr�rr��multiple)�
isinstancer��getattrrZr[r^r��tk�wantobjectsr�� splitlistr�)rPr�r��rr[r�s rRr�zOpen._fixresultQs����f�e�$��V�D�V��G�A�x��3�V�D�E�F���W�W�]�]�6�!�9�5�
��d�-1����\�*��M��y�y�$�$�&�:����+E��?�?�6�6�9�9�+>�+>�v�+F�G�G��!�!�$���7�7��Es�CN�r�r�r�r�r-r�r�rTrRrrLs�� ��G�8rTrc��eZdZdZdZy)r�Ask for a filename to save as�tk_getSaveFileN)r�r�r�r�r-r�rTrRrr`s
��#��GrTrc��eZdZdZdZd�Zy)rzAsk for a directory�tk_chooseDirectoryc�n�|r |j}||jd<||_|S#t$rY�#wxYw)Nr�)r�r�r�r5)rPr�r�s rRr�zDirectory._fixresultlsC���
�����
*0�D�L�L��&�����
��
"�
��
�s�(� 4�4Nr�r�rTrRrrgs���"�G�rTrc�4�tdi|��j�S)r�r��r�show�r�s rRrr}s���?�'�?���!�!rTc�4�tdi|��j�S)r�r�)rr�r�s rRr r �s����G��!�!�#�#rTc�>�d|d<tdi|��j�S)ztAsk for multiple filenames to open
Returns a list of filenames or empty list if
cancel button selected
r+r�r�r�r�s rRr
r
�s#���G�J���?�'�?���!�!rTc�R�tdi|��j�}|rt||�Sy)z8Ask for a filename to open, and returned the opened fileNr�)rr��open��moder�r�s rRrr�s+����g��#�#�%�H���H�d�#�#�rTc�l�tdi|��}|r&g}|D]}|jt||���|}|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
r�)r
r�r�)r�r�rA�ofilesr�s rRrr�s@��
�'�w�'�E�����H��M�M�$�x��.�/�����LrTc�R�tdi|��j�}|rt||�Sy)z;Ask for a filename to save as, and returned the opened fileNr�)rr�r�r�s rRr
r
�s-��� �� �%�%�'�H���H�d�#�#�rTc�4�tdi|��j�S)z-Ask for a directory, and return the file namer�)rr�r�s rRrr�s����w��$�$�&�&rTc��t�}|j�t|�}|jd��}t |�}|jd��}t||�d} ddl}|j|jd�|j|j�}tdg��} t|d �}|j�td|j#|��t%�} td| j#|��y#ttf$rY�|wxYw#t $r }td
�t|�Yd}~�zd}~wwxYw)
zSimple test program.�test)rlzutf-8rNrV)z all filesrU)r�r�zCould not open File: r��saveas)r�withdrawrrmr�print�locale� setlocale�LC_ALL�nl_langinfo�CODESET�ImportErrorr�rr��close�
BaseException�encoder )
�root�fd�loadfile�savefile�encr��openfilename�fp�exc�saveasfilenames
rRr�r��s#��
�4�D��M�M�O� �� �B��u�u��u� �H� �� �B��u�u��u� �H� �(�H���C�
��������r�*�� � ����0��!�,>�+?�@�L����S�!��
���
�
�&�,�%�%�c�*�+�%�&�N� �(�N�)�)�#�.�/��%
��(�
��
����
�%�&�
�c�
�
���s*�$;D
�-D�
D�D� E�(E�E�__main__)r�)�w)+r��__all__r�rZ�tkinterrrrrrrrrrrrrrrrr�tkinter.dialogr r!�tkinter.simpledialogr"rYrrrr�rrrrr r
rrr
rr�r�r�rTrR�<module>rs����K��
� ������"� �.���EG�EG�P�Z���Z��r�l�!�!��88�7�8�(�W����#�#��,"�$�"���"�'�(0�V�z���F�rT
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists