Skip to content

Commit 0cf063d

Browse files
committed
chore: Another batch of ruff check --fix
1 parent bb49686 commit 0cf063d

25 files changed

Lines changed: 427 additions & 536 deletions

scc/foreign/vdf.py

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
#!/usr/bin/env python3
2-
"""
3-
Imports VDF profile and converts it to Profile object.
2+
"""Imports VDF profile and converts it to Profile object.
43
"""
54

6-
from scc.uinput import Keys, Axes, Rels
7-
from scc.actions import Action, NoAction, ButtonAction, DPadAction, XYAction
8-
from scc.actions import HatRightAction, TriggerAction, MouseAction
9-
from scc.actions import HatUpAction, HatDownAction, HatLeftAction
10-
from scc.actions import AxisAction, RelAreaAction, MultiAction
11-
from scc.special_actions import ChangeProfileAction, GridMenuAction, RadialMenuAction, MenuAction
12-
from scc.modifiers import SensitivityModifier, ClickModifier, FeedbackModifier
13-
from scc.constants import SCButtons, HapticPos, TRIGGER_CLICK, YAW, ROLL
14-
from scc.modifiers import BallModifier, DoubleclickModifier
15-
from scc.modifiers import HoldModifier, ModeModifier
16-
from scc.parser import ActionParser, ParseError
5+
import logging
6+
7+
from scc.actions import (
8+
Action,
9+
AxisAction,
10+
ButtonAction,
11+
DPadAction,
12+
HatDownAction,
13+
HatLeftAction,
14+
HatRightAction,
15+
HatUpAction,
16+
MouseAction,
17+
MultiAction,
18+
NoAction,
19+
RelAreaAction,
20+
TriggerAction,
21+
XYAction,
22+
)
23+
from scc.constants import ROLL, TRIGGER_CLICK, YAW, HapticPos, SCButtons
24+
from scc.lib.vdf import ensure_list, parse_vdf
1725
from scc.menu_data import MenuData, MenuItem
26+
from scc.modifiers import (
27+
BallModifier,
28+
DoubleclickModifier,
29+
FeedbackModifier,
30+
HoldModifier,
31+
ModeModifier,
32+
SensitivityModifier,
33+
)
34+
from scc.parser import ActionParser, ParseError
1835
from scc.profile import Profile
19-
from scc.lib.vdf import parse_vdf, ensure_list
20-
21-
import logging
36+
from scc.special_actions import ChangeProfileAction, GridMenuAction, MenuAction, RadialMenuAction
37+
from scc.uinput import Axes, Keys, Rels
2238

2339
log = logging.getLogger("import.vdf")
2440

@@ -87,8 +103,7 @@ def __init__(self, name="Unnamed"):
87103
self.action_set_switches = set()
88104

89105
def parse_action(self, lst_or_str, button=None):
90-
"""
91-
Parses action from vdf file. a_string can be either string or list of
106+
"""Parses action from vdf file. a_string can be either string or list of
92107
strings, in which case MultiAction is returned.
93108
94109
Returns Action instance or ParseError if action is not recognized.
@@ -158,8 +173,7 @@ def parse_action(self, lst_or_str, button=None):
158173

159174
@staticmethod
160175
def parse_modifiers(group, action, side):
161-
"""
162-
If passed group or activator has 'settings' key, converts known
176+
"""If passed group or activator has 'settings' key, converts known
163177
settings to one or more Modifier.
164178
165179
Returns resulting Action
@@ -221,17 +235,16 @@ def convert_button_name(name):
221235
raise ParseError("Unknown button: '%s'" % (name,))
222236

223237
def parse_button(self, bdef, button=None):
224-
"""
225-
Parses button definition from vdf file.
238+
"""Parses button definition from vdf file.
226239
Parameter can be either string, as used in v2, or dict used in v3.
227240
"""
228241
if type(bdef) == str:
229242
# V2
230243
return self.parse_action(bdef, button)
231-
elif type(bdef) == list:
244+
if type(bdef) == list:
232245
# V2
233246
return MultiAction.make(*[self.parse_action(x, button) for x in bdef])
234-
elif "activators" in bdef:
247+
if "activators" in bdef:
235248
# V3
236249
act_actions = []
237250
for k in ("Full_Press", "Double_Press", "Long_Press"):
@@ -246,19 +259,16 @@ def parse_button(self, bdef, button=None):
246259
normal, double, hold = act_actions
247260
if not double and not hold:
248261
return normal
249-
elif hold and not double:
262+
if hold and not double:
250263
return HoldModifier(hold, normal)
251-
else:
252-
action = DoubleclickModifier(double, normal)
253-
action.holdaction = hold
254-
return action
255-
else:
256-
log.warning("Failed to parse button definition: %s" % (bdef,))
264+
action = DoubleclickModifier(double, normal)
265+
action.holdaction = hold
266+
return action
267+
log.warning("Failed to parse button definition: %s" % (bdef,))
257268

