示例#1
0
	def save(self):
		""" Saves configuration file """
		# Check & create directory
		if not os.path.exists(get_config_path()):
			os.makedirs(get_config_path())
		# Save
		data = { k:self.values[k] for k in self.values }
		jstr = Encoder(sort_keys=True, indent=4).encode(data)
		file(self.filename, "w").write(jstr)
		log.debug("Configuration saved")
示例#2
0
 def save(self):
     """ Saves configuration file """
     # Check & create directory
     if not os.path.exists(get_config_path()):
         os.makedirs(get_config_path())
     # Save
     data = {k: self.values[k] for k in self.values}
     jstr = Encoder(sort_keys=True, indent=4).encode(data)
     file(self.filename, "w").write(jstr)
     log.debug("Configuration saved")
示例#3
0
	def load_profile_selection(self):
		""" Returns name profile from config file or None if there is none saved """
		try:
			data = json.loads(open(os.path.join(get_config_path(), self.CONFIG), "r").read())
			return data['current_profile']
		except:
			return None
示例#4
0
 def _scan_thread_target(self):
     for fname in evdev.list_devices():
         try:
             dev = evdev.InputDevice(fname)
         except Exception:
             continue
         if dev.fn not in self._devices:
             key = (dev.info.bustype, dev.info.vendor, dev.info.product)
             config_file = os.path.join(
                 get_config_path(), "devices",
                 "evdev-%s.json" % (dev.name.strip(), ))
             if key in self._known_ids:
                 with self._lock:
                     callback = self._known_ids[key]
                     if callback not in self._callbacks_to_call:
                         self._callbacks_to_call[callback] = []
                     self._callbacks_to_call[callback].append(dev)
             elif os.path.exists(config_file):
                 config = None
                 try:
                     config = json.loads(open(config_file, "r").read())
                     with self._lock:
                         self._new_devices.put((dev, config_file, config))
                 except Exception, e:
                     log.exception(e)
示例#5
0
	def scan_files(self):
		"""
		Goes through ~/.config/scc/devices and enables hotplug callback for
		every known HID device
		"""
		path = os.path.join(get_config_path(), "devices")
		if not os.path.exists(path):
			# Nothing to do
			return
		
		known = set()
		for name in os.listdir(path):
			if name.startswith("hid-") and name.endswith(".json"):
				vid, pid = name.split("-", 2)[1].split(":")[0:2]
				vid = int(vid, 16)
				pid = int(pid, 16)
				config_file = os.path.join(path, name)
				try:
					config = json.loads(open(config_file, "r").read())
				except Exception, e:
					log.warning("Ignoring file that cannot be parsed: %s", name)
					continue
				
				self.config_files[vid, pid] = config_file
				self.configs[vid, pid] = config
				known.add((vid, pid))
 def load_controllers(self, *a):
     lstControllers = self.builder.get_object("lstControllers")
     lstControllers.clear()
     devices_path = os.path.join(get_config_path(), "devices")
     if not os.path.exists(devices_path):
         os.makedirs(os.path.join(get_config_path(), "devices"))
     for filename in os.listdir(os.path.join(get_config_path(), "devices")):
         if filename.endswith(".json"):
             if filename.startswith("hid-"):
                 drv, usbid, name = filename.split("-", 2)
                 name = "%s <i>(%s)</i>" % (name[0:-5], usbid.upper())
             else:
                 drv, name = filename.split("-", 1)
                 name = name[0:-5]
             path = os.path.join(get_config_path(), "devices", filename)
             lstControllers.append(
                 (path, name, self._get_gamepad_icon(drv)))
示例#7
0
	def save_profile_selection(self, path):
		""" Saves name of profile into config file """
		name = os.path.split(path)[-1]
		if name.endswith(".sccprofile"):
			name = name[0:-11]
		
		data = dict(current_profile=name)
		jstr = json.dumps(data, sort_keys=True, indent=4)
		
		open(os.path.join(get_config_path(), self.CONFIG), "w").write(jstr)
示例#8
0
	def save_profile_selection(self, path):
		""" Saves name of profile into config file """
		name = os.path.split(path)[-1]
		if name.endswith(".sccprofile"):
			name = name[0:-11]
		
		data = dict(current_profile=name)
		jstr = json.dumps(data, sort_keys=True, indent=4)
		
		open(os.path.join(get_config_path(), self.CONFIG), "w").write(jstr)
