From 221aa5b4f38982c4ce7771a1319f939342b17c75 Mon Sep 17 00:00:00 2001 From: Martin Rys Date: Sat, 28 Sep 2024 20:20:36 +0200 Subject: [PATCH] Fix DEFAULT_TIMEOUT typo and add linter fixes and type hints after digging through action editor Glade page for action editor was also updated --- glade/action_editor.glade | 913 ++++++++++++++++++++------------------ scc/actions.py | 13 +- scc/drivers/hiddrv.py | 2 +- scc/drivers/usb.py | 2 +- scc/gui/action_editor.py | 42 +- scc/gui/ae/gyro_action.py | 9 +- scc/gui/key_grabber.py | 4 +- scc/gui/macro_editor.py | 4 +- scc/modifiers.py | 17 +- 9 files changed, 515 insertions(+), 491 deletions(-) diff --git a/glade/action_editor.glade b/glade/action_editor.glade index 0c6d7eaf..738af17f 100644 --- a/glade/action_editor.glade +++ b/glade/action_editor.glade @@ -1,90 +1,90 @@ - + - + 32766 - 1 - 10 + 1 + 10 1 32767 32767 - 1 - 10 + 1 + 10 16 32767 512 - 32 - 128 - 128 + 32 + 128 + 128 1 100 4 - 1 - 10 + 1 + 10 16 32767 1024 - 32 - 128 - 128 + 32 + 128 + 128 6 - 1 - 10 + 1 + 10 -180 180 - 1 - 10 + 1 + 10 10 1 - 0.10000000000000001 - 1 + 0.10 + 1 10 1 - 0.10000000000000001 - 1 + 0.10 + 1 10 1 - 0.10000000000000001 - 1 + 0.10 + 1 100 2 - 1 - 10 + 1 + 10 2 20 8 - 1 - 3 + 1 + 3 - 0.10000000000000001 + 0.10 1 0.75 - 0.10000000000000001 - 0.29999999999999999 + 0.10 + 0.29999999999999999 @@ -153,65 +153,66 @@ - 650 - False + 650 + False action-editor False - center-on-parent - True - dialog + center-on-parent + True + dialog + True - False - 10 - 10 - 10 - 10 + False + 10 + 10 + 10 + 10 True - True - True - 20 - 2 + True + True + 20 + 2 True - True + True - 1 - 1 + 1 + 1 True - False - 20 - slide-right + False + 20 + slide-right - 0 - 3 + 0 + 3 2 True - False - 20 + False + 20 True - True + True False - True + True True @@ -221,17 +222,17 @@ - 0 - 6 + 0 + 6 2 True - False - 20 - 5 + False + 20 + 5 True 4 @@ -239,16 +240,16 @@ - 1 - 2 + 1 + 2 True - False - 20 - 20 + False + 20 + 20 Action Type 0 @@ -256,18 +257,18 @@ - 0 - 2 + 0 + 2 True - False - True - 20 - 50 - 2 + False + True + 20 + 50 + 2 Action Name 0 @@ -275,16 +276,16 @@ - 0 - 1 + 0 + 1 True - True - 5 - 5 + True + 5 + 5 @@ -292,7 +293,7 @@ True - False + False More... @@ -301,41 +302,42 @@ - 0 - 4 + 0 + 4 2 True - False - slide-up + False + slide-up True - True - left + True + left + True - False - 5 - 5 - 5 + False + 5 + 5 + 5 True - True - False - 5 + True + False + 5 0 - True + True True - False + False Display OSD 0 @@ -345,16 +347,16 @@ - 0 - 0 + 0 + 0 3 True - False - 10 + False + 10 Input Rotation 0 @@ -362,16 +364,16 @@ - 0 - 3 + 0 + 3 3 True - False - 10 + False + 10 Angle end 0 @@ -380,58 +382,58 @@ - 0 - 4 + 0 + 4 True - True + True True adjRotation - 1 - right + 1 + right - 1 - 4 + 1 + 4 True - True - True - 5 + True + True + 5 True - False + False gtk-clear - 2 - 4 + 2 + 4 True - True - False - 5 + True + False + 5 0 - True + True True - False + False Require Click 0 @@ -441,23 +443,23 @@ - 0 - 1 + 0 + 1 3 True - True - False + True + False 0 - True + True True - False + False Preview Changes Immediately 0 @@ -467,17 +469,17 @@ - 0 - 2 + 0 + 2 3 True - False - 10 - 5 + False + 10 + 5 Friction end 0 @@ -486,58 +488,58 @@ - 0 - 6 + 0 + 6 True - True + True True adjFriction - 1 - right + 1 + right - 1 - 6 + 1 + 6 True - True - True - 5 + True + True + 5 True - False + False gtk-clear - 2 - 6 + 2 + 6 True - True - False - 10 - True + True + False + 10 + True True - False + False Trackball Mode 0 @@ -547,8 +549,8 @@ - 0 - 5 + 0 + 5 3 @@ -557,25 +559,26 @@ True - False + False Basics 0 - False + False + True - False - 5 - 5 - 5 + False + 5 + 5 + 5 True - False + False Sensitivity 0 @@ -583,16 +586,16 @@ - 0 - 0 + 0 + 0 3 True - False - 10 + False + 10 X end 0 @@ -601,49 +604,49 @@ - 0 - 1 + 0 + 1 True - True + True True adjSensitivityX - 1 - right + 1 + right - 1 - 1 + 1 + 1 True - True - True + True + True True - False + False gtk-clear - 2 - 1 + 2 + 1 True - False - 10 + False + 10 Y end 0 @@ -652,49 +655,49 @@ - 0 - 2 + 0 + 2 True - True + True True adjSensitivityY - 1 - right + 1 + right - 1 - 2 + 1 + 2 True - True - True + True + True True - False + False gtk-clear - 2 - 2 + 2 + 2 True - False - 10 + False + 10 Roll end 0 @@ -703,56 +706,56 @@ - 0 - 3 + 0 + 3 True - True + True True adjSensitivityZ - 1 - right + 1 + right - 1 - 3 + 1 + 3 True - True - True + True + True True - False + False gtk-clear - 2 - 3 + 2 + 3 Invert X axis True - True - False - True + True + False + True - 0 - 4 + 0 + 4 3 @@ -760,29 +763,29 @@ Invert Y axis True - True - False - True + True + False + True - 0 - 5 + 0 + 5 3 Invert Roll - True - False - True - True + True + False + True + True - 0 - 6 + 0 + 6 3 @@ -794,29 +797,30 @@ True - False + False Sensitivity 0 1 - False + False + True - False - 5 - 5 - 5 - 2 - 10 + False + 5 + 5 + 5 + 2 + 10 - False - True - 10 + False + True + 10 Period end 0 @@ -825,14 +829,14 @@ - 0 - 4 + 0 + 4 True - False + False lstFeedbackSide 0 @@ -844,123 +848,123 @@ - 1 - 1 + 1 + 1 2 True - True - True + True + True True - False + False gtk-clear - 2 - 3 + 2 + 3 True - True - True + True + True True - False + False gtk-clear - 2 - 2 + 2 + 2 - True - True + True + True True adjFPeriod - 0 + 0 0 - right + right - 1 - 4 + 1 + 4 - True - True - True + True + True + True True - False + False gtk-clear - 2 - 4 + 2 + 4 True - True + True True adjFFrequency True - 0 + 0 0 - right + right - 1 - 3 + 1 + 3 True - True + True True adjFAmplitude - 0 + 0 0 - right + right - 1 - 2 + 1 + 2 True - False - 10 + False + 10 Frequency end 0 @@ -969,15 +973,15 @@ - 0 - 3 + 0 + 3 True - False - 10 + False + 10 Strength end 0 @@ -986,15 +990,15 @@ - 0 - 2 + 0 + 2 True - False - 10 + False + 10 Side end 0 @@ -1003,23 +1007,23 @@ - 0 - 1 + 0 + 1 True - True - False - 5 + True + False + 5 0 - True + True True - False + False Feedback Enabled 0 @@ -1029,8 +1033,8 @@ - 0 - 0 + 0 + 0 3 @@ -1042,29 +1046,30 @@ True - False + False Feedback 0 2 - False + False + True - False - 5 - 5 - 5 - 2 - 10 + False + 5 + 5 + 5 + 2 + 10 True - False - 10 + False + 10 Upper end 0 @@ -1073,15 +1078,15 @@ - 0 - 2 + 0 + 2 True - False - 10 + False + 10 Lower end 0 @@ -1090,93 +1095,93 @@ - 0 - 1 + 0 + 1 True - True + True True adjDeadzoneUpper - 0 + 0 0 - right + right - 1 - 2 + 1 + 2 True - True + True True adjDeadzoneLower - 0 + 0 0 - right + right - 1 - 1 + 1 + 1 True - True - True + True + True True - False + False gtk-clear - 2 - 2 + 2 + 2 True - True - True + True + True True - False + False gtk-clear - 2 - 1 + 2 + 1 True - True - False - 5 + True + False + 5 0 - True + True True - False + False Deadzone Enabled 0 @@ -1186,16 +1191,16 @@ - 0 - 0 + 0 + 0 3 True - False - 10 + False + 10 Mode end 0 @@ -1204,15 +1209,15 @@ - 0 - 3 + 0 + 3 True - False - 10 + False + 10 lstDeadzoneMode 0 @@ -1224,8 +1229,8 @@ - 1 - 3 + 1 + 3 2 @@ -1237,29 +1242,30 @@ True - False + False Deadzone 0 3 - False + False + True - False - 5 - 5 - 5 - 2 - 10 + False + 5 + 5 + 5 + 2 + 10 True - False - 10 + False + 10 Filter end 0 @@ -1268,15 +1274,15 @@ - 0 - 3 + 0 + 3 True - False - 10 + False + 10 Weight end 0 @@ -1285,15 +1291,15 @@ - 0 - 2 + 0 + 2 True - False - 10 + False + 10 Level end 0 @@ -1302,128 +1308,128 @@ - 0 - 1 + 0 + 1 True - True + True True adjSmoothFilter - 0 + 0 0 - right + right - 1 - 3 + 1 + 3 True - True + True True adjSmoothWeight - 2 + 2 2 - right + right - 1 - 2 + 1 + 2 True - True + True True adjSmoothLevel - 0 + 0 0 - right + right - 1 - 1 + 1 + 1 True - True - True + True + True True - False + False gtk-clear - 2 - 3 + 2 + 3 True - True - True + True + True True - False + False gtk-clear - 2 - 2 + 2 + 2 True - True - True + True + True True - False + False gtk-clear - 2 - 1 + 2 + 1 True - True - False - 5 + True + False + 5 0 - True + True True - False + False Smoothing Enabled 0 @@ -1433,8 +1439,8 @@ - 0 - 0 + 0 + 0 3 @@ -1446,32 +1452,32 @@ True - False + False Smoothing 0 4 - False + False - 0 - 5 + 0 + 5 2 - False - True - 20 - 50 - 10 - 7 + False + True + 20 + 50 + 10 + 7 (Widget) 0 0 @@ -1480,51 +1486,91 @@ - 0 - 0 + 0 + 0 - False - True - 20 - 7 + False + True + 20 + 7 vertical - 1 - 0 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + True - False - True + False + True Mode Shift True - True - True + True + True 2 + + + gtk-ok + True + True + True + True + True + True + + + + + end + 2 + + Macro True - True - True + True + True @@ -1535,44 +1581,25 @@ Ring Bindings True - True - True + True + True 4 - - - gtk-ok - True - True - True - True - True - True - - - - - end - 2 - - gtk-clear True - True - True - True + True + True + True - end + end 6 diff --git a/scc/actions.py b/scc/actions.py index 945494c0..c5a96131 100644 --- a/scc/actions.py +++ b/scc/actions.py @@ -146,14 +146,15 @@ def register_all(module, prefix=None): """ Registers all actions from module """ for x in dir(module): g = getattr(module, x) - if hasattr(g, 'COMMAND'): + if hasattr(g, "COMMAND"): Action.register(g, prefix=prefix) def encode(self): - """ Called from json encoder """ - rv = { 'action' : self.to_string() } - if self.name: rv['name'] = self.name + """Called from json encoder.""" + rv = { "action" : self.to_string() } + if self.name: + rv["name"] = self.name return rv @@ -213,7 +214,7 @@ def describe(self, context): return str(self) - def to_string(self, multiline=False, pad=0): + def to_string(self, multiline: bool = False, pad: int = 0): """Convert action back to string.""" return (" " * pad) + "{}({})".format(self.COMMAND, ", ".join([ x.to_string() if isinstance(x, Action) else f"{x.__class__.__name__}.{x.name}" if isinstance(x, IntEnum) else str(x) @@ -1203,7 +1204,7 @@ def get_compatible_modifiers(self): return Action.MOD_SENSITIVITY | Action.MOD_SENS_Z - def set_speed(self, x, y, z): + def set_speed(self, x: float, y: float, z: float): self.speed = (x, y, z) diff --git a/scc/drivers/hiddrv.py b/scc/drivers/hiddrv.py index 8023b620..67fd27a2 100644 --- a/scc/drivers/hiddrv.py +++ b/scc/drivers/hiddrv.py @@ -632,7 +632,7 @@ def scan_files(self) -> None: if (vid, pid) in self.configs: del self.configs[vid, pid] -def hiddrv_test(cls, args) -> None: +def hiddrv_test(cls, args) -> int: """Small input test used by GUI while setting up the device. Basically, if HID device works with this, it will work with daemon as well. diff --git a/scc/drivers/usb.py b/scc/drivers/usb.py index 50a42203..25a3d677 100644 --- a/scc/drivers/usb.py +++ b/scc/drivers/usb.py @@ -201,7 +201,7 @@ def __init__(self): self._changed = 0 - def set_daemon(self, daemon: SCCDaemon): + def set_daemon(self, daemon: SCCDaemon) -> None: self.daemon = daemon diff --git a/scc/gui/action_editor.py b/scc/gui/action_editor.py index 19fb5903..3675e4c8 100644 --- a/scc/gui/action_editor.py +++ b/scc/gui/action_editor.py @@ -263,7 +263,8 @@ def cb(): def on_action_type_changed(self, clicked_button): """Called when user clicks on one of Action Type buttons.""" # Prevent recurson - if self._recursing : return + if self._recursing: + return self._recursing = True # Don't allow user to deactivate buttons - I'm using them as # radio button and you can't 'uncheck' radiobutton by clicking on it @@ -535,7 +536,8 @@ def on_exMore_activate(self, ex, *a): def update_modifiers(self, *a): """Called when sensitivity, feedback or other modifier setting changes.""" - if self._recursing : return + if self._recursing: + return cbRequireClick = self.builder.get_object("cbRequireClick") cbFeedbackSide = self.builder.get_object("cbFeedbackSide") cbFeedback = self.builder.get_object("cbFeedback") @@ -617,15 +619,13 @@ def update_modifiers(self, *a): # Rest - if self.click is not None: - if cbRequireClick.get_active() != self.click: - self.click = cbRequireClick.get_active() - set_action = True + if self.click is not None and cbRequireClick.get_active() != self.click: + self.click = cbRequireClick.get_active() + set_action = True - if self.osd is not None: - if cbOSD.get_active() != self.osd: - self.osd = cbOSD.get_active() - set_action = True + if self.osd is not None and cbOSD.get_active() != self.osd: + self.osd = cbOSD.get_active() + set_action = True if self.rotation_angle != sclRotation.get_value(): self.rotation_angle = sclRotation.get_value() @@ -717,10 +717,7 @@ def is_editable_modifier(action) -> bool: DeadzoneModifier, FeedbackModifier, RotateInputModifier, SmoothModifier, BallModifier)): return True - if isinstance(action, OSDAction): - if action.action is not None: - return True - return False + return bool(isinstance(action, OSDAction) and action.action is not None) @staticmethod @@ -782,7 +779,7 @@ def load_modifiers(self, action, index: int = -1): cbRequireClick.set_active(self.click) cbOSD.set_active(self.osd) sclRotation.set_value(self.rotation_angle) - for i in range(0, len(self.sens)): + for i in range(len(self.sens)): self.sens_widgets[i][3].set_active(self.sens[i] < 0) self.sens_widgets[i][0].set_value(abs(self.sens[i])) # Feedback @@ -792,7 +789,7 @@ def load_modifiers(self, action, index: int = -1): cbFeedback = self.builder.get_object("cbFeedback") cbFeedbackSide.set_active(FEEDBACK_SIDES.index(self.feedback_position)) cbFeedback.set_active(True) - for i in range(0, len(self.feedback)): + for i in range(len(self.feedback)): self.feedback_widgets[i][0].set_value(self.feedback[i]) for grp in self.feedback_widgets: for w in grp[0:-1]: @@ -804,7 +801,7 @@ def load_modifiers(self, action, index: int = -1): cbSmoothing = self.builder.get_object("cbSmoothing") if self.smoothing: cbSmoothing.set_active(True) - for i in range(0, len(self.smoothing_widgets)): + for i in range(len(self.smoothing_widgets)): self.smoothing_widgets[i][1].set_value(self.smoothing[i]) for grp in self.smoothing_widgets: for w in grp[0:-1]: @@ -829,7 +826,7 @@ def load_modifiers(self, action, index: int = -1): cbDeadzone = self.builder.get_object("cbDeadzone") cbDeadzone.set_active(True) cbDeadzoneMode.set_active(DEADZONE_MODES.index(self.deadzone_mode)) - for i in range(0, len(self.deadzone)): + for i in range(len(self.deadzone)): self.deadzone_widgets[i][1].set_value(self.deadzone[i]) for grp in self.deadzone_widgets: @@ -993,7 +990,7 @@ def enable_modifiers(self, action): cbOSD.set_sensitive(cm & Action.MOD_OSD != 0) - def set_sensitivity(self, x: float, y: float = 1.0, z: float = 1.0): + def set_sensitivity(self, x: float, y: float = 1.0, z: float = 1.0) -> None: """Sets sensitivity for edited action.""" self._recursing = True xyz = [ x, y, z ] @@ -1006,9 +1003,10 @@ def set_sensitivity(self, x: float, y: float = 1.0, z: float = 1.0): self._selected_component.modifier_updated() - def get_sensitivity(self) -> tuple[float, float, float]: - """ Returns sensitivity currently set in editor """ - return tuple(self.sens) + def get_sensitivity(self) -> list[float]: + """Returns sensitivity currently set in editor.""" + print(f"CURRENT SENS: {self.sens}") + return self.sens def set_default_sensitivity(self, x: float, y: float = 1.0, z: float = 1.0): diff --git a/scc/gui/ae/gyro_action.py b/scc/gui/ae/gyro_action.py index d43ba779..fb817323 100644 --- a/scc/gui/ae/gyro_action.py +++ b/scc/gui/ae/gyro_action.py @@ -236,7 +236,7 @@ def on_cbInvertGyro_toggled(self, cb, *a): def on_sclSoftLevel_format_value(self, scale, value): - return "%s%%" % (int(value * 100.0),) + return "%s%%" % (int(value * 100.0),) def update(self, *a): @@ -252,8 +252,9 @@ def hidden(self): self.editor.set_default_sensitivity(1, 1, 1) - def send(self, *a): - if self._recursing : return + def send(self, *a) -> None: + if self._recursing: + return cbMode = self.builder.get_object("cbMode") cbYawRoll = self.builder.get_object("cbYawRoll") @@ -297,7 +298,7 @@ def send(self, *a): self.editor.set_action(action) -def is_gyro_enable(modemod): +def is_gyro_enable(modemod) -> bool: """ Returns True if ModeModifier instance is used to create "Gyro Enable Button" """ if isinstance(modemod, ModeModifier): if len(modemod.mods) != 1: diff --git a/scc/gui/key_grabber.py b/scc/gui/key_grabber.py index e691022a..44d02daa 100644 --- a/scc/gui/key_grabber.py +++ b/scc/gui/key_grabber.py @@ -1,6 +1,4 @@ -#!/usr/bin/env python3 -""" -SC-Controller - Action Editor +"""SC-Controller - Action Editor. Allows to edit button or trigger action. """ diff --git a/scc/gui/macro_editor.py b/scc/gui/macro_editor.py index 2f849650..cad11542 100644 --- a/scc/gui/macro_editor.py +++ b/scc/gui/macro_editor.py @@ -1,6 +1,4 @@ -#!/usr/bin/env python3 -""" -SC-Controller - Action Editor +"""SC-Controller - Action Editor. Allows to edit button or trigger action. """ diff --git a/scc/modifiers.py b/scc/modifiers.py index 9bab5547..724d59b5 100644 --- a/scc/modifiers.py +++ b/scc/modifiers.py @@ -836,7 +836,7 @@ def __init__(self, *stuff): self.old_action = None self.shell_commands = {} self.shell_timeout = 0.5 - self.timeout = DoubleclickModifier.DEAFAULT_TIMEOUT + self.timeout = DoubleclickModifier.DEFAULT_TIMEOUT # ShellCommandAction cannot be imported normally, it would create # import cycle of hell @@ -949,7 +949,7 @@ def describe(self, context): return "\n".join([ x.describe(context) for x in l ]) - def to_string(self, multiline=False, pad=0): + def to_string(self, multiline: bool = False, pad=0): if multiline: rv = [ (" " * pad) + "mode(" ] for check in self.mods: @@ -1139,7 +1139,7 @@ def whole(self, mapper, x, y, what): class DoubleclickModifier(Modifier, HapticEnabledAction): COMMAND = "doubleclick" - DEAFAULT_TIMEOUT = 0.2 + DEFAULT_TIMEOUT = 0.2 TIMEOUT_KEY = "time" PROFILE_KEY_PRIORITY = 3 @@ -1150,7 +1150,7 @@ def __init__(self, doubleclickaction, normalaction=None, time=None): self.normalaction = normalaction or NoAction() self.holdaction = NoAction() self.actions = ( self.action, self.normalaction, self.holdaction ) - self.timeout = time or DoubleclickModifier.DEAFAULT_TIMEOUT + self.timeout = time or DoubleclickModifier.DEFAULT_TIMEOUT self.waiting_task = None self.pressed = False self.active = None @@ -1214,7 +1214,7 @@ def describe(self, context): def to_string(self, multiline=False, pad=0): timeout = "" - if DoubleclickModifier.DEAFAULT_TIMEOUT != self.timeout: + if DoubleclickModifier.DEFAULT_TIMEOUT != self.timeout: timeout = ", %s" % (self.timeout) if self.action and self.normalaction and self.holdaction: return "doubleclick(%s, hold(%s, %s)%s)" % ( @@ -1354,7 +1354,7 @@ class SensitivityModifier(Modifier): PROFILE_KEYS = ("sensitivity",) PROFILE_KEY_PRIORITY = -5 - def _mod_init(self, *speeds): + def _mod_init(self, *speeds) -> None: self.speeds = [] for s in speeds: if type(s) in (int, float): @@ -1392,11 +1392,12 @@ def compress(self): def describe(self, context): - if self.name: return self.name + if self.name: + return self.name return self.action.describe(context) - def to_string(self, multiline=False, pad=0): + def to_string(self, multiline: bool = False, pad=0) -> str: speeds = [] + self.speeds while len(speeds) > 1 and speeds[-1] == 1.0: speeds = speeds[0:-1]