コード例 #1
0
    def send(self, *a):
        if self._recursing: return

        cbMode = self.builder.get_object("cbMode")
        cbYawRoll = self.builder.get_object("cbYawRoll")
        cbGyroButton = self.builder.get_object("cbGyroButton")
        cbInvertGyro = self.builder.get_object("cbInvertGyro")
        action = cbMode.get_model().get_value(cbMode.get_active_iter(), 0)
        key = cbMode.get_model().get_value(cbMode.get_active_iter(), 2)
        yawroll = cbYawRoll.get_model().get_value(cbYawRoll.get_active_iter(),
                                                  0)
        button = cbGyroButton.get_model().get_value(
            cbGyroButton.get_active_iter(), 0)

        match = re.match(r"([^\[]+)\[([^\|]+)\|([^\]]+)\](.*)", action)
        if match:
            grps = match.groups()
            if yawroll == YAW:
                action = "%s%s%s" % (grps[0], grps[1], grps[3])
            else:
                action = "%s%s%s" % (grps[0], grps[2], grps[3])
        action = self.parser.restart(action).parse()

        if button and action:
            if cbInvertGyro.get_active():
                action = ModeModifier(getattr(SCButtons, button), NoAction(),
                                      action)
            else:
                action = ModeModifier(getattr(SCButtons, button), action)
        if key == "mouse":
            self.editor.set_default_sensitivity(3.5, 3.5, 3.5)
        else:
            self.editor.set_default_sensitivity(1, 1, 1)

        self.editor.set_action(action)
コード例 #2
0
ファイル: gyro.py プロジェクト: soekul/sc-controller
    def send(self, *a):
        if self._recursing: return

        cbGyroButton = self.builder.get_object("cbGyroButton")
        button = cbGyroButton.get_model().get_value(
            cbGyroButton.get_active_iter(), 0)

        normal, n_set = [None, None, None], False
        absolute, a_set = [None, None, None], False

        for i in xrange(0, 3):
            if self.axes[i] is not None:
                if self.cbs[i].get_active():
                    absolute[i] = self.axes[i]
                    a_set = True
                else:
                    normal[i] = self.axes[i]
                    n_set = True

        if n_set and a_set:
            action = MultiAction(GyroAction(*normal), GyroAbsAction(*absolute))
        elif n_set:
            action = GyroAction(*normal)
        elif a_set:
            action = GyroAbsAction(*absolute)
        else:
            action = NoAction()

        if button and action:
            action = ModeModifier(getattr(SCButtons, button), action)

        self.editor.set_action(action)
コード例 #3
0
ファイル: vdf.py プロジェクト: miniskipper/sc-controller
    def _load_preset(data, profile, preset):
        profile.modeshifts = {}
        profile.modeshift_buttons = {}
        if not 'group_source_bindings' in preset:
            # Empty preset
            return

        gsb = preset['group_source_bindings']
        for group_id in gsb:
            binding = gsb[group_id]
            if not binding.endswith("inactive"):
                profile.parse_input_binding(data, group_id, binding)

        if "switch_bindings" in preset:
            profile.parse_switches(preset['switch_bindings'])

        for b in profile.modeshift_buttons:
            if profile.modeshift_buttons[b] in profile.modeshifts:
                # Should be always
                modeshift = profile.modeshift_buttons[b]
            else:
                continue
            action = profile.modeshifts[modeshift]
            trash, binding = modeshift
            old = profile.get_by_binding(binding)
            profile.set_by_binding(binding, ModeModifier(b, action, old))
コード例 #4
0
 def on_btModeshift_clicked(self, *a):
     """ Asks main window to close this one and display modeshift editor """
     if self.ac_callback is not None:
         # Convert current action into modeshift and send it to main window
         action = ModeModifier(self.generate_modifiers(self._action))
         self.close()
         self.ac_callback(self.id, action, reopen=True)
コード例 #5
0
    def send(self, *a):
        if self._recursing: return

        cbMode = self.builder.get_object("cbMode")
        cbYawRoll = self.builder.get_object("cbYawRoll")
        cbGyroButton = self.builder.get_object("cbGyroButton")
        action = cbMode.get_model().get_value(cbMode.get_active_iter(), 0)
        yawroll = cbYawRoll.get_model().get_value(cbYawRoll.get_active_iter(),
                                                  0)
        button = cbGyroButton.get_model().get_value(
            cbGyroButton.get_active_iter(), 0)

        match = re.match(r"([^\[]+)\[([^\|]+)\|([^\]]+)\](.*)", action)
        if match:
            grps = match.groups()
            if yawroll == YAW:
                action = "%s%s%s" % (grps[0], grps[1], grps[3])
            else:
                action = "%s%s%s" % (grps[0], grps[2], grps[3])
        action = self.parser.restart(action).parse()

        if button:
            action = ModeModifier(getattr(SCButtons, button), action)

        self.editor.set_action(action)
