qmk_settings: take care of setting width when caching
parent
587489db7d
commit
adcb9116c0
|
|
@ -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("<BBH", CMD_VIA_VIAL_PREFIX, CMD_VIAL_QMK_SETTINGS_GET, qsid),
|
||||
retries=20)
|
||||
if data[0] != 0:
|
||||
self.settings[qsid] = b""
|
||||
self.settings[qsid] = None
|
||||
else:
|
||||
self.settings[qsid] = data[1:]
|
||||
self.settings[qsid] = data[1:1+width]
|
||||
|
||||
def reload_dynamic(self):
|
||||
if self.vial_protocol < 4:
|
||||
|
|
@ -714,9 +719,6 @@ class Keyboard:
|
|||
macros = macros[:self.macro_count]
|
||||
return [self.macro_deserialize(x) for x in macros]
|
||||
|
||||
def qmk_settings_get(self, qsid):
|
||||
return self.settings[qsid]
|
||||
|
||||
def qmk_settings_set(self, qsid, value):
|
||||
self.settings[qsid] = value
|
||||
data = self.usb_send(self.dev, struct.pack("<BBH", CMD_VIA_VIAL_PREFIX, CMD_VIAL_QMK_SETTINGS_SET, qsid) + value,
|
||||
|
|
|
|||
|
|
@ -63,7 +63,8 @@ class MainWindow(QMainWindow):
|
|||
self.macro_recorder = MacroRecorder()
|
||||
self.tap_dance = TapDance()
|
||||
self.combos = Combos()
|
||||
self.qmk_settings = QmkSettings(self.appctx)
|
||||
QmkSettings.initialize(appctx)
|
||||
self.qmk_settings = QmkSettings()
|
||||
self.matrix_tester = MatrixTest(self.layout_editor)
|
||||
self.rgb_configurator = RGBConfigurator()
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,7 @@ class GenericOption:
|
|||
self.container.addWidget(self.lbl, self.row, 0)
|
||||
|
||||
def reload(self, keyboard):
|
||||
data = keyboard.qmk_settings_get(self.qsid)
|
||||
if not data:
|
||||
raise RuntimeError("failed to retrieve setting {} from keyboard".format(self.option))
|
||||
return data
|
||||
return keyboard.settings.get(self.qsid)
|
||||
|
||||
def delete(self):
|
||||
self.lbl.hide()
|
||||
|
|
@ -86,9 +83,8 @@ class IntegerOption(GenericOption):
|
|||
|
||||
class QmkSettings(BasicEditor):
|
||||
|
||||
def __init__(self, appctx):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.appctx = appctx
|
||||
self.keyboard = None
|
||||
|
||||
self.tabs_widget = QTabWidget()
|
||||
|
|
@ -135,11 +131,8 @@ class QmkSettings(BasicEditor):
|
|||
while self.tabs_widget.count() > 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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue