Пример #1
0
	def on_cbActionType_changed(self, *a):
		cbActionType = self.builder.get_object("cbActionType")
		stActionData = self.builder.get_object("stActionData")
		key = cbActionType.get_model().get_value(cbActionType.get_active_iter(), 0)
		if key == "shell":
			stActionData.set_visible_child(self.builder.get_object("vbShell"))
			self.on_enCommand_changed()
		elif key == "profile":
			stActionData.set_visible_child(self.builder.get_object("vbProfile"))
			self.on_cbProfile_changed()
		elif key == "keyboard":
			stActionData.set_visible_child(self.builder.get_object("nothing"))
			if not self._recursing:
				self.editor.set_action(KeyboardAction())
		elif key == "resetgyro":
			stActionData.set_visible_child(self.builder.get_object("nothing"))
			if not self._recursing:
				self.editor.set_action(ResetGyroAction())
		elif key == "osd":
			stActionData.set_visible_child(self.builder.get_object("vbOSD"))
			if not self._recursing:
				self.editor.set_action(OSDAction(""))
		elif key == "menu":
			stActionData.set_visible_child(self.builder.get_object("grMenu"))
			self.on_cbMenus_changed()
		elif key == "turnoff":
			stActionData.set_visible_child(self.builder.get_object("nothing"))
			if not self._recursing:
				self.editor.set_action(TurnOffAction())
		else: # none
			stActionData.set_visible_child(self.builder.get_object("nothing"))
			if not self._recursing:
				self.editor.set_action(NoAction())
Пример #2
0
 def on_osd_settings_changed(self, *a):
     if self._recursing: return
     enOSDText = self.builder.get_object("enOSDText")
     sclOSDTimeout = self.builder.get_object("sclOSDTimeout")
     cbOSDSize = self.builder.get_object("cbOSDSize")
     timeout = sclOSDTimeout.get_value()
     size = cbOSDSize.get_model().get_value(cbOSDSize.get_active_iter(), 0)
     self.editor.set_action(
         OSDAction(0 if timeout > 60.0 else timeout, size,
                   enOSDText.get_text().decode("utf-8")))
Пример #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
Пример #4
0
	def on_enOSDText_changed(self, *a):
		if self._recursing : return
		enOSDText = self.builder.get_object("enOSDText")
		self.editor.set_action(OSDAction(enOSDText.get_text().decode("utf-8")))
Пример #5
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
Пример #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