From d250180d483f3f1fb9d4db0e8b7092693501ad45 Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Sun, 20 Dec 2020 22:30:08 -0500 Subject: [PATCH] layout_editor: update changes done in GUI --- src/main/python/keyboard_container.py | 7 +++++++ src/main/python/keyboard_widget.py | 1 - src/main/python/layout_editor.py | 27 +++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/python/keyboard_container.py b/src/main/python/keyboard_container.py index 2aa8d45..7464d81 100644 --- a/src/main/python/keyboard_container.py +++ b/src/main/python/keyboard_container.py @@ -39,6 +39,8 @@ class KeyboardContainer(QWidget): self.keyboard = None self.current_layer = 0 + layout_editor.changed.connect(self.refresh_layer_display) + def rebuild_layers(self): self.number_layers_changed.emit() @@ -69,6 +71,11 @@ class KeyboardContainer(QWidget): def refresh_layer_display(self): """ Refresh text on key widgets to display data corresponding to current layer """ + if self.keyboard is None: + return + + self.container.update_layout() + for label in self.layer_labels: label.setStyleSheet(LAYER_BTN_STYLE) self.layer_labels[self.current_layer].setStyleSheet(ACTIVE_LAYER_BTN_STYLE) diff --git a/src/main/python/keyboard_widget.py b/src/main/python/keyboard_widget.py index 830f5fb..b165c21 100644 --- a/src/main/python/keyboard_widget.py +++ b/src/main/python/keyboard_widget.py @@ -184,7 +184,6 @@ class KeyboardWidget(QWidget): self.widgets += self.common_widgets for idx in self.widgets_for_layout.keys(): option = self.layout_editor.get_choice(idx) - print("index {} option {}".format(idx, option)) self.widgets += self.widgets_for_layout[idx][option] # determine maximum width and height of container diff --git a/src/main/python/layout_editor.py b/src/main/python/layout_editor.py index d19ee97..e142b4b 100644 --- a/src/main/python/layout_editor.py +++ b/src/main/python/layout_editor.py @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-or-later +from PyQt5.QtCore import pyqtSignal from PyQt5.QtWidgets import QLabel, QCheckBox, QComboBox, QGridLayout from basic_editor import BasicEditor @@ -7,11 +8,13 @@ from vial_device import VialKeyboard class BooleanChoice: - def __init__(self, container, label): + def __init__(self, cb, container, label): + self.cb = cb self.choice = False self.widget_label = QLabel(label) self.widget_checkbox = QCheckBox() + self.widget_checkbox.stateChanged.connect(self.on_checkbox) row = container.rowCount() container.addWidget(self.widget_label, row, 0) @@ -31,16 +34,22 @@ class BooleanChoice: self.choice = bool(value) self.widget_checkbox.setChecked(self.choice) + def on_checkbox(self): + self.choice = self.widget_checkbox.isChecked() + self.cb() + class SelectChoice: - def __init__(self, container, label, options): + def __init__(self, cb, container, label, options): + self.cb = cb self.choice = 0 self.options = options self.widget_label = QLabel(label) self.widget_options = QComboBox() self.widget_options.addItems(options) + self.widget_options.currentIndexChanged.connect(self.on_selection) row = container.rowCount() container.addWidget(self.widget_label, row, 0) @@ -62,9 +71,15 @@ class SelectChoice: self.choice = value self.widget_options.setCurrentIndex(self.choice) + def on_selection(self): + self.choice = self.widget_options.currentIndex() + self.cb() + class LayoutEditor(BasicEditor): + changed = pyqtSignal() + def __init__(self, parent=None): super().__init__(parent) self.device = None @@ -88,9 +103,10 @@ class LayoutEditor(BasicEditor): for item in device.keyboard.layouts["labels"]: if isinstance(item, str): - self.choices.append(BooleanChoice(self.container, item)) + choice = BooleanChoice(self.on_changed, self.container, item) else: - self.choices.append(SelectChoice(self.container, item[0], item[1:])) + choice = SelectChoice(self.on_changed, self.container, item[0], item[1:]) + self.choices.append(choice) self.unpack(self.device.keyboard.layout_options) @@ -118,3 +134,6 @@ class LayoutEditor(BasicEditor): def set_choice(self, index, value): self.choices[index].change(value) + + def on_changed(self): + self.changed.emit()