Example #1
0
	def new_internal_menu(self, item):
		""" Creates a new internal menu """
		
		returnlst = []
		
		# Get structure
		menu_settings = self.settings["Menu:%s" % item]
		structure = menu_settings["structure"].split(" ")

		# Get name
		if "%s_label" % item in self.extension_settings:
			label = self.extension_settings["%s_label" % item]
		else:
			label = None

		# Get icon
		if "%s_icon" % item in self.extension_settings:
			icon = self.extension_settings["%s_icon" % item]
		else:
			icon = None

		# Create containing menu
		menu = Menu(id=item, label=label, icon=self.IconPool.get_icon(icon))
		
		result = self.parse_structure(structure)
		for item in result: menu.append(item)
		
		return [menu,]
Example #2
0
    def new_internal_menu(self, item):
        """ Creates a new internal menu """

        returnlst = []

        # Get structure
        menu_settings = self.settings["Menu:%s" % item]
        structure = menu_settings["structure"].split(" ")

        # Get name
        if "%s_label" % item in self.extension_settings:
            label = self.extension_settings["%s_label" % item]
        else:
            label = None

        # Get icon
        if "%s_icon" % item in self.extension_settings:
            icon = self.extension_settings["%s_icon" % item]
        else:
            icon = None

        # Create containing menu
        menu = Menu(id=item, label=label, icon=self.IconPool.get_icon(icon))

        result = self.parse_structure(structure)
        for item in result:
            menu.append(item)

        return [
            menu,
        ]
Example #3
0
    def new_menu_link(self, item, pipe=None):
        """ Creates a new_menu_link """

        if self.is_pipe:
            _id = "PIPE_%s" % item
            execute = "%s %s %s" % (os.path.abspath(
                sys.argv[0]), self.pipe_arguments, item)
        elif pipe:
            _id = "PIPE_%s" % item
            execute = "%s %s %s" % ("/usr/bin/alan-pipe", self.pipe_arguments,
                                    item)
        else:
            _id = item
            execute = None

        # Get name
        if "%s_label" % item in self.extension_settings:
            label = self.extension_settings["%s_label" % item]
        else:
            label = None

        # Get icon
        if "%s_icon" % item in self.extension_settings:
            icon = self.extension_settings["%s_icon" % item]
        else:
            icon = None

        return [
            Menu(id=_id,
                 label=label,
                 execute=execute,
                 icon=self.IconPool.get_icon(icon)),
        ]
Example #4
0
    def generate(self):
        """ Actually generate things. """

        if "hide_settings_menu" in self.extension_settings and self.extension_settings[
                "hide_settings_menu"]:
            self.hide_settings_menu = True
            self.to_skip = ()
        else:
            self.hide_settings_menu = False
            self.to_skip = ("Administration", "Preferences")

        # Lookup menu file
        if "XDG_MENU_PREFIX" in os.environ and os.path.exists(
                os.path.join(
                    "/etc/xdg/menus",
                    "%s-applications.menu" % os.environ["XDG_MENU_PREFIX"])):
            applications_menu = "%s-applications.menu" % os.environ[
                "XDG_MENU_PREFIX"]
        else:
            applications_menu = "applications.menu"  # Force to applications.menu, may fail if not existent, of course.

        # Walk through the normal Applications menu
        tree = GMenu.Tree.new(applications_menu, GMenu.TreeFlags.NONE)
        tree.load_sync()
        self.walk(tree.get_root_directory())

        if not self.hide_settings_menu:
            self.add(Separator())

            # Preferences
            preferences = tree.get_directory_from_path("/System/Preferences")
            preferences_menu = Menu(escape(preferences.get_menu_id()),
                                    escape(preferences.get_name()),
                                    icon=self.IconPool.get_icon(
                                        preferences.get_icon()))
            self.walk(preferences, preferences_menu)
            self.add(preferences_menu)

            # Administration
            administration = tree.get_directory_from_path(
                "/System/Administration")
            administration_menu = Menu(escape(administration.get_menu_id()),
                                       escape(administration.get_name()),
                                       icon=self.IconPool.get_icon(
                                           administration.get_icon()))
            self.walk(administration, administration_menu)
            self.add(administration_menu)