示例#9
0
	def _scan_thread_target(self):
		for fname in evdev.list_devices():
			try:
				dev = evdev.InputDevice(fname)
			except Exception:
				continue
			if dev.fn not in self._devices:
				config_file = os.path.join(get_config_path(), "devices",
					"evdev-%s.json" % (dev.name.strip(),))
				if os.path.exists(config_file):
					config = None
					try:
						config = json.loads(open(config_file, "r").read())
						with self._lock:
							self._new_devices.put(( dev, config_file, config ))
					except Exception, e:
						log.exception(e)
示例#10
0
	def handle_new_device(self, syspath, *bunchofnones):
		# There is no way to get anything usefull from /sys/.../input node,
		# but I'm interested about event devices here anyway
		eventnode = EvdevDriver.get_event_node(syspath)
		if eventnode is None: return False				# Not evdev
		if eventnode in self._devices: return False		# Already handled
		
		try:
			dev = evdev.InputDevice(eventnode)
			assert dev.fn == eventnode
			config_fn = "evdev-%s.json" % (dev.name.strip().replace("/", ""),)
			config_file = os.path.join(get_config_path(), "devices", config_fn)
		except OSError, ose:
			if ose.errno == 13:
				# Excepted error that happens often, don't report
				return False
			log.exception(ose)
			return False
示例#11
0
	def __init__(self, config=None):
		self.bdisplay = os.path.join(get_config_path(), 'binding-display.svg')
		if not os.path.exists(self.bdisplay):
			# Prefer image in ~/.config/scc, but load default one as fallback
			self.bdisplay = os.path.join(get_share_path(), "images", 'binding-display.svg')
		
		OSDWindow.__init__(self, "osd-keyboard")
		self.daemon = None
		self.config = config or Config()
		self.group = None
		self.limits = {}
		self.background = None
		
		self._eh_ids = []
		self._stick = 0, 0
		
		self.c = Gtk.Box()
		self.c.set_name("osd-keyboard-container")
示例#12
0
    def __init__(self):
        OSDWindow.__init__(self, "osd-keyboard")
        TimerManager.__init__(self)
        self.daemon = None
        self.mapper = None
        self.keymap = Gdk.Keymap.get_default()
        self.keymap.connect('state-changed', self.on_state_changed)
        self.profile = Profile(TalkingActionParser())

        kbimage = os.path.join(get_config_path(), 'keyboard.svg')
        if not os.path.exists(kbimage):
            # Prefer image in ~/.config/scc, but load default one as fallback
            kbimage = os.path.join(get_share_path(), "images", 'keyboard.svg')
        self.background = SVGWidget(self, kbimage)

        self.limits = {}
        self.limits[LEFT] = self.background.get_rect_area(
            self.background.get_element("LIMIT_LEFT"))
        self.limits[RIGHT] = self.background.get_rect_area(
            self.background.get_element("LIMIT_RIGHT"))

        cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg')
        self.cursors = {}
        self.cursors[LEFT] = Gtk.Image.new_from_file(cursor)
        self.cursors[LEFT].set_name("osd-keyboard-cursor")
        self.cursors[RIGHT] = Gtk.Image.new_from_file(cursor)
        self.cursors[RIGHT].set_name("osd-keyboard-cursor")

        self._eh_ids = []
        self._stick = 0, 0
        self._hovers = {self.cursors[LEFT]: None, self.cursors[RIGHT]: None}
        self._pressed = {self.cursors[LEFT]: None, self.cursors[RIGHT]: None}

        self.c = Gtk.Box()
        self.c.set_name("osd-keyboard-container")

        self.f = Gtk.Fixed()
        self.f.add(self.background)
        self.f.add(self.cursors[LEFT])
        self.f.add(self.cursors[RIGHT])
        self.c.add(self.f)
        self.add(self.c)

        self.timer('labels', 0.1, self.update_labels)
