def build_menu(self): self.applications_items = [] self.settings_items = [] self.session_items = [] """ Applications """ tree = gmenu.lookup_tree("applications.menu") tree.add_monitor(self.menu_changed_cb, self.applications_items) if tree.root is not None: self.append_directory(tree.root, self.menu, item_list=self.applications_items) self.menu.append(gtk.SeparatorMenuItem()) """ Places """ self.create_places_submenu(self.menu) """ System """ tree = gmenu.lookup_tree("settings.menu") tree.add_monitor(self.menu_changed_cb, self.settings_items) if tree.root is not None: self.append_directory(tree.root, self.menu, item_list=self.settings_items) """ Session actions """ if dbus is not None: self.append_session_actions(self.menu) self.menu.show_all()
def __loadMenus(self): self.applications = Menu() self.applications.tree = gmenu.lookup_tree('applications.menu', gmenu.FLAGS_SHOW_EMPTY|gmenu.FLAGS_INCLUDE_EXCLUDED|gmenu.FLAGS_INCLUDE_NODISPLAY|gmenu.FLAGS_SHOW_ALL_SEPARATORS) self.applications.visible_tree = gmenu.lookup_tree('applications.menu') self.applications.tree.sort_key = gmenu.SORT_DISPLAY_NAME self.applications.visible_tree.sort_key = gmenu.SORT_DISPLAY_NAME self.applications.path = os.path.join(util.getUserMenuPath(), self.applications.tree.get_menu_file()) if not os.path.isfile(self.applications.path): self.applications.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.applications.tree)) else: self.applications.dom = xml.dom.minidom.parse(self.applications.path) self.__remove_whilespace_nodes(self.applications.dom) self.settings = Menu() self.settings.tree = gmenu.lookup_tree('settings.menu', gmenu.FLAGS_SHOW_EMPTY|gmenu.FLAGS_INCLUDE_EXCLUDED|gmenu.FLAGS_INCLUDE_NODISPLAY|gmenu.FLAGS_SHOW_ALL_SEPARATORS) self.settings.visible_tree = gmenu.lookup_tree('settings.menu') self.settings.tree.sort_key = gmenu.SORT_DISPLAY_NAME self.settings.visible_tree.sort_key = gmenu.SORT_DISPLAY_NAME self.settings.path = os.path.join(util.getUserMenuPath(), self.settings.tree.get_menu_file()) if not os.path.isfile(self.settings.path): self.settings.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.settings.tree)) else: self.settings.dom = xml.dom.minidom.parse(self.settings.path) self.__remove_whilespace_nodes(self.settings.dom) self.save(True)
def __loadMenus(self): self.applications = Menu() self.applications.tree = gmenu.lookup_tree('cinnamon-applications.menu', gmenu.FLAGS_SHOW_EMPTY|gmenu.FLAGS_INCLUDE_EXCLUDED|gmenu.FLAGS_INCLUDE_NODISPLAY|gmenu.FLAGS_SHOW_ALL_SEPARATORS) self.applications.visible_tree = gmenu.lookup_tree('cinnamon-applications.menu') self.applications.tree.sort_key = gmenu.SORT_DISPLAY_NAME self.applications.visible_tree.sort_key = gmenu.SORT_DISPLAY_NAME self.applications.path = os.path.join(util.getUserMenuPath(), self.applications.tree.get_menu_file()) if not os.path.isfile(self.applications.path): self.applications.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.applications.tree)) else: self.applications.dom = xml.dom.minidom.parse(self.applications.path) self.__remove_whilespace_nodes(self.applications.dom) self.save(True)
def __init__(self, filename=None): if filename: self._root = gmenu.lookup_tree(filename) self._node = self._root.root else: self._root = None self._node = None
def __init__(self, filename = None): if filename: self._root = gmenu.lookup_tree(filename) self._node = self._root.root else: self._root = None self._node = None
def refresh_dynamic_menu(): menu = 'applications.menu' #m = gtk.Menu() folder = gtk.MenuItem(None) global submenu # Fixes crash on Natty submenu = gtk.Menu() map(walk_menu, gmenu.lookup_tree(menu).root.get_contents()) # create menu item = gtk.ImageMenuItem(gtk.STOCK_DIALOG_INFO) item.get_children()[0].set_label("About") item.connect("activate",menuitembuildin_response,"about") m.insert(item,0) item = gtk.ImageMenuItem(gtk.STOCK_FIND) item.connect("activate",menuitembuildin_response,"/usr/bin/magi-kit.py search") m.insert(item,1) item = gtk.ImageMenuItem(gtk.STOCK_EXECUTE) item.connect("activate",menuitembuildin_response,"xfrun4") m.insert(item,2) item = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES) item.connect("activate",menuitembuildin_response,"magi2 -settings") m.insert(item,3) item=gtk.SeparatorMenuItem() m.insert(item,4) item = gtk.ImageMenuItem(gtk.STOCK_QUIT) item.connect("activate", menuitembuildin_response,"xfce4-session-logout") m.insert(item,5) item=gtk.SeparatorMenuItem() m.insert(item,6) #m.connect("deactivate", menuitem_quit) m.show_all()
def updateCache(self): if len(sys.argv) > 1: if sys.argv[1] == "default": menu = 'applications.menu' else: menu = sys.argv[1] + '.menu' else: if self.xdg_menu == 'default': menu = 'applications.menu' else: menu = self.xdg_menu + '.menu' ## xdg-menu if not os.path.exists('/etc/xdg/menus/' + menu): print '/etc/xdg/menus/'+menu + ' Not found!' # write menu cache self.createFile(self.file_path) self.file=open(self.file_path,'a') self.file.write( '<?xml version="1.0" encoding="UTF-8"?>\n') self.file.write( '<' + self.tag + '>\n') try: map(self.walk_menu, gmenu.lookup_tree(menu).root.get_contents()) except: print "ocurrio un problema" self.file.write('</'+ self.tag + '>\n') self.file.close()
def updateCache(self): if len(sys.argv) > 1: if sys.argv[1] == 'default': menu = 'applications.menu' else: menu = sys.argv[1] + '.menu' else: if self.xdg_menu == 'default': menu = 'applications.menu' else: menu = self.xdg_menu + '.menu' # # xdg-menu if not os.path.exists('/etc/xdg/menus/' + menu): print '/etc/xdg/menus/' + menu + ' Not found!' # write menu cache self.createFile(self.file_path) self.file = open(self.file_path, 'a') self.file.write('<?xml version="1.0" encoding="UTF-8"?>\n') self.file.write('<' + self.tag + '>\n') try: map(self.walk_menu, gmenu.lookup_tree(menu).root.get_contents()) except: print 'ocurrio un problema' self.file.write('</' + self.tag + '>\n') self.file.close()
def main(args): parser = optparse.OptionParser() parser.add_option('-f', '--file', dest='file', help='Menu file') parser.add_option('-i', '--include-excluded', dest='exclude', action='store_true', default=False, help='Include <Exclude>d entries') parser.add_option('-n', '--include-nodisplay', dest='nodisplay', action='store_true', default=False, help='Include NoDisplay=true entries') (options, args) = parser.parse_args() if options.file: menu_file = options.file else: menu_file = 'applications.menu' flags = gmenu.FLAGS_NONE if options.exclude: flags |= gmenu.FLAGS_INCLUDE_EXCLUDED if options.nodisplay: flags |= gmenu.FLAGS_INCLUDE_NODISPLAY tree = gmenu.lookup_tree(menu_file, flags) root = tree.get_root_directory() if not root: print 'Menu tree is empty' else: print_directory(root)
def refresh_dynamic_menu(): menu = 'applications.menu' #m = gtk.Menu() folder = gtk.MenuItem(None) global submenu # Fixes crash on Natty submenu = gtk.Menu() map(walk_menu, gmenu.lookup_tree(menu).root.get_contents()) # create menu item = gtk.ImageMenuItem(gtk.STOCK_DIALOG_INFO) item.get_children()[0].set_label("About") item.connect("activate", menuitembuildin_response, "about") m.insert(item, 0) item = gtk.ImageMenuItem(gtk.STOCK_FIND) item.connect("activate", menuitembuildin_response, "/usr/bin/magi-kit.py search") m.insert(item, 1) item = gtk.ImageMenuItem(gtk.STOCK_EXECUTE) item.connect("activate", menuitembuildin_response, "xfrun4") m.insert(item, 2) item = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES) item.connect("activate", menuitembuildin_response, "magi2 -settings") m.insert(item, 3) item = gtk.SeparatorMenuItem() m.insert(item, 4) item = gtk.ImageMenuItem(gtk.STOCK_QUIT) item.connect("activate", menuitembuildin_response, "xfce4-session-logout") m.insert(item, 5) item = gtk.SeparatorMenuItem() m.insert(item, 6) #m.connect("deactivate", menuitem_quit) m.show_all()
def on_quasimode_start(self): tree = gmenu.lookup_tree('applications.menu' ,gmenu.FLAGS_SHOW_EMPTY|gmenu.FLAGS_INCLUDE_EXCLUDED|gmenu.FLAGS_INCLUDE_NODISPLAY) self.possibles = [] for i in traverse_gmenu(tree.root): self.possibles.append(i) yield self.valid_args = [x["search"] for x in self.possibles]
def __init__(self, callback, menu_path): self.callback = callback self.menu = gtk.Menu() self.path = menu_path self.tree = gmenu.lookup_tree(self.path) if self.tree.root: self.add_to_menu(self.tree)
def __init__ (self, menu_file): gobject.GObject.__init__(self) self.tree = gmenu.lookup_tree(menu_file) if not self.tree.root: raise ValueError("The menu file %s could not be found." % menu_file) # NOTE: Re-enabled for 0.3. See Gimmie bug #419271, and # gnome-menus bug #442747. self.tree.add_monitor(lambda *args: self.emit("reload"))
def __init__(self): gobject.GObject.__init__(self) self._logger = logging.getLogger('bigboard.AppsDirectory') self._tree = gmenu.lookup_tree('applications.menu', gmenu.FLAGS_INCLUDE_EXCLUDED) self._apps = {} # with gnome-menus-2.16.0-2.fc6 omitting the user_data arg crashes the gmenu module self._tree.add_monitor(self._on_apps_changed, None) self.__last_local_app_update = 0.0 self.__last_local_app_idle_id = 0 self._on_apps_changed(None, None)
def do_startup(self): # start the application Gtk.Application.do_startup(self) # create a menu self.menu = Gtk.Menu() # append to the menu three options self.add_to_menu(gmenu.lookup_tree('applications.menu')) # set the menu as menu of the application self.menu.connect("selection-done", self.on_close, None) self.menu.popup(None,None,None,None,0,Gtk.get_current_event_time())
def create_cache(self): tree=gmenu.lookup_tree('unity-lens-applications.menu') root=tree.get_root_directory() table={} for category in root.get_contents(): apps=[] for program in category.get_contents(): apps.append({'name':program.name,'icon':program.icon,'exec':program.get_desktop_file_path()}) table[(category.name,category.icon)]=apps with open(self.cachefile,'w') as f: pickle.dump(table,f) return table
def getcat(self): """ Return a dictionary with the applications categories available """ lst =[] dic ={} contents = gmenu.lookup_tree("semplice-applications.menu", gmenu.FLAGS_SHOW_EMPTY|gmenu.FLAGS_INCLUDE_EXCLUDED|gmenu.FLAGS_INCLUDE_NODISPLAY).get_root_directory().get_contents() for itm in contents: dic[itm.name] = itm.menu_id lst.append(itm.name) return lst,dic;
def __init__ (self, menu_files): gtk.TreeStore.__init__ (self, bool, str, str, gtk.gdk.Pixbuf, str, bool, bool) self.entries_list_iter = None self.icon_theme = gtk.icon_theme_get_default () if (len (menu_files) < 1): menu_files = ["gnome-applications.menu", "gnome-settings.menu"] for menu_file in menu_files: if menu_file == "applications.menu" and os.environ.has_key ("XDG_MENU_PREFIX"): menu_file = os.environ["XDG_MENU_PREFIX"] + menu_file tree = gmenu.lookup_tree (menu_file, gmenu.FLAGS_INCLUDE_EXCLUDED) tree.sort_key = gmenu.SORT_DISPLAY_NAME self.__append_directory (tree.root, None, False, menu_file) system_file = lookup_system_menu_file (menu_file) if system_file: system_tree = gmenu.lookup_tree (system_file, gmenu.FLAGS_INCLUDE_EXCLUDED) system_tree.sort_key = gmenu.SORT_DISPLAY_NAME self.__append_directory (system_tree.root, None, True, menu_file)
def get_main_menu_path(self, desktop_file, menu_files_list=None): if not desktop_file: return import gmenu # use the system ones by default, but allow override for # easier testing if menu_files_list is None: menu_files_list = ["applications.menu", "settings.menu"] for n in menu_files_list: tree = gmenu.lookup_tree(n) self._search_gmenu_dir([tree.get_root_directory()], os.path.basename(desktop_file)) if self._found: return self._found
def ShowMenu(): mw = MenuWriter('menu') def WalkMenuTreeBranch(node): for child in node.contents: if isinstance (child, gmenu.Directory): WalkMenuTree(child) if not isinstance (child, gmenu.Entry): continue if child.type == gmenu.TYPE_ENTRY: PrintExecItem(child.name, child.get_exec()) def WalkMenuTree(node): mw.PrintMenuBegin(node.name) WalkMenuTreeBranch(node) mw.PrintMenuEnd() WalkMenuTreeBranch(gmenu.lookup_tree("applications.menu", gmenu.FLAGS_INCLUDE_EXCLUDED).root)
def main(args): parser = optparse.OptionParser() parser.add_option('-f',\ '--file',\ dest='file',\ help='Menu file') parser.add_option('-i',\ '--include-excluded',\ dest='exclude',\ action='store_true',\ default=False,\ help='Include <Exclude>d entries') parser.add_option('-n',\ '--include-nodisplay',\ dest='nodisplay',\ action='store_true',\ default=False,\ help='Include NoDisplay=true entries') (options, args) = parser.parse_args() if options.file: menu_file = options.file else: menu_file = 'applications.menu' flags = gmenu.FLAGS_NONE if options.exclude: flags |= gmenu.FLAGS_INCLUDE_EXCLUDED if options.nodisplay: flags |= gmenu.FLAGS_INCLUDE_NODISPLAY tree=gmenu.lookup_tree(menu_file,\ flags) root = tree.get_root_directory() if not root: print 'Menu tree is empty' else: print_directory(root)
def ShowMenu(): mw = MenuWriter('menu') def WalkMenuTreeBranch(node): for child in node.contents: if isinstance(child, gmenu.Directory): WalkMenuTree(child) if not isinstance(child, gmenu.Entry): continue if child.type == gmenu.TYPE_ENTRY: PrintExecItem(child.name, child.get_exec()) def WalkMenuTree(node): mw.PrintMenuBegin(node.name) WalkMenuTreeBranch(node) mw.PrintMenuEnd() WalkMenuTreeBranch( gmenu.lookup_tree("applications.menu", gmenu.FLAGS_INCLUDE_EXCLUDED).root)
def get_items(): m = gmenu.lookup_tree(os.path.expandvars('~/.config/menus/applications.menu')) return get_sub_items(m.root)
def run(self): ids = "" # Get split_menu split = self.cfg.printv("split_menu") # Get hide_settings_menus hide_settings_menus = self.cfg.printv("hide_settings_menus") if split: # Should edit menu? if len(sys.argv) > 2: ids = " ".join(sys.argv[2:]) if hide_settings_menus: # Should hide menus? to_skip = () else: to_skip = ("Administration", "Preferences") # Lookup menu file if os.path.exists("/etc/xdg/menus/semplice-applications.menu"): applications_menu = "semplice-applications.menu" elif os.path.exists("/etc/xdg/menus/gnome-applications.menu"): applications_menu = "gnome-applications.menu" else: applications_menu = "applications.menu" # Force to applications.menu, may fail if not existent, of course. def walk_menu_system(entry): return walk_menu(entry, is_system=True) def walk_menu(entry, is_system=False): if entry.get_type() == gmenu.TYPE_DIRECTORY and split and ids or entry.get_type() == gmenu.TYPE_DIRECTORY and not split: if not entry.menu_id in to_skip: obj = "\n".join(map(walk_menu, entry.get_contents())) elif is_system: obj = "\n".join(map(walk_menu_system, entry.get_contents())) else: return "" return core.menu(escape(entry.menu_id), escape(entry.name.replace("&","and")), obj, icon=entry.icon) elif entry.get_type() == gmenu.TYPE_DIRECTORY and split: if not entry.menu_id in to_skip: return core.pipemenu(escape(entry.menu_id), escape(entry.name.replace("&","and")), "alan-show-extension %s %s" % (sys.argv[1], entry.menu_id), icon=entry.icon) elif entry.get_type() == gmenu.TYPE_ENTRY and not entry.is_excluded: command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', entry.get_exec()) if "oneslip" in command and not ONESLIP: # oneslip not installed, link to bricks command = "pkexec /usr/bin/bricks \"%s\" oneslip" % escape(entry.name.replace("&","and")) if entry.launch_in_terminal: command = 'x-terminal-emulator --title "%s" -e %s' % \ (entry.name.replace("&","and"), command) # New action act = ga.execute(escape(command)) # Incorporate action in item item = core.item(escape(entry.name.replace("&","and")), act, icon=entry.icon) return item # Initiate pipemenu #self.menu = struct.PipeMenu(use_cache=self.cfg.printv("use_cache","Alan"), cache="xdgmenu", cache_trigger=(self.cfg.path, glob.glob("/usr/share/applications/desktop.*.cache")[0])) self.menu = struct.PipeMenu() if self.menu.cache_check(): # Read cache self.menu.cache_read() else: self.menu.start() # add initial tag # Alias menu.insert() to i() i = self.menu.insert ### Begin! if split: path = "/" + ids else: path = "/" i("\n".join(map(walk_menu, gmenu.lookup_tree(applications_menu).get_directory_from_path(path).get_contents()))) #### SYSTEM SETTINGS if not ids and not hide_settings_menus: i(core.separator) # Prefs prefs = gmenu.lookup_tree(applications_menu).get_directory_from_path("/System/Preferences") if not split: prefs_items = "\n".join(map(walk_menu_system, prefs.get_contents())) i(core.menu(escape(prefs.menu_id), escape(prefs.name.replace("&","and")), prefs_items, icon=prefs.icon)) else: i(core.pipemenu(escape(prefs.menu_id), escape(prefs.name.replace("&","and")), "alan-show-extension %s %s" % (sys.argv[1], "System/Preferences"), icon=prefs.icon)) # Admin admin = gmenu.lookup_tree(applications_menu).get_directory_from_path("/System/Administration") if not split: admin_items = "\n".join(map(walk_menu_system, admin.get_contents())) i(core.menu(escape(admin.menu_id), escape(admin.name.replace("&","and")), admin_items, icon=admin.icon)) else: i(core.pipemenu(escape(admin.menu_id), escape(admin.name.replace("&","and")), "alan-show-extension %s %s" % (sys.argv[1], "System/Administration"), icon=admin.icon)) # Display info object #i(core.info(infos)) # End self.menu.end()
def get_root_directory(self, menu_file, flags=NONE): tree = gmenu.lookup_tree(menu_file, flags) return GmenuDirectoryAdapter(tree.get_root_directory())
def __init__(self): self.apps = MultiDict() menus = [gmenu.lookup_tree('applications.menu'), gmenu.lookup_tree('settings.menu')] map(lambda m: self._recurse_tree(m.root), menus)
# Miroslav Lichvar <*****@*****.**> import gmenu, re, sys from xml.sax.saxutils import escape def walk_menu(entry): if entry.get_type() == gmenu.TYPE_DIRECTORY: print '<menu id="%s" label="%s">' % (escape(entry.menu_id), escape(entry.get_name())) map(walk_menu, entry.get_contents()) print "</menu>" elif entry.get_type() == gmenu.TYPE_ENTRY and not entry.is_excluded: print ' <item label="%s">' % escape(entry.get_name()) command = re.sub(" [^ ]*%[fFuUdDnNickvm]", "", entry.get_exec()) if entry.launch_in_terminal: command = 'xterm -title "%s" -e %s' % (entry.get_name(), command) print ' <action name="Execute">' + "<command>%s</command></action>" % escape(command) print " </item>" if len(sys.argv) > 1: menu = sys.argv[1] + ".menu" else: menu = "applications.menu" print '<?xml version="1.0" encoding="UTF-8"?>' print "<openbox_pipe_menu>" map(walk_menu, gmenu.lookup_tree(menu).root.get_contents()) print "</openbox_pipe_menu>"
def parse(self, menu_file, show_hidden=True): flags = gmenu.FLAGS_NONE if show_hidden: flags |= gmenu.FLAGS_INCLUDE_NODISPLAY|gmenu.FLAGS_INCLUDE_EXCLUDED tree = gmenu.lookup_tree(menu_file, flags) return GmenuDirectoryAdapter(tree.get_root_directory())
import gmenu def printobj(obj, level=0): i = ">>>" * level print i, str(obj.__class__) for prop in dir(obj): print i + '>>>', prop, '=>', repr(getattr(obj, prop)) print "" tree = gmenu.lookup_tree('uxm-applications.menu') root = tree.get_root_directory() print ">>> ROOT" printobj(root) for entry in root.get_contents(): printobj(entry, 1) print "\n" if hasattr(entry, 'get_contents'): for e in entry.get_contents(): printobj(e, 2) print "\n" if hasattr(e, 'get_contents'): for e2 in e.get_contents(): printobj(e2, 3) print "\n"
import gmenu, re, sys from xml.sax.saxutils import escape def walk_menu(entry): if entry.get_type() == gmenu.TYPE_DIRECTORY: print '<menu id="%s" label="%s">' \ % (escape(entry.menu_id), escape(entry.get_name())) map(walk_menu, entry.get_contents()) print '</menu>' elif entry.get_type() == gmenu.TYPE_ENTRY and not entry.is_excluded: print ' <item label="%s">' % escape(entry.get_name()) command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', entry.get_exec()) if entry.launch_in_terminal: command = 'xterm -title "%s" -e %s' % \ (entry.get_name(), command) print ' <action name="Execute">' + \ '<command>%s</command></action>' % escape(command) print ' </item>' if len(sys.argv) > 1: menu = sys.argv[1] + '.menu' else: menu = 'applications.menu' print '<?xml version="1.0" encoding="UTF-8"?>' print '<openbox_pipe_menu>' map(walk_menu, gmenu.lookup_tree(menu).root.get_contents()) print '</openbox_pipe_menu>'
def create_tree(self, name): flags = gmenu.FLAGS_NONE if include_nodisplay: flags = flags | gmenu.FLAGS_INCLUDE_NODISPLAY tree = gmenu.lookup_tree(name, flags) return tree
def __init__( self, MenuToLookup ): self.tree = gmenu.lookup_tree( MenuToLookup ) self.directory = self.tree.get_root_directory()
def print_menu(): tree = gmenu.lookup_tree('uxm-applications.menu') root = tree.get_root_directory() print_dir(root, 0)