[pygtk] Accel map and labels
John Finlay
finlay at moeraki.com
Mon Apr 3 10:50:30 WST 2006
Sebastian Pölsterl wrote:
> John Finlay wrote:
>
>> Sebastian Pölsterl wrote:
>>
>>> Hi!
>>>
>>> Currently, I'm trying to connect accelerators to MenuItems of a MenuBar.
>>> Therefore, I use the gtk.accel_map_add_entry function, connect the accel
>>> paths to a AccelGroup and finally I set the MenuItems' correct accel
>>> paths.
>>>
>>> The accelerators themselves work, but the labels don't get displayed.
>>>
>>> Whereas, if I use the add_acclerator method for each MenuItem it works,
>>> but with that solution the accelerators will be static and cannot be
>>> changed.
>>>
>>> Example code that doesn't display labels:
>>> gtk.accel_map_add_entry('<Videodb-menubar>/File/New', ord('n'),
>>> gtk.gdk.CONTROL_MASK)
>>> gtk.accel_map_add_entry('<Videodb-menubar>/File/Quit', ord('q'),
>>> gtk.gdk.CONTROL_MASK)
>>> gtk.accel_map_add_entry('<Videodb-menubar>/Edit/Edit', ord('e'),
>>> gtk.gdk.CONTROL_MASK)
>>>
>>> accelgroup.connect_by_path('<Videodb-menubar>/File/New',
>>> self.on_new_activate)
>>> accelgroup.connect_by_path('<Videodb-menubar>/File/Quit',
>>> gtk.main_quit)
>>> accelgroup.connect_by_path('<Videodb-menubar>/Edit/Edit',
>>> self.on_edit_activate)
>>>
>>> self.view['new'].set_accel_path('<Videodb-menubar>/File/New')
>>> self.view['quit'].set_accel_path('<Videodb-menubar>/File/Quit')
>>> self.view['edit'].set_accel_path('<Videodb-menubar>/Edit/Edit')
>>>
>>> Example code that does display labels:
>>> self.view['new'].add_accelerator("activate", accelgroup, ord('n'),
>>> gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
>>> self.view['quit'].add_accelerator("activate", accelgroup, ord('q'),
>>> gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
>>> self.view['edit'].add_accelerator("activate", accelgroup, ord('e'),
>>> gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
>>>
>>> I appreciate any help!
>>>
>>>
>>>
>> Did you call gtk.Menu.set_accel_group() for your menu?
>>
>> John
>>
>>
>>
> gtk.Menu is a popup menu, but I'm using gtk.MenuBar that doesn't have
> set_accel_group
>
>
My understanding is that a MenuBar is used to contain MenuItems with
associated popup menus not MenuItems alone. Perhaps you should think
about using a Toolbar instead. Otherwise associate Menus with the
MenuBar MenuItems.
John
More information about the pygtk
mailing list