Example #5
0
    def walk(self, parent, menu=None):
        """ Walks through the menu and does pretty things. """

        itr = parent.iter()
        typ = None

        while typ != GMenu.TreeItemType.INVALID:
            typ = itr.next()

            if typ == GMenu.TreeItemType.DIRECTORY:

                entry = itr.get_directory()

                if entry.get_menu_id(
                ) in self.to_skip or entry.get_is_nodisplay():
                    continue

                # Directory, create new submenu
                _menu = Menu(escape(entry.get_menu_id()),
                             entry.get_name(),
                             icon=self.IconPool.get_icon(entry.get_icon()))

                self.walk(itr.get_directory(), _menu)

                if menu is not None:
                    menu.append(_menu)
                else:
                    self.add(_menu)

            elif typ == GMenu.TreeItemType.ENTRY:

                entry = itr.get_entry().get_app_info()
                if entry.get_is_hidden():
                    continue

                name = entry.get_name()

                command = re.sub(' [^ ]*%[fFuUdDnNikvm]', '',
                                 entry.get_commandline()).replace(
                                     "%c", "\"\"")
                #if "oneslip" in command and not ONESLIP:
                #	# oneslip not installed, link to bricks
                #	command = "pkexec /usr/bin/bricks \"%s\" oneslip" % escape(name.replace("&","and"))
                if entry.has_key("Terminal") and entry.get_boolean("Terminal"):
                    command = 'x-terminal-emulator --title "%s" -e %s' % \
                     (name.replace("&","and"), command)

                menu.append(
                    self.return_executable_item(name,
                                                command,
                                                icon=entry.get_icon()))
Example #6
0
	def generate(self):
		""" Actually generate things. """

		# Wallpapers submenu
		_menu = Menu("wallpaper", _("Wallpaper"), icon=self.IconPool.get_icon("preferences-desktop-wallpaper"))
		_menu.append(self.return_executable_item(_("Add"), "nitrogen-add-wallpaper", icon="gtk-add"))
		_menu.append(self.return_executable_item(_("Manage"), "nitrogen", icon="preferences-desktop-wallpaper"))

		self.add(_menu)
		self.add(Separator())
		
		# Theme selector
		self.add(self.return_executable_item(_("Appearance settings"), "lxappearance", icon="preferences-desktop-theme"))
		
		# Paranoid
		if os.path.exists("/usr/bin/paranoid"):
			self.add(self.return_executable_item(_("Visual effects"), "paranoid", icon="desktop-effects"))
Example #7
0
	def generate_menu(self, _id):
		""" Generates a submenu. """
		
		count = 0
		menu = Menu("rss_%s" % _id, label=self.extension_settings["%s_label" % _id], icon=self.IconPool.get_icon("gtk-directory"))
		
		for feed in self.extension_settings["%s_feeds" % _id].split(" "):
			try:
				count += 1
				
				feed = feedparser.parse(feed)
				
				if "icon" in feed.feed:
					try:
						icon = os.path.join(CACHE, self.sanitize_link(feed.feed.link))
						if not os.path.exists(icon):
							with open(sanitized, "wb") as f:
								i = urllib2.urlopen(feed.feed.icon)
								f.write(i.read())
								i.close()
					except:
						pass
				else:
					icon = self.IconPool.get_icon("applications-internet")
				
				# Feed menu
				feed_menu = Menu("rss_%s_%s" % (_id, count), label=feed.feed.title, icon=icon)
				
				for new in feed.entries:
					feed_menu.append(self.return_executable_item(new['title'], new['link'], icon=icon))
				
				menu.append(feed_menu)
			except:
				pass
		
		return menu
Example #8
0
    def __init__(self, configuration=None, is_pipe=False, arguments=None):
        """ Initializes the object. """

        self.is_pipe = is_pipe

        if arguments:
            self.arguments = arguments.split(" ")
        else:
            self.arguments = None

        self.extensionId = self.__module__.replace("alan.extensions.", "")

        self.configuration = configuration
        self.settings = configuration.settings
        if "extension:%s" % self.extensionId in self.settings:
            self.extension_settings = self.settings["extension:%s" %
                                                    self.extensionId]
        else:
            self.extension_settings = {}

        if "structure" in self.extension_settings:
            self.structure = self.extension_settings["structure"].split(" ")

        if not "icons" in self.settings["alan"]:
            icons = False
        else:
            icons = self.settings["alan"]["icons"]

        self.IconPool = IconPool(icons)

        if is_pipe:
            # pipemenu, change things accordingly
            self.objectName = "openbox_pipe_menu"

        OpenboxMenu.__init__(self)

        if not is_pipe:
            if self.settings["alan"]["map_as_main"] == self.extensionId:
                self.menu = Menu("root-menu")
                self.menu.set("label", "Openbox 3")
            else:
                self.menu = Menu(self.extensionName)

                # Unfortunately in non-pipe mode Openbox gets the label from
                # the menu file and not from the id link in the main menu.
                # We need then to get the label.
                main = "extension:%s" % self.settings["alan"]["map_as_main"]
                if not main in self.configuration.sections():
                    label = "alan2"
                else:
                    self.configuration.populate_settings(main)

                    if not "%s_label" % self.extensionName in self.configuration.settings[
                            main]:
                        label = "alan2"
                    else:
                        label = self.configuration.settings[main][
                            "%s_label" % self.extensionName]

                self.menu.set("label", label)

            self.set("xmlns", "http://openbox.org/")
            self.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
            self.set("xsi:schemaLocation",
                     "http://openbox.org/ file:///usr/share/openbox/menu.xsd")

            self.append(self.menu)
