[wingide-users] File open boxKen Kinder firstname.lastname@example.org
02 Jun 2002 22:07:30 -0500
One thing that bugs me about 90% of the GTK programs out there: They follow the poorly written documentation. :) Like WingIDE. In the open file dialog box, if I type a DIRECTORY name into the file selection area, and hit return, I get an error that I must select a valid file. Or if I type '..' and hit return, I get an error. This is because the file selection dialog doesn't check to see if you're looking for a file or a directory. Well, here's a replacement for pygtk's file open class that doesn't do that if you're looking for a directory. A couple of other tweaks, like modal is defaulted to false, but you get the picture. Compare to the default in GtkExtra.py You might want to work this into Wing or something simpler. The key is calling os.path.normpath, and checking to see if it's a directory before closing the dialog. class FileSelection(gtk.GtkFileSelection): "Taken from pygtk, and made better" def __init__(self, title='Open', modal=gtk.FALSE, file_required=1): gtk.GtkFileSelection.__init__(self) self.file_required = file_required self.set_title(title) self.connect('destroy', self.quit) self.connect('delete_event', self.quit) if modal: gtk.grab_add(self) self.cancel_button.connect('clicked', self.quit) self.ok_button.connect('clicked', self.ok) self.return_filename = None def quit(self, *args): self.hide() self.destroy() gtk.mainquit() def ok(self, *args): filename = self.get_filename() filename = os.path.normpath(filename) if self.file_required and os.path.isdir(filename): if filename[-1:] != '/': filename += '/' self.set_filename(filename) else: self.return_filename self.quit() def select_file(title='Open', modal=gtk.FALSE): "Taken from pygtk and made better" win = FileSelection(title, modal, 1) win.show() gtk.mainloop() return win.return_filename
Run by Mailman v 2.0.8
Copyright (c) 2000-2002, Archaeopteryx Software, Inc.