Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
tkinter.filedialog.FileDialog Class Reference
Inheritance diagram for tkinter.filedialog.FileDialog:
Inheritance graph
[legend]
Collaboration diagram for tkinter.filedialog.FileDialog:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def go
def quit
def dirs_double_event
def dirs_select_event
def files_double_event
def files_select_event
def ok_event
def ok_command
def filter_command
def get_filter
def get_selection
def cancel_command
def set_filter
def set_selection

Public Attributes

 master
 directory
 top
 botframe
 selection
 filter
 midframe
 filesbar
 files
 dirsbar
 dirs
 ok_button
 filter_button
 cancel_button
 how

Static Public Attributes

string title = "File Selection Dialog"

Detailed Description

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.)

Definition at line 26 of file filedialog.py.


Constructor & Destructor Documentation

def tkinter.filedialog.FileDialog.__init__ (   self,
  master,
  title = None 
)

Definition at line 51 of file filedialog.py.

00051 
00052     def __init__(self, master, title=None):
00053         if title is None: title = self.title
00054         self.master = master
00055         self.directory = None
00056 
00057         self.top = Toplevel(master)
00058         self.top.title(title)
00059         self.top.iconname(title)
00060 
00061         self.botframe = Frame(self.top)
00062         self.botframe.pack(side=BOTTOM, fill=X)
00063 
00064         self.selection = Entry(self.top)
00065         self.selection.pack(side=BOTTOM, fill=X)
00066         self.selection.bind('<Return>', self.ok_event)
00067 
00068         self.filter = Entry(self.top)
00069         self.filter.pack(side=TOP, fill=X)
00070         self.filter.bind('<Return>', self.filter_command)
00071 
00072         self.midframe = Frame(self.top)
00073         self.midframe.pack(expand=YES, fill=BOTH)
00074 
00075         self.filesbar = Scrollbar(self.midframe)
00076         self.filesbar.pack(side=RIGHT, fill=Y)
00077         self.files = Listbox(self.midframe, exportselection=0,
00078                              yscrollcommand=(self.filesbar, 'set'))
00079         self.files.pack(side=RIGHT, expand=YES, fill=BOTH)
00080         btags = self.files.bindtags()
00081         self.files.bindtags(btags[1:] + btags[:1])
00082         self.files.bind('<ButtonRelease-1>', self.files_select_event)
00083         self.files.bind('<Double-ButtonRelease-1>', self.files_double_event)
00084         self.filesbar.config(command=(self.files, 'yview'))
00085 
00086         self.dirsbar = Scrollbar(self.midframe)
00087         self.dirsbar.pack(side=LEFT, fill=Y)
00088         self.dirs = Listbox(self.midframe, exportselection=0,
00089                             yscrollcommand=(self.dirsbar, 'set'))
00090         self.dirs.pack(side=LEFT, expand=YES, fill=BOTH)
00091         self.dirsbar.config(command=(self.dirs, 'yview'))
00092         btags = self.dirs.bindtags()
00093         self.dirs.bindtags(btags[1:] + btags[:1])
00094         self.dirs.bind('<ButtonRelease-1>', self.dirs_select_event)
00095         self.dirs.bind('<Double-ButtonRelease-1>', self.dirs_double_event)
00096 
00097         self.ok_button = Button(self.botframe,
00098                                  text="OK",
00099                                  command=self.ok_command)
00100         self.ok_button.pack(side=LEFT)
00101         self.filter_button = Button(self.botframe,
00102                                     text="Filter",
00103                                     command=self.filter_command)
00104         self.filter_button.pack(side=LEFT, expand=YES)
00105         self.cancel_button = Button(self.botframe,
00106                                     text="Cancel",
00107                                     command=self.cancel_command)
00108         self.cancel_button.pack(side=RIGHT)
00109 
00110         self.top.protocol('WM_DELETE_WINDOW', self.cancel_command)
00111         # XXX Are the following okay for a general audience?
00112         self.top.bind('<Alt-w>', self.cancel_command)
00113         self.top.bind('<Alt-W>', self.cancel_command)

Here is the caller graph for this function:


Member Function Documentation

def tkinter.filedialog.FileDialog.cancel_command (   self,
  event = None 
)

Definition at line 205 of file filedialog.py.

00205 
00206     def cancel_command(self, event=None):
00207         self.quit()

Here is the call graph for this function:

Definition at line 143 of file filedialog.py.

00143 
00144     def dirs_double_event(self, event):
00145         self.filter_command()

Here is the call graph for this function:

Definition at line 146 of file filedialog.py.

00146 
00147     def dirs_select_event(self, event):
00148         dir, pat = self.get_filter()
00149         subdir = self.dirs.get('active')
00150         dir = os.path.normpath(os.path.join(self.directory, subdir))
00151         self.set_filter(dir, pat)

Here is the call graph for this function:

Definition at line 152 of file filedialog.py.

00152 
00153     def files_double_event(self, event):
00154         self.ok_command()

Here is the call graph for this function:

Definition at line 155 of file filedialog.py.

00155 
00156     def files_select_event(self, event):
00157         file = self.files.get('active')
00158         self.set_selection(file)

Here is the call graph for this function:

def tkinter.filedialog.FileDialog.filter_command (   self,
  event = None 
)

Definition at line 165 of file filedialog.py.

