Skip to content

Commit 6c726cf

Browse files
committed
Cleanup python 2-style explicit (object) definitions for classes with a sprinkle of linter and typing fixes on top
1 parent 4b1a157 commit 6c726cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+542
-563
lines changed

generate_svg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def find_image(name):
2828
return None
2929

3030

31-
class Line(object):
31+
class Line:
3232

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

5151

52-
class LineCollection(object):
52+
class LineCollection:
5353
""" Allows calling add_icon on multiple lines at once """
5454

5555
def __init__(self, *lines):
@@ -62,7 +62,7 @@ def add_icon(self, icon):
6262
return self
6363

6464

65-
class Box(object):
65+
class Box:
6666
PADDING = 5
6767
SPACING = 2
6868
MIN_WIDTH = 100
@@ -235,7 +235,7 @@ def place_marker(self, gen, root):
235235

236236

237237

238-
class Generator(object):
238+
class Generator:
239239
PADDING = 10
240240

241241
def __init__(self):

scc/actions.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""SC Controller - Actions.
1+
"""SC Controller - Actions
22
33
Action describes what should be done when event from physical controller button,
44
stick, pad or trigger is generated - typicaly what emulated button, stick or
@@ -37,7 +37,7 @@
3737
TRIGGERS = ( Axes["ABS_Z"], Axes["ABS_RZ"] )
3838

3939

40-
class Action(object):
40+
class Action:
4141
"""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."""
4242

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

402402

403-
class RangeOP(object):
404-
"""
405-
Allows to specify and store axis range and then use it in modeshift
406-
instead of button.
407-
"""
403+
class RangeOP:
404+
"""Allows to specify and store axis range and then use it in modeshift instead of button."""
408405
OPS = ("<", ">", "<=", ">=")
409406

410407
def __init__(self, what, op, value):
@@ -498,7 +495,7 @@ def __str__(self):
498495
return "%s %s %s" % (nameof(self.what), self.op, self.value)
499496

500497

501-
class HapticEnabledAction(object):
498+
class HapticEnabledAction:
502499
""" Action that can generate haptic feedback """
503500
def __init__(self):
504501
self.haptic = None
@@ -516,7 +513,7 @@ def get_haptic(self):
516513
return self.haptic
517514

518515

519-
class OSDEnabledAction(object):
516+
class OSDEnabledAction:
520517
""" Action that displays some sort of OSD when executed """
521518
def __init__(self):
522519
self.osd_enabled = False
@@ -531,7 +528,7 @@ def enable_osd(self, timeout):
531528
self.osd_enabled = True
532529

533530

534-
class SpecialAction(object):
531+
class SpecialAction:
535532
"""
536533
Action that needs to call special_actions_handler (aka sccdaemon instance)
537534
to actually do something.

scc/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""SC-Controller - Config.
1+
"""SC Controller - Config
22
33
Handles loading, storing and querying config file
44
"""
@@ -10,7 +10,7 @@
1010
log = logging.getLogger("Config")
1111

1212

