Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _fill_button_images(self, buttons):
e = self.edit()
SVGEditor.update_parents(e)
target = SVGEditor.get_element(e, "controller")
target_x, target_y = SVGEditor.get_translation(target)
for i in xrange(len(ControllerImage.BUTTONS_WITH_IMAGES)):
b = nameof(ControllerImage.BUTTONS_WITH_IMAGES[i])
try:
elm = SVGEditor.get_element(e, "AREA_%s" % (b,))
if elm is None:
log.warning("Area for button %s not found", b)
continue
x, y = SVGEditor.get_translation(elm)
scale = 1.0
if "scc-button-scale" in elm.attrib:
w, h = SVGEditor.get_size(elm)
scale = float(elm.attrib['scc-button-scale'])
tw, th = w * scale, h * scale
if scale < 1.0:
x += (w - tw) * 0.5
y += (h - th) * 0.5
else:
x -= (tw - w) * 0.25
)
if target_axis not in ("ltrig", "rtrig"):
# Deadzone is generated with assumption that all sticks are left
# in center position before 'Save' is pressed.
center = axisdata.min + (axisdata.max - axisdata.min) / 2
deadzone = abs(axisdata.pos - center) * 2 + 2
if abs(axisdata.max) < 2:
# DPADs
deadzone = 0
rv["deadzone"] = deadzone
return rv
for code, target in self._mappings.iteritems():
if target in SCButtons:
config['buttons'][code] = nameof(target)
elif isinstance(target, DPadEmuData):
config['dpads'][code] = axis_to_json(target.axis_data)
config['dpads'][code]["positive"] = target.positive
config['dpads'][code]["button"] = nameof(target.button)
elif isinstance(target, AxisData):
config['axes'][code] = axis_to_json(target)
group = cbControllerButtons.get_model()[cbControllerButtons.get_active()][0]
controller = cbControllerType.get_model()[cbControllerType.get_active()][0]
config['gui'] = {
'background' : controller,
'buttons': self._groups[group]
}
buffRawData.set_text(json.dumps(config, sort_keys=True,
indent=4, separators=(',', ': ')))
def add(self, icon, context, action):
if not action: return LineCollection()
if isinstance(action, MultiAction):
if not action.is_key_combination():
return LineCollection([
self.add(icon, context, child)
for child in action.actions
])
elif isinstance(action, ModeModifier):
lines = [ self.add(icon, context, action.default) ]
for x in action.mods:
lines.append( self.add(nameof(x), context, action.mods[x])
.add_icon(icon) )
return LineCollection(*lines)
elif isinstance(action, DoubleclickModifier):
lines = []
if action.normalaction:
lines.append( self.add(icon, context, action.normalaction) )
if action.action:
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):
else:
if cbMenuAutoConfirm:
cbMenuAutoConfirm.set_active(False)
if cbMenuConfirmWithClick:
cbMenuAutoConfirm.set_active(False)
cbConfirmWith.set_sensitive(True)
self.set_cb(cbConfirmWith, nameof(cow), 1)
if cbCancelWith:
if caw == SAME and cbMenuAutoCancel:
cbMenuAutoCancel.set_active(True)
cbCancelWith.set_sensitive(False)
else:
if cbMenuAutoCancel:
cbMenuAutoCancel.set_active(False)
self.set_cb(cbCancelWith, nameof(caw), 1)
self.on_cbMenus_changed()
)
if target_axis not in ("ltrig", "rtrig"):
# Deadzone is generated with assumption that all sticks are left
# in center position before 'Save' is pressed.
center = axisdata.min + (axisdata.max - axisdata.min) / 2
deadzone = abs(axisdata.pos - center) * 2 + 2
if abs(axisdata.max) < 2:
# DPADs
deadzone = 0
rv["deadzone"] = deadzone
return rv
for code, target in self._mappings.iteritems():
if target in SCButtons:
config['buttons'][code] = nameof(target)
elif isinstance(target, DPadEmuData):
config['dpads'][code] = axis_to_json(target.axis_data)
config['dpads'][code]["positive"] = target.positive
config['dpads'][code]["button"] = nameof(target.button)
elif isinstance(target, AxisData):
config['axes'][code] = axis_to_json(target)
group = cbControllerButtons.get_model()[cbControllerButtons.get_active()][0]
controller = cbControllerType.get_model()[cbControllerType.get_active()][0]
config['gui'] = {
'background' : controller,
'buttons': self._groups[group]
}
buffRawData.set_text(json.dumps(config, sort_keys=True,
indent=4, separators=(',', ': ')))
class ControllerImage(SVGWidget):
DEFAULT = "sc"
BUTTONS_WITH_IMAGES = (
SCButtons.A, SCButtons.B, SCButtons.X, SCButtons.Y,
SCButtons.BACK, SCButtons.C, SCButtons.START
)
DEFAULT_AXES = (
# Shared between DS4 and Steam Controller
"stick_x", "stick_y", "lpad_x", "lpad_x",
"rpad_y", "rpad_y", "ltrig", "rtrig",
)
DEFAULT_BUTTONS = [ nameof(x) for x in BUTTONS_WITH_IMAGES ] + [
# Used only by Steam Controller
nameof(SCButtons.LB), nameof(SCButtons.RB),
nameof(SCButtons.LT), nameof(SCButtons.RT),
nameof(SCButtons.STICKPRESS),
nameof(SCButtons.RPAD), nameof(SCButtons.LPAD),
nameof(SCButtons.LGRIP), nameof(SCButtons.RGRIP),
]
def __init__(self, app, config=None):
self.app = app
self.backup = None
self.current = self._ensure_config({})
filename = self._make_controller_image_path(ControllerImage.DEFAULT)
SVGWidget.__init__(self, filename)
if config:
self._controller_image.use_config(config)
SCButtons.A, SCButtons.B, SCButtons.X, SCButtons.Y,
SCButtons.BACK, SCButtons.C, SCButtons.START
)
DEFAULT_AXES = (
# Shared between DS4 and Steam Controller
"stick_x", "stick_y", "lpad_x", "lpad_x",
"rpad_y", "rpad_y", "ltrig", "rtrig",
)
DEFAULT_BUTTONS = [ nameof(x) for x in BUTTONS_WITH_IMAGES ] + [
# Used only by Steam Controller
nameof(SCButtons.LB), nameof(SCButtons.RB),
nameof(SCButtons.LT), nameof(SCButtons.RT),
nameof(SCButtons.STICKPRESS),
nameof(SCButtons.RPAD), nameof(SCButtons.LPAD),
nameof(SCButtons.LGRIP), nameof(SCButtons.RGRIP),
]
def __init__(self, app, config=None):
self.app = app
self.backup = None
self.current = self._ensure_config({})
filename = self._make_controller_image_path(ControllerImage.DEFAULT)
SVGWidget.__init__(self, filename)
if config:
self._controller_image.use_config(config)
def _make_controller_image_path(self, img):
return os.path.join(self.app.imagepath,
def set_mapping(self, keycode, what):
parent = self.parent
if isinstance(what, AxisData) and what in parent._mappings.values():
for c in parent._mappings.keys():
if parent._mappings[c] == what:
del parent._mappings[c]
parent._mappings[keycode] = what
log.debug("Reassigned %s to %s", keycode, what)
if nameof(what) in parent._unassigned:
parent._unassigned.remove(nameof(what))
parent.unhilight(nameof(what))
self.parent.generate_unassigned()
self.parent.generate_raw_data()
self.cancel()
confirm_with = self.confirm_with
cancel_with = self.cancel_with
args = [ mapper ]
if confirm_with == SAME:
confirm_with = mapper.get_pressed_button() or DEFAULT
elif confirm_with == DEFAULT:
confirm_with = DEFAULT
if cancel_with == DEFAULT:
cancel_with = DEFAULT
if nameof(self.control_with) in (LEFT, RIGHT):
args += [ '--use-cursor' ]
args += [
'--control-with', nameof(self.control_with),
'-x', str(self.x), '-y', str(self.y),
'--size', str(self.size),
'--confirm-with', nameof(confirm_with),
'--cancel-with', nameof(cancel_with)
]
self.execute(*args)
rvSoftLevel = self.builder.get_object("rvSoftLevel")
sclSoftLevel = self.builder.get_object("sclSoftLevel")
lblSoftLevel = self.builder.get_object("lblSoftLevel")
model = cb.get_model()
self._recursing = True
button = None
if isinstance(item, RangeOP):
button = nameof(item.what)
sclSoftLevel.set_value(item.value)
rvSoftLevel.set_reveal_child(True)
if item.what == STICK:
lblSoftLevel.set_label(_("Stick deadzone"))
else:
lblSoftLevel.set_label(_("Trigger Pull Level"))
elif item is not None:
button = nameof(item.name)
for row in model:
if button == row[0] and row[1] != None:
cb.set_active_iter(row.iter)
self._recursing = False
return
self._recursing = False