layout_editor: update changes done in GUI

main
Ilya Zhuravlev 2020-12-20 22:30:08 -05:00
parent 5af3798445
commit d250180d48
3 changed files with 30 additions and 5 deletions

View File

@ -39,6 +39,8 @@ class KeyboardContainer(QWidget):
self.keyboard = None self.keyboard = None
self.current_layer = 0 self.current_layer = 0
layout_editor.changed.connect(self.refresh_layer_display)
def rebuild_layers(self): def rebuild_layers(self):
self.number_layers_changed.emit() self.number_layers_changed.emit()
@ -69,6 +71,11 @@ class KeyboardContainer(QWidget):
def refresh_layer_display(self): def refresh_layer_display(self):
""" Refresh text on key widgets to display data corresponding to current layer """ """ 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: for label in self.layer_labels:
label.setStyleSheet(LAYER_BTN_STYLE) label.setStyleSheet(LAYER_BTN_STYLE)
self.layer_labels[self.current_layer].setStyleSheet(ACTIVE_LAYER_BTN_STYLE) self.layer_labels[self.current_layer].setStyleSheet(ACTIVE_LAYER_BTN_STYLE)

View File

@ -184,7 +184,6 @@ class KeyboardWidget(QWidget):
self.widgets += self.common_widgets self.widgets += self.common_widgets
for idx in self.widgets_for_layout.keys(): for idx in self.widgets_for_layout.keys():
option = self.layout_editor.get_choice(idx) option = self.layout_editor.get_choice(idx)
print("index {} option {}".format(idx, option))
self.widgets += self.widgets_for_layout[idx][option] self.widgets += self.widgets_for_layout[idx][option]
# determine maximum width and height of container # determine maximum width and height of container

View File

@ -1,4 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QLabel, QCheckBox, QComboBox, QGridLayout from PyQt5.QtWidgets import QLabel, QCheckBox, QComboBox, QGridLayout
from basic_editor import BasicEditor from basic_editor import BasicEditor
@ -7,11 +8,13 @@ from vial_device import VialKeyboard
class BooleanChoice: class BooleanChoice:
def __init__(self, container, label): def __init__(self, cb, container, label):
self.cb = cb
self.choice = False self.choice = False
self.widget_label = QLabel(label) self.widget_label = QLabel(label)
self.widget_checkbox = QCheckBox() self.widget_checkbox = QCheckBox()
self.widget_checkbox.stateChanged.connect(self.on_checkbox)
row = container.rowCount() row = container.rowCount()
container.addWidget(self.widget_label, row, 0) container.addWidget(self.widget_label, row, 0)
@ -31,16 +34,22 @@ class BooleanChoice:
self.choice = bool(value) self.choice = bool(value)
self.widget_checkbox.setChecked(self.choice) self.widget_checkbox.setChecked(self.choice)
def on_checkbox(self):
self.choice = self.widget_checkbox.isChecked()
self.cb()
class SelectChoice: class SelectChoice:
def __init__(self, container, label, options): def __init__(self, cb, container, label, options):
self.cb = cb
self.choice = 0 self.choice = 0
self.options = options self.options = options
self.widget_label = QLabel(label) self.widget_label = QLabel(label)
self.widget_options = QComboBox() self.widget_options = QComboBox()
self.widget_options.addItems(options) self.widget_options.addItems(options)
self.widget_options.currentIndexChanged.connect(self.on_selection)
row = container.rowCount() row = container.rowCount()
container.addWidget(self.widget_label, row, 0) container.addWidget(self.widget_label, row, 0)
@ -62,9 +71,15 @@ class SelectChoice:
self.choice = value self.choice = value
self.widget_options.setCurrentIndex(self.choice) self.widget_options.setCurrentIndex(self.choice)
def on_selection(self):
self.choice = self.widget_options.currentIndex()
self.cb()
class LayoutEditor(BasicEditor): class LayoutEditor(BasicEditor):
changed = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent) super().__init__(parent)
self.device = None self.device = None
@ -88,9 +103,10 @@ class LayoutEditor(BasicEditor):
for item in device.keyboard.layouts["labels"]: for item in device.keyboard.layouts["labels"]:
if isinstance(item, str): if isinstance(item, str):
self.choices.append(BooleanChoice(self.container, item)) choice = BooleanChoice(self.on_changed, self.container, item)
else: 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) self.unpack(self.device.keyboard.layout_options)
@ -118,3 +134,6 @@ class LayoutEditor(BasicEditor):
def set_choice(self, index, value): def set_choice(self, index, value):
self.choices[index].change(value) self.choices[index].change(value)
def on_changed(self):
self.changed.emit()