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, ]
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,]
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"))
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
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)
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)
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"))
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"))