Hello,
I have successfully created a toolbar object in a window
with actions connected to each toolitem. I used UIManager
to accomplish this.
However, my accelerators do not work. I've looked at the
tutorials, read the documentations and all. And I still can't
figure out why it is not working.
Your help is appreciated. The code follows.
################################################################################
#
# Action Group and Actions for Toolbar
#
################################################################################
# Create an ActionGroup
actiongroup = gtk.ActionGroup("ToolbarActions")
self.actiongroup = actiongroup
# Actions
new_file_action = ("new_file", gtk.STOCK_NEW, None,
"<Control>N",
new_button_tip,
self.new_file_cb)
open_file_action = ("open_file", gtk.STOCK_OPEN, None,
"<Control>o",
open_button_tip,
self.open_file_cb)
saveas_file_action = ("saveas_file", gtk.STOCK_SAVE_AS, None,
"<Control><Shift>s",
save_button_tip,
self.saveas_file_cb)
print_file_action = ("print_file", gtk.STOCK_PRINT, None,
"<Control>p",
print_button_tip,
self.print_file_cb)
undo_edits_action = ("undo_edits", gtk.STOCK_UNDO, None,
"<Control>z",
undo_button_tip,
self.undo_edits_cb)
redo_edits_action = ("redo_edits", gtk.STOCK_REDO, None,
"<Control><Shift>z",
redo_button_tip,
self.redo_edits_cb)
goto_line_action = ("goto_line", gtk.STOCK_JUMP_TO, None,
"<Control>i",
goto_button_tip,
self.goto_line_cb)
search_text_action = ("search_text", gtk.STOCK_FIND, None,
"<Contro>f",
find_button_tip,
self.search_text_cb)
replace_text_action = ("replace_text",
gtk.STOCK_FIND_AND_REPLACE, None,
"<Contro>r",
replace_button_tip,
self.replace_text_cb)
preferences_action = ("preferences", gtk.STOCK_PREFERENCES,
None, None,
pref_button_tip,
self.preferences_cb)
help_action = ("help", gtk.STOCK_HELP, None, None,
help_button_tip,
self.help_cb)
# Action Entries.
entries = [new_file_action, open_file_action,
saveas_file_action,
print_file_action, undo_edits_action,
redo_edits_action,
goto_line_action, search_text_action,
replace_text_action,
preferences_action, help_action]
# Create Actions for actiongroup
actiongroup.add_actions(entries, user_data=None)
for actions in actiongroup.list_actions():
actions.connect_accelerator()
################################################################################
#
# UIManager: Toolbar and Toolbar Buttons
#
################################################################################
# Create a UIManager instance
uimanager = gtk.UIManager()
self.uimanager = uimanager
uimanager.connect("add-widget", self.uimanager_cb)
# Create Accelerators for the editor via the uimanager
accelgroup = uimanager.get_accel_group()
self.add_accel_group(accelgroup)
# Add the actiongroup to the uimanager
uimanager.insert_action_group(actiongroup, 0)
# Merge the User Interface
uifile = "/usr/share/scribes/scribes_toolbar_ui.xml"
merge_id = uimanager.add_ui_from_file(uifile)
# Create Toolbar
toolbar = uimanager.get_widget("/toolbar")
self.main_container.pack_start(toolbar, False, False, 0)
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/