25
25
gc .enable ()
26
26
supervisor .runtime .autoreload = False
27
27
28
- VERSION = "1.4.1 "
28
+ VERSION = "1.4.2 "
29
29
# The file in which the settings are saved
30
30
SETTINGSFILE = "settings.json"
31
31
# The file in which the macros are saved
@@ -173,7 +173,7 @@ def _init_group_label(self) -> None:
173
173
padding_bottom = 0 ,
174
174
padding_left = 0 ,
175
175
padding_right = 0 ,
176
- color = 0xFFFFFF ,
176
+ color = 0xffffff ,
177
177
anchored_position = (
178
178
self .macropad .display .width // 2 ,
179
179
self .macropad .display .height - 10 ),
@@ -196,7 +196,7 @@ def _init_keys(self) -> None:
196
196
padding_bottom = 1 ,
197
197
padding_left = 4 ,
198
198
padding_right = 4 ,
199
- color = 0xFFFFFF ,
199
+ color = 0xffffff ,
200
200
anchored_position = (
201
201
(self .macropad .display .width - 2 ) / 2 * (i % 3 ) + 1 ,
202
202
self .macropad .display .height / 5 * (i // 3 ) + 2 ),
@@ -235,16 +235,32 @@ def run_macro(self, item: tuple[str, list], *args) -> None:
235
235
if isinstance (key , (int , float )):
236
236
time .sleep (key )
237
237
elif isinstance (key , str ):
238
- self .macropad .keyboard_layout .write (key )
238
+ try :
239
+ self .macropad .keyboard_layout .write (key )
240
+ except ValueError :
241
+ # if any of the characters has no keycode
242
+ pass
239
243
elif isinstance (key , dict ):
240
244
if 'kc' in key :
241
- key_name = key ['kc' ][1 :] if key ['kc' ][:1 ] == "-" else key ['kc' ]
242
- key_code = getattr (Keycode , key_name .upper (), None )
243
- if key_code :
244
- if key ['kc' ][:1 ] != "-" :
245
- self .macropad .keyboard .press (key_code )
245
+ key_codes = [
246
+ getattr (Keycode , key_name , None )
247
+ for key_name in key ['kc' ].lstrip ('-+' ).upper ().split (',' )
248
+ if getattr (Keycode , key_name , None ) is not None
249
+ ]
250
+ if key_codes :
251
+ if key ['kc' ] == 'RELALL' :
252
+ # release all keys
253
+ self .macropad .keyboard .release_all ()
254
+ elif key ['kc' ][0 ] == '+' :
255
+ # tap keys
256
+ self .macropad .keyboard .press (* key_codes )
257
+ self .macropad .keyboard .release (* key_codes )
258
+ elif key ['kc' ][0 ] == '-' :
259
+ # release keys
260
+ self .macropad .keyboard .release (* key_codes )
246
261
else :
247
- self .macropad .keyboard .release (key_code )
262
+ # press keys
263
+ self .macropad .keyboard .press (* key_codes )
248
264
if 'ccc' in key :
249
265
control_code = getattr (
250
266
ConsumerControlCode , key ['ccc' ].upper (), None )
@@ -304,6 +320,11 @@ def go_to_root(self, *args) -> None:
304
320
def _update_tab (self ) -> None :
305
321
""" update the current displayed group tab
306
322
"""
323
+ key_funcs = {
324
+ "macro" : self .run_macro ,
325
+ "group" : self .open_group
326
+ }
327
+
307
328
for key in self .keys :
308
329
key .clear_props ()
309
330
@@ -313,33 +334,18 @@ def _update_tab(self) -> None:
313
334
if key_id :
314
335
macro_data = json .loads (self .macro_store [str (key_id )])
315
336
key_type = macro_data ["type" ]
316
-
317
- self .keys [i ].type = key_type
318
- self .keys [i ].label = "" if key_type == "blank" else macro_data ["label" ]
319
- self .keys [i ].color = (0 , 0 , 0 ) if key_type == "blank" else macro_data ["color" ]
320
- self .keys [i ].set_func (self ._get_key_func (key_type ), (str (key_id ), macro_data ["content" ]))
337
+
338
+ key = self .keys [i ]
339
+ key .type = key_type
340
+ key .label = macro_data ["label" ]
341
+ key .color = macro_data ["color" ]
342
+ key .set_func (key_funcs .get (key_type ), (str (key_id ), macro_data ["content" ]))
321
343
322
344
self .group_label .text = group ["label" ]
323
345
324
346
for key in self .keys :
325
347
key .update_colors ()
326
348
327
- def _get_key_func (self , type : str ) -> function :
328
- """ get the specific function for the type
329
-
330
- Args:
331
- type (str): the item type
332
-
333
- Returns:
334
- function: return the function for type
335
- """
336
- key_funcs = {
337
- "blank" : None ,
338
- "group" : self .open_group
339
- }
340
-
341
- return key_funcs .get (type , self .run_macro )
342
-
343
349
def _update_encoder_macros (self ) -> None :
344
350
""" update the rotary encoder macros defined for opened group
345
351
"""
@@ -429,7 +435,7 @@ def _handle_serial_data(self, payload: object) -> dict:
429
435
return
430
436
431
437
response ['ACK' ] = 'Macros received'
432
- response ['CONTENT' ] = len (self .macro_store )
438
+ response ['CONTENT' ] = len (self .macro_store ) - 1
433
439
return response
434
440
435
441
elif command == 'save_macros' :
@@ -545,14 +551,14 @@ def start(self) -> None:
545
551
if key_event .pressed and not any ([key .pressed for key in self .keys ]):
546
552
self .keys [key_event .key_number ].pressed = True
547
553
active_key = key_event .key_number
548
- self . active_key_delay = time .monotonic ()
554
+ active_key_delay = time .monotonic ()
549
555
550
556
elif key_event .released and key_event .key_number == active_key :
551
557
self .keys [key_event .key_number ].pressed = False
552
558
active_key = None
553
559
554
560
# if a key is pressed continuously, the function triggers again after a short delay
555
- if active_key and time .monotonic () - self . active_key_delay > 0.75 :
561
+ if active_key is not None and time .monotonic () - active_key_delay > 0.75 :
556
562
self ._display_on ()
557
563
self .keys [active_key ].call_func ()
558
564
0 commit comments