Skip to content

Commit

Permalink
Improve type hinting
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawstorant committed Oct 7, 2024
1 parent 82b0522 commit 77e9f37
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions boxflat/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def _activate_default(self) -> SettingsPanel:
return self._panels["Home"]


def _panel_buttons(self) -> list:
buttons = []
def _panel_buttons(self) -> list[Gtk.Button]:
buttons: list[Gtk.Button] = []
for panel in self._panels.values():
buttons.append(panel.button)

Expand Down
16 changes: 8 additions & 8 deletions boxflat/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, serial_data_path: str, dry_run=False):
self._dry_run = dry_run
self._shutdown = Event()

self._serial_devices = {}
self._serial_devices: dict[str, MozaSerialDevice] = {}
self._devices_lock = Lock()
self._exclusive_access = Event()
self._exclusive_access.set()
Expand All @@ -67,11 +67,11 @@ def __init__(self, serial_data_path: str, dry_run=False):
self._shutdown.set()
quit(1)

self._device_ids = self._serial_data["device-ids"]
self._device_ids: dict[str, int] = self._serial_data["device-ids"]

# register events
self._command_list = []
self._polling_list = []
self._command_list: list[str] = []
self._polling_list: list[str] = []
for device in self._serial_data["commands"]:
if self._device_ids[device] == -1:
continue
Expand All @@ -92,7 +92,7 @@ def __init__(self, serial_data_path: str, dry_run=False):
self._serial_lock = Lock()
self._refresh_cont = Event()

self._connected_subscriptions = {}
self._connected_subscriptions: dict[str, SubscriptionList] = {}
self._connected_thread = None
self._connected_lock = Lock()

Expand All @@ -119,14 +119,14 @@ def device_discovery(self, *args):
if device.find("Gudsen_MOZA"):
devices.append(os.path.join(self._serial_path, device))

serial_devices = {}
serial_devices: dict[str, MozaSerialDevice] = {}
for path in devices:
for part, name in SerialDeviceMapping.items():
if path.lower().find(part) == -1:
continue

serial_devices[name] = MozaSerialDevice(name, path)
print(f"\"{name}\" found".title())
# print(f"\"{name}\" found".title())

self._handle_devices(serial_devices)
# print("Device discovery end\n")
Expand Down Expand Up @@ -354,5 +354,5 @@ def cycle_wheel_id(self) -> int:
return wid


def get_command_data(self) -> dict:
def get_command_data(self) -> dict[str, dict]:
return self._serial_data["commands"]
4 changes: 2 additions & 2 deletions boxflat/hid_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class HidHandler(EventDispatcher):
def __init__(self):
super().__init__()

self._axis_values = {}
self._axis_values: dict[str, AxisValue] = {}
for i in range(0, MOZA_BUTTON_COUNT):
self._register_event(f"button-{i}")

Expand Down Expand Up @@ -160,7 +160,7 @@ def add_device(self, pattern: MozaHidDevice):
return

device = None
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
devices: list[evdev.InputDevice] = [evdev.InputDevice(path) for path in evdev.list_devices()]

for hid in devices:
if re.search(pattern, hid.name.lower()):
Expand Down
2 changes: 1 addition & 1 deletion boxflat/moza_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def set_data_from_name(self, name: str, commands_data: dict, device_name: str):


