Fix isort and formatting
This commit is contained in:
parent
8cb2a8b485
commit
a622239b4a
@ -1,4 +1,5 @@
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from kmk.keys import Key
|
||||
from kmk.types import (
|
||||
KeySeqSleepMeta,
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union
|
||||
|
||||
from kmk.consts import KMK_RELEASE, UnicodeMode
|
||||
from kmk.hid import AbstractHID, BLEHID, USBHID, HIDModes
|
||||
from kmk.hid import BLEHID, USBHID, AbstractHID, HIDModes
|
||||
from kmk.keys import KC, Key, KeyAttrDict
|
||||
from kmk.kmktime import ticks_ms
|
||||
from kmk.matrix import MatrixScanner, intify_coordinate
|
||||
@ -160,7 +160,13 @@ class KMKKeyboard:
|
||||
|
||||
return self.process_key(kc_changed, is_pressed, int_coord, (row, col))
|
||||
|
||||
def process_key(self, key: Union[Key, TapDanceKeyMeta], is_pressed: int, coord_int: Optional[int] = None, coord_raw: Tuple[int, int] = None) -> KMKKeyboard:
|
||||
def process_key(
|
||||
self,
|
||||
key: Union[Key, TapDanceKeyMeta],
|
||||
is_pressed: int,
|
||||
coord_int: Optional[int] = None,
|
||||
coord_raw: Tuple[int, int] = None,
|
||||
) -> KMKKeyboard:
|
||||
if self._tapping and not isinstance(key.meta, TapDanceKeyMeta):
|
||||
self._process_tap_dance(key, is_pressed)
|
||||
else:
|
||||
@ -186,7 +192,9 @@ class KMKKeyboard:
|
||||
|
||||
return self
|
||||
|
||||
def _process_tap_dance(self, changed_key: Union[Key, TapDanceKeyMeta], is_pressed: int) -> KMKKeyboard:
|
||||
def _process_tap_dance(
|
||||
self, changed_key: Union[Key, TapDanceKeyMeta], is_pressed: int
|
||||
) -> KMKKeyboard:
|
||||
if is_pressed:
|
||||
if not isinstance(changed_key.meta, TapDanceKeyMeta):
|
||||
# If we get here, changed_key is not a TapDanceKey and thus
|
||||
@ -429,7 +437,12 @@ class KMKKeyboard:
|
||||
if self.debug_enabled:
|
||||
print('Failed to run post hid function in extension: ', err, ext)
|
||||
|
||||
def go(self, hid_type: int = HIDModes.USB, secondary_hid_type: Optional[int] = None, **kwargs: Dict[Any, Any]) -> None:
|
||||
def go(
|
||||
self,
|
||||
hid_type: int = HIDModes.USB,
|
||||
secondary_hid_type: Optional[int] = None,
|
||||
**kwargs: Dict[Any, Any]
|
||||
) -> None:
|
||||
self.hid_type = hid_type
|
||||
self.secondary_hid_type = secondary_hid_type
|
||||
|
||||
|
@ -181,7 +181,9 @@ class Encoder:
|
||||
class EncoderHandler(Module):
|
||||
|
||||
encoders: ClassVar[List[Encoder]] = []
|
||||
debug_enabled: ClassVar[bool] = False # not working as inttended, do not use for now
|
||||
debug_enabled: ClassVar[
|
||||
bool
|
||||
] = False # not working as inttended, do not use for now
|
||||
|
||||
def __init__(
|
||||
self, pad_a: List[Any], pad_b: List[Any], encoder_map: EncoderMap
|
||||
|
@ -87,20 +87,26 @@ class Layers(Module):
|
||||
def on_powersave_disable(self, keyboard: KMKKeyboard) -> None:
|
||||
return
|
||||
|
||||
def _df_pressed(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _df_pressed(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
'''
|
||||
Switches the default layer
|
||||
'''
|
||||
keyboard.active_layers[-1] = key.meta.layer
|
||||
|
||||
def _mo_pressed(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _mo_pressed(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
'''
|
||||
Momentarily activates layer, switches off when you let go
|
||||
'''
|
||||
keyboard.active_layers.insert(0, key.meta.layer)
|
||||
|
||||
@staticmethod
|
||||
def _mo_released(key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _mo_released(
|
||||
key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
# remove the first instance of the target layer
|
||||
# from the active list
|
||||
# under almost all normal use cases, this will
|
||||
@ -115,7 +121,9 @@ class Layers(Module):
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def _lm_pressed(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _lm_pressed(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
'''
|
||||
As MO(layer) but with mod active
|
||||
'''
|
||||
@ -124,7 +132,9 @@ class Layers(Module):
|
||||
keyboard.keys_pressed.add(key.meta.kc)
|
||||
self._mo_pressed(key, keyboard, *args, **kwargs)
|
||||
|
||||
def _lm_released(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _lm_released(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
'''
|
||||
As MO(layer) but with mod active
|
||||
'''
|
||||
@ -132,12 +142,16 @@ class Layers(Module):
|
||||
keyboard.keys_pressed.discard(key.meta.kc)
|
||||
self._mo_released(key, keyboard, *args, **kwargs)
|
||||
|
||||
def _lt_pressed(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _lt_pressed(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
# Sets the timer start and acts like MO otherwise
|
||||
self.start_time[LayerType.LT] = accurate_ticks()
|
||||
self._mo_pressed(key, keyboard, *args, **kwargs)
|
||||
|
||||
def _lt_released(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _lt_released(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
# On keyup, check timer, and press key if needed.
|
||||
if self.start_time[LayerType.LT] and (
|
||||
accurate_ticks_diff(
|
||||
@ -150,7 +164,9 @@ class Layers(Module):
|
||||
self._mo_released(key, keyboard, *args, **kwargs)
|
||||
self.start_time[LayerType.LT] = None
|
||||
|
||||
def _tg_pressed(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _tg_pressed(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
'''
|
||||
Toggles the layer (enables it if not active, and vise versa)
|
||||
'''
|
||||
@ -161,14 +177,18 @@ class Layers(Module):
|
||||
except ValueError:
|
||||
keyboard.active_layers.insert(0, key.meta.layer)
|
||||
|
||||
def _to_pressed(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _to_pressed(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
'''
|
||||
Activates layer and deactivates all other layers
|
||||
'''
|
||||
keyboard.active_layers.clear()
|
||||
keyboard.active_layers.insert(0, key.meta.layer)
|
||||
|
||||
def _tt_pressed(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _tt_pressed(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
'''
|
||||
Momentarily activates layer if held, toggles it if tapped repeatedly
|
||||
'''
|
||||
@ -184,7 +204,9 @@ class Layers(Module):
|
||||
return
|
||||
return
|
||||
|
||||
def _tt_released(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _tt_released(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
if self.start_time[LayerType.TT] is None or not accurate_ticks_diff(
|
||||
accurate_ticks(), self.start_time[LayerType.TT], keyboard.tap_time
|
||||
):
|
||||
|
@ -38,14 +38,18 @@ class ModTap(Module):
|
||||
def on_powersave_disable(self, keyboard: KMKKeyboard) -> None:
|
||||
return
|
||||
|
||||
def mt_pressed(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> KMKKeyboard:
|
||||
def mt_pressed(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> KMKKeyboard:
|
||||
'''Sets the timer start and acts like a modifier otherwise'''
|
||||
keyboard.keys_pressed.add(key.meta.mods)
|
||||
|
||||
self._mod_tap_timer = accurate_ticks()
|
||||
return keyboard
|
||||
|
||||
def mt_released(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> KMKKeyboard:
|
||||
def mt_released(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> KMKKeyboard:
|
||||
'''On keyup, check timer, and press key if needed.'''
|
||||
keyboard.keys_pressed.discard(key.meta.mods)
|
||||
if self._mod_tap_timer and (
|
||||
|
@ -1,4 +1,3 @@
|
||||
from kmk.kmk_keyboard import KMKKeyboard
|
||||
import board
|
||||
import digitalio
|
||||
|
||||
@ -6,6 +5,7 @@ from typing import Any, Dict, Optional
|
||||
|
||||
from kmk.handlers.stock import passthrough as handler_passthrough
|
||||
from kmk.keys import Key, make_key
|
||||
from kmk.kmk_keyboard import KMKKeyboard
|
||||
from kmk.kmktime import sleep_ms, ticks_diff, ticks_ms
|
||||
from kmk.modules import Module
|
||||
|
||||
@ -134,16 +134,22 @@ class Power(Module):
|
||||
# https://github.com/adafruit/circuitpython/pull/3513
|
||||
return True
|
||||
|
||||
def _ps_tog(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _ps_tog(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
if self.enable:
|
||||
keyboard._trigger_powersave_disable = True
|
||||
else:
|
||||
keyboard._trigger_powersave_enable = True
|
||||
|
||||
def _ps_enable(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _ps_enable(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
if not self.enable:
|
||||
keyboard._trigger_powersave_enable = True
|
||||
|
||||
def _ps_disable(self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any) -> None:
|
||||
def _ps_disable(
|
||||
self, key: Key, keyboard: KMKKeyboard, *args: Any, **kwargs: Any
|
||||
) -> None:
|
||||
if self.enable:
|
||||
keyboard._trigger_powersave_disable = True
|
||||
|
@ -23,7 +23,9 @@ class LayerKeyMeta:
|
||||
|
||||
|
||||
class ModTapKeyMeta:
|
||||
def __init__(self, kc: Optional[Key] = None, mods: Optional[List[Key]] = None) -> None:
|
||||
def __init__(
|
||||
self, kc: Optional[Key] = None, mods: Optional[List[Key]] = None
|
||||
) -> None:
|
||||
self.mods: Optional[List[Key]] = mods
|
||||
self.kc: Optional[Key] = kc
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user