Esempio n. 1
0
def find_icon(name, prefer_bw=False, paths=None, extensions=("png", "svg")):
	"""
	Returns (filename, has_colors) for specified icon name.
	This is done by searching for name + '.png' and name + ".bw.png"
	in user and default menu-icons folders. ".svg" is also supported, but only
	if no pngs are found.
	
	If both colored and grayscale version is found, colored is returned, unless
	prefer_bw is set to True.
	
	paths defaults to icons for menuicons
	
	Returns (None, False) if icon cannot be found.
	"""
	if name is None:
		# Special case, so code can pass menuitem.icon directly
		return None, False
	if paths is None:
		paths = get_default_menuicons_path(), get_menuicons_path()
	if name.endswith(".bw"):
		name = name[0:-3]
	for extension in extensions:
		gray_filename = "%s.bw.%s" % (name, extension)
		colors_filename = "%s.%s" % (name, extension)
		gray, colors = None, None
		for p in paths:
			# Check grayscale
			if gray is None:
				path = os.path.join(p, gray_filename)
				if os.path.exists(path):
					if prefer_bw:
						return path, False
					gray = path
			# Check colors
			if colors is None:
				path = os.path.join(p, colors_filename)
				if os.path.exists(path):
					if not prefer_bw:
						return path, True
					colors = path
		if colors is not None:
			return colors, True
		if gray is not None:
			return gray, False
	return None, False
Esempio n. 2
0
def find_icon(name, prefer_bw=False, paths=None, extensions=("png", "svg")):
    """
	Returns (filename, has_colors) for specified icon name.
	This is done by searching for name + '.png' and name + ".bw.png"
	in user and default menu-icons folders. ".svg" is also supported, but only
	if no pngs are found.
	
	If both colored and grayscale version is found, colored is returned, unless
	prefer_bw is set to True.
	
	paths defaults to icons for menuicons
	
	Returns (None, False) if icon cannot be found.
	"""
    if name is None:
        # Special case, so code can pass menuitem.icon directly
        return None, False
    if paths is None:
        paths = get_default_menuicons_path(), get_menuicons_path()
    if name.endswith(".bw"):
        name = name[0:-3]
    for extension in extensions:
        gray_filename = "%s.bw.%s" % (name, extension)
        colors_filename = "%s.%s" % (name, extension)
        gray, colors = None, None
        for p in paths:
            # Check grayscale
            if gray is None:
                path = os.path.join(p, gray_filename)
                if os.path.exists(path):
                    if prefer_bw:
                        return path, False
                    gray = path
            # Check colors
            if colors is None:
                path = os.path.join(p, colors_filename)
                if os.path.exists(path):
                    if not prefer_bw:
                        return path, True
                    colors = path
        if colors is not None:
            return colors, True
        if gray is not None:
            return gray, False
    return None, False
Esempio n. 3
0
def find_icon(name, prefer_bw=False):
    """
	Returns (filename, has_colors) for specified icon name.
	This is done by searching for name + '.png' and name + ".bw.png"
	in user and default menu-icons folders.
	
	If both colored and grayscale version is found, colored is returned, unless
	prefer_bw is set to True.
	
	Returns (None, False) if icon cannot be found.
	"""
    if name is None:
        # Special case, so code can pass menuitem.icon directly
        return None, False
    gray_filename = "%s.bw.png" % (name, )
    colors_filename = "%s.png" % (name, )
    gray, colors = None, None
    # TODO: User menuicons folder
    for p in (get_default_menuicons_path(), get_menuicons_path()):
        # Check grayscale
        if gray is None:
            path = os.path.join(p, gray_filename)
            if os.path.exists(path):
                if prefer_bw:
                    return path, False
                gray = path
        # Check colors
        if colors is None:
            path = os.path.join(p, colors_filename)
            if os.path.exists(path):
                if not prefer_bw:
                    return path, True
                colors = path
    if colors is not None:
        return colors, True
    return gray, False
Esempio n. 4
0
 def load_menu_icons(self, category=None):
     paths = [get_default_menuicons_path(), get_menuicons_path()]
     self.load_user_data(paths, "*.png", category, self.on_menuicons_loaded)
Esempio n. 5
0
	def load_menu_icons(self, category=None):
		paths = [ get_default_menuicons_path(), get_menuicons_path() ]
		self.load_user_data(paths, "*.png", category, self.on_menuicons_loaded)