Gtk.ResponseType
its a small set of predefined values. These are negative values while positive values (including zero) are left for application developers to use them as needed. From the documentation:
Predefined values for use as response ids in Gtk.Dialog.add_button().
All predefined values are negative; GTK+ leaves values of 0 or greater
for application-defined response ids.
So, when you add buttons to the dialog, instead of using the predefined Gtk.ResponseType, you can use your own set of response values.
Lets take this example from the python-gtk3 tutorial and add a third option with our own response type value:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class DialogExample(Gtk.Dialog):
def __init__(self, parent):
Gtk.Dialog.__init__(self, "My Dialog", parent, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK, "OPTION 3", 1))
self.set_default_size(150, 100)
label = Gtk.Label("This is a dialog to display additional information")
box = self.get_content_area()
box.add(label)
self.show_all()
class DialogWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Dialog Example")
self.set_border_width(6)
button = Gtk.Button("Open dialog")
button.connect("clicked", self.on_button_clicked)
self.add(button)
def on_button_clicked(self, widget):
dialog = DialogExample(self)
response = dialog.run()
if response == Gtk.ResponseType.OK:
print("The OK button was clicked")
elif response == Gtk.ResponseType.CANCEL:
print("The Cancel button was clicked")
elif response == 1:
print("OPTION 3 was clicked")
dialog.destroy()
win = DialogWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
What was done?
We added a third button with label OPTION 3 which has a response id value of 1
:
Gtk.Dialog.__init__(self, "My Dialog", parent, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK, "OPTION 3", 1))
Then, when handling the response, we can check for that response id value and do something different:
...
print("The Cancel button was clicked")
elif response == 1:
print("OPTION 3 was clicked")
...
You can create your own enumerated set of positive response values and use them as needed (including zero). Good luck.
EDIT:
In glade, when using buttons, you can set the value of the response_id
as an integer. It's located in the general settings tab of the widget.