示例#13
0
	def __init__(self):
		OSDWindow.__init__(self, "osd-keyboard")
		TimerManager.__init__(self)
		self.daemon = None
		self.keyboard = None
		self.keymap = Gdk.Keymap.get_default()
		self.keymap.connect('state-changed', self.on_state_changed)
		
		
		kbimage = os.path.join(get_config_path(), 'keyboard.svg')
		if not os.path.exists(kbimage):
			# Prefer image in ~/.config/scc, but load default one as fallback
			kbimage = os.path.join(get_share_path(), "images", 'keyboard.svg')
		self.background = SVGWidget(self, kbimage)
		
		self.limit_left  = self.background.get_rect_area(self.background.get_element("LIMIT_LEFT"))
		self.limit_right = self.background.get_rect_area(self.background.get_element("LIMIT_RIGHT"))
		
		cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg')
		self.cursor_left = Gtk.Image.new_from_file(cursor)
		self.cursor_left.set_name("osd-keyboard-cursor")
		self.cursor_right = Gtk.Image.new_from_file(cursor)
		self.cursor_right.set_name("osd-keyboard-cursor")
		
		self._eh_ids = []
		self._stick = 0, 0
		self._hovers = { self.cursor_left : None, self.cursor_right : None }
		self._pressed = { self.cursor_left : None, self.cursor_right : None }
		
		self.c = Gtk.Box()
		self.c.set_name("osd-keyboard-container")
		
		self.f = Gtk.Fixed()
		self.f.add(self.background)
		self.f.add(self.cursor_left)
		self.f.add(self.cursor_right)
		self.c.add(self.f)
		self.add(self.c)
		
		self.set_cursor_position(0, 0, self.cursor_left, self.limit_left)
		self.set_cursor_position(0, 0, self.cursor_right, self.limit_right)
		
		self.timer('labels', 0.1, self.update_labels)
示例#14
0
    def __init__(self, config=None):
        self.kbimage = os.path.join(get_config_path(), 'keyboard.svg')
        if not os.path.exists(self.kbimage):
            # Prefer image in ~/.config/scc, but load default one as fallback
            self.kbimage = os.path.join(get_share_path(), "images",
                                        'keyboard.svg')

        TimerManager.__init__(self)
        OSDWindow.__init__(self, "osd-keyboard")
        self.daemon = None
        self.mapper = None
        self.keymap = Gdk.Keymap.get_default()
        self.keymap.connect('state-changed', self.on_keymap_state_changed)
        Action.register_all(sys.modules['scc.osd.osk_actions'], prefix="OSK")
        self.profile = Profile(TalkingActionParser())
        self.config = config or Config()
        self.dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay()))
        self.group = None
        self.limits = {}
        self.background = None

        cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg')
        self.cursors = {}
        self.cursors[LEFT] = Gtk.Image.new_from_file(cursor)
        self.cursors[LEFT].set_name("osd-keyboard-cursor")
        self.cursors[RIGHT] = Gtk.Image.new_from_file(cursor)
        self.cursors[RIGHT].set_name("osd-keyboard-cursor")
        self.cursors[CPAD] = Gtk.Image.new_from_file(cursor)
        self.cursors[CPAD].set_name("osd-keyboard-cursor")

        self._eh_ids = []
        self._controller = None
        self._stick = 0, 0
        self._hovers = {self.cursors[LEFT]: None, self.cursors[RIGHT]: None}
        self._pressed = {self.cursors[LEFT]: None, self.cursors[RIGHT]: None}
        self._pressed_areas = {}

        self.c = Gtk.Box()
        self.c.set_name("osd-keyboard-container")

        self.f = Gtk.Fixed()
    def scan_files(self):
        """
		Goes through ~/.config/scc/devices and enables hotplug callback for
		every known HID device
		"""
        path = os.path.join(get_config_path(), "devices")
        if not os.path.exists(path):
            # Nothing to do
            return

        known = set()
        for name in os.listdir(path):
            if name.startswith("hid-") and name.endswith(".json"):
                vid, pid = name.split("-", 2)[1].split(":")[0:2]
                vid = int(vid, 16)
                pid = int(pid, 16)
                config_file = os.path.join(path, name)
                try:
                    config = json.loads(open(config_file, "r").read())
                except Exception:
                    log.warning("Ignoring file that cannot be parsed: %s",
                                name)
                    continue

                self.config_files[vid, pid] = config_file.decode("utf-8")
                self.configs[vid, pid] = config
                known.add((vid, pid))

        for new in known - self.registered:
            vid, pid = new
            register_hotplug_device(self.hotplug_cb, vid, pid)
            self.registered.add(new)

        for removed in self.registered - known:
            vid, pid = removed
            unregister_hotplug_device(self.hotplug_cb, vid, pid)
            self.registered.remove(removed)
            if (vid, pid) in self.config_files:
                del self.config_files[vid, pid]
            if (vid, pid) in self.configs:
                del self.configs[vid, pid]