Example #9
0
class Extension(OpenboxMenu):
    """ A base Extension object. Extension should subclass this. """

    extensionName = "Extension"
    structure = []

    def __init__(self, configuration=None, is_pipe=False, arguments=None):
        """ Initializes the object. """

        self.is_pipe = is_pipe

        if arguments:
            self.arguments = arguments.split(" ")
        else:
            self.arguments = None

        self.extensionId = self.__module__.replace("alan.extensions.", "")

        self.configuration = configuration
        self.settings = configuration.settings
        if "extension:%s" % self.extensionId in self.settings:
            self.extension_settings = self.settings["extension:%s" %
                                                    self.extensionId]
        else:
            self.extension_settings = {}

        if "structure" in self.extension_settings:
            self.structure = self.extension_settings["structure"].split(" ")

        if not "icons" in self.settings["alan"]:
            icons = False
        else:
            icons = self.settings["alan"]["icons"]

        self.IconPool = IconPool(icons)

        if is_pipe:
            # pipemenu, change things accordingly
            self.objectName = "openbox_pipe_menu"

        OpenboxMenu.__init__(self)

        if not is_pipe:
            if self.settings["alan"]["map_as_main"] == self.extensionId:
                self.menu = Menu("root-menu")
                self.menu.set("label", "Openbox 3")
            else:
                self.menu = Menu(self.extensionName)

                # Unfortunately in non-pipe mode Openbox gets the label from
                # the menu file and not from the id link in the main menu.
                # We need then to get the label.
                main = "extension:%s" % self.settings["alan"]["map_as_main"]
                if not main in self.configuration.sections():
                    label = "alan2"
                else:
                    self.configuration.populate_settings(main)

                    if not "%s_label" % self.extensionName in self.configuration.settings[
                            main]:
                        label = "alan2"
                    else:
                        label = self.configuration.settings[main][
                            "%s_label" % self.extensionName]

                self.menu.set("label", label)

            self.set("xmlns", "http://openbox.org/")
            self.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
            self.set("xsi:schemaLocation",
                     "http://openbox.org/ file:///usr/share/openbox/menu.xsd")

            self.append(self.menu)

    def generate(self):
        """ Override this method to actually do things. """

        pass

    def add(self, obj):
        """ Appends to the main menu the specified object. """

        if self.is_pipe:
            return self.append(obj)
        else:
            return self.menu.append(obj)

    def get_menu(self):
        """ Prints the resulting menu. """

        etree.ElementTree(self).write(sys.stdout)

    def write_menu(self, dest):
        """ Writes the menu in dest."""

        etree.ElementTree(self).write(dest,
                                      encoding='utf-8',
                                      xml_declaration=True)
Example #10
0
	def __init__(self, configuration=None, is_pipe=False, arguments=None):
		""" Initializes the object. """
		
		self.is_pipe = is_pipe
		
		if arguments:
			self.arguments = arguments.split(" ")
		else:
			self.arguments = None
		
		self.extensionId = self.__module__.replace("alan.extensions.", "")
		
		self.configuration = configuration
		self.settings = configuration.settings
		if "extension:%s" % self.extensionId in self.settings:
			self.extension_settings = self.settings["extension:%s" % self.extensionId]
		else:
			self.extension_settings = {}
		
		if "structure" in self.extension_settings:
			self.structure = self.extension_settings["structure"].split(" ")
		
		if not "icons" in self.settings["alan"]:
			icons = False
		else:
			icons = self.settings["alan"]["icons"]
		
		self.IconPool = IconPool(icons)
		
		if is_pipe:
			# pipemenu, change things accordingly
			self.objectName = "openbox_pipe_menu"

		OpenboxMenu.__init__(self)

		if not is_pipe:
			if self.settings["alan"]["map_as_main"] == self.extensionId:
				self.menu = Menu("root-menu")
				self.menu.set("label", "Openbox 3")
			else:
				self.menu = Menu(self.extensionName)
				
				# Unfortunately in non-pipe mode Openbox gets the label from
				# the menu file and not from the id link in the main menu.
				# We need then to get the label.
				main = "extension:%s" % self.settings["alan"]["map_as_main"]
				if not main in self.configuration.sections():
					label = "alan2"
				else:
					self.configuration.populate_settings(main)
					
					if not "%s_label" % self.extensionName in self.configuration.settings[main]:
						label = "alan2"
					else:
						label = self.configuration.settings[main]["%s_label" % self.extensionName]
				
				self.menu.set("label", label)
				
			

			self.set("xmlns", "http://openbox.org/")
			self.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
			self.set("xsi:schemaLocation", "http://openbox.org/ file:///usr/share/openbox/menu.xsd")
			
			self.append(self.menu)
