[pygtk] External activation of gtk.FileChooserButton
Osmo Salomaa
otsaloma at cc.hut.fi
Sun Jan 15 22:27:53 WST 2006
I want to have a filechooser button on a toolbar and an item in the
menubar that corresponds to it. How do I get the menu item to perform
the same function as what happens when the filechooser button is
clicked, which is running the filechooser dialog associated with the
filechooser button?
I assume that if I make the filechooser dialog an instance variable, I
can later call run() on it,
def __init__(self):
self.dialog = gtk.FileChooserDialog(...)
self.button = gtk.FileChooserButton(dialog)
...
def on_menu_item_activated(self, *args):
self.dialog.run()
but I'd rather not have yet another instance variable. I tried the
activate() method and emitting button-press/release-events on the
filechooser button, but they did not work.
Below is a simple test app, where the menu item has been replaced by a
button. The "on_clicked" method is the part that needs modification.
Thanks,
Osmo Salomaa
#!/usr/bin/env python
import gtk
fcbutton = gtk.FileChooserButton('Select File')
def on_clicked(*args):
fcbutton.activate() # Does not work.
button = gtk.Button('Activate file chooser button')
button.connect('clicked', on_clicked)
vbox = gtk.VBox()
vbox.pack_start(fcbutton)
vbox.pack_start(button)
window = gtk.Window()
window.set_default_size(400, 60)
window.add(vbox)
window.connect('delete-event', gtk.main_quit)
window.show_all()
gtk.main()
More information about the pygtk
mailing list