[SOLVED] Global accelerators using actions

Hi guys,

I have a bunch of actions with accelerators setup in my GtkApplication. I also have a dialog (a text editor) where I insert those actions from the app. The actions work if I use them in a button or a menu, but the accelerators don’t work. I can’t find anything in the docs about inserting accelerators.

Relevant code:

    def _set_actions(self):
        """Setup actions."""

        action_entries = [
            ('quit', lambda a, p: self.quit(), ('app.quit', ['<ctrl>Q'])),
            ('open_about', self.open_about, None),
            ('open_plugins', self.open_plugins_manager, None),
            ('new_task', self.new_task, ('app.new_task', ['<ctrl>N'])),
            ('new_subtask', self.new_subtask,
             ('app.new_subtask', ['<ctrl><shift>N'])),
            ('edit_task', self.edit_task, ('app.edit_task', ['<ctrl>E'])),
            ('mark_as_done', self.mark_as_done,
             ('app.mark_as_done', ['<ctrl>D'])),
            ('dismiss', self.dismiss, ('app.dismiss', ['<ctrl>I'])),
            ('open_backends', self.open_backends_manager, None),
            ('open_help', self.open_help, ('app.open_help', ['F1'])),
            ('open_preferences', self.open_preferences,
                ('app.open_preferences', ['<ctrl>P'])),
        ]

        for action, callback, accel in action_entries:
            simple_action = Gio.SimpleAction.new(action, None)
            simple_action.connect('activate', callback)
            simple_action.set_enabled(True)

            self.add_action(simple_action)

            if accel is not None:
                self.set_accels_for_action(*accel)
class TaskEditor():

    def __init__(self,  app):
        self.builder.add_from_file(self.EDITOR_UI_FILE)
        self.window = self.builder.get_object("TaskEditor")

        # ...
        self.window.insert_action_group('app', app)

Found out the issue: I had to set the application for the window.

        self.window.set_application(app)

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