[pygtk] How to use gtk.FileChooserButton?
Alexandre Abadie
Alexandre.Abadie at irisa.fr
Mon Aug 13 20:29:48 WST 2007
Taras a écrit :
> Hello, everybody!
> Now I currently use such code with usual button for run and process
> response file chooser dialog.
> Some times ago I found in PyGTK reference new gtk.FileChooserButton (
> http://pygtk.org/docs/pygtk/class-gtkfilechooserbutton.html)
> but from manual I didn't understand how to use it.
> Can you give me some example of it?
>
> # ...
>
> fileselButton = gtk.Button("Browse")
> fileselButton.connect("clicked", self.open_file_dialog)
>
> # ...
>
> def open_file_dialog(self, widget):
> self.chooser = gtk.FileChooserDialog(title=None,action=
> gtk.FILE_CHOOSER_ACTION_OPEN,
> buttons=(gtk.STOCK_CANCEL,
> gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
> self.chooser.set_current_folder(os.environ['HOME'])
> self.chooser.set_default_response(gtk.RESPONSE_OK)
> response = self.chooser.run()
>
> if response == gtk.RESPONSE_OK:
> # some actions
> self.chooser.destroy()
>
>
Hi,
I use it like this :
# in the __init__ method
self.button = gtk.Button("Browse...")
self.button.connect("clicked", self.browse_for_file, None)
# ...
# my class method for browsing the file
def browse_for_file(self):
file_open = gtk.FileChooserDialog(title="Select dicomdir"
, action=gtk.FILE_CHOOSER_ACTION_OPEN
, buttons=(gtk.STOCK_CANCEL
, gtk.RESPONSE_CANCEL
, gtk.STOCK_OPEN
, gtk.RESPONSE_OK))
result = ""
if file_open.run() == gtk.RESPONSE_OK:
result = file_open.get_filename()
file_open.destroy()
return result
It works fine.
Alex
More information about the pygtk
mailing list