コード例 #6
0
	def on_btModeshift_clicked(self, *a):
		""" Convert current action into modeshift and send it to ModeshiftEditor """
		e = ModeshiftEditor(self.app, self.ac_callback)
		action = ModeModifier(self.generate_modifiers(self._action, self._selected_component.NAME=="custom"))
		e.set_input(self.id, action, mode=self._mode)
		self.close()
		e.show(self.get_transient_for())
コード例 #7
0
    def send(self, *a):
        if self._recursing: return

        cbMode = self.builder.get_object("cbMode")
        cbYawRoll = self.builder.get_object("cbYawRoll")
        rvSoftLevel = self.builder.get_object("rvSoftLevel")
        sclSoftLevel = self.builder.get_object("sclSoftLevel")
        cbGyroButton = self.builder.get_object("cbGyroButton")
        cbInvertGyro = self.builder.get_object("cbInvertGyro")
        cbInvertGyro = self.builder.get_object("cbInvertGyro")
        action = cbMode.get_model().get_value(cbMode.get_active_iter(), 0)
        key = cbMode.get_model().get_value(cbMode.get_active_iter(), 2)
        yawroll = cbYawRoll.get_model().get_value(cbYawRoll.get_active_iter(),
                                                  0)
        item = cbGyroButton.get_model().get_value(
            cbGyroButton.get_active_iter(), 0)
        rvSoftLevel.set_reveal_child(item in TRIGGERS)

        match = re.match(r"([^\[]+)\[([^\|]+)\|([^\]]+)\](.*)", action)
        if match:
            grps = match.groups()
            if yawroll == YAW:
                action = "%s%s%s" % (grps[0], grps[1], grps[3])
            else:
                action = "%s%s%s" % (grps[0], grps[2], grps[3])
        action = self.parser.restart(action).parse()

        if item and action:
            if item in TRIGGERS:
                what = RangeOP(getattr(SCButtons, item), ">=",
                               sclSoftLevel.get_value())
            elif item == STICK:
                what = RangeOP(item, ">=", sclSoftLevel.get_value())
            else:
                what = getattr(SCButtons, item)
            if cbInvertGyro.get_active():
                action = ModeModifier(what, NoAction(), action)
            else:
                action = ModeModifier(what, action)
        if key == "mouse":
            self.editor.set_default_sensitivity(3.5, 3.5, 3.5)
        else:
            self.editor.set_default_sensitivity(1, 1, 1)

        self.update()
        self.editor.set_action(action)
コード例 #8
0
    def send(self, *a):
        if self._recursing: return

        rvSoftLevel = self.builder.get_object("rvSoftLevel")
        sclSoftLevel = self.builder.get_object("sclSoftLevel")
        cbGyroButton = self.builder.get_object("cbGyroButton")
        cbInvertGyro = self.builder.get_object("cbInvertGyro")
        item = cbGyroButton.get_model().get_value(
            cbGyroButton.get_active_iter(), 0)
        rvSoftLevel.set_reveal_child(item in TRIGGERS)

        normal, n_set = [None, None, None], False
        absolute, a_set = [None, None, None], False

        for i in xrange(0, 3):
            if self.axes[i] is not None:
                if self.cbs[i].get_active():
                    absolute[i] = self.axes[i]
                    a_set = True
                else:
                    normal[i] = self.axes[i]
                    n_set = True

        if n_set and a_set:
            action = MultiAction(GyroAction(*normal), GyroAbsAction(*absolute))
        elif n_set:
            action = GyroAction(*normal)
        elif a_set:
            action = GyroAbsAction(*absolute)
        else:
            action = NoAction()

        if item and action:
            what = getattr(SCButtons, item)
            if item in TRIGGERS:
                what = RangeOP(what, ">=", sclSoftLevel.get_value())
            if cbInvertGyro.get_active():
                action = ModeModifier(what, NoAction(), action)
            else:
                action = ModeModifier(what, action)

        self.editor.set_action(action)
コード例 #9
0
 def _save_modemod(self, index):
     """ Generates ModeModifier from page in Notebook """
     pars = []
     # TODO: Other pages
     for button, action, l, b, clearb in self.actions[index]:
         pars += [button, action]
     if self.nomods[index]:
         pars += [self.nomods[index]]
     action = ModeModifier(*pars)
     if len(pars) == 0:
         # No action is actually set
         action = NoAction()
     elif len(pars) == 1:
         # Only default action left
         action = self.nomods[index]
     return action
コード例 #10
0
 def _save_modemod(self, index):
     """ Generates ModeModifier from page in Notebook """
     adjSoftLevel = self.builder.get_object("adjSoftLevel")
     pars = []
     for item, action, l, b, clearb in self.actions[index]:
         if isinstance(item, RangeOP) and item.value == -1:
             # Value taken from slider
             item.value = adjSoftLevel.get_value()
         pars += [item, action]
     if self.nomods[index]:
         pars += [self.nomods[index]]
     action = ModeModifier(*pars)
     if len(pars) == 0:
         # No action is actually set
         action = NoAction()
     elif len(pars) == 1:
         # Only default action left
         action = self.nomods[index]
     return action
コード例 #11
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
コード例 #12
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