def on_btUserFolder_activate_link(self, *a): for c in DEFAULT_ICON_CATEGORIES: try: os.makedirs(os.path.join(get_menuicons_path(), c)) except: # Dir. exists pass
def setup_widgets(self): Editor.setup_widgets(self) clIcon = self.builder.get_object("clIcon") crIconName = self.builder.get_object("crIconName") btUserFolder = self.builder.get_object("btUserFolder") cr = CellRendererMenuIcon(32) clIcon.clear() clIcon.pack_start(cr, False) clIcon.pack_start(crIconName, True) clIcon.set_attributes(cr, icon=1, has_colors=2) clIcon.set_attributes(crIconName, text=0) btUserFolder.set_label("Add icons...") btUserFolder.set_uri("file://%s" % (get_menuicons_path(),)) headerbar(self.builder.get_object("header")) self.load_menu_icons()
def setup_widgets(self): Editor.setup_widgets(self) clIcon = self.builder.get_object("clIcon") crIconName = self.builder.get_object("crIconName") btUserFolder = self.builder.get_object("btUserFolder") cr = CellRendererMenuIcon(32) clIcon.clear() clIcon.pack_start(cr, False) clIcon.pack_start(crIconName, True) clIcon.set_attributes(cr, icon=1, has_colors=2) clIcon.set_attributes(crIconName, text=0) btUserFolder.set_label("Add icons...") btUserFolder.set_uri("file://%s" % (get_menuicons_path(), )) headerbar(self.builder.get_object("header")) self.load_menu_icons()
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
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
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)
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)