Esempio n. 1
0
	def on_sens_value_changed(self, *a):
		if self._recursing : return
		s = (self.builder.get_object("sclSensX").get_value(),
			self.builder.get_object("sclSensY").get_value())
		
		profile = self._load_osk_profile()
		if s == (1.0, 1.0):
			profile.pads[LEFT]  = OSKCursorAction(LEFT)
			profile.pads[RIGHT] = OSKCursorAction(RIGHT)
		else:
			profile.pads[LEFT]  = SensitivityModifier(s[0], s[1], OSKCursorAction(LEFT))
			profile.pads[RIGHT] = SensitivityModifier(s[0], s[1], OSKCursorAction(RIGHT))
		self._save_osk_profile(profile)
Esempio n. 2
0
    def parse_modifiers(group, action, side):
        """
		If passed group or activator has 'settings' key, converts known
		settings to one or more Modifier.
		
		Returns resulting Action
		"""
        if "settings" in group:
            settings = group["settings"]
            sens = 1.0, 1.0, 1.0
            if "sensitivity" in settings:
                s = float(settings["sensitivity"]) / 100.0
                sens = s, s, s
            if "haptic_intensity" in settings:
                action = FeedbackModifier(
                    HapticPos.LEFT
                    if side == Profile.LEFT else HapticPos.RIGHT,
                    512 * int(settings["haptic_intensity"]), 8, action)
            if "invert_x" in settings and int(settings["invert_x"]):
                sens = -1.0 * sens[0], sens[1], sens[2]
            if "invert_y" in settings and int(settings["invert_y"]):
                sens = sens[0], -1.0 * sens[1], sens[2]
            if "invert_z" in settings and int(settings["invert_z"]):
                sens = sens[0], sens[1], -1.0 * sens[2]

            if sens != (1.0, 1.0, 1.0):
                action = SensitivityModifier(sens[0], sens[1], sens[2], action)

        return action
Esempio n. 3
0
	def generate_modifiers(self, action, from_custom=False):
		if not self._modifiers_enabled and not from_custom:
			# Editing in custom aciton dialog, don't meddle with that
			return action
		
		# Strip 1.0's from sensitivity values
		sens = [] + self.sens
		while len(sens) > 0 and sens[-1] == 1.0:
			sens = sens[0:-1]
		
		# Strip defaults from feedback values
		feedback = [] + self.feedback
		while len(feedback) > 0 and feedback[-1] == self.feedback_widgets[len(feedback)-1][-1]:
			feedback = feedback[0:-1]
		
		if len(sens) > 0:
			# Build arguments
			sens.append(action)
			# Create modifier
			action = SensitivityModifier(*sens)
		
		if self.feedback_position != None:
			cbFeedbackSide = self.builder.get_object("cbFeedbackSide")
			cbFeedback = self.builder.get_object("cbFeedback")
			if from_custom or (cbFeedback.get_active() and cbFeedback.get_sensitive()):
				# Build FeedbackModifier arguments
				feedback = [ FEEDBACK_SIDES[cbFeedbackSide.get_active()] ] + feedback
				feedback += [ action ]
				# Create modifier
				action = FeedbackModifier(*feedback)
		
		if self.deadzone_enabled:
			action = DeadzoneModifier(self.deadzone[0], self.deadzone[1], action)
		
		if self.rotation_angle != 0.0:
			action = RotateInputModifier(self.rotation_angle, action)
		
		if self.osd:
			action = OSDAction(action)
		
		if self.click:
			action = ClickModifier(action)
		
		return action
