def build_menu(self):
        self.applications_items = []
        self.settings_items = []
        self.session_items = []

        """ Applications """
        tree = matemenu.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 = matemenu.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()
Beispiel #2
0
	def __loadMenus(self):
		self.applications = Menu()
		self.applications.tree = matemenu.lookup_tree('mate-applications.menu', matemenu.FLAGS_SHOW_EMPTY|matemenu.FLAGS_INCLUDE_EXCLUDED|matemenu.FLAGS_INCLUDE_NODISPLAY|matemenu.FLAGS_SHOW_ALL_SEPARATORS)
		self.applications.visible_tree = matemenu.lookup_tree('mate-applications.menu')
		self.applications.tree.sort_key = matemenu.SORT_DISPLAY_NAME
		self.applications.visible_tree.sort_key = matemenu.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 = matemenu.lookup_tree('mate-settings.menu', matemenu.FLAGS_SHOW_EMPTY|matemenu.FLAGS_INCLUDE_EXCLUDED|matemenu.FLAGS_INCLUDE_NODISPLAY|matemenu.FLAGS_SHOW_ALL_SEPARATORS)
		self.settings.visible_tree = matemenu.lookup_tree('mate-settings.menu')
		self.settings.tree.sort_key = matemenu.SORT_DISPLAY_NAME
		self.settings.visible_tree.sort_key = matemenu.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)
Beispiel #3
0
	def __loadMenus(self):
		self.applications = Menu()
		self.applications.tree = matemenu.lookup_tree('mate-applications.menu', matemenu.FLAGS_SHOW_EMPTY|matemenu.FLAGS_INCLUDE_EXCLUDED|matemenu.FLAGS_INCLUDE_NODISPLAY|matemenu.FLAGS_SHOW_ALL_SEPARATORS)
		self.applications.visible_tree = matemenu.lookup_tree('mate-applications.menu')
		self.applications.tree.sort_key = matemenu.SORT_DISPLAY_NAME
		self.applications.visible_tree.sort_key = matemenu.SORT_DISPLAY_NAME
		self.applications.path = os.path.join(util.getUserMenuPath(), self.applications.tree.get_menu_file())
		try:
			self.applications.dom = xml.dom.minidom.parse(self.applications.path)
		except (IOError, xml.parsers.expat.ExpatError):
			self.applications.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.applications.tree))
		util.removeWhitespaceNodes(self.applications.dom)

		self.settings = Menu()
		self.settings.tree = matemenu.lookup_tree('mate-settings.menu', matemenu.FLAGS_SHOW_EMPTY|matemenu.FLAGS_INCLUDE_EXCLUDED|matemenu.FLAGS_INCLUDE_NODISPLAY|matemenu.FLAGS_SHOW_ALL_SEPARATORS)
		self.settings.visible_tree = matemenu.lookup_tree('mate-settings.menu')
		self.settings.tree.sort_key = matemenu.SORT_DISPLAY_NAME
		self.settings.visible_tree.sort_key = matemenu.SORT_DISPLAY_NAME
		self.settings.path = os.path.join(util.getUserMenuPath(), self.settings.tree.get_menu_file())
		try:
			self.settings.dom = xml.dom.minidom.parse(self.settings.path)
		except (IOError, xml.parsers.expat.ExpatError):
			self.settings.dom = xml.dom.minidom.parseString(util.getUserMenuXml(self.settings.tree))
		util.removeWhitespaceNodes(self.settings.dom)

		self.save(True)