258269
@staticmethod
259270
def get_inputs(group):
260-
"""
261-
Returns 'inputs' or 'bindings', whichever exists in passed group.
271+
"""Returns 'inputs' or 'bindings', whichever exists in passed group.
262272
If neither exists, return None.
263273
"""
264274
if "inputs" in group:
@@ -276,11 +286,10 @@ def find_group(data, id):
276286
return None
277287

278288
def parse_group(self, group, side):
279-
"""
280-
Parses output (group) from vdf profile.
289+
"""Parses output (group) from vdf profile.
281290
Returns Action.
282291
"""
283-
if not "mode" in group:
292+
if "mode" not in group:
284293
raise ParseError("Group without mode")
285294
mode = group["mode"]
286295
inputs = VDFProfile.get_inputs(group)
@@ -342,7 +351,7 @@ def parse_group(self, group, side):
342351
"item_%s" % (next_item_id,),
343352
action.describe(Action.AC_BUTTON),
344353
action,
345-
)
354+
),
346355
)
347356
next_item_id += 1
348357
# Menu is stored in profile, with generated ID
@@ -446,9 +455,7 @@ def parse_switches(self, group):
446455
def parse_input_binding(self, data, group_id, binding):
447456
group = VDFProfile.find_group(data, group_id)
448457
if group and "mode" in group:
449-
if binding.startswith("switch"):
450-
self.parse_switches(group)
451-
elif binding.startswith("button_diamond"):
458+
if binding.startswith("switch") or binding.startswith("button_diamond"):
452459
self.parse_switches(group)
453460
else:
454461
if binding.startswith("right_"):
@@ -498,25 +505,25 @@ def get_by_binding(self, binding):
498505
"""
499506
if binding in SCButtons.__members__.values():
500507
return self.buttons[binding]
501-
elif binding.startswith("left_trackpad"):
508+
if binding.startswith("left_trackpad"):
502509
return self.pads[Profile.LEFT]
503-
elif binding.startswith("right_trackpad"):
510+
if binding.startswith("right_trackpad"):
504511
return self.pads[Profile.RIGHT]
505-
elif binding.startswith("left_trigger"):
512+
if binding.startswith("left_trigger"):
506513
return self.triggers[Profile.LEFT]
507-
elif binding.startswith("right_trigger"):
514+
if binding.startswith("right_trigger"):
508515
return self.triggers[Profile.RIGHT]
509-
elif binding.startswith("joystick"):
516+
if binding.startswith("joystick"):
510517
return self.stick
511-
elif binding.startswith("gyro"):
518+
if binding.startswith("gyro"):
512519
return self.gyro
513520
raise ParseError("Unknown group source binding: '%s'" % (binding,))
514521

515522
@staticmethod
516523
def _load_preset(data, profile, preset):
517524
profile.modeshifts = {}
518525
profile.modeshift_buttons = {}
519-
if not "group_source_bindings" in preset:
526+
if "group_source_bindings" not in preset:
520527
# Empty preset
521528
return
522529

@@ -567,7 +574,7 @@ def load(self, filename):
567574
568575
May raise ValueError.
569576
"""
570-
with open(filename, "r") as file:
577+
with open(filename) as file:
571578
data = parse_vdf(file)
572579
self.load_data(data)
573580

scc/foreign/vdffz.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
#!/usr/bin/env python3
2-
"""
3-
Imports VDFFZ profile and converts it to Profile object.
2+
"""Imports VDFFZ profile and converts it to Profile object.
43
VDFFZ is just VDF encapsulated in json, so this just gets one value and calls
54
VDFProfile to decode rest.
65
"""
76

8-
from .vdf import VDFProfile
7+
import json
8+
import logging
9+
910
from scc.lib.vdf import parse_vdf
1011

11-
import json, logging
12+
from .vdf import VDFProfile
1213

1314
log = logging.getLogger("import.vdffz")
1415

1516

1617
class VDFFZProfile(VDFProfile):
1718
def load(self, filename):
1819
try:
19-
data = json.loads(open(filename, "r").read())
20-
except Exception as e:
20+
data = json.loads(open(filename).read())
21+
except Exception:
2122
raise ValueError("Failed to parse JSON")
2223
if "ConfigData" not in data:
2324
raise ValueError("ConfigData missing in JSON")

scc/gui/action_editor.py

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
"""
55

66
from __future__ import annotations
7+
78
import importlib
89
import logging
910
import math
10-
import os
11-
import types
1211

13-
from gi.repository import Gtk, Gdk, GLib
12+
from gi.repository import GLib, Gtk
1413

