def populate_category(self): self.categories = {} try: from xdg.Menu import parse, Menu menu = parse() for submenu in menu.getEntries(): if isinstance(submenu, Menu) and submenu.Visible: name = submenu.getName() if self.categories.get(name) is None: self.categories[name] = submenu except Exception: log("failed to parse menus", exc_info=True) model = self.category_combo.get_model() if model: model.clear() for name in sorted(self.categories.keys()): self.category_combo.append_text(name) if self.categories: self.category_combo.set_active(0)
def do_load_xdg_menu_data(): try: from xdg.Menu import parse, Menu, ParsingError except ImportError: log("do_load_xdg_menu_data()", exc_info=True) log.warn("Warning: cannot use application menu data:") log.warn(" no python-xdg module") return None menu = None error = None with OSEnvContext(): #see ticket #2174, #things may break if the prefix is not set, #and it isn't set when logging in via ssh for prefix in (None, "", "gnome-", "kde-"): if prefix is not None: os.environ["XDG_MENU_PREFIX"] = prefix try: menu = parse() break except ParsingError as e: log("do_load_xdg_menu_data()", exc_info=True) error = e menu = None if menu is None: if error: log.error("Error parsing xdg menu data:") log.error(" %s", error) log.error(" this is either a bug in python-xdg,") log.error(" or an invalid system menu configuration") return None menu_data = {} for submenu in menu.getEntries(): if isinstance(submenu, Menu) and submenu.Visible: name = submenu.getName() try: menu_data[name] = load_xdg_menu(submenu) except Exception as e: log("load_xdg_menu_data()", exc_info=True) log.error("Error loading submenu '%s':", name) log.error(" %s", e) return menu_data
def load_xdg_menu_data(): try: from xdg.Menu import parse, Menu #pylint: disable=import-outside-toplevel except ImportError: log("load_xdg_menu_data()", exc_info=True) if first_time("no-python-xdg"): log.warn("Warning: cannot use application menu data:") log.warn(" no python-xdg module") return None menu = None error = None #see ticket #2340, #invalid values for XDG_CONFIG_DIRS can cause problems, #so try unsetting it if we can't load the menus with it: for cd in (False, True): with OSEnvContext(): if cd: if not os.environ.pop("XDG_CONFIG_DIRS", ""): #was already unset continue #see ticket #2174, #things may break if the prefix is not set, #and it isn't set when logging in via ssh for prefix in (None, "", "gnome-", "kde-"): if prefix is not None: os.environ["XDG_MENU_PREFIX"] = prefix try: log( "parsing xdg menu data for prefix %r with XDG_CONFIG_DIRS=%s and XDG_MENU_PREFIX=%s", prefix, os.environ.get("XDG_CONFIG_DIRS"), os.environ.get("XDG_MENU_PREFIX")) menu = parse() break except Exception as e: log("load_xdg_menu_data()", exc_info=True) error = e menu = None if menu: break if menu is None: if error: log.error("Error parsing xdg menu data:") log.error(" %s", error) log.error(" this is either a bug in python-xdg,") log.error(" or an invalid system menu configuration") return None menu_data = {} entries = tuple(menu.getEntries()) log("%s.getEntries()=%s", menu, entries) if len(entries) == 1 and entries[0].Submenus: entries = entries[0].Submenus log("using submenus %s", entries) for i, submenu in enumerate(entries): if not isinstance(submenu, Menu): log("entry '%s' is not a submenu", submenu) continue name = submenu.getName() log("* %-3i %s", i, name) if not submenu.Visible: log(" submenu '%s' is not visible", name) continue try: md = load_xdg_menu(submenu) if md: menu_data[name] = md else: log(" no menu data for %s", name) except Exception as e: log("load_xdg_menu_data()", exc_info=True) log.error("Error loading submenu '%s':", name) log.error(" %s", e) if LOAD_APPLICATIONS: from xdg.Menu import MenuEntry entries = {} for d in LOAD_APPLICATIONS: for f in os.listdir(d): if not f.endswith(".desktop"): continue try: me = MenuEntry(f, d) except Exception: log("failed to load %s from %s", f, d, exc_info=True) else: ed = load_xdg_entry(me.DesktopEntry) if not ed: continue name = ed.get("Name") #ensure we don't already have it in another submenu: for menu_category in menu_data.values(): if name in menu_category.get("Entries", {}): ed = None break if ed: entries[name] = ed log("entries(%s)=%s", LOAD_APPLICATIONS, remove_icons(entries)) if entries: #add an 'Applications' menu if we don't have one: md = menu_data.get("Applications") if not md: md = { "Name": "Applications", } menu_data["Applications"] = md md.setdefault("Entries", {}).update(entries) return menu_data
def create_script(filename, content): try: os.makedirs(os.path.dirname(filename)) except OSError as e: if e.errno is not errno.EEXIST: raise content = content.replace('${SHELL:-bash}', '') with open(filename, 'w') as f: f.write(content) st = os.stat(filename) os.chmod(filename, st.st_mode | stat.S_IEXEC) # Main if not len(sys.argv) > 1: print """ Usage: kalimenu2dir <path> """ sys.exit() menu = parse('/etc/xdg/menus/gnome-applications.menu') kindex = [str(x) for x in menu.getEntries()].index("Kali") + 1 kalimenu = menu.Entries[kindex] dest_dir = os.path.abspath(sys.argv[1]) create_dir_menu(kalimenu, dest_dir)
def __init__(self): self.current_node = parse() self.stack = [] menu = self.get_menu() super(MainFrame, self).__init__(menu, left=2, right=2)
# Only Append if it's executable #if (item.findTryExec()): # menuJSON.append(newitem); #if newitem["name"]!="": menuJSON.append(newitem); return menuJSON # Ompli el item i el retorna #m=parse("/etc/xdg/menus/applications.menu"); #m=parse("/etc/xdg/menus/gnome-flashback-applications.menu"); m=parse("/etc/xdg/menus/corellian.menu"); catmenu={"categories":[]} # Cleaning directory for icons: pngpath=xdg_config_home+"/llx-launchpad/icons/" if os.path.exists(pngpath): shutil.rmtree(pngpath); os.mkdir(pngpath) # Create empty path catmenu["categories"]=parseMenu(m, catmenu["categories"]) import json with open('mymenu.json', 'w') as outfile: json.dump(catmenu, outfile)
# menuJSON.append(newitem); #if newitem["name"]!="": menuJSON.append(newitem); return menuJSON # Ompli el item i el retorna if (len(sys.argv)!=2): iconTheme="hicolor" else: iconTheme=sys.argv[1] #m=parse("./corellian-system.menu"); m=parse("/etc/xdg/menus/xfce-applications.menu"); catmenu={"categories":[]} # Cleaning directory for icons: if not os.path.exists(xdg_config_home+"/corellian-launcher/"): os.mkdir(xdg_config_home+"/corellian-launcher/") pngpath=xdg_config_home+"/corellian-launcher/icons/" if os.path.exists(pngpath): shutil.rmtree(pngpath); os.mkdir(pngpath) # Create empty path catmenu["categories"]=parseMenu(m, catmenu["categories"])
dmenu_opts = '-b -i -l 20 -fn -*-terminus-bold-r-*-*-16 -nf #fff -nb #000 -sf #f00 -sb #300' #make this an arg later dmenu = 'dmenu ' + dmenu_opts.strip() dmenu = dmenu.split(' ') def parse_menu(menu): items = {} for submenu in menu.Entries: if isinstance(submenu, Menu): items[submenu.getName() + '/'] = submenu elif isinstance(submenu, MenuEntry): items[submenu.DesktopEntry.getName()] = submenu.DesktopEntry.getExec() return items active_menu = parse() bin = '' while bin == '': menus = parse_menu(active_menu) pipes = subprocess.Popen(dmenu, stdout=subprocess.PIPE, stdin=subprocess.PIPE) selected, err = pipes.communicate('\n'.join(menus.keys())) menu = menus[selected.strip()] if isinstance(menu, str): bin = menu else:
#if (item.findTryExec()): # menuJSON.append(newitem); #if newitem["name"]!="": menuJSON.append(newitem); return menuJSON # Ompli el item i el retorna if (len(sys.argv)!=2): iconTheme="hicolor" else: iconTheme=sys.argv[1] m=parse("./corellian-system.menu"); #m=parse("/etc/xdg/menus/xfce-applications.menu"); catmenu={"categories":[]} # Cleaning directory for icons: if not os.path.exists(xdg_config_home+"/corellian-launcher/"): os.mkdir(xdg_config_home+"/corellian-launcher/") pngpath=xdg_config_home+"/corellian-launcher/icons/" if os.path.exists(pngpath): shutil.rmtree(pngpath); os.mkdir(pngpath) # Create empty path catmenu["categories"]=parseMenu(m, catmenu["categories"])