def update(self): cb = self.builder.get_object("cbActionType") scl = self.builder.get_object("sclDiagonalRange") key = cb.get_model().get_value(cb.get_active_iter(), 1) if key == "dpad8": # 8-way dpad self.editor.set_action(DPad8Action(scl.get_value(), *self.actions)) elif key == "dpad": # 4-way dpad self.editor.set_action( DPadAction(scl.get_value(), *self.actions[0:4])) elif key == "wsad": # special case of 4-way dpad a = DPadAction(scl.get_value(), ButtonAction(Keys.KEY_W), ButtonAction(Keys.KEY_S), ButtonAction(Keys.KEY_A), ButtonAction(Keys.KEY_D)) self.actions = [NoAction()] * 8 self.editor.set_action(a) self.update_button_desc(a) elif key == "arrows": # special case of 4-way dpad a = DPadAction(scl.get_value(), ButtonAction(Keys.KEY_UP), ButtonAction(Keys.KEY_DOWN), ButtonAction(Keys.KEY_LEFT), ButtonAction(Keys.KEY_RIGHT)) self.actions = [NoAction()] * 8 self.editor.set_action(a) self.update_button_desc(a) elif key == "actual_dpad": # maps to dpad as real gamepad usually has a = DPadAction(scl.get_value(), HatUpAction(Axes.ABS_HAT0Y), HatDownAction(Axes.ABS_HAT0Y), HatLeftAction(Axes.ABS_HAT0X), HatRightAction(Axes.ABS_HAT0X)) self.actions = [NoAction()] * 8 self.editor.set_action(a) self.update_button_desc(a) else: # Menu self.on_cbMenus_changed()
def parse_action(self, lst_or_str, button=None): """ Parses action from vdf file. a_string can be either string or list of strings, in which case MultiAction is returned. Returns Action instance or ParseError if action is not recognized. """ if type(lst_or_str) == list: return MultiAction.make( *[self.parse_action(x) for x in lst_or_str]) # Split string into binding type, name and parameters binding, params = lst_or_str.split(" ", 1) if "," in params: params, name = params.split(",", 1) else: params, name = params, None params = params.split(" ") if name: name = name.strip() # Return apropriate Action for binding type if binding in ("key_press", "mouse_button"): if binding == "mouse_button": b = VDFProfile.convert_button_name(params[0]) else: b = VDFProfile.convert_key_name(params[0]) return ButtonAction(b).set_name(name) elif binding == "xinput_button": # Special cases, as dpad is apparently button on Windows b = params[0].strip().lower() if b == "dpad_up": return HatUpAction(Axes.ABS_HAT0Y) elif b == "dpad_down": return HatDownAction(Axes.ABS_HAT0Y) elif b == "dpad_left": return HatLeftAction(Axes.ABS_HAT0X) elif b == "dpad_right": return HatRightAction(Axes.ABS_HAT0X) elif b == "trigger_left": return AxisAction(Axes.ABS_Z) elif b == "trigger_right": return AxisAction(Axes.ABS_RZ) else: b = VDFProfile.convert_button_name(b) return ButtonAction(b).set_name(name) elif binding in ("mode_shift"): if button is None: log.warning("Ignoring modeshift assigned to no button: '%s'" % (lst_or_str, )) return NoAction() if button not in VDFProfile.BUTTON_TO_BUTTON: log.warning( "Ignoring modeshift assigned to unknown button: '%s'" % (button, )) return NoAction() self.modeshift_buttons[VDFProfile.BUTTON_TO_BUTTON[button]] = ( params[1], params[0]) 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, ))