Example #11
0
class Extension(OpenboxMenu):
	""" A base Extension object. Extension should subclass this. """
	
	extensionName = "Extension"
	structure = []
	
	def __init__(self, configuration=None, is_pipe=False, arguments=None):
		""" Initializes the object. """
		
		self.is_pipe = is_pipe
		
		if arguments:
			self.arguments = arguments.split(" ")
		else:
			self.arguments = None
		
		self.extensionId = self.__module__.replace("alan.extensions.", "")
		
		self.configuration = configuration
		self.settings = configuration.settings
		if "extension:%s" % self.extensionId in self.settings:
			self.extension_settings = self.settings["extension:%s" % self.extensionId]
		else:
			self.extension_settings = {}
		
		if "structure" in self.extension_settings:
			self.structure = self.extension_settings["structure"].split(" ")
		
		if not "icons" in self.settings["alan"]:
			icons = False
		else:
			icons = self.settings["alan"]["icons"]
		
		self.IconPool = IconPool(icons)
		
		if is_pipe:
			# pipemenu, change things accordingly
			self.objectName = "openbox_pipe_menu"

		OpenboxMenu.__init__(self)

		if not is_pipe:
			if self.settings["alan"]["map_as_main"] == self.extensionId:
				self.menu = Menu("root-menu")
				self.menu.set("label", "Openbox 3")
			else:
				self.menu = Menu(self.extensionName)
				
				# Unfortunately in non-pipe mode Openbox gets the label from
				# the menu file and not from the id link in the main menu.
				# We need then to get the label.
				main = "extension:%s" % self.settings["alan"]["map_as_main"]
				if not main in self.configuration.sections():
					label = "alan2"
				else:
					self.configuration.populate_settings(main)
					
					if not "%s_label" % self.extensionName in self.configuration.settings[main]:
						label = "alan2"
					else:
						label = self.configuration.settings[main]["%s_label" % self.extensionName]
				
				self.menu.set("label", label)
				
			

			self.set("xmlns", "http://openbox.org/")
			self.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
			self.set("xsi:schemaLocation", "http://openbox.org/ file:///usr/share/openbox/menu.xsd")
			
			self.append(self.menu)
	
	def generate(self):
		""" Override this method to actually do things. """
		
		pass
	
	def add(self, obj):
		""" Appends to the main menu the specified object. """
		
		if self.is_pipe:
			return self.append(obj)
		else:
			return self.menu.append(obj)
	
	def get_menu(self):
		""" Prints the resulting menu. """
		
		etree.ElementTree(self).write(sys.stdout)
	
	def write_menu(self, dest):
		""" Writes the menu in dest."""
		
		etree.ElementTree(self).write(dest, encoding='utf-8', xml_declaration=True)