00165 
00166     def filter_command(self, event=None):
00167         dir, pat = self.get_filter()
00168         try:
00169             names = os.listdir(dir)
00170         except os.error:
00171             self.master.bell()
00172             return
00173         self.directory = dir
00174         self.set_filter(dir, pat)
00175         names.sort()
00176         subdirs = [os.pardir]
00177         matchingfiles = []
00178         for name in names:
00179             fullname = os.path.join(dir, name)
00180             if os.path.isdir(fullname):
00181                 subdirs.append(name)
00182             elif fnmatch.fnmatch(name, pat):
00183                 matchingfiles.append(name)
00184         self.dirs.delete(0, END)
00185         for name in subdirs:
00186             self.dirs.insert(END, name)
00187         self.files.delete(0, END)
00188         for name in matchingfiles:
00189             self.files.insert(END, name)
00190         head, tail = os.path.split(self.get_selection())
00191         if tail == os.curdir: tail = ''
00192         self.set_selection(tail)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 193 of file filedialog.py.

00193 
00194     def get_filter(self):
00195         filter = self.filter.get()
00196         filter = os.path.expanduser(filter)
00197         if filter[-1:] == os.sep or os.path.isdir(filter):
00198             filter = os.path.join(filter, "*")
00199         return os.path.split(filter)

Here is the caller graph for this function:

Definition at line 200 of file filedialog.py.

00200 
00201     def get_selection(self):
00202         file = self.selection.get()
00203         file = os.path.expanduser(file)
00204         return file

Here is the caller graph for this function:

def tkinter.filedialog.FileDialog.go (   self,
  dir_or_file = os.curdir,
  pattern = "*",
  default = "",
  key = None 
)

Definition at line 114 of file filedialog.py.

00114 
00115     def go(self, dir_or_file=os.curdir, pattern="*", default="", key=None):
00116         if key and key in dialogstates:
00117             self.directory, pattern = dialogstates[key]
00118         else:
00119             dir_or_file = os.path.expanduser(dir_or_file)
00120             if os.path.isdir(dir_or_file):
00121                 self.directory = dir_or_file
00122             else:
00123                 self.directory, default = os.path.split(dir_or_file)
00124         self.set_filter(self.directory, pattern)
00125         self.set_selection(default)
00126         self.filter_command()
00127         self.selection.focus_set()
00128         self.top.wait_visibility() # window needs to be visible for the grab
00129         self.top.grab_set()
00130         self.how = None
00131         self.master.mainloop()          # Exited by self.quit(how)
00132         if key:
00133             directory, pattern = self.get_filter()
00134             if self.how:
00135                 directory = os.path.dirname(self.how)
00136             dialogstates[key] = directory, pattern
00137         self.top.destroy()
00138         return self.how

Here is the call graph for this function:

Reimplemented in tkinter.filedialog.SaveFileDialog, and tkinter.filedialog.LoadFileDialog.

Definition at line 162 of file filedialog.py.

00162 
00163     def ok_command(self):
00164         self.quit(self.get_selection())

Here is the call graph for this function:

Here is the caller graph for this function:

def tkinter.filedialog.FileDialog.ok_event (   self,
  event 
)

Definition at line 159 of file filedialog.py.

00159 
00160     def ok_event(self, event):
00161         self.ok_command()

Here is the call graph for this function:

def tkinter.filedialog.FileDialog.quit (   self,
  how = None 
)

Definition at line 139 of file filedialog.py.

00139 
00140     def quit(self, how=None):
00141         self.how = how
00142         self.master.quit()              # Exit mainloop()

Here is the caller graph for this function:

def tkinter.filedialog.FileDialog.set_filter (   self,
  dir,
  pat 
)

Definition at line 208 of file filedialog.py.

00208 
00209     def set_filter(self, dir, pat):
00210         if not os.path.isabs(dir):
00211             try:
00212                 pwd = os.getcwd()
00213             except os.error:
00214                 pwd = None
00215             if pwd:
00216                 dir = os.path.join(pwd, dir)
00217                 dir = os.path.normpath(dir)
00218         self.filter.delete(0, END)
00219         self.filter.insert(END, os.path.join(dir or os.curdir, pat or "*"))

Here is the caller graph for this function:

def tkinter.filedialog.FileDialog.set_selection (   self,
  file 
)

Definition at line 220 of file filedialog.py.

00220 
00221     def set_selection(self, file):
00222         self.selection.delete(0, END)
00223         self.selection.insert(END, os.path.join(self.directory, file))
00224 

Here is the caller graph for this function:


Member Data Documentation

Definition at line 60 of file filedialog.py.

Definition at line 104 of file filedialog.py.

Definition at line 54 of file filedialog.py.

Definition at line 87 of file filedialog.py.

Definition at line 85 of file filedialog.py.

Definition at line 76 of file filedialog.py.

Definition at line 74 of file filedialog.py.

Definition at line 67 of file filedialog.py.

Definition at line 100 of file filedialog.py.

Definition at line 129 of file filedialog.py.

Definition at line 53 of file filedialog.py.

Definition at line 71 of file filedialog.py.

Definition at line 96 of file filedialog.py.

Definition at line 63 of file filedialog.py.

string tkinter.filedialog.FileDialog.title = "File Selection Dialog" [static]

Reimplemented in tkinter.filedialog.SaveFileDialog, and tkinter.filedialog.LoadFileDialog.

Definition at line 49 of file filedialog.py.

Definition at line 56 of file filedialog.py.


The documentation for this class was generated from the following file: