Esempio n. 1
0
def find_controller_icon(name):
	"""
	Returns filename for specified controller icon name.
	This is done by searching for name in ~/.config/controller-icons
	first and in /usr/share/scc/images/controller-icons later.
	
	Returns None if icon cannot be found.
	"""
	for p in (get_controller_icons_path(), get_default_controller_icons_path()):
		path = os.path.join(p, name)
		if os.path.exists(path):
			return path
	return None
Esempio n. 2
0
def find_controller_icon(name):
    """
	Returns filename for specified controller icon name.
	This is done by searching for name in ~/.config/controller-icons
	first and in /usr/share/scc/images/controller-icons later.
	
	Returns None if icon cannot be found.
	"""
    for p in (get_controller_icons_path(),
              get_default_controller_icons_path()):
        path = os.path.join(p, name)
        if os.path.exists(path):
            return path
    return None
Esempio n. 3
0
    def update_icon(self):
        """ Changes displayed icon to whatever is currently set in config """
        # Called internally and from ControllerSettings
        if not self._controller:
            self._icon.set_from_file(
                os.path.join(self.imagepath, "controller-icon.svg"))
            return

        id = self._controller.get_id()
        cfg = self.config.get_controller_config(id)
        if cfg["icon"]:
            icon = find_controller_icon(cfg["icon"])
            self._icon.set_from_file(icon)
        else:
            log.debug("There is no icon for controller %s, auto assinging one",
                      id)
            paths = [
                get_default_controller_icons_path(),
                get_controller_icons_path()
            ]

            def cb(icons):
                if id != self._controller.get_id():
                    # Controller was changed before callback was called
                    return
                icon = None
                used_icons = {
                    self.config['controllers'][x]['icon']
                    for x in self.config['controllers']
                    if 'icon' in self.config['controllers'][x]
                }
                tp = "%s-" % (self._controller.get_type(), )
                icons = sorted(
                    (os.path.split(x.get_path())[-1] for x in icons))
                log.debug("Searching for icon type: %s", tp.strip("-"))
                for i in icons:
                    if i not in used_icons and i.startswith(tp):
                        # Unused icon found
                        icon = i
                        break
                else:
                    # All icons are already used, assign anything
                    icon = random.choice(icons)
                log.debug("Auto-assigned icon %s for controller %s", icon, id)
                cfg = self.config.get_controller_config(id)
                cfg["icon"] = icon
                self.config.save()
                GLib.idle_add(self.update_icon)

            self.load_user_data(paths, "*.svg", None, cb)
Esempio n. 4
0
	def update_icon(self):
		""" Changes displayed icon to whatever is currently set in config """
		# Called internally and from ControllerSettings
		if not self._controller:
			self._icon.set_from_file(os.path.join(self.imagepath, "controller-icon.svg"))
			return
		
		id = self._controller.get_id()
		cfg = self.config.get_controller_config(id)
		if cfg["icon"]:
			icon = find_controller_icon(cfg["icon"])
			self._icon.set_from_file(icon)
		else:
			log.debug("There is no icon for controller %s, auto assinging one", id)
			paths = [ get_default_controller_icons_path(), get_controller_icons_path() ]
			
			def cb(icons):
				if id != self._controller.get_id():
					# Controller was changed before callback was called
					return
				icon = None
				used_icons = { 
					self.config['controllers'][x]['icon']
					for x in self.config['controllers']
					if 'icon' in self.config['controllers'][x]
				}
				tp = "%s-" % (self._controller.get_type(),)
				icons = sorted(( os.path.split(x.get_path())[-1] for x in icons ))
				log.debug("Searching for icon type: %s", tp.strip("-"))
				for i in icons:
					if i not in used_icons and i.startswith(tp):
						# Unused icon found
						icon = i
						break
				else:
					# All icons are already used, assign anything
					icon = random.choice(icons)
				log.debug("Auto-assigned icon %s for controller %s", icon, id)
				cfg = self.config.get_controller_config(id)
				cfg["icon"] = icon
				self.config.save()
				GLib.idle_add(self.update_icon)
			
			self.load_user_data(paths, "*.svg", None, cb)
	def load_icons(self):
		paths = [ get_default_controller_icons_path(), get_controller_icons_path() ]
		self.load_user_data(paths, "*.svg", None, self.on_icons_loaded)
Esempio n. 6
0
	def load_icons(self):
		paths = [ get_default_controller_icons_path(), get_controller_icons_path() ]
		self.load_user_data(paths, "*.svg", None, self.on_icons_loaded)