Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_feedback(self):
"""
Tests if FeedbackModifier can be converted to string and parsed
back to same.
"""
# TODO: Here, with actual tests
assert _parses_as_itself(FeedbackModifier(HapticPos.BOTH, MouseAction()))
assert _parses_as_itself(FeedbackModifier(HapticPos.BOTH, 10, MouseAction()))
assert _parses_as_itself(FeedbackModifier(HapticPos.BOTH, 10, 8, MouseAction()))
assert _parses_as_itself(FeedbackModifier(HapticPos.BOTH, 10, 8, 512, MouseAction()))
# Bellow was failing in past
assert _parses_as_itself(FeedbackModifier(HapticPos.LEFT, MouseAction()))
assert _parses_as_itself(FeedbackModifier(HapticPos.RIGHT, MouseAction()))
action = action.strip()
if isinstance(action, MenuAction):
if self.name == "bcs" and action.menu_id == "Default.menu":
# Special case, this action is expected in every profile,
# so there is no need to draw it here
return LineCollection()
elif isinstance(action, DPadAction):
return LineCollection(
self.add("DPAD_UP", Action.AC_BUTTON, action.actions[0]),
self.add("DPAD_DOWN", Action.AC_BUTTON, action.actions[1]),
self.add("DPAD_LEFT", Action.AC_BUTTON, action.actions[2]),
self.add("DPAD_RIGHT", Action.AC_BUTTON, action.actions[3])
)
elif isinstance(action, XYAction):
if isinstance(action.x, MouseAction) and isinstance(action.y, MouseAction):
if action.x.get_axis() in (Rels.REL_HWHEEL, Rels.REL_WHEEL):
# Special case, pad bound to wheel
line = Line(icon, _("Mouse Wheel"))
self.lines.append(line)
return line
return LineCollection(
self.add("AXISX", Action.AC_BUTTON, action.x),
self.add("AXISY", Action.AC_BUTTON, action.y)
)
line = Line(icon, action.describe(context))
self.lines.append(line)
return line
def handles(self, mode, action):
if isinstance(action, (NoAction, MouseAction, CircularModifier,
InvalidAction, AreaAction, ButtonAction)):
return True
if isinstance(action, BallModifier):
if isinstance(action.action, XYAction):
return (
isinstance(action.action.x, (AxisAction, MouseAction))
and isinstance(action.action.x, (AxisAction, MouseAction))
)
return isinstance(action.action, MouseAction)
if isinstance(action, XYAction):
p = [ None, None ]
for x in (0, 1):
if len(action.actions[0].strip().parameters) >= x:
if len(action.actions[x].strip().parameters) > 0:
p[x] = action.actions[x].strip().parameters[0]
if p[0] == Axes.ABS_X and p[1] == Axes.ABS_Y:
return True
elif p[0] == Axes.ABS_RX and p[1] == Axes.ABS_RY:
return True
elif p[0] == Axes.ABS_HAT0X and p[1] == Axes.ABS_HAT0Y:
return True
elif p[0] == Rels.REL_HWHEEL and p[1] == Rels.REL_WHEEL:
return True
iswheelaction = ( lambda x : isinstance(x, MouseAction) and
x.parameters[0] in (Rels.REL_HWHEEL, Rels.REL_WHEEL) )
for p in (Profile.LEFT, Profile.RIGHT):
action = XYAction(AxisAction(Axes.ABS_RX), AxisAction(Axes.ABS_RY))
elif mode == "joystick_camera":
output_joystick = 0
if 'output_joystick' in settings:
output_joystick = int(settings['output_joystick'])
if output_joystick == 0:
action = BallModifier(XYAction(AxisAction(Axes.ABS_X), AxisAction(Axes.ABS_Y)))
elif output_joystick == 1:
action = BallModifier(XYAction(AxisAction(Axes.ABS_RX), AxisAction(Axes.ABS_RY)))
else:
# TODO: Absolute mouse? Doesn't seems to do anything in Steam
action = BallModifier(SensitivityModifier(0.1, 0.1, MouseAction()))
elif mode == "mouse_joystick":
action = BallModifier(XYAction(AxisAction(Axes.ABS_RX), AxisAction(Axes.ABS_RY)))
elif mode == "scrollwheel":
action = BallModifier(XYAction(MouseAction(Rels.REL_HWHEEL), MouseAction(Rels.REL_WHEEL)))
elif mode == "touch_menu":
# Touch menu is converted to GridMenu
items = []
next_item_id = 1
for k in inputs:
action = self.parse_button(inputs[k])
items.append(MenuItem(
"item_%s" % (next_item_id,),
action.describe(Action.AC_BUTTON),
action
))
next_item_id += 1
# Menu is stored in profile, with generated ID
menu_id = "menu_%s" % (self.next_menu_id,)
self.next_menu_id += 1
self.menus[menu_id] = MenuData(*items)
def load_mouse_action(self, action):
cbMouseOutput = self.builder.get_object("cbMouseOutput")
cbAxisOutput = self.builder.get_object("cbAxisOutput")
self._recursing = True
if isinstance(action, MouseAction):
self.set_cb(cbMouseOutput, "mouse", 1)
self.set_cb(cbAxisOutput, "mouse", 2)
elif isinstance(action, XYAction):
if isinstance(action.x, AxisAction):
if action.x.parameters[0] == Axes.ABS_X:
self.set_cb(cbMouseOutput, "left", 1)
else:
self.set_cb(cbMouseOutput, "right", 1)
self.set_cb(cbAxisOutput, "mouse", 2)
elif isinstance(action.x, MouseAction):
if self.editor.get_id() in STICKS:
self.set_cb(cbAxisOutput, "wheel_stick", 2)
else:
self.set_cb(cbAxisOutput, "wheel_pad", 2)
self._recursing = False
)
elif mode == "absolute_mouse":
if "click" in inputs:
if side == Profile.LEFT:
self.add_by_binding(SCButtons.LPAD,
self.parse_button(inputs["click"]))
else:
self.add_by_binding(SCButtons.RPAD,
self.parse_button(inputs["click"]))
if "gyro_axis" in settings:
if int(settings["gyro_axis"]) == 1:
action = MouseAction(ROLL)
else:
action = MouseAction(YAW)
else:
action = MouseAction()
elif mode == "mouse_wheel":
action = BallModifier(XYAction(MouseAction(Rels.REL_HWHEEL),
ouseAction(Rels.REL_WHEEL)))
elif mode == "trigger":
actions = []
if "click" in inputs:
actions.append(TriggerAction(TRIGGER_CLICK,
self.parse_button(inputs["click"])))
if side == Profile.LEFT:
actions.append(AxisAction(Axes.ABS_Z))
else:
actions.append(AxisAction(Axes.ABS_RZ))
action = MultiAction.make(*actions)
elif mode == "mouse_region":
# Mouse
'MOUSE_LEFT' : (MouseAction, Rels.REL_X, -1),
'MOUSE_RIGHT' : (MouseAction, Rels.REL_X, 1),
'MOUSE_UP' : (MouseAction, Rels.REL_Y, -1),
'MOUSE_DOWN' : (MouseAction, Rels.REL_Y, 1,),
'MOUSE_X' : (MouseAction, Rels.REL_X, 1),
'MOUSE_Y' : (MouseAction, Rels.REL_Y, 1),
'MOUSE_WHEEL' : (MouseAction, Rels.REL_WHEEL, 1),
'MOUSE_HWHEEL' : (MouseAction, Rels.REL_HWHEEL, 1),
# Mouse buttons
'MOUSE1' : (ButtonAction, Keys.BTN_LEFT),
'MOUSE2' : (ButtonAction, Keys.BTN_MIDDLE),
'MOUSE3' : (ButtonAction, Keys.BTN_RIGHT),
'MOUSE4' : (MouseAction, Rels.REL_WHEEL, 1),
'MOUSE5' : (MouseAction, Rels.REL_WHEEL, -1),
'MOUSE8' : (ButtonAction, Keys.BTN_SIDE),
'MOUSE9' : (ButtonAction, Keys.BTN_EXTRA),
}
_CLS_TO_AREA = {}
for x in AREA_TO_ACTION:
cls, params = AREA_TO_ACTION[x][0], AREA_TO_ACTION[x][1:]
if not cls in _CLS_TO_AREA:
_CLS_TO_AREA[cls] = []
_CLS_TO_AREA[cls].append((x, params))
def action_to_area(action):
"""
Returns area that matches provided action (both class and parameters)
or None if there is no such area.
def describe(self, context):
if self.name: return self.name
# Special cases just to make GUI look pretty
if isinstance(self.action, MouseAction):
return _("Trackball")
if isinstance(self.action, XYAction):
if isinstance(self.action.x, AxisAction) and isinstance(self.action.y, AxisAction):
x, y = self.action.x.parameters[0], self.action.y.parameters[0]
if x == Axes.ABS_X and y == Axes.ABS_Y:
return _("Mouse-like LStick")
else:
return _("Mouse-like RStick")
if isinstance(self.action.x, MouseAction) and isinstance(self.action.y, MouseAction):
x, y = self.action.x.parameters[0], self.action.y.parameters[0]
if x in (Rels.REL_HWHEEL, Rels.REL_WHEEL) and y in (Rels.REL_HWHEEL, Rels.REL_WHEEL):
return _("Mouse Wheel")
return _("Ball(%s)") % (self.action.describe(context))
)
return NoAction()
elif binding in ("controller_action"):
if params[0] == "CHANGE_PRESET":
id = int(params[1]) - 1
cpa = ChangeProfileAction("action_set:%s" % (id,))
self.action_set_switches.add(cpa)
return cpa
log.warning("Ignoring controller_action '%s' binding" % (params[0],))
return NoAction()
elif binding == "mouse_wheel":
if params[0].lower() == "scroll_down":
return MouseAction(Rels.REL_WHEEL, -1)
else:
return MouseAction(Rels.REL_WHEEL, 1)
else:
raise ParseError("Unknown binding: '%s'" % (binding,))