diff --git a/src/main/python/keyboard.py b/src/main/python/keyboard.py index 609d376..6a88587 100644 --- a/src/main/python/keyboard.py +++ b/src/main/python/keyboard.py @@ -39,7 +39,7 @@ class Keyboard: self.encoder_layout = dict() self.rows = self.cols = self.layers = 0 self.layouts = None - self.layout_options = 0 + self.layout_options = -1 self.keys = [] self.encoders = [] @@ -158,7 +158,7 @@ class Keyboard: self.encoder_layout[key] = code def set_layout_options(self, options): - if self.layout_options != options: + if self.layout_options != -1 and self.layout_options != options: self.layout_options = options self.usb_send(self.dev, struct.pack(">BBI", CMD_VIA_SET_KEYBOARD_VALUE, VIA_LAYOUT_OPTIONS, options)) diff --git a/src/main/python/keyboard_container.py b/src/main/python/keyboard_container.py index 7464d81..1ba188c 100644 --- a/src/main/python/keyboard_container.py +++ b/src/main/python/keyboard_container.py @@ -17,6 +17,8 @@ class KeyboardContainer(QWidget): def __init__(self, layout_editor): super().__init__() + self.layout_editor = layout_editor + self.layout_layers = QHBoxLayout() layer_label = QLabel(tr("KeyboardContainer", "Layer")) @@ -39,7 +41,7 @@ class KeyboardContainer(QWidget): self.keyboard = None self.current_layer = 0 - layout_editor.changed.connect(self.refresh_layer_display) + layout_editor.changed.connect(self.on_layout_changed) def rebuild_layers(self): self.number_layers_changed.emit() @@ -66,14 +68,11 @@ class KeyboardContainer(QWidget): self.container.set_keys(keyboard.keys, keyboard.encoders) self.current_layer = 0 - self.refresh_layer_display() + self.on_layout_changed() 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: @@ -150,3 +149,10 @@ class KeyboardContainer(QWidget): def restore_layout(self, data): self.keyboard.restore_layout(data) self.refresh_layer_display() + + def on_layout_changed(self): + if self.keyboard is None: + return + + self.refresh_layer_display() + self.keyboard.set_layout_options(self.layout_editor.pack()) diff --git a/src/main/python/layout_editor.py b/src/main/python/layout_editor.py index e142b4b..7d5a223 100644 --- a/src/main/python/layout_editor.py +++ b/src/main/python/layout_editor.py @@ -115,7 +115,7 @@ class LayoutEditor(BasicEditor): def pack(self): val = "" - for choice in self.choices[::-1]: + for choice in self.choices: val += choice.pack() return int(val, 2)