I'm developing a GUI application using Glade and Python 3. I've designed the UI in Glade; it consists of a main application window and a custom dialog with certain information that is shown when the user clicks a specified button. The dialog has its own class, let's call it InfoDialog
; its constructor handles creating the dialog window and showing it. The class also has methods that correspond to signals sent by widgets in the dialog; for example, there is a "Cancel" button, and the signal (and the handler method in the class) is called on_cancelButton_clicked
.
The problem is that I would like to connect this signal on a per-instance basis in InfoDialog
's constructor and specify self
as user-data, so that InfoDialog.on_cancelButton_clicked
receives all the arguments and can take action on that instance of InfoDialog
. The problem is that as I connect the signals for my main window after I create it, Gtk.builder
expects me to provide all the signal handlers in there, not just for the main window, but also for InfoDialog
and its children - in general for every single signal defined in the UI .xml file.
What can I do to solve this, other than just calling widget.connect()
manually for every child?
The usual way is to split the UI definitions for different windows/dialogs into separate XML files.
If you don't want to do that, you could use Gtk.Builder.connect_signals_full()
, and pass a custom function that connects only the signals you want to connect.