Lines Matching refs:self
58 def __init__(self, master, title=None):
59 if title is None: title = self.title
60 self.master = master
61 self.directory = None
63 self.top = Toplevel(master)
64 self.top.title(title)
65 self.top.iconname(title)
66 _setup_dialog(self.top)
68 self.botframe = Frame(self.top)
69 self.botframe.pack(side=BOTTOM, fill=X)
71 self.selection = Entry(self.top)
72 self.selection.pack(side=BOTTOM, fill=X)
73 self.selection.bind('<Return>', self.ok_event)
75 self.filter = Entry(self.top)
76 self.filter.pack(side=TOP, fill=X)
77 self.filter.bind('<Return>', self.filter_command)
79 self.midframe = Frame(self.top)
80 self.midframe.pack(expand=YES, fill=BOTH)
82 self.filesbar = Scrollbar(self.midframe)
83 self.filesbar.pack(side=RIGHT, fill=Y)
84 self.files = Listbox(self.midframe, exportselection=0,
85 yscrollcommand=(self.filesbar, 'set'))
86 self.files.pack(side=RIGHT, expand=YES, fill=BOTH)
87 btags = self.files.bindtags()
88 self.files.bindtags(btags[1:] + btags[:1])
89 self.files.bind('<ButtonRelease-1>', self.files_select_event)
90 self.files.bind('<Double-ButtonRelease-1>', self.files_double_event)
91 self.filesbar.config(command=(self.files, 'yview'))
93 self.dirsbar = Scrollbar(self.midframe)
94 self.dirsbar.pack(side=LEFT, fill=Y)
95 self.dirs = Listbox(self.midframe, exportselection=0,
96 yscrollcommand=(self.dirsbar, 'set'))
97 self.dirs.pack(side=LEFT, expand=YES, fill=BOTH)
98 self.dirsbar.config(command=(self.dirs, 'yview'))
99 btags = self.dirs.bindtags()
100 self.dirs.bindtags(btags[1:] + btags[:1])
101 self.dirs.bind('<ButtonRelease-1>', self.dirs_select_event)
102 self.dirs.bind('<Double-ButtonRelease-1>', self.dirs_double_event)
104 self.ok_button = Button(self.botframe,
106 command=self.ok_command)
107 self.ok_button.pack(side=LEFT)
108 self.filter_button = Button(self.botframe,
110 command=self.filter_command)
111 self.filter_button.pack(side=LEFT, expand=YES)
112 self.cancel_button = Button(self.botframe,
114 command=self.cancel_command)
115 self.cancel_button.pack(side=RIGHT)
117 self.top.protocol('WM_DELETE_WINDOW', self.cancel_command)
119 self.top.bind('<Alt-w>', self.cancel_command)
120 self.top.bind('<Alt-W>', self.cancel_command)
122 def go(self, dir_or_file=os.curdir, pattern="*", default="", key=None):
124 self.directory, pattern = dialogstates[key]
128 self.directory = dir_or_file
130 self.directory, default = os.path.split(dir_or_file)
131 self.set_filter(self.directory, pattern)
132 self.set_selection(default)
133 self.filter_command()
134 self.selection.focus_set()
135 self.top.wait_visibility() # window needs to be visible for the grab
136 self.top.grab_set()
137 self.how = None
138 self.master.mainloop() # Exited by self.quit(how)
140 directory, pattern = self.get_filter()
141 if self.how:
142 directory = os.path.dirname(self.how)
144 self.top.destroy()
145 return self.how
147 def quit(self, how=None):
148 self.how = how
149 self.master.quit() # Exit mainloop()
151 def dirs_double_event(self, event):
152 self.filter_command()
154 def dirs_select_event(self, event):
155 dir, pat = self.get_filter()
156 subdir = self.dirs.get('active')
157 dir = os.path.normpath(os.path.join(self.directory, subdir))
158 self.set_filter(dir, pat)
160 def files_double_event(self, event):
161 self.ok_command()
163 def files_select_event(self, event):
164 file = self.files.get('active')
165 self.set_selection(file)
167 def ok_event(self, event):
168 self.ok_command()
170 def ok_command(self):
171 self.quit(self.get_selection())
173 def filter_command(self, event=None):
174 dir, pat = self.get_filter()
178 self.master.bell()
180 self.directory = dir
181 self.set_filter(dir, pat)
191 self.dirs.delete(0, END)
193 self.dirs.insert(END, name)
194 self.files.delete(0, END)
196 self.files.insert(END, name)
197 head, tail = os.path.split(self.get_selection())
199 self.set_selection(tail)
201 def get_filter(self):
202 filter = self.filter.get()
208 def get_selection(self):
209 file = self.selection.get()
213 def cancel_command(self, event=None):
214 self.quit()
216 def set_filter(self, dir, pat):
225 self.filter.delete(0, END)
226 self.filter.insert(END, os.path.join(dir or os.curdir, pat or "*"))
228 def set_selection(self, file):
229 self.selection.delete(0, END)
230 self.selection.insert(END, os.path.join(self.directory, file))
239 def ok_command(self):
240 file = self.get_selection()
242 self.master.bell()
244 self.quit(file)
253 def ok_command(self):
254 file = self.get_selection()
257 self.master.bell()
259 d = Dialog(self.top,
270 self.master.bell()
272 self.quit(file)
306 def _fixoptions(self):
309 self.options["filetypes"] = tuple(self.options["filetypes"])
313 def _fixresult(self, widget, result):
323 self.options["initialdir"] = path
324 self.options["initialfile"] = file
325 self.filename = result # compatibility
337 def _fixresult(self, widget, result):
343 self.options["initialdir"] = path
346 if not widget.tk.wantobjects() and "multiple" in self.options:
348 return self._fixresult(widget, widget.tk.splitlist(result))
349 return _Dialog._fixresult(self, widget, result)
364 def _fixresult(self, widget, result):
373 self.options["initialdir"] = result
374 self.directory = result # compatibility