How to use the xdg.Menu.MenuEntry function in xdg

To help you get started, we’ve selected a few xdg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github takluyver / pyxdg / test / test-menu.py View on Github external
def test_unicode_menuentry(self):
        test_file = os.path.join(self.tmpdir, "unicode.desktop")
        with io.open(test_file, 'w', encoding='utf-8') as f:
            f.write(resources.unicode_desktop)
        
        entry = xdg.Menu.MenuEntry(test_file)
        assert entry == entry
        assert not entry < entry
github ArnaudValensi / xdg-menu-to-awesome-wm / awesome-xdg-menu.py View on Github external
def walk_menu(entry):
	if isinstance(entry, xdg.Menu.Menu) and entry.Show is True:
		print '<menu label="%s" id="%s">' \
			% (entry_name(entry),
			entry_name(entry),
			escape_utf8(icon_attr(entry)))
		map(walk_menu, entry.getEntries())
		print '</menu>'
	elif isinstance(entry, xdg.Menu.MenuEntry) and entry.Show is True:
		print '	' % \
			(entry_name(entry.DesktopEntry).replace('"', ''),
			escape_utf8(icon_attr(entry.DesktopEntry)))
		command = re.sub(' -caption "%c"| -caption %c', ' -caption "%s"' % entry_name(entry.DesktopEntry), entry.DesktopEntry.getExec())
		command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', command)
		if entry.DesktopEntry.getTerminal():
			command = 'xterm -title "%s" -e %s' % \
				(entry_name(entry.DesktopEntry), command)
		print '		' + \
			'%s' % command
		print '	'
github trisquelgnulinux / trisquel-packages / 6.0 / gnome-app-install / AppInstall / CoreMenu.py View on Github external
def _populateFromEntry(self, node, parent=None, progress=None):
        # for some reason xdg hiddes some entries, but we don't like that
        for entry in node.getEntries(hidden=True):
            self._dbg(2, "entry: %s" % (entry))
            if isinstance(entry, xdg.Menu.Menu):
                # we found a toplevel menu
                name = xmlescape(entry.getName())
                self._dbg(1, "we have a sub-menu %s " % name)
                item = Category(self, name, entry.getIcon())
                #print "adding: %s" % name
                self.pickle[item] = []
                self._populateFromEntry(entry, item,  progress=progress)
            elif isinstance(entry, xdg.Menu.MenuEntry):
                # more debug output
                self._dbg(3, node.getPath() + "/\t" + entry.DesktopFileID + "\t" + entry.DesktopEntry.getFileName())
                # we found a application
                name = xmlescape(entry.DesktopEntry.getName())
                self._dbg(1, "we have a application %s (%s) " % (name,entry.DesktopFileID))
                if name and entry.DesktopEntry.hasKey("X-AppInstall-Package"):
                    self._dbg(2,"parent is %s" % parent.name)

                    # check for duplicates, caused by e.g. scribus that has:
                    #   Categories=Application;Graphics;Qt;Office;
                    # so it appears in Graphics and Office
                    if entry.DesktopFileID in self.desktopEntriesSeen:
                        #print "already seen %s (%s)" % (name, entry)
                        continue
                    self.desktopEntriesSeen.add(entry.DesktopFileID)
github clinton-hall / nzbToMedia / libs / xdg / MenuEditor.py View on Github external
def __saveEntries(self, menu):
        if not menu:
            menu = self.menu
        if isinstance(menu.Directory, MenuEntry):
            menu.Directory.save()
        for entry in menu.getEntries(hidden=True):
            if isinstance(entry, MenuEntry):
                entry.save()
            elif isinstance(entry, Menu):
                self.__saveEntries(entry)
github clinton-hall / nzbToMedia / libs / xdg / MenuEditor.py View on Github external
def editMenu(self, menu, name=None, genericname=None, comment=None, icon=None, nodisplay=None, hidden=None):
        # Hack for legacy dirs
        if isinstance(menu.Directory, MenuEntry) and menu.Directory.Filename == ".directory":
            xml_menu = self.__getXmlMenu(menu.getPath(True, True))
            self.__addXmlTextElement(xml_menu, 'Directory', menu.Name + ".directory")
            menu.Directory.setAttributes(menu.Name + ".directory")
        # Hack for New Entries
        elif not isinstance(menu.Directory, MenuEntry):
            if not name:
                name = menu.Name
            filename = self.__getFileName(name, ".directory").replace("/", "")
            if not menu.Name:
                menu.Name = filename.replace(".directory", "")
            xml_menu = self.__getXmlMenu(menu.getPath(True, True))
            self.__addXmlTextElement(xml_menu, 'Directory', filename)
            menu.Directory = MenuEntry(filename)

        deskentry = menu.Directory.DesktopEntry

        if name:
            if not deskentry.hasKey("Name"):
                deskentry.set("Name", name)
            deskentry.set("Name", name, locale=True)
        if genericname:
            if not deskentry.hasKey("GenericName"):
                deskentry.set("GenericName", genericname)
            deskentry.set("GenericName", genericname, locale=True)
        if comment:
            if not deskentry.hasKey("Comment"):
                deskentry.set("Comment", comment)
            deskentry.set("Comment", comment, locale=True)
        if icon:
github clinton-hall / nzbToMedia / libs / xdg / MenuEditor.py View on Github external
def createMenuEntry(self, parent, name, command=None, genericname=None, comment=None, icon=None, terminal=None, after=None, before=None):
        menuentry = MenuEntry(self.__getFileName(name, ".desktop"))
        menuentry = self.editMenuEntry(menuentry, name, genericname, comment, command, icon, terminal)

        self.__addEntry(parent, menuentry, after, before)

        self.menu.sort()

        return menuentry
github ssokolow / game_launcher / src / game_providers / xdg_menu.py View on Github external
def _process_menu(menu):
    """Recursive handler for getting games from menus.

    Written based on this public-domain code by Konstantin Korikov:
    http://mmoeller.fedorapeople.org/icewm/icewm-xdg-menu/icewm-xdg-menu
    """
    entries = []
    for entry in menu.getEntries():
        if isinstance(entry, xdg.Menu.Menu):
            entries.extend(_process_menu(entry))
        elif isinstance(entry, xdg.Menu.MenuEntry):
            dentry = entry.DesktopEntry

            entries.append(dentry)
        else:
            log.debug("S: %s", entry)

    return entries
github takluyver / pyxdg / xdg / Menu.py View on Github external
for submenu in menu.Submenus:
            self.post_parse(submenu)

        # reverse so handling is easier
        menu.Directories.reverse()
        menu.DirectoryDirs.reverse()
        menu.AppDirs.reverse()

        # get the valid .directory file out of the list
        for directory in menu.Directories:
            for dir in menu.DirectoryDirs:
                if os.path.isfile(os.path.join(dir, directory)):
                    menuentry = MenuEntry(directory, dir)
                    if not menu.Directory:
                        menu.Directory = menuentry
                    elif menuentry.Type == MenuEntry.TYPE_SYSTEM:
                        if menu.Directory.Type == MenuEntry.TYPE_USER:
                            menu.Directory.Original = menuentry
            if menu.Directory:
                break