[pygtk] UIManagers and accelerators

Pietro Battiston toobaz at email.it
Sat Jan 24 00:53:35 WST 2009


I'm trying to smartly use ActionGroups and UIManagers to simplify my
callbacks management, but I can't understand totally the logic behind
them.

I define my actions in my gtk.ActionGroup, adding them with add_actions.
At this point, I would like to just say "OK, every action has its
accelerator defined; gtk.Window, just listen to them!". Instead, I found
no way to do that (better than just:

self.accelgroup = gtk.AccelGroup()
self.add_accel_group(self.accelgroup)

for action in actiongroup.list_actions():
	action.set_accel_group(self.accelgroup)

).

The only "orthodox" way I found is: you take your UIManager "uimanager",
you connect it to the ActionGroup with:

uimanager.insert_action_group(self.actiongroup)

and then:

self.add_accel_group(uimanager.get_accel_group())

In that way, all the actions _that have a proxy widget realized_ will
have shortcuts enabled. This means that if I then do for instance:

self.child_which_is_a_container.add(uimanager.get_widget('/root'))

, my problem is solved. But in my case the problem is _not_ solved,
since I don't want to pass through a UIManager and be obliged to insert
proxies somewhere (more precisely, in my particular case I do use a
UIManager, but only to produce a popup menu, which is not constantly
realized, so my accelerators do not work).

So:
- is there a way to just enable the accelerators an actiongroup, without
messing up with UIManagers? (and if there isn't; isnt' it weird?)
- is there a way to get a popup from a UIManager, keep it constantly
realized but only show it when needed? I tried to just create it at
startup and then use "popup()" when needed, but it doesn't react well:
first time, it's all right, but for instance the other times it pops up
it doesn't disappear when "ESC" is pressed (it does when it is pressed
the second time)

thanks

Pietro



More information about the pygtk mailing list