Migrated from pyxdg to gmenu

This commit is contained in:
Clement Lefebvre 2009-11-19 00:45:09 +00:00
parent c5effee231
commit 224f0f159f
2 changed files with 53 additions and 45 deletions

2
debian/control vendored
View File

@ -7,6 +7,6 @@ Standards-Version: 3.7.2
Package: mintmenu Package: mintmenu
Architecture: all Architecture: all
Depends: python (>= 2.4), python (<< 3), python-gtk2, python-glade2, deskbar-applet, mint-common Depends: python (>= 2.4), python (<< 3), python-gtk2, python-glade2, deskbar-applet, mint-common, python-gmenu
Description: Advanced Gnome menu Description: Advanced Gnome menu
One of the most advanced menus under Linux. MintMenu supports filtering, favorites, easy-uninstallation, autosession, and many other features. One of the most advanced menus under Linux. MintMenu supports filtering, favorites, easy-uninstallation, autosession, and many other features.

View File

@ -21,6 +21,7 @@ from easyfiles import *
from filemonitor import monitor as filemonitor from filemonitor import monitor as filemonitor
import xdg.Menu import xdg.Menu
import gmenu
# i18n # i18n
gettext.install("mintmenu", "/usr/share/linuxmint/locale") gettext.install("mintmenu", "/usr/share/linuxmint/locale")
@ -73,29 +74,30 @@ def xdgParsePatched(filename=None):
xdg.Menu.parse = xdgParsePatched xdg.Menu.parse = xdgParsePatched
class Menu: class Menu:
def __init__( self, menu ): def __init__( self, MenuToLookup ):
if isinstance( menu , xdg.Menu.Menu): self.tree = gmenu.lookup_tree( MenuToLookup )
self.directory = menu self.directory = self.tree.get_root_directory()
def getMenus( self, parent=None ):
if parent == None:
#gives top-level "Applications" item
yield self.tree.root
else: else:
self.directory = xdg.Menu.parse( menu ) for menu in parent.get_contents():
if menu.get_type() == gmenu.TYPE_DIRECTORY and self.__isVisible( menu ):
yield menu
def getMenus( self, parent = None ): def getItems( self, menu ):
if not parent: for item in menu.get_contents():
parent = self.directory if item.get_type() == gmenu.TYPE_ENTRY and item.get_desktop_file_id()[-19:] != '-usercustom.desktop' and self.__isVisible( item ):
if not parent:
return
for menu in parent.getEntries():
if isinstance( menu, xdg.Menu.Menu ):
yield menu
def getItems( self, recursive = False ):
for item in self.directory.getEntries():
if isinstance( item, xdg.Menu.MenuEntry ):
yield item yield item
elif isinstance( item, xdg.Menu.Menu ):
for subitem in Menu( item ).getItems( True ): def __isVisible( self, item ):
yield subitem if item.get_type() == gmenu.TYPE_ENTRY:
return not ( item.get_is_excluded() or item.get_is_nodisplay() )
if item.get_type() == gmenu.TYPE_DIRECTORY and len( item.get_contents() ):
return True
class SuggestionButton ( gtk.Button ): class SuggestionButton ( gtk.Button ):
@ -251,10 +253,11 @@ class pluginclass( object ):
for mainitems in [ "applications.menu", "settings.menu" ]: for mainitems in [ "applications.menu", "settings.menu" ]:
mymenu = Menu( mainitems ) mymenu = Menu( mainitems )
for f in mymenu.directory.Files: mymenu.tree.add_monitor( self.menuChanged, None )
self.menuFileMonitors.append( filemonitor.addMonitor(f, self.onMenuChanged, mymenu.directory.Filename ) ) #for f in mymenu.directory.Files:
for f in mymenu.directory.AppDirs: # self.menuFileMonitors.append( filemonitor.addMonitor(f, self.onMenuChanged, mymenu.directory.Filename ) )
self.menuFileMonitors.append( filemonitor.addMonitor(f, self.onMenuChanged, mymenu.directory.Filename ) ) #for f in mymenu.directory.AppDirs:
# self.menuFileMonitors.append( filemonitor.addMonitor(f, self.onMenuChanged, mymenu.directory.Filename ) )
sizeIcon = 0 sizeIcon = 0
if isinstance(self.iconSize, int): if isinstance(self.iconSize, int):
@ -1022,7 +1025,7 @@ class pluginclass( object ):
if targetType == self.TARGET_TYPE_FAV: if targetType == self.TARGET_TYPE_FAV:
self.favoritesReorder( int(selection.data), widget.position ) self.favoritesReorder( int(selection.data), widget.position )
def onMenuChanged( self, menu ): def menuChanged( self, x, y ):
# wait some miliseconds because there a multiple events send at the same time and we don't want to rebuild the menu for each # wait some miliseconds because there a multiple events send at the same time and we don't want to rebuild the menu for each
if self.menuChangedTimer: if self.menuChangedTimer:
gobject.source_remove( self.menuChangedTimer ) gobject.source_remove( self.menuChangedTimer )
@ -1124,7 +1127,7 @@ class pluginclass( object ):
for item in newApplicationList: for item in newApplicationList:
found = False found = False
for item2 in self.applicationList: for item2 in self.applicationList:
if item["entry"].filename == item2["entry"].filename: if item["entry"].get_desktop_file_path() == item2["entry"].get_desktop_file_path():
found = True found = True
break break
if not found: if not found:
@ -1134,7 +1137,7 @@ class pluginclass( object ):
for item in self.applicationList: for item in self.applicationList:
found = False found = False
for item2 in newApplicationList: for item2 in newApplicationList:
if item["entry"].filename == item2["entry"].filename: if item["entry"].get_desktop_file_path() == item2["entry"].get_desktop_file_path():
found = True found = True
break break
if not found: if not found:
@ -1156,7 +1159,7 @@ class pluginclass( object ):
sortedApplicationList.append( ( item["button"].appName, item["button"] ) ) sortedApplicationList.append( ( item["button"].appName, item["button"] ) )
for item in addedApplications: for item in addedApplications:
item["button"] = MenuApplicationLauncher( item["entry"], self.iconSize, item["category"], self.showapplicationcomments ) item["button"] = MenuApplicationLauncher( item["entry"].get_desktop_file_path(), self.iconSize, item["category"], self.showapplicationcomments )
if item["button"].appExec: if item["button"].appExec:
self.mintMenuWin.setTooltip( item["button"], item["button"].getTooltip() ) self.mintMenuWin.setTooltip( item["button"], item["button"].getTooltip() )
item["button"].connect( "button-release-event", self.menuPopup ) item["button"].connect( "button-release-event", self.menuPopup )
@ -1189,13 +1192,15 @@ class pluginclass( object ):
newCategoryList = [ { "name": _("All"), "icon": self.mintMenuWin.icon, "tooltip": _("Show all applications"), "filter":"", "index": 0 } ] newCategoryList = [ { "name": _("All"), "icon": self.mintMenuWin.icon, "tooltip": _("Show all applications"), "filter":"", "index": 0 } ]
num = 1 num = 1
for menu in self.menuFiles: for menu in self.menuFiles:
for child in menu.getMenus(): for child in menu.directory.get_contents():
icon = str(child.getIcon()) if child.get_type() == gmenu.TYPE_DIRECTORY:
if (icon == "preferences-system"): icon = str(child.icon)
self.adminMenu = child.getName() if (icon == "preferences-system"):
if (icon != "applications-system" and icon != "applications-other"): self.adminMenu = child.name
newCategoryList.append( { "name": child.getName(), "icon": child.getIcon(), "tooltip": child.getName(), "filter": child.getName(), "index": num } ) if (icon != "applications-system" and icon != "applications-other"):
newCategoryList.append( { "name": child.name, "icon": child.icon, "tooltip": child.name, "filter": child.name, "index": num } )
num += 1 num += 1
return newCategoryList return newCategoryList
@ -1206,14 +1211,17 @@ class pluginclass( object ):
newApplicationsList = [] newApplicationsList = []
for menu in self.menuFiles: for menu in self.menuFiles:
for child in menu.getMenus(): for directory in menu.directory.get_contents():
for application in Menu(child).getItems( True ): if directory.get_type() == gmenu.TYPE_DIRECTORY:
if isinstance( application, xdg.Menu.MenuEntry ): for application in directory.get_contents():
catName = child.getName() if application.get_type() == gmenu.TYPE_ENTRY:
icon = str(child.getIcon()) catName = directory.name
if (icon == "applications-system" or icon == "applications-other"): icon = str(directory.icon)
catName = self.adminMenu if (icon == "applications-system" or icon == "applications-other"):
newApplicationsList.append( { "entry": application.DesktopEntry, "category": catName } ) catName = self.adminMenu
newApplicationsList.append( { "entry": application, "category": catName } )
else:
print "Missing something"
return newApplicationsList return newApplicationsList