示例#16
0
	def scan_files(self):
		"""
		Goes through ~/.config/scc/devices and enables hotplug callback for
		every known HID device
		"""
		path = os.path.join(get_config_path(), "devices")
		if not os.path.exists(path):
			# Nothing to do
			return
		
		known = set()
		for name in os.listdir(path):
			if name.startswith("hid-") and name.endswith(".json"):
				vid, pid = name.split("-", 2)[1].split(":")[0:2]
				vid = int(vid, 16)
				pid = int(pid, 16)
				config_file = os.path.join(path, name)
				try:
					config = json.loads(open(config_file, "r").read())
				except Exception:
					log.warning("Ignoring file that cannot be parsed: %s", name)
					continue
				
				self.config_files[vid, pid] = config_file
				self.configs[vid, pid] = config
				known.add((vid, pid))
		
		for new in known - self.registered:
			vid, pid = new
			register_hotplug_device(self.hotplug_cb, vid, pid)
			self.registered.add(new)
		
		for removed in self.registered - known:
			vid, pid = removed
			unregister_hotplug_device(self.hotplug_cb, vid, pid)
			self.registered.remove(removed)
			if (vid, pid) in self.config_files:
				del self.config_files[vid, pid]
			if (vid, pid) in self.configs:
				del self.configs[vid, pid]
示例#17
0
	def __init__(self, config=None):
		self.kbimage = os.path.join(get_config_path(), 'keyboard.svg')
		if not os.path.exists(self.kbimage):
			# Prefer image in ~/.config/scc, but load default one as fallback
			self.kbimage = os.path.join(get_share_path(), "images", 'keyboard.svg')
		
		TimerManager.__init__(self)
		OSDWindow.__init__(self, "osd-keyboard")
		self.daemon = None
		self.mapper = None
		self.keymap = Gdk.Keymap.get_default()
		self.keymap.connect('state-changed', self.on_keymap_state_changed)
		Action.register_all(sys.modules['scc.osd.osk_actions'], prefix="OSK")
		self.profile = Profile(TalkingActionParser())
		self.config = config or Config()
		self.dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay()))
		self.group = None
		self.limits = {}
		self.background = None
		
		cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg')
		self.cursors = {}
		self.cursors[LEFT] = Gtk.Image.new_from_file(cursor)
		self.cursors[LEFT].set_name("osd-keyboard-cursor")
		self.cursors[RIGHT] = Gtk.Image.new_from_file(cursor)
		self.cursors[RIGHT].set_name("osd-keyboard-cursor")
		self.cursors[CPAD] = Gtk.Image.new_from_file(cursor)
		self.cursors[CPAD].set_name("osd-keyboard-cursor")
		
		self._eh_ids = []
		self._controller = None
		self._stick = 0, 0
		self._hovers = { self.cursors[LEFT]: None, self.cursors[RIGHT]: None }
		self._pressed = { self.cursors[LEFT]: None, self.cursors[RIGHT]: None }
		self._pressed_areas = {}
		
		self.c = Gtk.Box()
		self.c.set_name("osd-keyboard-container")
		
		self.f = Gtk.Fixed()
示例#18
0
def load_custom_module(log, who_calls="daemon"):
	"""
	Loads and imports ~/.config/scc/custom.py, if it is present and displays
	big, fat warning in such case.
	
	Returns True if file exists.
	"""
	
	filename = os.path.join(get_config_path(), "custom.py")
	if os.path.exists(filename):
		log.warning("=" * 60)
		log.warning("Loading %s" % (filename, ))
		log.warning("If you don't know what this means or you haven't "
			"created it, stop daemon right now and remove this file.")
		log.warning("")
		log.warning("Also try removing it if %s crashes "
			"shortly after this message." % (who_calls,))
		
		import imp
		imp.load_source("custom", filename)
		log.warning("=" * 60)
		return True
	return False
示例#19
0
def load_custom_module(log, who_calls="daemon"):
    """
	Loads and imports ~/.config/scc/custom.py, if it is present and displays
	big, fat warning in such case.
	
	Returns True if file exists.
	"""

    filename = os.path.join(get_config_path(), "custom.py")
    if os.path.exists(filename):
        log.warning("=" * 60)
        log.warning("Loading %s" % (filename, ))
        log.warning("If you don't know what this means or you haven't "
                    "created it, stop daemon right now and remove this file.")
        log.warning("")
        log.warning("Also try removing it if %s crashes "
                    "shortly after this message." % (who_calls, ))

        import imp
        imp.load_source("custom", filename)
        log.warning("=" * 60)
        return True
    return False
示例#20
0
 def __init__(self):
     self.filename = os.path.join(get_config_path(), "config.json")
     self.reload()
示例#21
0
	def __init__(self):
		self.filename = os.path.join(get_config_path(), "config.json")
		self.reload()