From 840a95eeb21a597db7be1699623f9d84fa410012 Mon Sep 17 00:00:00 2001 From: dkmvs <67212386+dkmvs@users.noreply.github.com> Date: Tue, 29 Sep 2020 17:10:56 +0300 Subject: [PATCH 1/3] Use Empty String for Cleared Accels When a key binding is cleared its value is now set to "" (an empty string) instead of `None` as before. This change is introduced because `Gtk.accelerator_parse` does not allow `None` to be used as a value, which in turn breaks `on_cellrenderer_accel_edited` function in `terminatorlib/prefseditor.py` by raising a `TypeError` every time a new key binding is introduced. Note that this only happens if at least one key binding has been cleared first. --- terminatorlib/prefseditor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index a198fc5c..85b9f223 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -1745,7 +1745,7 @@ class PrefsEditor: liststore.set(celliter, 2, 0, 3, 0) binding = liststore.get_value(liststore.get_iter(path), 0) - self.config['keybindings'][binding] = None + self.config['keybindings'][binding] = "" self.config.save() def on_open_manual(self, widget): From 03d5e206950c4cc800a4782ea6f134cfe3fd51eb Mon Sep 17 00:00:00 2001 From: dkmvs <67212386+dkmvs@users.noreply.github.com> Date: Tue, 29 Sep 2020 22:05:54 +0300 Subject: [PATCH 2/3] Add Test for `Keybinding>Preferences` This commit adds `test_keybinding_successfully_reassigned_after_clearing` test, which checks that a key binding is successfully reassigned after it has been cleared. --- tests/test_prefseditor_keybindings.py | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/test_prefseditor_keybindings.py b/tests/test_prefseditor_keybindings.py index 4fa9db70..9d8ec02d 100644 --- a/tests/test_prefseditor_keybindings.py +++ b/tests/test_prefseditor_keybindings.py @@ -251,3 +251,50 @@ def test_keybinding_edit_produce_expected_accels( accel_after_edit = (keyval_after_edit, mods_after_edit) assert accel_after_edit == expected_accel + + +@pytest.mark.parametrize( + "accel_params", + [ + # Format: (path, key, mods, hardware_keycode) + # 1) 'broadcast_all' 1 + ("0", Gdk.KEY_1, Gdk.ModifierType(0), 10), + # 2) 'broadcast_group' Ctrl+Alt+Shift+Up + ("1", Gdk.KEY_Up, CONTROL_ALT_SHIFT_MOD, 111), + ], +) +def test_keybinding_successfully_reassigned_after_clearing(accel_params): + """ + Tests that a key binding is successfully reassigned after it has been cleared, + that is no error is thrown at any stage. + """ + from terminatorlib import terminal + from terminatorlib import prefseditor + + term = terminal.Terminal() + prefs_editor = prefseditor.PrefsEditor(term=term) + + widget = prefs_editor.builder.get_object("keybindingtreeview") + liststore = widget.get_model() + + path, key, mods, hardware_keycode = accel_params + # Assign a key binding + prefs_editor.on_cellrenderer_accel_edited( + liststore=liststore, + path=path, + key=key, + mods=mods, + _code=hardware_keycode, + ) + # Clear the key binding + prefs_editor.on_cellrenderer_accel_cleared(liststore=liststore, path=path) + # Reassign the key binding + prefs_editor.on_cellrenderer_accel_edited( + liststore=liststore, + path=path, + key=key, + mods=mods, + _code=hardware_keycode, + ) + + reset_config_keybindings() From ba5d155c36e59731b8322d60fcf223d73dceb11f Mon Sep 17 00:00:00 2001 From: dkmvs <67212386+dkmvs@users.noreply.github.com> Date: Wed, 30 Sep 2020 00:37:30 +0300 Subject: [PATCH 3/3] Reset Key Bindings to Default in Prefseditor Test This commit adds a function that resets key bindings to the default in `test_keybinding_edit_produce_expected_accels` test. Note that this function needs to run at the end of every test that modifies the key bindings as they are not automatically reset after the test has run. --- tests/test_prefseditor_keybindings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_prefseditor_keybindings.py b/tests/test_prefseditor_keybindings.py index 9d8ec02d..661d8f3e 100644 --- a/tests/test_prefseditor_keybindings.py +++ b/tests/test_prefseditor_keybindings.py @@ -252,6 +252,8 @@ def test_keybinding_edit_produce_expected_accels( assert accel_after_edit == expected_accel + reset_config_keybindings() + @pytest.mark.parametrize( "accel_params",