Skip to content

Commit

Permalink
Cleanup python 2-style explicit (object) definitions for classes with…
Browse files Browse the repository at this point in the history
… a sprinkle of linter and typing fixes on top
  • Loading branch information
C0rn3j committed Nov 2, 2024
1 parent 4b1a157 commit 6c726cf
Show file tree
Hide file tree
Showing 56 changed files with 542 additions and 563 deletions.
8 changes: 4 additions & 4 deletions generate_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def find_image(name):
return None


class Line(object):
class Line:

def __init__(self, icon, text):
self.icons = [ icon ]
Expand All @@ -49,7 +49,7 @@ def to_string(self):
return "%-10s: %s" % (",".join([ x for x in self.icons if x ]), self.text)


class LineCollection(object):
class LineCollection:
""" Allows calling add_icon on multiple lines at once """

def __init__(self, *lines):
Expand All @@ -62,7 +62,7 @@ def add_icon(self, icon):
return self


class Box(object):
class Box:
PADDING = 5
SPACING = 2
MIN_WIDTH = 100
Expand Down Expand Up @@ -235,7 +235,7 @@ def place_marker(self, gen, root):



class Generator(object):
class Generator:
PADDING = 10

def __init__(self):
Expand Down
17 changes: 7 additions & 10 deletions scc/actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""SC Controller - Actions.
"""SC Controller - Actions
Action describes what should be done when event from physical controller button,
stick, pad or trigger is generated - typicaly what emulated button, stick or
Expand Down Expand Up @@ -37,7 +37,7 @@
TRIGGERS = ( Axes["ABS_Z"], Axes["ABS_RZ"] )


class Action(object):
class Action:
"""Action is what actually does something in SC-Controller. User can assotiate one or more Action to each available button, stick or pad in profile file."""

# Static dict of all available actions, filled later
Expand Down Expand Up @@ -400,11 +400,8 @@ def trigger(self, mapper: Mapper, position, old_position):
log.warning("Action %s can't handle trigger event", self.__class__.__name__)


class RangeOP(object):
"""
Allows to specify and store axis range and then use it in modeshift
instead of button.
"""
class RangeOP:
"""Allows to specify and store axis range and then use it in modeshift instead of button."""
OPS = ("<", ">", "<=", ">=")

def __init__(self, what, op, value):
Expand Down Expand Up @@ -498,7 +495,7 @@ def __str__(self):
return "%s %s %s" % (nameof(self.what), self.op, self.value)


class HapticEnabledAction(object):
class HapticEnabledAction:
""" Action that can generate haptic feedback """
def __init__(self):
self.haptic = None
Expand All @@ -516,7 +513,7 @@ def get_haptic(self):
return self.haptic


class OSDEnabledAction(object):
class OSDEnabledAction:
""" Action that displays some sort of OSD when executed """
def __init__(self):
self.osd_enabled = False
Expand All @@ -531,7 +528,7 @@ def enable_osd(self, timeout):
self.osd_enabled = True


class SpecialAction(object):
class SpecialAction:
"""
Action that needs to call special_actions_handler (aka sccdaemon instance)
to actually do something.
Expand Down
4 changes: 2 additions & 2 deletions scc/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""SC-Controller - Config.
"""SC Controller - Config
Handles loading, storing and querying config file
"""
Expand All @@ -10,7 +10,7 @@
log = logging.getLogger("Config")


