Run black against source tree

This commit is contained in:
Josh Klar 2019-07-24 22:57:11 -07:00
parent 5c0c13e8d0
commit aaeaa74a0c
No known key found for this signature in database
GPG Key ID: A4A0C7B4E8EEE222
19 changed files with 126 additions and 166 deletions

View File

@ -7,14 +7,7 @@ from kmk.util import intify_coordinate as ic
# board, by flipping various row3 (bottom physical row) keys so their
# coord_mapping matches what the user pressed (even if the wiring
# underneath is sending different coordinates)
_r3_swap_conversions = {
3: 9,
4: 10,
5: 11,
9: 3,
10: 4,
11: 5,
}
_r3_swap_conversions = {3: 9, 4: 10, 5: 11, 9: 3, 10: 4, 11: 5}
def r3_swap(col):

View File

@ -114,7 +114,9 @@ def tt_pressed(key, state, *args, **kwargs):
def tt_released(key, state, *args, **kwargs):
tap_timed_out = ticks_diff(ticks_ms(), state.start_time['tt']) >= state.config.tap_time
tap_timed_out = (
ticks_diff(ticks_ms(), state.start_time['tt']) >= state.config.tap_time
)
if state.start_time['tt'] is None or tap_timed_out:
# On first press, works like MO. On second press, does nothing unless let up within
# time window, then acts like TG.

View File

