def get_main_menu_path(self, desktop_file, menu_files_list=None):
if not desktop_file:
return
from gi.repository import GMenu
from gi.repository import GObject
# 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:
if n.startswith("/"):
tree = GMenu.Tree.new_for_path(n, 0)
else:
tree = GMenu.Tree.new(n, 0)
try:
tree.load_sync()
except GObject.GError as e:
LOG.warning("could not load GMenu path: %s" % e)
return
root = tree.get_root_directory()
self._search_gmenu_dir([root],
os.path.basename(desktop_file))
# retry search for app-install-data desktop files
if not self._found and ":" in os.path.basename(desktop_file):
# the desktop files in app-install-data have a layout
# like "pkg:file.desktop" so we need to take that into
# account when searching
desktop_file = os.path.basename(desktop_file).split(":")[1]
self._search_gmenu_dir([root], desktop_file)
return self._found
# these are the old static bindinds that are no longer required
# (this is just kept here in case of problems with the dynamic
# GIR and the old gtk2 gtk ui)
评论列表
文章目录