When I create a GtkFileChooserDialog
in Glade and then connect that to a Python class using Gtk.Builder
, how do I tell it which is the default button?
Currently, my 'Open' button is the stock gtk-open
button and when it's clicked, run()
returns 0. But double-clicking on a file or selecting a file and pressing Enter doesn't do anything. As far as I can see, this is because the dialog doesn't know what the default button is in Glade, possibly because the 'Open' button isn't using one of GTK_RESPONSE_ACCEPT
, GTK_RESPONSE_OK
, GTK_RESPONSE_YES
or GTK_RESPONSE_APPLY
as its response code; but how do I set the response code to one of these when the button is created through Glade?
I'm using Gtk 3, Python 3 and PyGObject (ie gi.repository
).
Edit: Here is the relevant bit of the Glade file:
<object class="GtkFileChooserDialog" id="file_chooser">
<property name="can_focus">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<property name="select_multiple">True</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button1">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-open</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-1">button1</action-widget>
<action-widget response="-5">button2</action-widget>
</action-widgets>
</object>