Example #12
0
	def generate(self):
		""" Actually generate things. """

		### Begin!
		
		settings = Gio.Settings("org.semplicelinux.vera")
		if settings.get_boolean("ninja-shortcut"):
			last = ExitAction[settings.get_enum("last-exit-action")]
		else:
			last = None

		# Add that choice!
		if last:
			choice = last + " " + _("(CTRL+ALT+SPACE)")
			self.add(self.return_executable_item(choice, "vera-command --ninja-shortcut", icon="favorites"))
			self.add(Separator())

		# Add normal choices
			
		# Lock screen
		self.add(self.return_executable_item(_("Lock Screen"), "vera-command --lock", icon="system-lock-screen"))
		# Logout
		self.add(self.return_executable_item(_("Logout"), "vera-command --logout", icon="system-log-out"))
		
		# Switch User
		# create menu:
		switch_items = Menu("switchuser_vera", _("Switch User"), icon=self.IconPool.get_icon("system-users"))
		# open passwd and populate switch_items
		at_least_one = False
		with open("/etc/passwd", "r") as passwd:
			for line in passwd.readlines():
				line = line.split(":")
				_uid = int(line[2])
				if _uid < userbegin or _uid == 65534:
					continue # Skip users < userbegin and 65534 (nobody)
				
				_uname = line[0]
				_udesc = line[4].split(",")[0]
				if not _udesc: _udesc = _uname
				
				if not _uname == USER:
					at_least_one = True
					_uhome = line[5]
					if os.path.exists(os.path.join(_uhome, ".face")):
						_uface = os.path.join(_uhome, ".face")
					else:
						_uface = "system-users"
				
					switch_items.append(self.return_executable_item(_udesc, "vera-command --switch-to-user " + _uname, icon=_uface))

		switch_items.append(Separator())
		switch_items.append(self.return_executable_item(_("Other..."), "vera-command --switch-user", icon="gdm"))
		
		if at_least_one:
			self.add(switch_items)
		else:
			# Generic switch user command
			self.return_executable_item(_("Switch User"), "vera-command --switch-user", icon="system-users")

		self.add(Separator())

		# Suspend
		self.add(self.return_executable_item(_("Suspend"), "vera-command --suspend", icon="system-suspend"))

		# Hibernate
		self.add(self.return_executable_item(_("Hibernate"), "vera-command --hibernate", icon="system-hibernate"))

		self.add(Separator())

		# Shutdown
		self.add(self.return_executable_item(_("Shutdown"), "vera-command --poweroff", icon="system-shutdown"))

		# Reboot
		self.add(self.return_executable_item(_("Reboot"), "vera-command --reboot", icon="system-reboot"))
Example #13
0
    def generate(self):
        """ Actually generate things. """

        ### Begin!

        settings = Gio.Settings("org.semplicelinux.vera")
        if settings.get_boolean("ninja-shortcut"):
            last = ExitAction[settings.get_enum("last-exit-action")]
        else:
            last = None

        # Add that choice!
        if last:
            choice = last + " " + _("(CTRL+ALT+SPACE)")
            self.add(
                self.return_executable_item(choice,
                                            "vera-command --ninja-shortcut",
                                            icon="favorites"))
            self.add(Separator())

        # Add normal choices

        # Lock screen
        self.add(
            self.return_executable_item(_("Lock Screen"),
                                        "vera-command --lock",
                                        icon="system-lock-screen"))
        # Logout
        self.add(
            self.return_executable_item(_("Logout"),
                                        "vera-command --logout",
                                        icon="system-log-out"))

        # Switch User
        # create menu:
        switch_items = Menu("switchuser_vera",
                            _("Switch User"),
                            icon=self.IconPool.get_icon("system-users"))
        # open passwd and populate switch_items
        at_least_one = False
        with open("/etc/passwd", "r") as passwd:
            for line in passwd.readlines():
                line = line.split(":")
                _uid = int(line[2])
                if _uid < userbegin or _uid == 65534:
                    continue  # Skip users < userbegin and 65534 (nobody)

                _uname = line[0]
                _udesc = line[4].split(",")[0]
                if not _udesc: _udesc = _uname

                if not _uname == USER:
                    at_least_one = True
                    _uhome = line[5]
                    if os.path.exists(os.path.join(_uhome, ".face")):
                        _uface = os.path.join(_uhome, ".face")
                    else:
                        _uface = "system-users"

                    switch_items.append(
                        self.return_executable_item(
                            _udesc,
                            "vera-command --switch-to-user " + _uname,
                            icon=_uface))

        switch_items.append(Separator())
        switch_items.append(
            self.return_executable_item(_("Other..."),
                                        "vera-command --switch-user",
                                        icon="gdm"))

        if at_least_one:
            self.add(switch_items)
        else:
            # Generic switch user command
            self.return_executable_item(_("Switch User"),
                                        "vera-command --switch-user",
                                        icon="system-users")

        self.add(Separator())

        # Suspend
        self.add(
            self.return_executable_item(_("Suspend"),
                                        "vera-command --suspend",
                                        icon="system-suspend"))

        # Hibernate
        self.add(
            self.return_executable_item(_("Hibernate"),
                                        "vera-command --hibernate",
                                        icon="system-hibernate"))

        self.add(Separator())

        # Shutdown
        self.add(
            self.return_executable_item(_("Shutdown"),
                                        "vera-command --poweroff",
                                        icon="system-shutdown"))

        # Reboot
        self.add(
            self.return_executable_item(_("Reboot"),
                                        "vera-command --reboot",
                                        icon="system-reboot"))