Exemplo n.º 1
0
	def on_btOK_clicked(self, *a):
		""" Handler for OK button """
		action = self._save_modemod(0)
		hold_action = self._save_modemod(1)
		dbl_action = self._save_modemod(2)
		if hold_action:
			action = HoldModifier(hold_action, action)
			if dbl_action:
				action.action = dbl_action
		elif dbl_action:
			action = DoubleclickModifier(hold_action, action)
		print action.to_string(True, 4)
		if self.ac_callback is not None:
			self.ac_callback(self.id, action)
		self.close()
Exemplo n.º 2
0
    def load_data(self, data):
        if 'controller_mappings' not in data:
            raise ValueError("Invalid profile file")
        data = data['controller_mappings']
        if 'title' in data:
            name = data['title'].strip()
            if name:
                self.name = name
        presets = ensure_list(data['preset'])
        for p in presets:
            id = int(p["id"])
            if id == 0:
                # Default profile
                VDFProfile._load_preset(data, self, p)
            else:
                aset = VDFProfile(VDFProfile._get_preset_name(data, p))
                aset.action_set_id = id
                aset.action_set_switches = self.action_set_switches
                self.action_sets[aset.name] = aset
                VDFProfile._load_preset(data, aset, p)

        for aset in self.action_sets.values():
            aset.buttons[SCButtons.C] = HoldModifier(
                MenuAction("Default.menu"), MenuAction("Default.menu"))

        return self
Exemplo n.º 3
0
	def parse_button(self, bdef, button=None):
		"""
		Parses button definition from vdf file.
		Parameter can be either string, as used in v2, or dict used in v3.
		"""
		if type(bdef) == str:
			# V2
			return self.parse_action(bdef, button)
		elif type(bdef) == list:
			# V2
			return MultiAction.make(*[ self.parse_action(x, button) for x in bdef ])
		elif "activators" in bdef:
			# V3
			act_actions = []
			for k in ("full_press", "double_press", "long_press"):
				a = NoAction()
				if k in bdef["activators"]:
					# TODO: Handle multiple bindings
					bindings = ensure_list(bdef["activators"][k])[0]
					a = self.parse_action(bindings["bindings"]["binding"], button)
					a = VDFProfile.parse_modifiers(bindings, a, Profile.RIGHT)
					# holly...
				act_actions.append(a)
			normal, double, hold = act_actions
			if not double and not hold:
				return normal
			elif hold and not double:
				return HoldModifier(hold, normal)
			else:
				action = DoubleclickModifier(double, normal)
				action.holdaction = hold
				return action
		else:
			log.warning("Failed to parse button definition: %s" % (bdef,))
Exemplo n.º 4
0
 def clear(self):
     """ Clears all actions and adds default menu action on center button """
     self.buttons = {x: NoAction() for x in SCButtons}
     self.buttons[SCButtons.C] = HoldModifier(
         MenuAction("Default.menu"),
         normalaction=MenuAction("Default.menu"))
     self.menus = {}
     self.stick = NoAction()
     self.is_template = False
     self.triggers = {Profile.LEFT: NoAction(), Profile.RIGHT: NoAction()}
     self.pads = {Profile.LEFT: NoAction(), Profile.RIGHT: NoAction()}
     self.gyro = NoAction()
Exemplo n.º 5
0
 def _make_action(self):
     """ Generates and returns Action instance """
     normalaction = self._save_modemod(0)
     holdaction = self._save_modemod(1)
     dblaction = self._save_modemod(2)
     if dblaction:
         action = DoubleclickModifier(dblaction, normalaction)
         action.holdaction = holdaction
     elif holdaction:
         action = HoldModifier(holdaction, normalaction)
     else:
         action = normalaction
     action.timeout = self.builder.get_object("adjTime").get_value()
     return action
Exemplo n.º 6
0
 def on_btOK_clicked(self, *a):
     """ Handler for OK button """
     action = self._save_modemod(0)
     hold_action = self._save_modemod(1)
     dbl_action = self._save_modemod(2)
     if hold_action:
         action = HoldModifier(hold_action, action)
         if dbl_action:
             action.action = dbl_action
     elif dbl_action:
         action = DoubleclickModifier(hold_action, action)
     print action.to_string(True, 4)
     if self.ac_callback is not None:
         self.ac_callback(self.id, action)
     self.close()
Exemplo n.º 7
0
    def _make_action(self):
        """ Generates and returns Action instance """
        cbHoldFeedback = self.builder.get_object("cbHoldFeedback")
        sclHoldFeedback = self.builder.get_object("sclHoldFeedback")
        normalaction = self._save_modemod(0)
        holdaction = self._save_modemod(1)
        dblaction = self._save_modemod(2)
        if dblaction:
            action = DoubleclickModifier(dblaction, normalaction)
            action.holdaction = holdaction
        elif holdaction:
            action = HoldModifier(holdaction, normalaction)
        else:
            action = normalaction
        action.timeout = self.builder.get_object("adjTime").get_value()

        if cbHoldFeedback.get_active():
            action = FeedbackModifier(HapticPos.BOTH,
                                      sclHoldFeedback.get_value(), action)

        return action