@ -64,10 +64,7 @@ def unicode_string_sequence(unistring):
Allows sending things like (°° directly, without
manual conversion to Unicode codepoints.
'''
return unicode_codepoint_sequence([
hex(get_wide_ordinal(s))[2:]
for s in unistring
])
return unicode_codepoint_sequence([hex(get_wide_ordinal(s))[2:] for s in unistring])
def generate_codepoint_keysym_seq(codepoint, expected_length=4):
@ -95,31 +92,22 @@ def generate_leader_dictionary_seq(string):
def unicode_codepoint_sequence(codepoints):
kc_seqs = (
generate_codepoint_keysym_seq(codepoint)
for codepoint in codepoints
)
kc_seqs = (generate_codepoint_keysym_seq(codepoint) for codepoint in codepoints)
kc_macros = [
simple_key_sequence(kc_seq)
for kc_seq in kc_seqs
]
kc_macros = [simple_key_sequence(kc_seq) for kc_seq in kc_seqs]
def _unicode_sequence(key, state, *args, **kwargs):
if state.config.unicode_mode == UnicodeMode.IBUS:
state.process_key(
simple_key_sequence(_ibus_unicode_sequence(kc_macros, state)),
True,
simple_key_sequence(_ibus_unicode_sequence(kc_macros, state)), True
)
elif state.config.unicode_mode == UnicodeMode.RALT:
state.process_key(
simple_key_sequence(_ralt_unicode_sequence(kc_macros, state)),
True,
simple_key_sequence(_ralt_unicode_sequence(kc_macros, state)), True
)
elif state.config.unicode_mode == UnicodeMode.WINC:
state.process_key(
simple_key_sequence(_winc_unicode_sequence(kc_macros, state)),
True,
simple_key_sequence(_winc_unicode_sequence(kc_macros, state)), True
)
return make_key(on_press=_unicode_sequence)

View File

@ -22,10 +22,7 @@ class USB_HID:
self.post_init()
def __repr__(self):
return '{}(REPORT_BYTES={})'.format(
self.__class__.__name__,
self.REPORT_BYTES,
)
return '{}(REPORT_BYTES={})'.format(self.__class__.__name__, self.REPORT_BYTES)
def post_init(self):
pass
@ -157,10 +154,12 @@ class USB_HID:
try:
import usb_hid
PLATFORM_CIRCUITPYTHON = True
except ImportError:
PLATFORM_CIRCUITPYTHON = False
else:
class CircuitPythonUSB_HID(USB_HID):
REPORT_BYTES = 9
@ -192,5 +191,5 @@ else:
reporting_device_const = self.report_device[0]
return self.devices[reporting_device_const].send_report(
evt[1:HID_REPORT_SIZES[reporting_device_const] + 1],
evt[1 : HID_REPORT_SIZES[reporting_device_const] + 1]
)

View File

@ -18,13 +18,7 @@ class InternalState:
# overhead (the underlying list was never used anyway)
active_layers = [0]
start_time = {
'lt': None,
'tg': None,
'tt': None,
'lm': None,
'leader': None,
}
start_time = {'lt': None, 'tg': None, 'tt': None, 'lm': None, 'leader': None}
timeouts = {}
tapping = False
tap_dance_counts = {}
@ -72,11 +66,7 @@ class InternalState:
except ValueError:
if self.config.debug_enabled:
print(
'CoordMappingNotFound(ic={}, row={}, col={})'.format(
ic,
row,
col,
),
'CoordMappingNotFound(ic={}, row={}, col={})'.format(ic, row, col)
)
return None
@ -128,11 +118,7 @@ class InternalState:
def matrix_changed(self, row, col, is_pressed):
if self.config.debug_enabled:
print('MatrixChange(col={} row={} pressed={})'.format(
col,
row,
is_pressed,
))
print('MatrixChange(col={} row={} pressed={})'.format(col, row, is_pressed))
int_coord = intify_coordinate(row, col)
kc_changed = self._find_key_in_map(row, col)
@ -189,10 +175,13 @@ class InternalState:
return self
if (
changed_key not in self.tap_dance_counts or not self.tap_dance_counts[changed_key]
changed_key not in self.tap_dance_counts
or not self.tap_dance_counts[changed_key]
):
self.tap_dance_counts[changed_key] = 1
self.set_timeout(self.config.tap_time, lambda: self._end_tap_dance(changed_key))
self.set_timeout(
self.config.tap_time, lambda: self._end_tap_dance(changed_key)
)
self.tapping = True
else:
self.tap_dance_counts[changed_key] += 1
@ -201,7 +190,9 @@ class InternalState:
self.tap_side_effects[changed_key] = None
else:
has_side_effects = self.tap_side_effects[changed_key] is not None
hit_max_defined_taps = self.tap_dance_counts[changed_key] == len(changed_key.codes)
hit_max_defined_taps = self.tap_dance_counts[changed_key] == len(
changed_key.codes
)
if has_side_effects or hit_max_defined_taps:
self._end_tap_dance(changed_key)
@ -241,7 +232,9 @@ class InternalState:
self.config.leader_mode += 1
if self.config.leader_mode == LeaderMode.TIMEOUT_ACTIVE:
self.set_timeout(self.config.leader_timeout, self._handle_leader_sequence)
self.set_timeout(
self.config.leader_timeout, self._handle_leader_sequence
)
return self
@ -256,8 +249,7 @@ class InternalState:
self.process_key(self.config.leader_dictionary[lmh], True)
self.set_timeout(
False,
lambda: self.remove_key(self.config.leader_dictionary[lmh]),
False, lambda: self.remove_key(self.config.leader_dictionary[lmh])
)
return self
@ -273,9 +265,7 @@ class InternalState:
self.leader_last_len = len(self.keys_pressed)
for key in keys_pressed:
if (
self.config.leader_mode == LeaderMode.ENTER_ACTIVE and key == KC.ENT
):
if self.config.leader_mode == LeaderMode.ENTER_ACTIVE and key == KC.ENT:
self._handle_leader_sequence()
break
elif key == KC.ESC or key == KC.GESC:

View File

@ -1,5 +1,10 @@
from kmk.types import (KeySeqSleepMeta, LayerKeyMeta, ModTapKeyMeta,
TapDanceKeyMeta, UnicodeModeKeyMeta)
from kmk.types import (
KeySeqSleepMeta,
LayerKeyMeta,
ModTapKeyMeta,
TapDanceKeyMeta,
UnicodeModeKeyMeta,
)
def key_seq_sleep_validator(ms):

View File

@ -156,12 +156,11 @@ class KeyboardConfig:
print(self)
print(self._state)
print('GCStats(pre_alloc={} pre_free={} alloc={} free={})'.format(
pre_alloc,
pre_free,
gc.mem_alloc(),
gc.mem_free(),
))
print(
'GCStats(pre_alloc={} pre_free={} alloc={} free={})'.format(
pre_alloc, pre_free, gc.mem_alloc(), gc.mem_free()
)
)
def _send_hid(self):
self._hid_helper_inst.create_report(self._state.keys_pressed).send()
@ -183,11 +182,7 @@ class KeyboardConfig:
'''
if update is not None:
self._state.matrix_changed(
update[0],
update[1],
update[2],
)
self._state.matrix_changed(update[0], update[1], update[2])
def _send_to_master(self, update):
if self.split_master_left:
@ -202,6 +197,7 @@ class KeyboardConfig:
if self.uart.in_waiting >= 60:
# This is a dirty hack to prevent crashes in unrealistic cases
import microcontroller
microcontroller.reset()
while self.uart.in_waiting >= 3:

View File

@ -4,9 +4,13 @@ import kmk.handlers.layers as layers
import kmk.handlers.modtap as modtap
import kmk.handlers.stock as handlers
from kmk.consts import UnicodeMode
from kmk.key_validators import (key_seq_sleep_validator, layer_key_validator,
mod_tap_validator, tap_dance_key_validator,
unicode_mode_key_validator)
from kmk.key_validators import (
key_seq_sleep_validator,
layer_key_validator,
mod_tap_validator,
tap_dance_key_validator,
unicode_mode_key_validator,
)
from kmk.types import AttrDict, UnicodeModeKeyMeta
FIRST_KMK_INTERNAL_KEY = 1000
@ -231,16 +235,14 @@ class ModifierKey(Key):
if modified_code.has_modifiers:
new_keycode.has_modifiers |= modified_code.has_modifiers
else:
new_keycode = Key(
self.code,
no_press=no_press,
no_release=no_release,
)
new_keycode = Key(self.code, no_press=no_press, no_release=no_release)
return new_keycode
def __repr__(self):
return 'ModifierKey(code={}, has_modifiers={})'.format(self.code, self.has_modifiers)
return 'ModifierKey(code={}, has_modifiers={})'.format(
self.code, self.has_modifiers
)
class ConsumerKey(Key):
@ -268,12 +270,7 @@ def register_key_names(key, names=tuple()): # NOQA
return key
def make_key(
code=None,
names=tuple(), # NOQA
type=KEY_SIMPLE,
**kwargs,
):
def make_key(code=None, names=tuple(), type=KEY_SIMPLE, **kwargs): # NOQA
'''
Create a new key, aliased by `names` in the KC lookup table.
@ -348,10 +345,7 @@ def make_argumented_key(
if meta:
key = Key(
NEXT_AVAILABLE_KEY,
meta=meta,
*constructor_args,
**constructor_kwargs,
NEXT_AVAILABLE_KEY, meta=meta, *constructor_args, **constructor_kwargs
)
NEXT_AVAILABLE_KEY += 1
@ -362,7 +356,7 @@ def make_argumented_key(
raise ValueError(
'Argumented key validator failed for unknown reasons. '
"This may not be the keymap's fault, as a more specific error "
'should have been raised.',
'should have been raised.'
)
for name in names:
@ -584,7 +578,9 @@ make_consumer_key(code=234, names=('AUDIO_VOL_DOWN', 'VOLD')) # 0xEA
make_consumer_key(code=181, names=('MEDIA_NEXT_TRACK', 'MNXT')) # 0xB5
make_consumer_key(code=182, names=('MEDIA_PREV_TRACK', 'MPRV')) # 0xB6
make_consumer_key(code=183, names=('MEDIA_STOP', 'MSTP')) # 0xB7
make_consumer_key(code=205, names=('MEDIA_PLAY_PAUSE', 'MPLY')) # 0xCD (this may not be right)
make_consumer_key(
code=205, names=('MEDIA_PLAY_PAUSE', 'MPLY')
) # 0xCD (this may not be right)
make_consumer_key(code=184, names=('MEDIA_EJECT', 'EJCT')) # 0xB8
make_consumer_key(code=179, names=('MEDIA_FAST_FORWARD', 'MFFD')) # 0xB3
make_consumer_key(code=180, names=('MEDIA_REWIND', 'MRWD')) # 0xB4
@ -596,19 +592,28 @@ make_consumer_key(code=180, names=('MEDIA_REWIND', 'MRWD')) # 0xB4
# two keys with the exact same functionality
for names in (('NO',), ('TRANSPARENT', 'TRNS')):
make_key(
names=names,
on_press=handlers.passthrough,
on_release=handlers.passthrough,
names=names, on_press=handlers.passthrough, on_release=handlers.passthrough
)
make_key(names=('RESET',), on_press=handlers.reset)
make_key(names=('BOOTLOADER',), on_press=handlers.bootloader)
make_key(names=('DEBUG', 'DBG'), on_press=handlers.debug_pressed, on_release=handlers.passthrough)
make_key(
names=('DEBUG', 'DBG'),
on_press=handlers.debug_pressed,
on_release=handlers.passthrough,
)
make_key(names=('GESC',), on_press=handlers.gesc_pressed, on_release=handlers.gesc_released)
make_key(names=('BKDL',), on_press=handlers.bkdl_pressed, on_release=handlers.bkdl_released)
make_key(names=('GESC', 'GRAVE_ESC'), on_press=handlers.gesc_pressed,
on_release=handlers.gesc_released)
make_key(
names=('GESC',), on_press=handlers.gesc_pressed, on_release=handlers.gesc_released
)
make_key(
names=('BKDL',), on_press=handlers.bkdl_pressed, on_release=handlers.bkdl_released
)
make_key(
names=('GESC', 'GRAVE_ESC'),
on_press=handlers.gesc_pressed,
on_release=handlers.gesc_released,
)
make_key(names=('RGB_TOG',), on_press=handlers.rgb_tog)
make_key(names=('RGB_HUI',), on_press=handlers.rgb_hui)
make_key(names=('RGB_HUD',), on_press=handlers.rgb_hud)
@ -621,8 +626,10 @@ make_key(names=('RGB_AND',), on_press=handlers.rgb_and)
make_key(names=('RGB_MODE_PLAIN', 'RGB_M_P'), on_press=handlers.rgb_mode_static)
make_key(names=('RGB_MODE_BREATHE', 'RGB_M_B'), on_press=handlers.rgb_mode_breathe)
make_key(names=('RGB_MODE_RAINBOW', 'RGB_M_R'), on_press=handlers.rgb_mode_rainbow)
make_key(names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'),
on_press=handlers.rgb_mode_breathe_rainbow)
make_key(
names=('RGB_MODE_BREATHE_RAINBOW', 'RGB_M_BR'),
on_press=handlers.rgb_mode_breathe_rainbow,
)
make_key(names=('RGB_MODE_SWIRL', 'RGB_M_S'), on_press=handlers.rgb_mode_swirl)
make_key(names=('RGB_MODE_KNIGHT', 'RGB_M_K'), on_press=handlers.rgb_mode_knight)
@ -650,9 +657,7 @@ make_argumented_key(
on_release=layers.mo_released,
)
make_argumented_key(
validator=layer_key_validator,
names=('DF',),
on_press=layers.df_pressed,
validator=layer_key_validator, names=('DF',), on_press=layers.df_pressed
)
make_argumented_key(
validator=layer_key_validator,
@ -667,14 +672,10 @@ make_argumented_key(
on_release=layers.lt_released,
)
make_argumented_key(
validator=layer_key_validator,
names=('TG',),
on_press=layers.tg_pressed,
validator=layer_key_validator, names=('TG',), on_press=layers.tg_pressed
)
make_argumented_key(
validator=layer_key_validator,
names=('TO',),
on_press=layers.to_pressed,
validator=layer_key_validator, names=('TO',), on_press=layers.to_pressed
)
make_argumented_key(
validator=layer_key_validator,

View File

@ -5,7 +5,9 @@ from kmk.consts import DiodeOrientation
class MatrixScanner:
def __init__(
self, cols, rows,
self,
cols,
rows,
diode_orientation=DiodeOrientation.COLUMNS,
rollover_cols_every_rows=None,
):
@ -33,9 +35,9 @@ class MatrixScanner:
self.inputs = self.cols
self.translate_coords = False
else:
raise ValueError('Invalid DiodeOrientation: {}'.format(
self.diode_orientation,
))
raise ValueError(
'Invalid DiodeOrientation: {}'.format(self.diode_orientation)
)
for pin in self.outputs:
pin.switch_to_output()
@ -81,7 +83,9 @@ class MatrixScanner:
if old_val != new_val:
if self.translate_coords:
new_oidx = oidx + self.len_cols * (iidx // self.rollover_cols_every_rows)
new_oidx = oidx + self.len_cols * (
iidx // self.rollover_cols_every_rows
)
new_iidx = iidx - self.rollover_cols_every_rows * (
iidx // self.rollover_cols_every_rows
)

View File

@ -51,10 +51,13 @@ class RGB:
def __init__(self, config, pixel_pin):
try:
import neopixel
self.neopixel = neopixel.NeoPixel(pixel_pin,
self.neopixel = neopixel.NeoPixel(
pixel_pin,
config['num_pixels'],
pixel_order=config['rgb_order'],
auto_write=False)
auto_write=False,
)
if len(config['rgb_order']) == 4:
self.rgbw = True
self.num_pixels = const(config['num_pixels'])
@ -398,7 +401,10 @@ class RGB:
return False
def _init_effect(self):
if self.animation_mode == 'breathing' or self.animation_mode == 'breathing_rainbow':
if (
self.animation_mode == 'breathing'
or self.animation_mode == 'breathing_rainbow'
):
self.intervals = (30, 20, 10, 5)
elif self.animation_mode == 'swirl':
self.intervals = (50, 50)
@ -451,10 +457,8 @@ class RGB:
self.disable_auto_write = True # Turn off instantly showing
for i in range(0, self.num_pixels):
self.set_hsv(
(self.hue - (i * self.num_pixels)) % 360,
self.sat,
self.val,
i)
(self.hue - (i * self.num_pixels)) % 360, self.sat, self.val, i
)
# Show final results
self.disable_auto_write = False # Resume showing changes

View File

@ -6,6 +6,7 @@ class AttrDict(dict):
This is read-only on purpose.
'''
def __getattr__(self, key):
return self[key]
@ -14,6 +15,7 @@ class Anything:
'''
A stub class which will repr as a provided name
'''
def __init__(self, name):
self.name = name

View File

@ -24,19 +24,23 @@ def flatten_dict(d):
def reset_keyboard():
try:
import machine
machine.reset()
except ImportError:
import microcontroller
microcontroller.reset()
def reset_bootloader():
try:
import machine
machine.bootloader()
except ImportError:
import microcontroller
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
microcontroller.reset()

View File

@ -16,14 +16,6 @@ keymap = [
[KC.MO(2), KC.I, KC.ENTER],
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
],
[
[KC.TRNS, KC.B, KC.C],
[KC.NO, KC.D, KC.E],
[KC.F, KC.G, KC.H],
],
[
[KC.X, KC.Y, KC.Z],
[KC.TRNS, KC.N, KC.O],
[KC.R, KC.P, KC.Q],
],
[[KC.TRNS, KC.B, KC.C], [KC.NO, KC.D, KC.E], [KC.F, KC.G, KC.H]],
[[KC.X, KC.Y, KC.Z], [KC.TRNS, KC.N, KC.O], [KC.R, KC.P, KC.Q]],
]

