summaryrefslogtreecommitdiff
path: root/kvmd/keyboard
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-09-04 18:08:40 +0300
committerMaxim Devaev <[email protected]>2022-09-04 18:08:40 +0300
commitee3e224e396494cd0d69bb6167087a071a20349c (patch)
tree5becd28570e58a03c6e1e231d0db24c264a73f88 /kvmd/keyboard
parent4b75221e9470b4a009955d7677f16adf8e23e302 (diff)
new typing style
Diffstat (limited to 'kvmd/keyboard')
-rw-r--r--kvmd/keyboard/keysym.py15
-rw-r--r--kvmd/keyboard/mappings.py.mako4
-rw-r--r--kvmd/keyboard/printer.py6
3 files changed, 9 insertions, 16 deletions
diff --git a/kvmd/keyboard/keysym.py b/kvmd/keyboard/keysym.py
index 623155f3..e9697717 100644
--- a/kvmd/keyboard/keysym.py
+++ b/kvmd/keyboard/keysym.py
@@ -24,9 +24,6 @@ import pkgutil
import functools
import importlib.machinery
-from typing import List
-from typing import Dict
-
import Xlib.keysymdef
from ..logging import get_logger
@@ -44,11 +41,11 @@ class SymmapModifiers:
CTRL: int = 0x4
-def build_symmap(path: str) -> Dict[int, Dict[int, str]]:
+def build_symmap(path: str) -> dict[int, dict[int, str]]:
# https://github.com/qemu/qemu/blob/95a9457fd44ad97c518858a4e1586a5498f9773c/ui/keymaps.c
logger = get_logger()
- symmap: Dict[int, Dict[int, str]] = {}
+ symmap: dict[int, dict[int, str]] = {}
for (src, items) in [
("<builtin>", list(X11_TO_AT1.items())),
(path, list(_read_keyboard_layout(path).items())),
@@ -78,8 +75,8 @@ def build_symmap(path: str) -> Dict[int, Dict[int, str]]:
# =====
@functools.lru_cache()
-def _get_keysyms() -> Dict[str, int]:
- keysyms: Dict[str, int] = {}
+def _get_keysyms() -> dict[str, int]:
+ keysyms: dict[str, int] = {}
for (finder, module_name, _) in pkgutil.walk_packages(Xlib.keysymdef.__path__):
if not isinstance(finder, importlib.machinery.FileFinder):
continue
@@ -109,14 +106,14 @@ def _resolve_keysym(name: str) -> int:
return 0
-def _read_keyboard_layout(path: str) -> Dict[int, List[At1Key]]: # Keysym to evdev (at1)
+def _read_keyboard_layout(path: str) -> dict[int, list[At1Key]]: # Keysym to evdev (at1)
logger = get_logger(0)
logger.info("Reading keyboard layout %s ...", path)
with open(path) as layout_file:
lines = list(map(str.strip, layout_file.read().split("\n")))
- layout: Dict[int, List[At1Key]] = {}
+ layout: dict[int, list[At1Key]] = {}
for (lineno, line) in enumerate(lines):
if len(line) == 0 or line.startswith(("#", "map ", "include ")):
continue
diff --git a/kvmd/keyboard/mappings.py.mako b/kvmd/keyboard/mappings.py.mako
index 91d46297..b8a6596c 100644
--- a/kvmd/keyboard/mappings.py.mako
+++ b/kvmd/keyboard/mappings.py.mako
@@ -22,8 +22,6 @@
import dataclasses
-from typing import Dict
-
# =====
@dataclasses.dataclass(frozen=True)
@@ -43,7 +41,7 @@ class Key:
usb: UsbKey
<%! import operator %>
-KEYMAP: Dict[str, Key] = {
+KEYMAP: dict[str, Key] = {
% for km in sorted(keymap, key=operator.attrgetter("mcu_code")):
"${km.web_name}": Key(mcu=McuKey(code=${km.mcu_code}), usb=UsbKey(code=${km.usb_key.code}, is_modifier=${km.usb_key.is_modifier})),
% endfor
diff --git a/kvmd/keyboard/printer.py b/kvmd/keyboard/printer.py
index 20ff9a56..7261a8ef 100644
--- a/kvmd/keyboard/printer.py
+++ b/kvmd/keyboard/printer.py
@@ -20,8 +20,6 @@
# ========================================================================== #
-from typing import Tuple
-from typing import Dict
from typing import Generator
from .keysym import SymmapModifiers
@@ -31,9 +29,9 @@ from .mappings import WebModifiers
# =====
def text_to_web_keys( # pylint: disable=too-many-branches
text: str,
- symmap: Dict[int, Dict[int, str]],
+ symmap: dict[int, dict[int, str]],
shift_key: str=WebModifiers.SHIFT_LEFT,
-) -> Generator[Tuple[str, bool], None, None]:
+) -> Generator[tuple[str, bool], None, None]:
assert shift_key in WebModifiers.SHIFTS