How to use the scc.profile.Profile function in scc

To help you get started, we’ve selected a few scc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kozec / sc-controller / scc / gui / importexport / export.py View on Github external
def _add_refereced_profile(self, model, giofile, used):
		"""
		Loads profile file and recursively adds all profiles and menus
		referenced by it into 'package' list.
		
		Returns True on success or False if something cannot be parsed.
		"""
		# Load & parse selected profile and check every action in it
		profile = Profile(ActionParser())
		try:
			profile.load(giofile.get_path())
		except Exception, e:
			# Profile that cannot be parsed shouldn't be exported
			log.error(e)
			return False
		
		for action in profile.get_actions():
			self._parse_action(model, action, used)
		
		for menu in profile.menus:
			for item in profile.menus[menu]:
				if isinstance(item, Submenu):
					self._add_refereced_menu(model, os.path.split(item.filename)[-1], used)
				if hasattr(item, "action"):
					self._parse_action(model, item.action, used)
github kozec / sc-controller / scc / gui / binding_editor.py View on Github external
before, profile.buttons[id] = profile.buttons[id], action
			self.button_widgets[id].update()
		if id in PRESSABLE:
			before, profile.buttons[id] = profile.buttons[id], action
			self.button_widgets[id.name].update()
		elif id in TRIGGERS:
			before, profile.triggers[id] = profile.triggers[id], action
			self.button_widgets[id].update()
		elif id in GYROS:
			before, profile.gyro = profile.gyro, action
			self.button_widgets[id].update()
		elif id in STICKS + PADS:
			if id in STICKS:
				before, profile.stick = profile.stick, action
			elif id == "LPAD":
				before, profile.pads[Profile.LEFT] = profile.pads[Profile.LEFT], action
			else:
				before, profile.pads[Profile.RIGHT] = profile.pads[Profile.RIGHT], action
			self.button_widgets[id].update()
		return before
github kozec / sc-controller / python / scc / gui / global_settings.py View on Github external
def _load_osk_profile(self):
		"""
		Loads and returns on-screen keyboard profile.
		Used by methods that are changing it.
		"""
		profile = Profile(GuiActionParser())
		profile.load(find_profile(OSDKeyboard.OSK_PROF_NAME))
		return profile
github kozec / sc-controller / scc / gui / controller_widget.py View on Github external
Wraps around actual button defined in glade file.
"""
from __future__ import unicode_literals
from scc.tools import _

from gi.repository import Gtk, Gdk, Pango
from scc.constants import SCButtons, STICK, GYRO, LEFT, RIGHT
from scc.actions import Action, XYAction, MultiAction
from scc.gui.ae.gyro_action import is_gyro_enable
from scc.profile import Profile
import os, sys, logging

log = logging.getLogger("ControllerWidget")

TRIGGERS = [ Profile.LEFT, Profile.RIGHT ]
PADS	= [ "LPAD", "RPAD" ]
STICKS	= [ STICK ]
GYROS	= [ GYRO ]
PRESSABLE = [ SCButtons.LPAD, SCButtons.RPAD, SCButtons.STICK ]
_NOT_BUTTONS = PADS + STICKS + GYROS + [ "LT", "RT" ] 
_NOT_BUTTONS += [ x + "TOUCH" for x in PADS ]
BUTTONS = [ b for b in SCButtons if b.name not in _NOT_BUTTONS ]
LONG_TEXT = 12

class ControllerWidget:
	ACTION_CONTEXT = None

	def __init__(self, app, id, use_icon, widget):
		self.app = app
		self.id = id
		self.name = id if type(id) in (str, unicode) else id.name
github kozec / sc-controller / scc / sccdaemon.py View on Github external
def _set_profile(self, mapper, filename):
		# Called from socket server thread
		p = Profile(TalkingActionParser())
		p.load(filename).compress()
		self.profile_file = filename
		
		if mapper.profile.gyro and not p.gyro:
			# Turn off gyro sensor that was enabled but is no longer needed
			if mapper.get_controller():
				log.debug("Turning gyrosensor OFF")
				mapper.get_controller().set_gyro_enabled(False)
		elif not mapper.profile.gyro and p.gyro:
			# Turn on gyro sensor that was turned off, if profile has gyro action set
			if mapper.get_controller():
				log.debug("Turning gyrosensor ON")
				mapper.get_controller().set_gyro_enabled(True)
		# Cancel everything
		mapper.cancel_all()
		# Release all buttons
github kozec / sc-controller / scc / foreign / vdf.py View on Github external
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,))
github kozec / sc-controller / scc / gui / app.py View on Github external
def convert_old_profiles(self):
		"""
		Checks all available profiles and automatically converts anything with
		version 1.3 or lower.
		"""
		from scc.parser import ActionParser
		to_convert = {}
		for name in os.listdir(get_profiles_path()):
			if name.endswith("~"):
				# Ignore backups - https://github.com/kozec/sc-controller/issues/440
				continue
			try:
				p = Profile(ActionParser())
				p.load(os.path.join(get_profiles_path(), name))
			except:
				# Just ignore invalid profiles here
				continue
			if p.original_version < 1.4:
				to_convert[name] = p
		
		if to_convert:
			log.warning("Auto-converting old profile files to version 1.4. This should take only moment.")
			log.warning("All files are modified in-place, but backup files are created. Feel free to remove them later.")
			for name in to_convert:
				try:
					to_convert[name].save("%s/%s.convert" % (get_profiles_path(), name))
					os.rename("%s/%s" % (get_profiles_path(), name),
							"%s/%s~" % (get_profiles_path(), name))
					os.rename("%s/%s.convert" % (get_profiles_path(), name),
github kozec / sc-controller / scc / gui / importexport / export.py View on Github external
def _export(self, giofile, target_filename):
		"""
		Performs actual exporting.
		This method is used when only profile with no referenced files
		is to be exported and works pretty simple - load, parse, save in new file.
		"""
		profile = Profile(TalkingActionParser())
		try:
			profile.load(giofile.get_path())
		except Exception, e:
			# Profile that cannot be parsed shouldn't be exported
			log.error(e)
			return False
		
		profile.save(target_filename)
		return True