diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2025-04-30 08:44:23 +0200 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2025-04-30 08:44:23 +0200 |
commit | 1ca99c295ca33d759292271a11ebcd6ea908d627 (patch) | |
tree | 5c56975aede23603a93eb5ab975158db8b173f69 | |
parent | 109c4395a86c72fb34f820c633a1679590dc8fdb (diff) |
Update the screen when the pad is disconnectedmain
-rw-r--r-- | json_layer.py | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/json_layer.py b/json_layer.py index 4d4c69c..91699b5 100644 --- a/json_layer.py +++ b/json_layer.py @@ -88,12 +88,24 @@ class Layer(object): """ Layer as an object. This class gives the property name in addition of the keymap list """ + def __init__(self, jdata): - self.load(jdata) + json_data = json.loads(jdata.strip()) + self.load(json_data) def load(self, json_data): - jdata = json.loads(json_data.strip()) - for name, keys in jdata.items(): + """ Load the json dictionnary into the layer. The dictionnary shall be + either + - a string: The key named will be sent: "A" + - a list: All the keys will be chained in a single stroke: + ["^", "A"] + - a dictionnary: Used to create custom sequences: + {"seq": ["/", "W", "C", "ENTER"]} + - null: The key will do nothing. + + The dictionnary must be one of the operators declared above. + """ + for name, keys in json_data.items(): self.name = name self.keys = list(map(key_of_json, keys)) @@ -131,6 +143,10 @@ class JsonLayer(Module): if not data: return + if not data.connected: + keyboard.keymap[0].name = "Disconnected" + return + # Nothing to parse. if data.in_waiting <= 0: return @@ -139,7 +155,8 @@ class JsonLayer(Module): return try: - keyboard.keymap[0].load(line.decode()) + jdata = json.loads(line.decode().strip()) + keyboard.keymap[0].load(jdata) except Exception as err: print(err) |