move validators and metas to their respective modules

This commit is contained in:
xs5871 2022-07-21 15:50:30 +00:00 committed by Kyle Brown
parent e0ca1124fb
commit 5a85c6cfb3
7 changed files with 58 additions and 64 deletions

View File

@ -1,35 +1,9 @@
from kmk.types import KeySeqSleepMeta, LayerKeyMeta, ModTapKeyMeta, UnicodeModeKeyMeta from kmk.types import KeySeqSleepMeta, UnicodeModeKeyMeta
def key_seq_sleep_validator(ms): def key_seq_sleep_validator(ms):
return KeySeqSleepMeta(ms) return KeySeqSleepMeta(ms)
def layer_key_validator(layer, kc=None):
'''
Validates the syntax (but not semantics) of a layer key call. We won't
have access to the keymap here, so we can't verify much of anything useful
here (like whether the target layer actually exists). The spirit of this
existing is mostly that Python will catch extraneous args/kwargs and error
out.
'''
return LayerKeyMeta(layer, kc)
def mod_tap_validator(
kc, mods=None, prefer_hold=True, tap_interrupted=False, tap_time=None
):
'''
Validates that mod tap keys are correctly used
'''
return ModTapKeyMeta(
kc=kc,
mods=mods,
prefer_hold=prefer_hold,
tap_interrupted=tap_interrupted,
tap_time=tap_time,
)
def unicode_mode_key_validator(mode): def unicode_mode_key_validator(mode):
return UnicodeModeKeyMeta(mode) return UnicodeModeKeyMeta(mode)

View File

@ -2,7 +2,6 @@ from micropython import const
from kmk.keys import make_argumented_key from kmk.keys import make_argumented_key
from kmk.modules import Module from kmk.modules import Module
from kmk.types import HoldTapKeyMeta
class ActivationType: class ActivationType:
@ -20,6 +19,22 @@ class HoldTapKeyState:
self.activated = ActivationType.PRESSED self.activated = ActivationType.PRESSED
class HoldTapKeyMeta:
def __init__(
self,
tap,
hold,
prefer_hold=True,
tap_interrupted=False,
tap_time=None,
):
self.tap = tap
self.hold = hold
self.prefer_hold = prefer_hold
self.tap_interrupted = tap_interrupted
self.tap_time = tap_time
class HoldTap(Module): class HoldTap(Module):
tap_time = 300 tap_time = 300

View File

@ -1,13 +1,22 @@
'''One layer isn't enough. Adds keys to get to more of them''' '''One layer isn't enough. Adds keys to get to more of them'''
from kmk.key_validators import layer_key_validator
from kmk.keys import KC, make_argumented_key from kmk.keys import KC, make_argumented_key
from kmk.modules.holdtap import ActivationType, HoldTap from kmk.modules.holdtap import ActivationType, HoldTap, HoldTapKeyMeta
from kmk.types import HoldTapKeyMeta
from kmk.utils import Debug from kmk.utils import Debug
debug = Debug(__name__) debug = Debug(__name__)
def layer_key_validator(layer, kc=None):
'''
Validates the syntax (but not semantics) of a layer key call. We won't
have access to the keymap here, so we can't verify much of anything useful
here (like whether the target layer actually exists). The spirit of this
existing is mostly that Python will catch extraneous args/kwargs and error
out.
'''
return LayerKeyMeta(layer, kc)
def layer_key_validator_lt(layer, kc, prefer_hold=False, **kwargs): def layer_key_validator_lt(layer, kc, prefer_hold=False, **kwargs):
return HoldTapKeyMeta(tap=kc, hold=KC.MO(layer), prefer_hold=prefer_hold, **kwargs) return HoldTapKeyMeta(tap=kc, hold=KC.MO(layer), prefer_hold=prefer_hold, **kwargs)
@ -18,6 +27,12 @@ def layer_key_validator_tt(layer, prefer_hold=True, **kwargs):
) )
class LayerKeyMeta:
def __init__(self, layer, kc=None):
self.layer = layer
self.kc = kc
class Layers(HoldTap): class Layers(HoldTap):
'''Gives access to the keys used to enable the layer system''' '''Gives access to the keys used to enable the layer system'''

View File

@ -1,7 +1,26 @@
import kmk.handlers.stock as handlers import kmk.handlers.stock as handlers
from kmk.key_validators import mod_tap_validator
from kmk.keys import make_argumented_key from kmk.keys import make_argumented_key
from kmk.modules.holdtap import HoldTap from kmk.modules.holdtap import HoldTap, HoldTapKeyMeta
def mod_tap_validator(
kc, mods=None, prefer_hold=True, tap_interrupted=False, tap_time=None
):
'''
Validates that mod tap keys are correctly used
'''
return ModTapKeyMeta(
kc=kc,
mods=mods,
prefer_hold=prefer_hold,
tap_interrupted=tap_interrupted,
tap_time=tap_time,
)
class ModTapKeyMeta(HoldTapKeyMeta):
def __init__(self, kc=None, mods=None, **kwargs):
super().__init__(tap=kc, hold=mods, **kwargs)
class ModTap(HoldTap): class ModTap(HoldTap):

View File

@ -1,6 +1,5 @@
from kmk.keys import make_argumented_key from kmk.keys import make_argumented_key
from kmk.modules.holdtap import ActivationType, HoldTap from kmk.modules.holdtap import ActivationType, HoldTap, HoldTapKeyMeta
from kmk.types import HoldTapKeyMeta
def oneshot_validator(kc, tap_time=None): def oneshot_validator(kc, tap_time=None):

View File

@ -1,6 +1,5 @@
from kmk.keys import KC, make_argumented_key from kmk.keys import KC, make_argumented_key
from kmk.modules.holdtap import ActivationType, HoldTap from kmk.modules.holdtap import ActivationType, HoldTap, HoldTapKeyMeta
from kmk.types import HoldTapKeyMeta
class TapDanceKeyMeta: class TapDanceKeyMeta:

View File

@ -11,33 +11,6 @@ class AttrDict(dict):
return self[key] return self[key]
class HoldTapKeyMeta:
def __init__(
self,
tap,
hold,
prefer_hold=True,
tap_interrupted=False,
tap_time=None,
):
self.tap = tap
self.hold = hold
self.prefer_hold = prefer_hold
self.tap_interrupted = tap_interrupted
self.tap_time = tap_time
class LayerKeyMeta:
def __init__(self, layer, kc=None):
self.layer = layer
self.kc = kc
class ModTapKeyMeta(HoldTapKeyMeta):
def __init__(self, kc=None, mods=None, **kwargs):
super().__init__(tap=kc, hold=mods, **kwargs)
class KeySequenceMeta: class KeySequenceMeta:
def __init__(self, seq): def __init__(self, seq):
self.seq = seq self.seq = seq