Esempio n. 4
0
	def generate_modifiers(self, action, from_custom=False):
		"""
		Returns Action with all modifiers from UI applied.
		"""
		if not self._modifiers_enabled and not from_custom:
			# Editing in custom aciton dialog, don't meddle with that
			return action
		
		if isinstance(action, ModeModifier):
			args = []
			for k in action.mods:
				if action.mods[k]:
					args += [ k, self.generate_modifiers(ActionEditor.strip_modifiers(action.mods[k])) ]
			if action.default:
				args += [ self.generate_modifiers(ActionEditor.strip_modifiers(action.default)) ]
			return ModeModifier(*args)
		
		cm = action.get_compatible_modifiers()
		
		if (cm & Action.MOD_SENSITIVITY) != 0:
			# Strip 1.0's from sensitivity values
			sens = [] + self.sens
			while len(sens) > 0 and sens[-1] == 1.0:
				sens = sens[0:-1]
			
			if len(sens) > 0:
				# Build arguments
				sens.append(action)
				# Create modifier
				action = SensitivityModifier(*sens)
		
		if (cm & Action.MOD_FEEDBACK) != 0:
			if self.feedback_position != None:
				# Strip defaults from feedback values
				feedback = [] + self.feedback
				while len(feedback) > 0 and feedback[-1] == self.feedback_widgets[len(feedback)-1][-1]:
					feedback = feedback[0:-1]
				
				cbFeedbackSide = self.builder.get_object("cbFeedbackSide")
				cbFeedback = self.builder.get_object("cbFeedback")
				grFeedback = self.builder.get_object("grFeedback")
				if from_custom or (cbFeedback.get_active() and grFeedback.get_sensitive()):
					# Build FeedbackModifier arguments
					feedback = [ FEEDBACK_SIDES[cbFeedbackSide.get_active()] ] + feedback
					feedback += [ action ]
					# Create modifier
					action = FeedbackModifier(*feedback)
		
		if (cm & Action.MOD_SMOOTH) != 0:
			if self.smoothing != None:
				action = SmoothModifier(*( list(self.smoothing) + [ action ]))
		
		
		if (cm & Action.MOD_DEADZONE) != 0:
			if self.deadzone_mode is not None:
				action = DeadzoneModifier(self.deadzone_mode, self.deadzone[0], self.deadzone[1], action)
		
		if (cm & Action.MOD_ROTATE) != 0:
			if self.rotation_angle != 0.0:
				action = RotateInputModifier(self.rotation_angle, action)
		
		if (cm & Action.MOD_OSD) != 0:
			if self.osd:
				action = OSDAction(action)
		
		if (cm & Action.MOD_CLICK) != 0:
			if self.click:
				action = ClickModifier(action)
		
		return action
Esempio n. 5
0
    def parse_group(self, group, side):
        """
		Parses output (group) from vdf profile.
		Returns Action.
		"""
        if not "mode" in group:
            raise ParseError("Group without mode")
        mode = group["mode"]
        inputs = VDFProfile.get_inputs(group)

        settings = group["settings"] if "settings" in group else {}
        for o in ("output_trigger", "output_joystick"):
            if o in settings:
                if int(settings[o]) <= 1:
                    side = Profile.LEFT
                else:
                    side = Profile.RIGHT

        if mode == "dpad":
            keys = []
            for k in ("dpad_north", "dpad_south", "dpad_east", "dpad_west"):
                if k in inputs:
                    keys.append(self.parse_button(inputs[k]))
                else:
                    keys.append(NoAction())
            action = DPadAction(*keys)
        elif mode == "four_buttons":
            keys = []
            for k in ("button_y", "button_a", "button_x", "button_b"):
                if k in inputs:
                    keys.append(self.parse_button(inputs[k]))
                else:
                    keys.append(NoAction())
            action = DPadAction(*keys)
        elif mode == "joystick_move":
            if side == Profile.LEFT:
                # Left
                action = XYAction(AxisAction(Axes.ABS_X),
                                  AxisAction(Axes.ABS_Y))
            else:
                # 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)

            action = GridMenuAction(
                menu_id, 'LEFT' if side == Profile.LEFT else 'RIGHT',
                SCButtons.LPAD if side == Profile.LEFT else SCButtons.RPAD)
        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":
            # Read value and assume dafaults
            scale = float(settings["scale"]) if "scale" in settings else 100.0
            x = float(
                settings["position_x"]) if "position_x" in settings else 50.0
            y = float(
                settings["position_y"]) if "position_y" in settings else 50.0
            w = float(settings["sensitivity_horiz_scale"]
                      ) if "sensitivity_horiz_scale" in settings else 100.0
            h = float(settings["sensitivity_vert_scale"]
                      ) if "sensitivity_vert_scale" in settings else 100.0
            # Apply scale
            w = w * scale / 100.0
            h = h * scale / 100.0
            # Convert to (0, 1) range
            x, y = x / 100.0, 1.0 - (y / 100.0)
            w, h = w / 100.0, h / 100.0
            # Convert to rectangle
            x1 = max(0.0, x - (w * VDFProfile.REGION_IMPORT_FACTOR))
            x2 = min(1.0, x + (w * VDFProfile.REGION_IMPORT_FACTOR))
            y1 = max(0.0, y - (h * VDFProfile.REGION_IMPORT_FACTOR))
            y2 = min(1.0, y + (h * VDFProfile.REGION_IMPORT_FACTOR))

            action = RelAreaAction(x1, y1, x2, y2)
        else:
            raise ParseError("Unknown mode: '%s'" % (group["mode"], ))

        action = VDFProfile.parse_modifiers(group, action, side)
        return action
Esempio n. 6
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