@staticmethod
def value_from_response(values: bytes, device_name: str, commands_data: dict, device_ids: dict) -> tuple:
def value_from_response(values: bytes, device_name: str, commands_data: dict, device_ids: dict) -> tuple[str]:
ret = (None, None)
if values is None:
return ret
Expand Down
11 changes: 5 additions & 6 deletions boxflat/panels/settings_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ def __init__(self, title: str, button_callback,
self._cm = connection_manager
self._hid_handler = hid_handler

self._current_page = None
self._current_group: BoxflatPreferencesGroup=None
self._current_stack = None
self._current_row: BoxflatRow=None
self._header = None
self._current_page: Adw.PreferencesPage = None
self._current_group: BoxflatPreferencesGroup = None
self._current_stack: Adw.ViewStack = None
self._current_row: BoxflatRow = None

self._groups = []
self._groups: list[BoxflatPreferencesGroup] = []

self._active = True
self._shutdown = False
Expand Down
15 changes: 8 additions & 7 deletions boxflat/panels/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ def __init__(self, button_callback, connection_manager: MozaConnectionManager, h
self._timing_row = None
self._timing_preset_row = None
self._stick_row = None
self._timings = []
self._timings.append([65, 69, 72, 75, 78, 80, 83, 85, 88, 91]) # Early
self._timings.append([75, 79, 82, 85, 87, 88, 89, 90, 92, 94]) # Normal
self._timings.append([80, 83, 86, 89, 91, 92, 93, 94, 96, 97]) # Late
self._timings: list[list[int]] = [
[65, 69, 72, 75, 78, 80, 83, 85, 88, 91], # Early
[75, 79, 82, 85, 87, 88, 89, 90, 92, 94], # Normal
[80, 83, 86, 89, 91, 92, 93, 94, 96, 97], # Late
]
# self._timings.append([80, 83, 86, 89, 91, 92, 93, 94, 96, 97]) # Central
self._wheel_combination_data = []
self._wheel_combination_data: list[int] = []

self._timings2 = [
self._timings2: list[list[int]] = [
[5400, 5700, 6000, 6300, 6500, 6700, 6900, 7100, 7300, 7600],
[6300, 6600, 6800, 7100, 7300, 7300, 7400, 7500, 7700, 7800],
[6700, 6900, 7200, 7400, 7600, 7700, 7800, 7800, 8000, 8100]
Expand Down Expand Up @@ -330,7 +331,7 @@ def _get_combination_settings(self, values):
byte1 = values[1]
byte2 = values[3]

switch_values = []
switch_values: list[int] = []

switch_values.append(test_bit(byte2, 0))
switch_values.append(test_bit(byte2, 3))
Expand Down
8 changes: 4 additions & 4 deletions boxflat/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Subscription():
def __init__(self, callback, *args):
self._callback = callback
self._args = args
self._args: tuple = args


def call(self):
Expand Down Expand Up @@ -75,7 +75,7 @@ def append_subscription(self, subscription: Subscription):

def call(self):
for sub in self._subscriptions:
sub.
sub.call()

while not self._single_time_subs.empty():
self._single_time_subs.get().call()
Expand Down Expand Up @@ -122,7 +122,7 @@ def clear(self):

class EventDispatcher():
def __init__(self):
self.__events = {}
self.__events: dict[str, SubscriptionList] = {}


def _event_sub_count(self, event_name: str) -> int:
Expand Down Expand Up @@ -167,7 +167,7 @@ def _deregister_event(self, event_name: str) -> bool:


def _deregister_all_events(self) -> bool:
self.__events = {}
self.__events.clear()


def _dispatch(self, event_name: str, *values) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions boxflat/widgets/dialog_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, title: str, subtitle=""):
self._title = title
self._set_widget(icon)
self._icon = icon
self._switches = []
self._switches: list[BoxflatSwitchRow] = []

self._group = Adw.PreferencesGroup()
self._group.add_css_class("wheel-dialog-setting")
Expand Down Expand Up @@ -51,7 +51,7 @@ def add_switch(self, title: str, subtitle=""):
row.subscribe(self._notify)


def get_value(self) -> list:
def get_value(self) -> list[int]:
values = []
for switch in self._switches:
values.append(switch.get_value())
Expand Down
4 changes: 2 additions & 2 deletions boxflat/widgets/equalizer_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, title: str, sliders_number: int,
super().__init__(title, subtitle)

self._suffix = suffix
self._slider_subs_list = []
self._slider_subs_list: list[SubscriptionList] = []
self._sliders_subs = SubscriptionList()
self._button_row = button_row
self._draw_marks = draw_marks
Expand Down Expand Up @@ -108,7 +108,7 @@ def set_height(self, height: int):
slider.set_size_request(0, height)


def get_sliders_value(self) -> list:
def get_sliders_value(self) -> list[int]:
values = []
for slider in self._sliders:
values.append(round(slider.get_value()))
Expand Down
8 changes: 4 additions & 4 deletions boxflat/widgets/new_color_picker_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
MOZA_RPM_LEDS = 10
MOZA_RGB_BUTTONS = 10

def extract_rgb(rgba: Gdk.RGBA) -> list:
def extract_rgb(rgba: Gdk.RGBA) -> list[int]:
rgb = rgba.to_string()[4:-1]
rgb = list(map(int, rgb.split(",")))
return rgb
Expand Down Expand Up @@ -38,10 +38,10 @@ def __init__(self, title="", subtitle="", blinking=False):
main_box.append(colors_box)

self._dialog = Gtk.ColorDialog(with_alpha=False)
self._blinking_event = []
self._blinking_event: list[Event] = []
self._value_lock = Lock()

self._colors = []
self._colors: list[Gtk.ColorDialogButton] = []
red = Gdk.RGBA()
red.parse("rgb(230,60,60)")
for i in range(MOZA_RPM_LEDS):
Expand All @@ -66,7 +66,7 @@ def __init__(self, title="", subtitle="", blinking=False):
self._blinking_event.append(Event())


def get_value(self, index: int) -> list:
def get_value(self, index: int) -> list[int]:
if index >= 0 and index < len(self._colors):
rgba = self._colors[index].get_rgba()
return extract_rgb(rgba)
Expand Down
2 changes: 1 addition & 1 deletion boxflat/widgets/toggle_button_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, title: str, subtitle=""):
self._set_widget(box)
self._box = box
self._group = None
self._buttons = []
self._buttons: list[Gtk.ToggleButton] = []

self._box.add_css_class("linked")

Expand Down

0 comments on commit 77e9f37

Please sign in to comment.