13-
class Config(object):
13+
class Config:
1414
DEFAULTS = {
1515
"autoswitch_osd": True, # True to show OSD message when profile is autoswitched
1616
"autoswitch": [], # Empty list of conditions

scc/controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
next_id = 1 # Used with fallback controller id generator
1616

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

123123

124-
class HapticData(object):
124+
class HapticData:
125125
""" Simple container to hold haptic feedback settings """
126126

127127
def __init__(self, position, amplitude=512, frequency=4, period=1024, count=1):

scc/drivers/evdevdrv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def parse_axis(axis):
359359
return AxisCalibrationData(scale, offset, center, clamp_min, clamp_max, deadzone)
360360

361361

362-
class EvdevDriver(object):
362+
class EvdevDriver:
363363
SCAN_INTERVAL = 5
364364

365365
def __init__(self):

scc/drivers/hiddrv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ def set_gyro_enabled(self, enabled):
576576
pass
577577

578578

579-
class HIDDrv(object):
579+
class HIDDrv:
580580

581581
def __init__(self, daemon: SCCDaemon):
582582
self.registered = set()
@@ -650,7 +650,7 @@ def hiddrv_test(cls, args) -> int:
650650
except Exception:
651651
raise InvalidArguments()
652652

653-
class FakeDaemon(object):
653+
class FakeDaemon:
654654

655655
def __init__(self) -> None:
656656
self.poller = Poller()

scc/drivers/sc_by_bt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""SC Controller - Steam Controller Driver.
1+
"""SC Controller - Steam Controller Driver
22
33
Driver for Steam Controller over bluetooth (evdev)
44
@@ -312,7 +312,7 @@ def _input(self, *a):
312312

313313

314314
def hidraw_test(filename):
315-
class FakeDaemon(object):
315+
class FakeDaemon:
316316

317317
def add_error(self, id, error):
318318
log.error(error)

scc/drivers/usb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
log = logging.getLogger("USB")
2626

27-
class USBDevice(object):
27+
class USBDevice:
2828
"""Base class for all handled usb devices."""
2929

3030
def __init__(self, device: USBDevice, handle: USBDeviceHandle) -> None:
@@ -130,7 +130,7 @@ def flush(self):
130130
def force_restart(self):
131131
"""Restart device, close handle and try to re-grab it again.
132132
133-
Don't use unless absolutelly necessary.
133+
Don't use unless absolutely necessary.
134134
"""
135135
tp = self.device.getVendorID(), self.device.getProductID()
136136
self.close()
@@ -189,7 +189,7 @@ def close(self):
189189
pass
190190

191191

192-
class USBDriver(object):
192+
class USBDriver:
193193
def __init__(self):
194194
self.daemon = None
195195
self._known_ids = {}

scc/gui/ae/axis_action.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#!/usr/bin/env python3
2-
"""
3-
SC-Controller - Action Editor - Axis Component
1+
"""SC Controller - Action Editor - Axis Component
42
53
Assigns emulated axis to trigger
64
"""
@@ -494,7 +492,7 @@ def on_cbAxisOutput_changed(self, *a):
494492
self.editor.set_action(action)
495493

496494

497-
class FakeMapper(object):
495+
class FakeMapper:
498496
"""
499497
Class that pretends to be mapper used when calling update_osd_area.
500498
It has two purposes: To provide get_xdisplay() method that does what it says

scc/gui/ae/gesture.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#!/usr/bin/env python3
2-
# coding=utf-8
3-
"""
4-
SC-Controller - Action Editor - Gesture Component
1+
"""SC Controller - Action Editor - Gesture Component
52
63
Handles gesture recognition settings.
74
"""
@@ -205,7 +202,7 @@ def update(self):
205202
self.editor.set_action(a)
206203

207204

208-
class GestureGrabber(object):
205+
class GestureGrabber:
209206
def __init__(self, editor, builder):
210207
self.editor = editor
211208
self.builder = builder

scc/gui/ae/gyro_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def send(self, *a) -> None:
299299

300300

301301
def is_gyro_enable(modemod) -> bool:
302-
""" Returns True if ModeModifier instance is used to create "Gyro Enable Button" """
302+
"""Return True if ModeModifier instance is used to create 'Gyro Enable Button'."""
303303
if isinstance(modemod, ModeModifier):
304304
if len(modemod.mods) != 1:
305305
return False

scc/gui/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ def convert_old_profiles(self):
16991699
log.warning("Failed to convert %s: %s", name, e)
17001700

17011701

1702-
class UndoRedo(object):
1702+
class UndoRedo:
17031703
""" Just dummy container """
17041704
def __init__(self, id, before, after):
17051705
self.id = id

scc/gui/binding_editor.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#!/usr/bin/env python3
2-
"""
3-
SC-Controller - BindingEditor
1+
"""SC Controller - BindingEditor
42
53
Base class for main application window and OSD Keyboard bindings editor.
64
"""
@@ -23,18 +21,15 @@
2321
from scc.gui.ring_editor import RingEditor
2422

2523

26-
class BindingEditor(object):
24+
class BindingEditor:
2725

2826
def __init__(self, app):
2927
self.button_widgets = {}
3028
self.app = app
3129

3230

3331
def create_binding_buttons(self, use_icons=True, enable_press=True):
34-
"""
35-
Creates ControllerWidget instances for available Gtk.Buttons defined
36-
in glade file.
37-
"""
32+
"""Create ControllerWidget instances for available Gtk.Buttons defined in glade file."""
3833
for b in BUTTONS:
3934
w = self.builder.get_object("bt" + b.name)
4035
if w:

scc/gui/creg/data.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#!/usr/bin/env python3
2-
"""
3-
SC-Controller - Controller Registration data
1+
"""SC Controller - Controller Registration data
42
53
Dummy container classes
64
"""
@@ -11,9 +9,9 @@
119
log = logging.getLogger("CReg.data")
1210

1311

14-
class AxisData(object):
15-
"""
16-
(Almost) dumb container.
12+
class AxisData:
13+
"""(Almost) dumb container.
14+
1715
Stores position, center and limits for single axis.
1816
"""
1917

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

3230

3331
def reset(self):
34-
"""
35-
Resets min and max value so axis can (has to be) recalibrated again
36-
"""
32+
"""Reset min and max value so axis can (has to be) recalibrated again"""
3733
self.min = STICK_PAD_MAX
3834
self.max = STICK_PAD_MIN
3935

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

4440

4541
def set_position(self, value):
46-
"""
47-
Returns (changed, x), value determining if axis limits were changed and
48-
current position position.
42+
"""Return (changed, x), value determining if axis limits were changed and current position position.
43+
4944
translated to range of (STICK_PAD_MIN, STICK_PAD_MAX)
5045
"""
5146
changed = False
@@ -67,9 +62,9 @@ def set_position(self, value):
6762
return changed, 0
6863

6964

70-
class DPadEmuData(object):
71-
"""
72-
Dumb container that stores dpad emulation data.
65+
class DPadEmuData:
66+
"""Dumb container that stores dpad emulation data.
67+
7368
DPAd emulation is used, for example, on PS3 controller, where dpad does not
7469
inputs as 2 axes, but as 4 buttons.
7570

scc/gui/creg/grabs.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#!/usr/bin/env python3
2-
"""
3-
SC-Controller - Controller Registration - Grabs
1+
"""SC Controller - Controller Registration - Grabs
42
53
Helper classes for grabbing buttons and axes from physical gamepads.
64
@@ -16,11 +14,8 @@
1614
log = logging.getLogger("CReg.grabs")
1715

1816

19-
class InputGrabber(object):
20-
"""
21-
Base class for input grabbing. Waits for physical button being pressed
22-
by default.
23-
"""
17+
class InputGrabber:
18+
"""Base class for input grabbing. Waits for physical button being pressed by default."""
2419

2520
def __init__(self, parent, what, text=_("Press a button...")):
2621
self.parent = parent

scc/gui/editor.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""SC-Controller - Action Editor.
1+
"""SC Controller - Action Editor
22
33
Allows to edit button or trigger action.
44
"""
@@ -17,11 +17,11 @@
1717
log = logging.getLogger("Editor")
1818

1919

20-
class ComboSetter(object):
20+
class ComboSetter:
21+
22+
def set_cb(self, cb, key, keyindex=0) -> bool:
23+
"""Set combobox value.
2124
22-
def set_cb(self, cb, key, keyindex=0):
23-
"""
24-
Sets combobox value.
2525
Returns True on success or False if key is not found.
2626
"""
2727
model = cb.get_model()
@@ -31,8 +31,7 @@ def set_cb(self, cb, key, keyindex=0):
3131
cb.set_active_iter(row.iter)
3232
self._recursing = False
3333
return True
34-
else:
35-
log.warning("Failed to set combobox value, key '%s' not found", key)
34+
log.warning("Failed to set combobox value, key '%s' not found", key)
3635
self._recursing = False
3736
return False
3837

0 commit comments

Comments
 (0)