View File

@ -16,14 +16,6 @@ keymap = [
[KC.MO(2), KC.I, KC.ENTER],
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
],
[
[KC.TRNS, KC.B, KC.C],
[KC.NO, KC.D, KC.E],
[KC.F, KC.G, KC.H],
],
[
[KC.X, KC.Y, KC.Z],
[KC.TRNS, KC.N, KC.O],
[KC.R, KC.P, KC.Q],
],
[[KC.TRNS, KC.B, KC.C], [KC.NO, KC.D, KC.E], [KC.F, KC.G, KC.H]],
[[KC.X, KC.Y, KC.Z], [KC.TRNS, KC.N, KC.O], [KC.R, KC.P, KC.Q]],
]

View File

@ -16,14 +16,6 @@ keymap = [
[KC.MO(2), KC.I, KC.ENTER],
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
],
[
[KC.A, KC.B, KC.C],
[KC.NO, KC.D, KC.E],
[KC.F, KC.G, KC.H],
],
[
[KC.X, KC.Y, KC.Z],
[KC.TRNS, KC.N, KC.O],
[KC.R, KC.P, KC.Q],
],
[[KC.A, KC.B, KC.C], [KC.NO, KC.D, KC.E], [KC.F, KC.G, KC.H]],
[[KC.X, KC.Y, KC.Z], [KC.TRNS, KC.N, KC.O], [KC.R, KC.P, KC.Q]],
]

View File

@ -16,14 +16,6 @@ keymap = [
[KC.MO(2), KC.I, KC.ENTER],
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
],
[
[KC.TRNS, KC.B, KC.C],
[KC.NO, KC.D, KC.E],
[KC.F, KC.G, KC.H],
],
[
[KC.X, KC.Y, KC.Z],
[KC.TRNS, KC.N, KC.O],
[KC.R, KC.P, KC.Q],
],
[[KC.TRNS, KC.B, KC.C], [KC.NO, KC.D, KC.E], [KC.F, KC.G, KC.H]],
[[KC.X, KC.Y, KC.Z], [KC.TRNS, KC.N, KC.O], [KC.R, KC.P, KC.Q]],
]

View File

@ -1,8 +1,10 @@
try:
import machine
machine.bootloader()
except ImportError:
import microcontroller
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
microcontroller.reset()

View File

@ -1,7 +1,9 @@
try:
import machine
machine.reset()
except ImportError:
import microcontroller
microcontroller.reset()