Skip to content

Commit

Permalink
Fix DEFAULT_TIMEOUT typo and add linter fixes and type hints after di…
Browse files Browse the repository at this point in the history
…gging through action editor

Glade page for action editor was also updated
  • Loading branch information
C0rn3j committed Sep 28, 2024
1 parent 926b053 commit 221aa5b
Show file tree
Hide file tree
Showing 9 changed files with 515 additions and 491 deletions.
913 changes: 470 additions & 443 deletions glade/action_editor.glade

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions scc/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion scc/drivers/hiddrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion scc/drivers/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
42 changes: 20 additions & 22 deletions scc/gui/action_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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]:
Expand All @@ -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]:
Expand All @@ -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:
Expand Down Expand Up @@ -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 ]
Expand All @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions scc/gui/ae/gyro_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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")
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions scc/gui/key_grabber.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
"""
SC-Controller - Action Editor
"""SC-Controller - Action Editor.
Allows to edit button or trigger action.
"""
Expand Down
4 changes: 1 addition & 3 deletions scc/gui/macro_editor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
"""
SC-Controller - Action Editor
"""SC-Controller - Action Editor.
Allows to edit button or trigger action.
"""
Expand Down
17 changes: 9 additions & 8 deletions scc/modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)" % (
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 221aa5b

Please sign in to comment.