コード例 #1
0
ファイル: vdf.py プロジェクト: miniskipper/sc-controller
    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
コード例 #2
0
ファイル: vdf.py プロジェクト: kozec/sc-controller
	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
コード例 #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,))
コード例 #4
0
ファイル: vdf.py プロジェクト: miniskipper/sc-controller
 def find_group(data, id):
     """ Returns group with specified ID or None """
     for g in ensure_list(data["group"]):
         if "id" in g and g["id"] == id:
             return g
     return None
コード例 #5
0
ファイル: vdf.py プロジェクト: kozec/sc-controller
	def find_group(data, id):
		""" Returns group with specified ID or None """
		for g in ensure_list(data["group"]):
			if "id" in g and g["id"] == id:
				return g
		return None