예제 #1
0
 def _make_action(self):
     """ Generates and returns Action instance """
     entName = self.builder.get_object("entName")
     cbMacroType = self.builder.get_object("cbMacroType")
     pars = [x[0] for x in self.actions]
     if len(pars) == 0:
         # No action is actually set
         action = NoAction()
     elif cbMacroType.get_active() == 2:
         # Cycle
         pars = filter(lambda a: not isinstance(a, SleepAction), pars)
         action = Cycle(*pars)
     elif cbMacroType.get_active() == 1:
         # Repeating macro
         action = Macro(*pars)
         action.repeat = True
     elif len(pars) == 1:
         # Only one action
         action = pars[0]
     else:
         # Macro
         action = Macro(*pars)
     if entName.get_text().strip() != "":
         action.name = entName.get_text().strip()
     return action
예제 #2
0
	def _make_action(self):
		""" Generates and returns Action instance """
		entName = self.builder.get_object("entName")
		cbMacroType = self.builder.get_object("cbMacroType")
		pars = [ x[0] for x in self.actions ]
		if len(pars) == 0:
			# No action is actually set
			action = NoAction()
		elif cbMacroType.get_active() == 2:
			# Cycle
			pars = filter(lambda a : not isinstance(a, SleepAction), pars)
			action = Cycle(*pars)
		elif cbMacroType.get_active() == 1:
			# Repeating macro
			action = Macro(*pars)
			action.repeat = True
		elif len(pars) == 1:
			# Only one action
			action = pars[0]
		else:
			# Macro
			action = Macro(*pars)
		if entName.get_text().decode("utf-8").strip() != "":
			action.name = entName.get_text().decode("utf-8").strip()
		return action
예제 #3
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)
		return a
예제 #4
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