layout_editor: send layout options to keyboard

main
Ilya Zhuravlev 2020-12-20 22:42:08 -05:00
parent d250180d48
commit 46b498057b
3 changed files with 14 additions and 8 deletions

View File

@ -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))

View File

@ -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())

View File

@ -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)