Thread: [gtkmvc-users] Working with subviews
Brought to you by:
cavada
From: Steve M. <smc...@gm...> - 2012-05-25 15:26:25
|
Greetings, I've been trying to figure out the best way to deal with subviews using gtkmvc with gtkbuilder, and I came across this message on the mailing list archive: >> I personally use always the third. My latest preferences actually go to: >> >> 1. Separate glade 'builder' files per each view >> 2. Subview instantiated and connected in parent views >> 3. menu and toolbars not designed in glade, but constructed in ui manager >> 3.1 The top-level view has the space to accomodate the "tools" subview >> (menu and toolbars) >> 3.2 There is a glade (builder) file associated to one or more views to >> represent menu ad toolbars. The glade file contains actions, action >> groups and one uimanager object. >> 3.3 The view(s) for the menu and toolbars sets up the action groups, the >> actions, the accelerators, and using the uimanager instance create menus >> and toolbars out of xml files. The view has also the methods for >> dynamically change menu and toolbars throught visibility and sensitivity >> of actions and action groups. >> >> Cheers, >> r. I'm having some trouble getting my head around a few things though. Is there any published code out there using this pattern? I'm not entirely certain how to break everything down, especially dealing with the menu and toolbars. Right now, I have three views with their own glade files. There is a main window, and two subviews which each contain a set of controls to pack into a vbox in the main window. The top level objects in each subview's glade file are containers, one uses a vbox, one uses a table. In my main view's constructor, I pack them into the main window's vbox. This part seems to work alright, except that if a subview's controls have accelerator keys defined, I get this warning: "GtkWarning: IA__gtk_window_add_accel_group: assertion `GTK_IS_WINDOW (window)' failed" My motivation for creating the subviews was so that I could create matching subcontrollers, to split up my controller class before it got too big and messy. This leads me to the toolbar/menu problem. Some toolbar and menu actions should be handled directly be the various subcontrollers, so defining them in the main view and and using the main controller to pass events down to the subcontrollers seems inelegant. I'd like to find a way to define pieces of the toolbar/menubar in each subview, and connect their signals directly to handlers in the subcontrollers. Does anyone have any insight or examples? Thanks, -Steve McGrath -- If it ain't broke, you're not using a new enough version |
From: <to...@ce...> - 2012-05-25 20:44:10
|
On 25.05.2012, at 17:26, Steve McGrath wrote: > Is there any published code out there using this pattern? I don't think so. The repository contains a UIManager example, but it's using a new View class we're working on. > This part seems to work alright, And it sounds good! > except that if a subview's controls have accelerator keys defined, I get this warning: "GtkWarning: IA__gtk_window_add_accel_group: assertion `GTK_IS_WINDOW (window)' failed" You used the Common tab in Glade's inspector? Libglade or GtkBuilder? > I'd like to find a way to define pieces of the toolbar/menubar in each subview, and connect their signals directly to handlers in the subcontrollers. That's how examples/converter works. > Does anyone have any insight or examples? If you can show your code I'll write one ;) Tobias |
From: Roberto C. <rob...@gm...> - 2012-05-25 21:00:34
|
2012/5/25 Steve McGrath <smc...@gm...> > I'm having some trouble getting my head around a few things though. Is > there any published code out there using this pattern? I'm not > entirely certain how to break everything down, especially dealing with > the menu and toolbars. > Typically in large applications you have: - One view (possibly with a controller associated) for toolbars and menubars (BarsView and possible BarsCtrl) - M views to decompose the rest of the application presentation - N controllers (N <= M) to decompose the controllers of the M views Now you want some (not necessarily all) controls in the menu and toolbars to be handled in the N controllers, to keep locality. The way I always solve this problem is: 1. Each of the M views contains its own actions to be later associated to the UI manager allocated in BarsView 2. The signal handlers of the actions are located in the N controllers, attached automatically when views and controllers are connected each other. 3. BarsView creates and handles the UIManager. This Bars view has the visibility of all M views (throught the ApplicationView which stays at top-level and has to be passed down to BarsView's constructor. In this way the BarsView can access the actions allocated in the M views to associate them in the UIManager. Let me think what you think about this, and if it is not clear enough I will try to make an example. r. |
From: Steve M. <smc...@gm...> - 2012-05-25 21:23:38
|
On Fri, May 25, 2012 at 3:27 PM, <to...@ce...> wrote: > On 25.05.2012, at 17:26, Steve McGrath wrote: > >> except that if a subview's controls have accelerator keys defined, I get this warning: "GtkWarning: IA__gtk_window_add_accel_group: assertion `GTK_IS_WINDOW (window)' failed" > > You used the Common tab in Glade's inspector? Libglade or GtkBuilder? Yes, I defined the accelerator keys for a couple buttons using the common properties in Glade. I'm using GtkBuilder format for all my UI definitions. >> I'd like to find a way to define pieces of the toolbar/menubar in each subview, and connect their signals directly to handlers in the subcontrollers. > > That's how examples/converter works. I'll have to take a look at that one, thanks. >> Does anyone have any insight or examples? > > If you can show your code I'll write one ;) If you want to take a look, my code can be seen on github at https://github.com/smcgrath/azathoth-client/tree/gtkmvc-refactor For context, this application is used to monitor and control a robot over a wi-fi connection. It's kind of a mess because I got a little ways into it and decided to refactor everything into the gtkmvc framework before proceeding any further. Roberto: Thank you, I think this explanation is a bit more clear than the old message from you that I quoted. Part of the problem I think is more generally GTK-related, in that I haven't worked with the UIManager or Actions/ActionGroups yet. So far I've always defined toolbars and menubars traditionally, as object hierarchies within my main window's glade file. Any small example of how to connect all the "plumbing" of UIManager in a gtkmvc application would be useful indeed. Thanks much, -Steve McGrath -- If it ain't broke, you're not using a new enough version |
From: <to...@ce...> - 2012-05-25 22:05:29
|
On 25.05.2012, at 23:23, Steve McGrath wrote: > Any small example of how to connect all the "plumbing" of UIManager in a gtkmvc application would be useful indeed. https://sourceforge.net/apps/trac/pygtkmvc/browser/trunk/gtkmvco/examples/uimanager Didn't plan to commit these, but there you are. |
From: <to...@ce...> - 2012-05-25 22:40:22
|
On 25.05.2012, at 17:26, Steve McGrath wrote: > This part seems to work alright, except that if a subview's controls have accelerator keys defined, I get this warning: "GtkWarning: IA__gtk_window_add_accel_group: assertion `GTK_IS_WINDOW (window)' failed" Accelerators only work if they're assigned to a window, since this is where keyboard events come in from the OS. Some of your files don't contain windows. I didn't know this was possible, I presume you started with one and then used "remove parent" in Glade. This is why GtkBuilder fails to set up the accelerator. Using the common tab in Glade does not make any intermediate steps (like an ActionGroup) available, so it is not possible to fix this in code. Even if you had dummy windows in the subview files, reparenting the widgets into the main window would break the accelerators. The bottom line is, the common tab will never work with subviews. You'll have to do it manually in code (like examples/uimanager) or wait for us to finish extending GTKMVC. |
From: Steve M. <smc...@gm...> - 2012-05-25 22:52:17
|
On Fri, May 25, 2012 at 5:40 PM, <to...@ce...> wrote: > On 25.05.2012, at 17:26, Steve McGrath wrote: > >> This part seems to work alright, except that if a subview's controls have accelerator keys defined, I get this warning: "GtkWarning: IA__gtk_window_add_accel_group: assertion `GTK_IS_WINDOW (window)' failed" > > Accelerators only work if they're assigned to a window, since this is where keyboard events come in from the OS. > > Some of your files don't contain windows. I didn't know this was possible, I presume you started with one and then used "remove parent" in Glade. > > This is why GtkBuilder fails to set up the accelerator. Using the common tab in Glade does not make any intermediate steps (like an ActionGroup) available, so it is not possible to fix this in code. > > Even if you had dummy windows in the subview files, reparenting the widgets into the main window would break the accelerators. > > The bottom line is, the common tab will never work with subviews. You'll have to do it manually in code (like examples/uimanager) or wait for us to finish extending GTKMVC. > Ah. Actually I had just cut & pasted the subsections out of my main glade file into their own glade projects. Glade didn't complain, so I never thought to think about whether or not it was a good idea. I was guessing the problem had something to do with the subview not having its own window. I suppose I'll work on integrating UIManager into the mix, and figure out my accelerator keys from there. -Steve -- If it ain't broke, you're not using a new enough version |
From: Steve M. <smc...@gm...> - 2012-05-26 20:38:07
|
Roberto, Tobias, thanks. I spent some time last night working on moving my toolbar and menubar to a UIManager, and it's working perfectly. I added a new subview which creates a UIManager and populates it with ActionGroups stored in the other views' Glade files. Works great. I just had to stop thinking about it and start coding it. Thanks again, -Steve McGrath -- If it ain't broke, you're not using a new enough version |
From: Roberto C. <ca...@fb...> - 2012-05-28 07:32:02
|
On 05/26/2012 10:38 PM, Steve McGrath wrote: > Roberto, Tobias, thanks. I spent some time last night working on > moving my toolbar and menubar to a UIManager, and it's working > perfectly. I added a new subview which creates a UIManager and > populates it with ActionGroups stored in the other views' Glade files. > Works great. I just had to stop thinking about it and start coding it. That's great! I also have been working in the WE on a complete example. I should be able to commit it today. Cheers, r. |
From: Roberto C. <ca...@fb...> - 2012-05-28 10:43:27
|
On 05/28/2012 09:16 AM, Roberto Cavada wrote: > I also have been working in the WE on a complete example. I should be > able to commit it today. Done. See rev. 391 r. |