Mercurial > libervia-backend
diff sat.tac @ 101:783e9d6980ec
Couchsurfing plugin: first draft
SàT core: adding additionnal menu method
bridge: new methods getMenus, getMenuHelp and callMenu
wix: new menu are added on startup
CS plugin: login on CS
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Jun 2010 17:15:30 +0800 |
parents | 4020931569b8 |
children | 94011f553cd0 |
line wrap: on
line diff
--- a/sat.tac Fri Jun 18 17:14:14 2010 +0800 +++ b/sat.tac Sat Jun 19 17:15:30 2010 +0800 @@ -327,6 +327,7 @@ self.__private_data = {} #used for internal callbacks (key = id) self.profiles = {} self.plugins = {} + self.menus = {} #used to know which new menus are wanted by plugins self.memory=Memory(self) self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future @@ -357,6 +358,9 @@ self.bridge.register("launchAction", self.launchAction) self.bridge.register("confirmationAnswer", self.confirmationAnswer) self.bridge.register("getProgress", self.getProgress) + self.bridge.register("getMenus", self.getMenus) + self.bridge.register("getMenuHelp", self.getMenuHelp) + self.bridge.register("callMenu", self.callMenu) self._import_plugins() @@ -689,7 +693,7 @@ def confirmationAnswer(self, id, accepted, data): """Called by frontends to answer confirmation requests""" - debug (_("Received confirmation answer for id [%(id)s]: %(success)s") % {'id': id, 'success':u("accepted") if accepted else _("refused")}) + debug (_("Received confirmation answer for id [%(id)s]: %(success)s") % {'id': id, 'success':_("accepted") if accepted else _("refused")}) if not self.__waiting_conf.has_key(id): error (_("Received an unknown confirmation")) else: @@ -740,6 +744,46 @@ error(_("Trying to call unknown function")) return None + #Menus management + + def importMenu(self, category, name, callback, help_string = "", type = "NORMAL"): + """register a new menu for frontends + @param category: category of the menu + @param name: menu item entry + @param callback: method to be called when menuitem is selected""" + if self.menus.has_key((category,name)): + error ("Want to register a menu which already existe") + return + self.menus[(category,name,type)] = {'callback':callback, 'help_string':help_string, 'type':type} + + def getMenus(self): + """Return all menus registered""" + return self.menus.keys() + + def getMenuHelp(self, category, name, type="NORMAL"): + """return the help string of the menu""" + try: + return self.menus[(category,name,type)]['help_string'] + except KeyError: + error (_("Trying to access an unknown menu")) + return "" + + def callMenu(self, category, name, type="NORMAL", profile_key='@DEFAULT@'): + """return the help string of the menu""" + profile = self.memory.getProfileName(profile_key) + if not profile_key: + error (_('Non-exsitant profile')) + return "" + try: + id = self.get_next_id() + self.menus[(category,name,type)]['callback'](id, profile) + return id + except KeyError: + error (_("Trying to access an unknown menu")) + return "" + + + application = service.Application('SàT') service = SAT() service.setServiceParent(application)