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
1725from 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
1835from 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
2339log = 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
0 commit comments