aboutsummaryrefslogtreecommitdiff
path: root/json_layer.py
diff options
context:
space:
mode:
Diffstat (limited to 'json_layer.py')
-rw-r--r--json_layer.py25
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)