Why does Gtk not have a specific controller class (MV'C')?

I’m looking for some advice.

My application uses Application and WindowApplication for the main UI for the user. However I have a number of pop-up windows that allow me to select, enter, edit and delete SQLlite data. The data entered is to be processed, aggregated, charted, tabulated before presentation on the main UI. Not difficult.

My question relates to the model, view, controller pattern and specifically to the “controller”. I want to create a controller to which I can add Gtk Actions and Signals for a pop-up GtkWindow, similar to the Application/ApplicationWindow combination. The controller interfaces to a model (SQLite DB) and to the pop-up window. But there isn’t a specific Gtk “controller” class to use.

I could get the GtkApplication instance to do the work but after creating two pop-up windows the Application class became unwieldy and messy.

Currently the controller is instantiated which in turn instantiates the pop-up window with the controller passed as a parameter. This allows window callbacks to be forwarded back to the controller. It works but would be a lot cleaner if callbacks went directly to the controller.

There are other options but I would like to if anyone knows how to create a custom controller with GActionGroup and GActionMap interfaces.

Thanks in advance

Greg

You can just put a GSimpleActionGroup as a member inside any object class. There is nothing special that needs to be done to create a controller object.

Thanks Jason for responding.
I deliberately left out a couple of aspects from my question, I was hoping I get a broad range of ideas. My not have been a good idea.

My project is using GTK4 and Python. The consequence’s of which are:
GSimpleActionGroup has been deprecated and you cannot inherit from GObject (I assumed you meant GObject when referring to “…any object class.”) . However It occurred to me that I could inherit from GtkWidget then add a controller to receive the events.
Thanks again

GSimpleActionGroup is not deprecated, only some of the methods are deprecated. They have been replaced with methods on GActionMap. And what do you mean you cannot inherit from GObject? The docs show how to do just that: GObject.Object — PyGObject

But you should not even need to do this if not adding properties or signals, an ordinary Python object can contain a GSimpleActionGroup. You probably do not want to use an empty GtkWidget either, there is some overhead to that. One thing you can do is add widget actions to the GtkWindow, that should actually be faster than using a GSimpleActionGroup. But then the window effectively becomes the controller class, and I am not sure if those work correctly in python.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.