15-
from scc.actions import Action, NoAction, RingAction, TriggerAction, XYAction
14+
from scc.actions import Action, NoAction, RingAction, TriggerAction
1615
from scc.constants import CUT, LINEAR, MINIMUM, ROUND, HapticPos, SCButtons
17-
from scc.controller import HapticData
1816
from scc.gui.ae import AEComponent
19-
from scc.gui.controller_widget import BUTTONS, GYROS, PADS, PRESSABLE, STICKS, TRIGGERS
17+
from scc.gui.controller_widget import GYROS, PADS, PRESSABLE, STICKS, TRIGGERS
2018
from scc.gui.dwsnc import headerbar
2119
from scc.gui.editor import Editor
2220
from scc.gui.macro_editor import MacroEditor
@@ -31,14 +29,13 @@
3129
DeadzoneModifier,
3230
FeedbackModifier,
3331
ModeModifier,
34-
Modifier,
3532
NameModifier,
3633
RotateInputModifier,
3734
SensitivityModifier,
3835
SmoothModifier,
3936
)
4037
from scc.profile import Profile
41-
from scc.special_actions import GesturesAction, MenuAction, OSDAction
38+
from scc.special_actions import OSDAction
4239
from scc.tools import _, nameof
4340

4441
log = logging.getLogger("ActionEditor")
@@ -151,7 +148,7 @@ def setup_widgets(self):
151148
self.builder.get_object("lblSens%s" % (XYZ[i],)),
152149
self.builder.get_object("btClearSens%s" % (XYZ[i],)),
153150
self.builder.get_object("cbSensInvert%s" % (XYZ[i],)),
154-
)
151+
),
155152
)
156153
for key in AFP:
157154
i = AFP.index(key)
@@ -162,7 +159,7 @@ def setup_widgets(self):
162159
self.builder.get_object("lblF%s" % (key,)),
163160
self.builder.get_object("btClearF%s" % (key,)),
164161
self.feedback[i], # default value
165-
)
162+
),
166163
)
167164
for key in SMT:
168165
i = SMT.index(key)
@@ -172,7 +169,7 @@ def setup_widgets(self):
172169
self.builder.get_object("sclSmooth%s" % (key,)),
173170
self.builder.get_object("btClearSmooth%s" % (key,)),
174171
self.builder.get_object("sclSmooth%s" % (key,)).get_value(),
175-
)
172+
),
176173
)
177174
for key in DZN:
178175
i = DZN.index(key)
@@ -183,7 +180,7 @@ def setup_widgets(self):
183180
self.builder.get_object("sclDZ%s" % (key,)),
184181
self.builder.get_object("btClearDZ%s" % (key,)),
185182
self.deadzone[i], # default value
186-
)
183+
),
187184
)
188185

189186
if self.app.osd_mode:
@@ -386,29 +383,25 @@ def hide_modifiers(self):
386383
self.builder.get_object("exMore").set_visible(False)
387384

388385
def hide_advanced_settings(self):
389-
"""
390-
Hides entire 'Advanced Settings' expander.
386+
"""Hides entire 'Advanced Settings' expander.
391387
"""
392388
self.builder.get_object("exMore").set_visible(False)
393389
self.builder.get_object("rvMore").set_visible(False)
394390

395391
def hide_modeshift(self):
396-
"""
397-
Hides Mode Shift button.
392+
"""Hides Mode Shift button.
398393
Used when displaying ActionEditor from ModeshiftEditor
399394
"""
400395
self.builder.get_object("btModeshift").set_visible(False)
401396

402397
def hide_macro(self):
403-
"""
404-
Hides Macro button.
398+
"""Hides Macro button.
405399
Used when editing macro of pad/stick bindings.
406400
"""
407401
self.builder.get_object("btMacro").set_visible(False)
408402

409403
def hide_ring(self):
410-
"""
411-
Hides Ring Bindings button.
404+
"""Hides Ring Bindings button.
412405
Used when editing anything but pad.
413406
"""
414407
self.builder.get_object("btInnerRing").set_visible(False)
@@ -918,8 +911,7 @@ def on_cbPreview_toggled(self, cb):
918911
self._replaced_action = None
919912

920913
def enable_preview(self, action):
921-
"""
922-
Enables or disables and hides 'preview immediately' option, based on
914+
"""Enables or disables and hides 'preview immediately' option, based on
923915
if currently selected action supports it.
924916
"""
925917
cbPreview = self.builder.get_object("cbPreview")
@@ -928,8 +920,7 @@ def enable_preview(self, action):
928920
cbPreview.set_sensitive(enabled)
929921

930922
def enable_modifiers(self, action):
931-
"""
932-
Enables or disables and hides modifier settings according to what
923+
"""Enables or disables and hides modifier settings according to what
933924
is applicable for specified action AND what's allowed for current
934925
editor mode.
935926
@@ -1048,10 +1039,9 @@ def on_sclFFrequency_format_value(self, scale, value):
10481039
def on_sclFriction_format_value(self, scale, value):
10491040
if value <= 0:
10501041
return "%0.3f" % (0,)
1051-
elif value >= 6:
1042+
if value >= 6:
10521043
return "%0.3f" % (1000.00,)
1053-
else:
1054-
return "%0.3f" % ((10.0**value) / 1000.0)
1044+
return "%0.3f" % ((10.0**value) / 1000.0)
10551045

10561046
def on_btClearFriction_clicked(self, *a):
10571047
sclFriction = self.builder.get_object("sclFriction")

0 commit comments

Comments
 (0)