diff --git a/src/main/python/keyboard_comm.py b/src/main/python/keyboard_comm.py index 5186dd8..5420e9f 100644 --- a/src/main/python/keyboard_comm.py +++ b/src/main/python/keyboard_comm.py @@ -400,12 +400,17 @@ class Keyboard: self.supported_settings.add(qsid) for qsid in self.supported_settings: + from qmk_settings import QmkSettings + width = QmkSettings.setting_width(qsid) + if width is None: + continue + data = self.usb_send(self.dev, struct.pack(" 0: self.tabs_widget.removeTab(0) - with open(self.appctx.get_resource("qmk_settings.json"), "r") as inf: - settings = json.load(inf) - # create new GUI - for tab in settings["tabs"]: + for tab in self.settings_defs["tabs"]: # don't bother creating tabs that would be empty - i.e. at least one qsid in a tab should be supported use_tab = False for field in tab["fields"]: @@ -163,6 +156,7 @@ class QmkSettings(BasicEditor): self.tabs.append(self.populate_tab(tab, container)) def reload_settings(self): + self.keyboard.reload_settings() self.recreate_gui() for tab in self.tabs: @@ -201,3 +195,22 @@ class QmkSettings(BasicEditor): return isinstance(self.device, VialKeyboard) and \ (self.device.keyboard and self.device.keyboard.vial_protocol >= 4 and len(self.device.keyboard.supported_settings)) + + @classmethod + def initialize(cls, appctx): + cls.settings_widths = dict() + with open(appctx.get_resource("qmk_settings.json"), "r") as inf: + cls.settings_defs = json.load(inf) + for tab in cls.settings_defs["tabs"]: + for field in tab["fields"]: + if field["type"] == "boolean": + width = 1 + elif field["type"] == "integer": + width = field["width"] + else: + raise RuntimeError("unsupported field type: {}".format(field)) + cls.settings_widths[field["qsid"]] = width + + @classmethod + def setting_width(cls, qsid): + return cls.settings_widths.get(qsid)