From 9b85832f285df1a9c60e5b9b291fe4b9ea6d88b9 Mon Sep 17 00:00:00 2001 From: ione Date: Fri, 26 Feb 2021 12:31:02 +0200 Subject: [PATCH 1/3] Fixed key binding reset key Fixed issue #131 The reset key binding to default values key would remove all bindings insted of setting them to the default values. This commit fixes that by reloading the default vals. --- mcomix/mcomix/keybindings.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mcomix/mcomix/keybindings.py b/mcomix/mcomix/keybindings.py index b06f89c9..fa07ce1a 100644 --- a/mcomix/mcomix/keybindings.py +++ b/mcomix/mcomix/keybindings.py @@ -135,6 +135,19 @@ def clear_all(self): self._action_to_callback = {} self._action_to_bindings = defaultdict(list) self._binding_to_action = {} + + stored_action_bindings = keybindings_map.DEFAULT_BINDINGS.copy() + + for action in keybindings_map.BINDING_INFO.keys(): + if action in stored_action_bindings: + bindings = [ + Gtk.accelerator_parse(keyname) + for keyname in stored_action_bindings[action] ] + self._action_to_bindings[action] = bindings + for binding in bindings: + self._binding_to_action[binding] = action + else: + self._action_to_bindings[action] = [] def execute(self, keybinding): ''' Executes an action that has been registered for the From 481ec724b4a50c57b4412f128cea84a9847c6b37 Mon Sep 17 00:00:00 2001 From: multiSnow Liu <2306079+multiSnow@users.noreply.github.com> Date: Fri, 26 Feb 2021 20:05:29 +0800 Subject: [PATCH 2/3] remove tailing space --- mcomix/mcomix/keybindings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcomix/mcomix/keybindings.py b/mcomix/mcomix/keybindings.py index fa07ce1a..bae428fb 100644 --- a/mcomix/mcomix/keybindings.py +++ b/mcomix/mcomix/keybindings.py @@ -135,7 +135,7 @@ def clear_all(self): self._action_to_callback = {} self._action_to_bindings = defaultdict(list) self._binding_to_action = {} - + stored_action_bindings = keybindings_map.DEFAULT_BINDINGS.copy() for action in keybindings_map.BINDING_INFO.keys(): From e48dafec5c05c4369297d9f67e76660b33585169 Mon Sep 17 00:00:00 2001 From: multiSnow Liu <2306079+multiSnow@users.noreply.github.com> Date: Fri, 26 Feb 2021 20:08:05 +0800 Subject: [PATCH 3/3] 'clear_all' is misleading --- mcomix/mcomix/keybindings.py | 4 ++-- mcomix/mcomix/preferences_dialog.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mcomix/mcomix/keybindings.py b/mcomix/mcomix/keybindings.py index bae428fb..02c586f4 100644 --- a/mcomix/mcomix/keybindings.py +++ b/mcomix/mcomix/keybindings.py @@ -129,8 +129,8 @@ def clear_accel(self, name, binding): self.save() - def clear_all(self): - ''' Removes all keybindings. The changes are only persisted if + def reset_keybindings(self): + ''' Reset all keybindings. The changes are only persisted if save() is called afterwards. ''' self._action_to_callback = {} self._action_to_bindings = defaultdict(list) diff --git a/mcomix/mcomix/preferences_dialog.py b/mcomix/mcomix/preferences_dialog.py index 467c09ab..e50dcf6e 100644 --- a/mcomix/mcomix/preferences_dialog.py +++ b/mcomix/mcomix/preferences_dialog.py @@ -445,7 +445,7 @@ def _response(self, dialog, response): if self.notebook.get_nth_page(self.notebook.get_current_page()) == self.shortcuts: # "Shortcuts" page is active, reset all keys to their default value km = keybindings.keybinding_manager(self._window) - km.clear_all() + km.reset_keybindings() self._window._event_handler.register_key_events() km.save() self.shortcuts.refresh_model()