From 40ead965c0eb864114cea6941c721fed29094757 Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Sat, 22 May 2021 11:54:49 -0400 Subject: [PATCH] disable KeyboardWidget to stop propagating events when not needed --- src/main/python/keyboard_widget.py | 14 +++++++++++++- src/main/python/keymap_editor.py | 1 + src/main/python/main_window.py | 3 ++- src/main/python/matrix_test.py | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/python/keyboard_widget.py b/src/main/python/keyboard_widget.py index 94968e6..b270e51 100644 --- a/src/main/python/keyboard_widget.py +++ b/src/main/python/keyboard_widget.py @@ -116,6 +116,14 @@ class KeyWidget: def setColor(self, color): self.color = color + def __repr__(self): + qualifiers = ["KeyboardWidget"] + if self.desc.row is not None: + qualifiers.append("matrix:{},{}".format(self.desc.row, self.desc.col)) + if self.desc.layout_index != -1: + qualifiers.append("layout:{},{}".format(self.desc.layout_index, self.desc.layout_option)) + return " ".join(qualifiers) + class EncoderWidget(KeyWidget): @@ -138,6 +146,9 @@ class EncoderWidget(KeyWidget): path.lineTo(int(self.x + self.w / 5), int(self.y + self.h - self.h / 3)) return path + def __repr__(self): + return "EncoderWidget" + class KeyboardWidget(QWidget): @@ -355,7 +366,8 @@ class KeyboardWidget(QWidget): self.update() def resizeEvent(self, ev): - self.update_layout() + if self.isEnabled(): + self.update_layout() def select_next(self): """ Selects next key based on their order in the keymap """ diff --git a/src/main/python/keymap_editor.py b/src/main/python/keymap_editor.py index 8ac1b09..7642ddc 100644 --- a/src/main/python/keymap_editor.py +++ b/src/main/python/keymap_editor.py @@ -99,6 +99,7 @@ class KeymapEditor(BasicEditor): recreate_keyboard_keycodes(self.keyboard) self.tabbed_keycodes.recreate_keycode_buttons() self.refresh_layer_display() + self.container.setEnabled(self.valid()) def valid(self): return isinstance(self.device, VialKeyboard) diff --git a/src/main/python/main_window.py b/src/main/python/main_window.py index cf3c4f7..334641a 100644 --- a/src/main/python/main_window.py +++ b/src/main/python/main_window.py @@ -237,7 +237,8 @@ class MainWindow(QMainWindow): Unlocker.unlock(self.current_device.keyboard) self.current_device.keyboard.reload() - for e in [self.layout_editor, self.keymap_editor, self.firmware_flasher, self.macro_recorder, self.matrix_tester]: + for e in [self.layout_editor, self.keymap_editor, self.firmware_flasher, self.macro_recorder, + self.matrix_tester]: e.rebuild(self.current_device) def refresh_tabs(self): diff --git a/src/main/python/matrix_test.py b/src/main/python/matrix_test.py index 6808542..b02bff1 100644 --- a/src/main/python/matrix_test.py +++ b/src/main/python/matrix_test.py @@ -48,6 +48,7 @@ class MatrixTest(BasicEditor): self.keyboard = device.keyboard self.keyboardWidget.set_keys(self.keyboard.keys, self.keyboard.encoders) + self.keyboardWidget.setEnabled(self.valid()) def valid(self): # Check if vial protocol is v3 or later