implement global debug interface.

This commit is contained in:
xs5871
2022-07-20 13:35:56 +00:00
committed by Kyle Brown
parent 3f826267b4
commit 3f3bd93109
4 changed files with 117 additions and 112 deletions

View File

@@ -4,8 +4,7 @@ import kmk.handlers.stock as handlers
from kmk.consts import UnicodeMode
from kmk.key_validators import key_seq_sleep_validator, unicode_mode_key_validator
from kmk.types import UnicodeModeKeyMeta
DEBUG_OUTPUT = False
from kmk.utils import Debug
FIRST_KMK_INTERNAL_KEY = const(1000)
NEXT_AVAILABLE_KEY = 1000
@@ -19,6 +18,8 @@ ALL_NUMBERS = '1234567890'
# since KC.1 isn't valid Python, alias to KC.N1
ALL_NUMBER_ALIASES = tuple(f'N{x}' for x in ALL_NUMBERS)
debug = Debug(__name__)
def maybe_make_key(code, names, *args, **kwargs):
def closure(candidate):
@@ -412,12 +413,11 @@ class KeyAttrDict:
maybe_key = func(key)
if maybe_key:
break
else:
raise ValueError(f'Invalid key: {key}')
if DEBUG_OUTPUT:
print(f'{key}: {maybe_key}')
if debug.enabled:
debug(f'{key}: {maybe_key}')
return self.__cache[key]