Exemplo n.º 8
0
    def _convert(self, from_version):
        """ Performs conversion from older profile version """
        if from_version < 1:
            from scc.modifiers import ModeModifier
            # Add 'display Default.menu if center button is held' for old profiles
            c = self.buttons[SCButtons.C]
            if not c:
                # Nothing set to C button
                self.buttons[SCButtons.C] = HoldModifier(
                    MenuAction("Default.menu"),
                    normalaction=MenuAction("Default.menu"))
            elif hasattr(c, "holdaction") and c.holdaction:
                # Already set to something, don't overwrite it
                pass
            elif c.to_string().startswith("OSK."):
                # Special case, don't touch this either
                pass
            else:
                self.buttons[SCButtons.C] = HoldModifier(
                    MenuAction("Default.menu"),
                    normalaction=self.buttons[SCButtons.C])
        if from_version < 1.1:
            # Convert old scrolling wheel to new representation
            from scc.modifiers import FeedbackModifier, BallModifier
            from scc.actions import MouseAction, XYAction
            from scc.uinput import Rels
            iswheelaction = (
                lambda x: isinstance(x, MouseAction) and x.parameters[0] in
                (Rels.REL_HWHEEL, Rels.REL_WHEEL))
            for p in (Profile.LEFT, Profile.RIGHT):
                a, feedback = self.pads[p], None
                if isinstance(a, FeedbackModifier):
                    feedback = a.haptic.get_position()
                    a = a.action
                if isinstance(a, XYAction):
                    if iswheelaction(a.x) or iswheelaction(a.y):
                        n = BallModifier(XYAction(a.x, a.y))
                        if feedback is not None:
                            n = FeedbackModifier(feedback, 4096, 16, n)
                        self.pads[p] = n
                        log.info("Converted %s to %s", a.to_string(),
                                 n.to_string())
        if from_version < 1.2:
            # Convert old trigger settings that were done with ButtonAction
            # to new TriggerAction
            from scc.constants import TRIGGER_HALF, TRIGGER_MAX, TRIGGER_CLICK
            from scc.actions import ButtonAction, TriggerAction, MultiAction
            from scc.uinput import Keys
            for p in (Profile.LEFT, Profile.RIGHT):
                if isinstance(self.triggers[p], ButtonAction):
                    buttons, numbers = [], []
                    n = None
                    # There were one or two keys and zero to two numeric
                    # parameters for old button action
                    for param in self.triggers[p].parameters:
                        if param in Keys:
                            buttons.append(param)
                        elif type(param) in (int, float):
                            numbers.append(int(param))
                    if len(numbers) == 0:
                        # Trigger range was not specified, assume defaults
                        numbers = (TRIGGER_HALF, TRIGGER_CLICK)
                    elif len(numbers) == 1:
                        # Only lower range was specified, add default upper range
                        numbers.append(TRIGGER_CLICK)
                    if len(buttons) == 1:
                        # If only one button was set, trigger should work like
                        # one big button
                        n = TriggerAction(numbers[0], ButtonAction(buttons[0]))
                    elif len(buttons) == 2:
                        # Both buttons were set
                        n = MultiAction(
                            TriggerAction(numbers[0], numbers[1],
                                          ButtonAction(buttons[0])),
                            TriggerAction(numbers[1], TRIGGER_MAX,
                                          ButtonAction(buttons[1])))

                    if n:
                        log.info("Converted %s to %s",
                                 self.triggers[p].to_string(), n.to_string())
                        self.triggers[p] = n
Exemplo n.º 9
0
	def from_json_data(self, data, key=None):
		"""
		Converts dict stored in profile file into action.
		
		May throw ParseError.
		"""
		if key is not None:
			# Don't fail if called for non-existent key, return NoAction instead.
			# Using this is sorter than
			# calling 'if button in data["buttons"]: ...' everywhere
			if key in data:
				return self.from_json_data(data[key], None)
			else:
				return NoAction()
		
		a = NoAction()
		if "action" in data:
			a = self.restart(data["action"]).parse() or NoAction()
		if "X" in data or "Y" in data:
			# "action" is ignored if either "X" or "Y" is there
			x = self.from_json_data(data["X"]) if "X" in data else NoAction()
			y = self.from_json_data(data["Y"]) if "Y" in data else NoAction()
			a = XYAction(x, y)
		if "deadzone" in data:
			lower = data["deadzone"]["lower"] if "lower" in data["deadzone"] else STICK_PAD_MIN
			upper = data["deadzone"]["upper"] if "upper" in data["deadzone"] else STICK_PAD_MAX
			a = DeadzoneModifier(lower, upper, a)
		if "sensitivity" in data:
			args = data["sensitivity"]
			args.append(a)
			a = SensitivityModifier(*args)
		if "feedback" in data:
			args = data["feedback"]
			if hasattr(HapticPos, args[0]):
				args[0] = getattr(HapticPos, args[0])
			args.append(a)
			a = FeedbackModifier(*args)
		if "osd" in data:
			a = OSDAction(a)
			if data["osd"] is not True:
				a.timeout = float(data["osd"])
		if "click" in data:
			a = ClickModifier(a)
		if "name" in data:
			a.name = data["name"]
		if "modes" in data:
			args = []
			for button in data['modes']:
				if hasattr(SCButtons, button):
					args += [ getattr(SCButtons, button), self.from_json_data(data['modes'][button]) ]
			if a:
				args += [ a ]
			a = ModeModifier(*args)
		if "doubleclick" in data:
			args = [ self.from_json_data(data['doubleclick']), a ]
			a = DoubleclickModifier(*args)
		if "hold" in data:
			if isinstance(a, DoubleclickModifier):
				a.holdaction = self.from_json_data(data['hold'])
			else:
				args = [ self.from_json_data(data['hold']), a ]
				a = HoldModifier(*args)
		return a