class Config(object):
class Config:
DEFAULTS = {
"autoswitch_osd": True, # True to show OSD message when profile is autoswitched
"autoswitch": [], # Empty list of conditions
Expand Down
4 changes: 2 additions & 2 deletions scc/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

next_id = 1 # Used with fallback controller id generator

class Controller(object):
class Controller:
"""Base class for all controller drivers. Implementations are in scc.drivers package.
Derived class should implement every method from here.
Expand Down Expand Up @@ -121,7 +121,7 @@ def disconnected(self) -> None:
pass


class HapticData(object):
class HapticData:
""" Simple container to hold haptic feedback settings """

def __init__(self, position, amplitude=512, frequency=4, period=1024, count=1):
Expand Down
2 changes: 1 addition & 1 deletion scc/drivers/evdevdrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def parse_axis(axis):
return AxisCalibrationData(scale, offset, center, clamp_min, clamp_max, deadzone)


class EvdevDriver(object):
class EvdevDriver:
SCAN_INTERVAL = 5

def __init__(self):
Expand Down
4 changes: 2 additions & 2 deletions scc/drivers/hiddrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def set_gyro_enabled(self, enabled):
pass


class HIDDrv(object):
class HIDDrv:

def __init__(self, daemon: SCCDaemon):
self.registered = set()
Expand Down Expand Up @@ -650,7 +650,7 @@ def hiddrv_test(cls, args) -> int:
except Exception:
raise InvalidArguments()

class FakeDaemon(object):
class FakeDaemon:

def __init__(self) -> None:
self.poller = Poller()
Expand Down
4 changes: 2 additions & 2 deletions scc/drivers/sc_by_bt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""SC Controller - Steam Controller Driver.
"""SC Controller - Steam Controller Driver
Driver for Steam Controller over bluetooth (evdev)
Expand Down Expand Up @@ -312,7 +312,7 @@ def _input(self, *a):


def hidraw_test(filename):
class FakeDaemon(object):
class FakeDaemon:

def add_error(self, id, error):
log.error(error)
Expand Down
6 changes: 3 additions & 3 deletions scc/drivers/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

log = logging.getLogger("USB")

class USBDevice(object):
class USBDevice:
"""Base class for all handled usb devices."""

def __init__(self, device: USBDevice, handle: USBDeviceHandle) -> None:
Expand Down Expand Up @@ -130,7 +130,7 @@ def flush(self):
def force_restart(self):
"""Restart device, close handle and try to re-grab it again.
Don't use unless absolutelly necessary.
Don't use unless absolutely necessary.
"""
tp = self.device.getVendorID(), self.device.getProductID()
self.close()
Expand Down Expand Up @@ -189,7 +189,7 @@ def close(self):
pass


class USBDriver(object):
class USBDriver:
def __init__(self):
self.daemon = None
self._known_ids = {}
Expand Down
6 changes: 2 additions & 4 deletions scc/gui/ae/axis_action.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
"""
SC-Controller - Action Editor - Axis Component
"""SC Controller - Action Editor - Axis Component
Assigns emulated axis to trigger
"""
Expand Down Expand Up @@ -494,7 +492,7 @@ def on_cbAxisOutput_changed(self, *a):
self.editor.set_action(action)


class FakeMapper(object):
class FakeMapper:
"""
Class that pretends to be mapper used when calling update_osd_area.
It has two purposes: To provide get_xdisplay() method that does what it says
Expand Down
7 changes: 2 additions & 5 deletions scc/gui/ae/gesture.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/env python3
# coding=utf-8
"""
SC-Controller - Action Editor - Gesture Component
"""SC Controller - Action Editor - Gesture Component
Handles gesture recognition settings.
"""
Expand Down Expand Up @@ -205,7 +202,7 @@ def update(self):
self.editor.set_action(a)


class GestureGrabber(object):
class GestureGrabber:
def __init__(self, editor, builder):
self.editor = editor
self.builder = builder
Expand Down
2 changes: 1 addition & 1 deletion scc/gui/ae/gyro_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def send(self, *a) -> None:


def is_gyro_enable(modemod) -> bool:
""" Returns True if ModeModifier instance is used to create "Gyro Enable Button" """
"""Return True if ModeModifier instance is used to create 'Gyro Enable Button'."""
if isinstance(modemod, ModeModifier):
if len(modemod.mods) != 1:
return False
Expand Down
2 changes: 1 addition & 1 deletion scc/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ def convert_old_profiles(self):
log.warning("Failed to convert %s: %s", name, e)


class UndoRedo(object):
class UndoRedo:
""" Just dummy container """
def __init__(self, id, before, after):
self.id = id
Expand Down
11 changes: 3 additions & 8 deletions scc/gui/binding_editor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
"""
SC-Controller - BindingEditor
"""SC Controller - BindingEditor
Base class for main application window and OSD Keyboard bindings editor.
"""
Expand All @@ -23,18 +21,15 @@
from scc.gui.ring_editor import RingEditor


class BindingEditor(object):
class BindingEditor:

def __init__(self, app):
self.button_widgets = {}
self.app = app


def create_binding_buttons(self, use_icons=True, enable_press=True):
"""
Creates ControllerWidget instances for available Gtk.Buttons defined
in glade file.
"""
"""Create ControllerWidget instances for available Gtk.Buttons defined in glade file."""
for b in BUTTONS:
w = self.builder.get_object("bt" + b.name)
if w:
Expand Down
25 changes: 10 additions & 15 deletions scc/gui/creg/data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
"""
SC-Controller - Controller Registration data
"""SC Controller - Controller Registration data
Dummy container classes
"""
Expand All @@ -11,9 +9,9 @@
log = logging.getLogger("CReg.data")


class AxisData(object):
"""
(Almost) dumb container.
class AxisData:
"""(Almost) dumb container.
Stores position, center and limits for single axis.
"""

Expand All @@ -31,9 +29,7 @@ def __init__(self, name, xy, min=STICK_PAD_MAX, max=STICK_PAD_MIN):


def reset(self):
"""
Resets min and max value so axis can (has to be) recalibrated again
"""
"""Reset min and max value so axis can (has to be) recalibrated again"""
self.min = STICK_PAD_MAX
self.max = STICK_PAD_MIN

Expand All @@ -43,9 +39,8 @@ def __repr__(self):


def set_position(self, value):
"""
Returns (changed, x), value determining if axis limits were changed and
current position position.
"""Return (changed, x), value determining if axis limits were changed and current position position.
translated to range of (STICK_PAD_MIN, STICK_PAD_MAX)
"""
changed = False
Expand All @@ -67,9 +62,9 @@ def set_position(self, value):
return changed, 0


class DPadEmuData(object):
"""
Dumb container that stores dpad emulation data.
class DPadEmuData:
"""Dumb container that stores dpad emulation data.
DPAd emulation is used, for example, on PS3 controller, where dpad does not
inputs as 2 axes, but as 4 buttons.
Expand Down
11 changes: 3 additions & 8 deletions scc/gui/creg/grabs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
"""
SC-Controller - Controller Registration - Grabs
"""SC Controller - Controller Registration - Grabs
Helper classes for grabbing buttons and axes from physical gamepads.
Expand All @@ -16,11 +14,8 @@
log = logging.getLogger("CReg.grabs")


class InputGrabber(object):
"""
Base class for input grabbing. Waits for physical button being pressed
by default.
"""
class InputGrabber:
"""Base class for input grabbing. Waits for physical button being pressed by default."""

def __init__(self, parent, what, text=_("Press a button...")):
self.parent = parent
Expand Down
13 changes: 6 additions & 7 deletions scc/gui/editor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""SC-Controller - Action Editor.
"""SC Controller - Action Editor
Allows to edit button or trigger action.
"""
Expand All @@ -17,11 +17,11 @@
log = logging.getLogger("Editor")


class ComboSetter(object):
class ComboSetter:

def set_cb(self, cb, key, keyindex=0) -> bool:
"""Set combobox value.
def set_cb(self, cb, key, keyindex=0):
"""
Sets combobox value.
Returns True on success or False if key is not found.
"""
model = cb.get_model()
Expand All @@ -31,8 +31,7 @@ def set_cb(self, cb, key, keyindex=0):
cb.set_active_iter(row.iter)
self._recursing = False
return True
else:
log.warning("Failed to set combobox value, key '%s' not found", key)
log.warning("Failed to set combobox value, key '%s' not found", key)
self._recursing = False
return False

Expand Down
Loading

0 comments on commit 6c726cf

Please sign in to comment.