Beispiel #4
0
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 = 'mate-applications.menu'

    flags = matemenu.FLAGS_NONE
    if options.exclude:
        flags |= matemenu.FLAGS_INCLUDE_EXCLUDED
    if options.nodisplay:
        flags |= matemenu.FLAGS_INCLUDE_NODISPLAY

    tree = matemenu.lookup_tree(menu_file, flags)
    root = tree.get_root_directory()

    if not root:
        print 'Menu tree is empty'
    else:
        print_directory(root)
    def __loadMenus(self):
        self.applications = Menu()
        self.applications.tree = matemenu.lookup_tree(
            'mate-applications.menu',
            matemenu.FLAGS_SHOW_EMPTY | matemenu.FLAGS_INCLUDE_EXCLUDED
            | matemenu.FLAGS_INCLUDE_NODISPLAY
            | matemenu.FLAGS_SHOW_ALL_SEPARATORS)
        self.applications.visible_tree = matemenu.lookup_tree(
            'mate-applications.menu')
        self.applications.tree.sort_key = matemenu.SORT_DISPLAY_NAME
        self.applications.visible_tree.sort_key = matemenu.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 = matemenu.lookup_tree(
            'mate-settings.menu',
            matemenu.FLAGS_SHOW_EMPTY | matemenu.FLAGS_INCLUDE_EXCLUDED
            | matemenu.FLAGS_INCLUDE_NODISPLAY
            | matemenu.FLAGS_SHOW_ALL_SEPARATORS)
        self.settings.visible_tree = matemenu.lookup_tree('mate-settings.menu')
        self.settings.tree.sort_key = matemenu.SORT_DISPLAY_NAME
        self.settings.visible_tree.sort_key = matemenu.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 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 = "mate-applications.menu"

    flags = matemenu.FLAGS_NONE
    if options.exclude:
        flags |= matemenu.FLAGS_INCLUDE_EXCLUDED
    if options.nodisplay:
        flags |= matemenu.FLAGS_INCLUDE_NODISPLAY

    tree = matemenu.lookup_tree(menu_file, flags)
    root = tree.get_root_directory()

    if not root:
        print "Menu tree is empty"
    else:
        print_directory(root)
Beispiel #7
0
	def ParseMenus(self):
		"""parse menus using xdg"""

		if has_matemenu:
			self.CacheGmenuApplications = matemenu.lookup_tree(os.environ.get("XDG_MENU_PREFIX", "") + "applications.menu")		
			self.CacheApplications = self.CacheGmenuApplications.get_root_directory()
			if self.CacheApplications is None:
				self.CacheGmenuApplications = matemenu.lookup_tree("mate-applications.menu")		
				self.CacheApplications = self.CacheGmenuApplications.get_root_directory()

			if self.CacheApplications is None:
				print 'unable to parse the menu'
			else:
				self.CacheGmenuApplications.add_monitor(self.monitor_callback)

			self.CacheGmenuSettings = matemenu.lookup_tree("settings.menu")		
			self.CacheSettings = self.CacheGmenuSettings.get_root_directory()
			if self.CacheSettings is None:
				self.CacheGmenuSettings = matemenu.lookup_tree("mate-settings.menu")		
				self.CacheSettings = self.CacheGmenuSettings.get_root_directory()
			if self.CacheSettings is None:
				self.CacheGmenuSettings = matemenu.lookup_tree(os.environ.get("XDG_MENU_PREFIX", "") + "settings.menu")		
				self.CacheSettings = self.CacheGmenuSettings.get_root_directory()
			else:
				self.CacheGmenuSettings.add_monitor(self.monitor_callback)
		
			self.MenuInstance = matemenu.Directory
			self.EntryInstance = matemenu.Entry


		else:
			#http://www.rkblog.rk.edu.pl/w/p/pyxdg-freedesktoporg-specifications-support/
			try:
				#standard applications.menu with XDG_MENU_PREFIX that may be null
				self.CacheApplications = xdg.Menu.parse(os.environ.get("XDG_MENU_PREFIX", "") + "applications.menu")
			except:
				print 'Error parsing'
				try:
					# Some distros rename applications.menu without setting XDG_MENU_PREFIX.
					self.CacheApplications = xdg.Menu.parse("mate-applications.menu")
				except:
					print 'unable to parse the menu'
	
	
			try:
				self.CacheSettings = xdg.Menu.parse("settings.menu")
			except:
				try:
					self.CacheSettings = xdg.Menu.parse("mate-settings.menu")
				except: 
					try:
						self.CacheSettings = xdg.Menu.parse(os.environ.get("XDG_MENU_PREFIX", "") + "settings.menu")
					except:
						print 'unable to parse the settings menu'

			self.AppsFile = self.CacheApplications.Filename
			self.SetFile = self.CacheSettings.Filename

			if isgio:
				dirs = bd.xdg_data_dirs
				if bd.xdg_data_home not in dirs:
					dirs.append(bd.xdg_data_home)
				for d in dirs:
					self.parentfile = d + '/applications'
					if os.path.isdir(self.parentfile) and os.path.exists(self.parentfile):
						self.current_file1 = gio.File(self.parentfile).monitor_directory()
						self.current_file1.connect_after("changed", self.monitor_callback)
	
				self.current_file = gio.File(self.AppsFile).monitor_file()
				self.current_file.connect_after("changed", self.monitor_callback)

			self.MenuInstance = xdg.Menu.Menu
			self.EntryInstance = xdg.Menu.MenuEntry