mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-02-02 02:51:53 +08:00
new typing style
This commit is contained in:
@@ -20,11 +20,8 @@
|
||||
# ========================================================================== #
|
||||
|
||||
|
||||
from typing import Tuple
|
||||
from typing import Dict
|
||||
from typing import Iterable
|
||||
from typing import AsyncGenerator
|
||||
from typing import Optional
|
||||
from typing import Any
|
||||
|
||||
from ....logging import get_logger
|
||||
@@ -49,9 +46,9 @@ from .mouse import MouseProcess
|
||||
class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
def __init__( # pylint: disable=super-init-not-called
|
||||
self,
|
||||
keyboard: Dict[str, Any],
|
||||
mouse: Dict[str, Any],
|
||||
mouse_alt: Dict[str, Any],
|
||||
keyboard: dict[str, Any],
|
||||
mouse: dict[str, Any],
|
||||
mouse_alt: dict[str, Any],
|
||||
noop: bool,
|
||||
udc: str, # XXX: Not from options, see /kvmd/apps/kvmd/__init__.py for details
|
||||
) -> None:
|
||||
@@ -66,8 +63,8 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
self.__keyboard_proc = KeyboardProcess(**common, **keyboard)
|
||||
self.__mouse_current = self.__mouse_proc = MouseProcess(**common, **mouse)
|
||||
|
||||
self.__mouse_alt_proc: Optional[MouseProcess] = None
|
||||
self.__mouses: Dict[str, MouseProcess] = {}
|
||||
self.__mouse_alt_proc: (MouseProcess | None) = None
|
||||
self.__mouses: dict[str, MouseProcess] = {}
|
||||
if mouse_alt["device_path"]:
|
||||
self.__mouse_alt_proc = MouseProcess(
|
||||
absolute=(not mouse["absolute"]),
|
||||
@@ -84,7 +81,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
self.__mouses["usb_win98"] = self.__mouses["usb"]
|
||||
|
||||
@classmethod
|
||||
def get_plugin_options(cls) -> Dict:
|
||||
def get_plugin_options(cls) -> dict:
|
||||
return {
|
||||
"keyboard": {
|
||||
"device": Option("/dev/kvmd-hid-keyboard", type=valid_abs_path, unpack_as="device_path"),
|
||||
@@ -121,7 +118,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
if self.__mouse_alt_proc:
|
||||
self.__mouse_alt_proc.start(udc)
|
||||
|
||||
async def get_state(self) -> Dict:
|
||||
async def get_state(self) -> dict:
|
||||
keyboard_state = await self.__keyboard_proc.get_state()
|
||||
mouse_state = await self.__mouse_current.get_state()
|
||||
return {
|
||||
@@ -146,8 +143,8 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
},
|
||||
}
|
||||
|
||||
async def poll_state(self) -> AsyncGenerator[Dict, None]:
|
||||
prev_state: Dict = {}
|
||||
async def poll_state(self) -> AsyncGenerator[dict, None]:
|
||||
prev_state: dict = {}
|
||||
while True:
|
||||
state = await self.get_state()
|
||||
if state != prev_state:
|
||||
@@ -173,7 +170,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
|
||||
# =====
|
||||
|
||||
def send_key_events(self, keys: Iterable[Tuple[str, bool]]) -> None:
|
||||
def send_key_events(self, keys: Iterable[tuple[str, bool]]) -> None:
|
||||
self.__keyboard_proc.send_key_events(keys)
|
||||
|
||||
def send_mouse_button_event(self, button: str, state: bool) -> None:
|
||||
@@ -188,7 +185,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None:
|
||||
self.__mouse_current.send_wheel_event(delta_x, delta_y)
|
||||
|
||||
def set_params(self, keyboard_output: Optional[str]=None, mouse_output: Optional[str]=None) -> None:
|
||||
def set_params(self, keyboard_output: (str | None)=None, mouse_output: (str | None)=None) -> None:
|
||||
_ = keyboard_output
|
||||
if mouse_output in self.__mouses and mouse_output != self.__get_current_mouse_mode():
|
||||
self.__mouse_current.send_clear_event()
|
||||
|
||||
@@ -28,9 +28,7 @@ import errno
|
||||
import logging
|
||||
import time
|
||||
|
||||
from typing import Dict
|
||||
from typing import Generator
|
||||
from typing import Optional
|
||||
|
||||
from ....logging import get_logger
|
||||
|
||||
@@ -48,7 +46,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
|
||||
self,
|
||||
name: str,
|
||||
read_size: int,
|
||||
initial_state: Dict,
|
||||
initial_state: dict,
|
||||
notifier: aiomulti.AioProcessNotifier,
|
||||
|
||||
device_path: str,
|
||||
@@ -76,7 +74,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
|
||||
self.__stop_event = multiprocessing.Event()
|
||||
self.__no_device_reported = False
|
||||
|
||||
self.__logger: Optional[logging.Logger] = None
|
||||
self.__logger: (logging.Logger | None) = None
|
||||
|
||||
def start(self, udc: str) -> None: # type: ignore # pylint: disable=arguments-differ
|
||||
self.__udc_state_path = usb.get_udc_path(udc, usb.U_STATE)
|
||||
@@ -125,7 +123,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
|
||||
|
||||
self.__close_device()
|
||||
|
||||
async def get_state(self) -> Dict:
|
||||
async def get_state(self) -> dict:
|
||||
return (await self.__state_flags.get())
|
||||
|
||||
# =====
|
||||
|
||||
@@ -23,11 +23,6 @@
|
||||
import struct
|
||||
import dataclasses
|
||||
|
||||
from typing import List
|
||||
from typing import Set
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
|
||||
from ....keyboard.mappings import UsbKey
|
||||
from ....keyboard.mappings import KEYMAP
|
||||
|
||||
@@ -66,7 +61,7 @@ class ModifierEvent(BaseEvent):
|
||||
assert self.modifier.is_modifier
|
||||
|
||||
|
||||
def make_keyboard_event(key: str, state: bool) -> Union[KeyEvent, ModifierEvent]:
|
||||
def make_keyboard_event(key: str, state: bool) -> (KeyEvent | ModifierEvent):
|
||||
usb_key = KEYMAP[key].usb
|
||||
if usb_key.is_modifier:
|
||||
return ModifierEvent(usb_key, state)
|
||||
@@ -87,8 +82,8 @@ def get_led_num(flags: int) -> bool:
|
||||
|
||||
|
||||
def make_keyboard_report(
|
||||
pressed_modifiers: Set[UsbKey],
|
||||
pressed_keys: List[Optional[UsbKey]],
|
||||
pressed_modifiers: set[UsbKey],
|
||||
pressed_keys: list[UsbKey | None],
|
||||
) -> bytes:
|
||||
|
||||
modifiers = 0
|
||||
@@ -168,7 +163,7 @@ def make_mouse_report(
|
||||
buttons: int,
|
||||
move_x: int,
|
||||
move_y: int,
|
||||
wheel_x: Optional[int],
|
||||
wheel_x: (int | None),
|
||||
wheel_y: int,
|
||||
) -> bytes:
|
||||
|
||||
|
||||
@@ -20,12 +20,8 @@
|
||||
# ========================================================================== #
|
||||
|
||||
|
||||
from typing import Tuple
|
||||
from typing import List
|
||||
from typing import Set
|
||||
from typing import Iterable
|
||||
from typing import Generator
|
||||
from typing import Optional
|
||||
from typing import Any
|
||||
|
||||
from ....logging import get_logger
|
||||
@@ -56,8 +52,8 @@ class KeyboardProcess(BaseDeviceProcess):
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
self.__pressed_modifiers: Set[UsbKey] = set()
|
||||
self.__pressed_keys: List[Optional[UsbKey]] = [None] * 6
|
||||
self.__pressed_modifiers: set[UsbKey] = set()
|
||||
self.__pressed_keys: list[UsbKey | None] = [None] * 6
|
||||
|
||||
def cleanup(self) -> None:
|
||||
self._stop()
|
||||
@@ -72,7 +68,7 @@ class KeyboardProcess(BaseDeviceProcess):
|
||||
self._clear_queue()
|
||||
self._queue_event(ResetEvent())
|
||||
|
||||
def send_key_events(self, keys: Iterable[Tuple[str, bool]]) -> None:
|
||||
def send_key_events(self, keys: Iterable[tuple[str, bool]]) -> None:
|
||||
for (key, state) in keys:
|
||||
self._queue_event(make_keyboard_event(key, state))
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
|
||||
from typing import Generator
|
||||
from typing import Optional
|
||||
from typing import Any
|
||||
|
||||
from ....logging import get_logger
|
||||
@@ -145,8 +144,8 @@ class MouseProcess(BaseDeviceProcess):
|
||||
|
||||
def __make_report(
|
||||
self,
|
||||
relative_event: Optional[MouseRelativeEvent]=None,
|
||||
wheel_event: Optional[MouseWheelEvent]=None,
|
||||
relative_event: (MouseRelativeEvent | None)=None,
|
||||
wheel_event: (MouseWheelEvent | None)=None,
|
||||
) -> bytes:
|
||||
|
||||
if self.__absolute:
|
||||
|
||||
Reference in New Issue
Block a user