From b61638fa28786ea6f17dd00ab54fba11426d6bb1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 29 Aug 2011 13:02:38 -0600 Subject: [PATCH] Add replace_action() to keyboard manager --- src/calibre/gui2/actions/__init__.py | 6 ++++++ src/calibre/gui2/keyboard.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/calibre/gui2/actions/__init__.py b/src/calibre/gui2/actions/__init__.py index 9498d8ad9d..c9643d2f3d 100644 --- a/src/calibre/gui2/actions/__init__.py +++ b/src/calibre/gui2/actions/__init__.py @@ -198,6 +198,10 @@ class InterfaceAction(QObject): :param shortcut_name: The test displayed to the user when customizing the keyboard shortcuts for this action. By default it is set to the value of ``text``. + + :return: The created Qation, This action has one extra attribute + calibre_shortcut_unique_name which if not None refers to the unique + name under which this action is registered with the keyboard manager. ''' if shortcut_name is None: shortcut_name = unicode(text) @@ -216,10 +220,12 @@ class InterfaceAction(QObject): ac.setStatusTip(description) ac.setWhatsThis(description) + ac.calibre_shortcut_unique_name = None if shortcut is not False: self.gui.keyboard.register_shortcut(unique_name, shortcut_name, default_keys=keys, action=ac, description=description, group=self.action_spec[0]) + ac.calibre_shortcut_unique_name = unique_name if triggered is not None: ac.triggered.connect(triggered) return ac diff --git a/src/calibre/gui2/keyboard.py b/src/calibre/gui2/keyboard.py index 889e472d06..49ce08fe2c 100644 --- a/src/calibre/gui2/keyboard.py +++ b/src/calibre/gui2/keyboard.py @@ -117,6 +117,13 @@ class Manager(QObject): # {{{ #import pprint #pprint.pprint(self.keys_map) + def replace_action(self, unique_name, new_action): + sc = self.shortcuts[unique_name] + ac = sc['action'] + if ac is not None: + new_action.setShortcuts(ac.shortcuts()) + ac.setShortcuts([]) + # }}} # Model {{{