Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_action(self, mode, action):
if self.handles(mode, action):
if isinstance(action, MultiAction) and len(action.actions) == 2:
# axis + button on fully pressed trigger
self.full = action.actions[0].button2
self.builder.get_object("lblFullPressed").set_label(describe_action(Action.AC_BUTTON, ButtonAction, self.full))
action = action.actions[1]
area = action_to_area(action)
if area is not None:
self.set_active_area(area)
return
self.set_active_area(None)
def __init__(self, app, callback):
Editor.__init__(self)
self.app = app
self.id = None
self.mode = Action.AC_BUTTON
self.ac_callback = callback
self.soft_level = -1
self.current_page = 0
self.actions = ( [], [], [] )
self.nomods = [ NoAction(), NoAction(), NoAction() ]
self.setup_widgets()
def _update(self):
for i in xrange(0, len(self.action_widgets)):
button, clearb = self.action_widgets[i]
button.set_label(self.actions[i].describe(Action.AC_BUTTON))
self.builder.get_object("sclRadius").set_value(self.radius)
def describe(self, context):
if self.name: return self.name
axis, neg, pos = AxisAction.get_axis_description(self.id)
if context == Action.AC_BUTTON:
for x in self.parameters:
if type(x) in (int, float):
if x > 0:
return "%s %s" % (axis, pos)
if x < 0:
return "%s %s" % (axis, neg)
if context in (Action.AC_TRIGGER, Action.AC_STICK, Action.AC_PAD):
if self.id in AxisAction.Z: # Trigger
return axis
else:
xy = "X" if self.id in AxisAction.X else "Y"
return "%s %s" % (axis, xy)
return axis
def set_button(self, button, action):
""" Setups action editor as editor for button action """
self._set_mode(action, Action.AC_BUTTON)
self.hide_advanced_settings()
self.set_action(action)
self.id = button
def _setup_editor(self, ae, action):
if self.mode == Action.AC_BUTTON:
ae.set_button(self.id, action)
elif self.mode == Action.AC_TRIGGER:
ae.set_trigger(self.id, action)
elif self.mode == Action.AC_STICK:
ae.set_stick(action)
elif self.mode == Action.AC_GYRO:
ae.set_gyro(action)
elif self.mode == Action.AC_PAD:
ae.set_pad(self.id, action)
def update(self):
self.builder.get_object("lblPartPressed").set_label(describe_action(Action.AC_BUTTON, ButtonAction, self.half))
self.builder.get_object("lblFullPressed").set_label(describe_action(Action.AC_BUTTON, ButtonAction, self.full))
self.builder.get_object("lblAnalog").set_label(describe_action(Action.AC_BUTTON, AxisAction, self.analog))
from scc.gui.key_grabber import KeyGrabber
from scc.gui.parser import InvalidAction
from scc.gui.chooser import Chooser
from scc.gui.ae import AEComponent
import os, logging
log = logging.getLogger("AE.Buttons")
__all__ = [ 'ButtonsComponent' ]
class ButtonsComponent(AEComponent, Chooser):
GLADE = "ae/buttons.glade"
NAME = "buttons"
IMAGES = { "buttons" : "buttons.svg" }
CTXS = Action.AC_BUTTON | Action.AC_MENU
PRIORITY = 1
def __init__(self, app, editor):
AEComponent.__init__(self, app, editor)
Chooser.__init__(self, app)
self.axes_allowed = True
def load(self):
if not self.loaded:
AEComponent.load(self)
self.setup_image()
if self.app.osd_controller:
self.enable_cursors(self.app.osd_controller)
lines.append( self.add("HOLD", context, action.holdaction)
.add_icon(icon) )
return LineCollection(*lines)
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
lines.append( self.add("DOUBLECLICK", context, action.action)
.add_icon(icon) )
if action.holdaction:
lines.append( self.add("HOLD", context, action.holdaction)
.add_icon(icon) )
return LineCollection(*lines)
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))