changeset 18:6928e3cb73a8

refactoring: using xml params part II
author Goffi <goffi@goffi.org>
date Fri, 06 Nov 2009 23:31:00 +0100
parents 74a39f40eb6d
children f2a745ca0fbc
files frontends/quick_frontend/quick_app.py frontends/sat_bridge_frontend/DBus.py frontends/wix/main_window.py frontends/wix/param.py sat.tac sat_bridge/DBus.py tools/memory.py
diffstat 7 files changed, 68 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/quick_frontend/quick_app.py	Fri Nov 06 19:48:57 2009 +0100
+++ b/frontends/quick_frontend/quick_app.py	Fri Nov 06 23:31:00 2009 +0100
@@ -42,8 +42,8 @@
         self.bridge.register("askConfirmation", self.askConfirmation, "request")
         
         ###now we get the essential params###
-        self.whoami=JID(self.bridge.getParam("JabberID","Connection")[0])
-        self.watched=self.bridge.getParam("Watched", "Misc")[0].split() #TODO: put this in a plugin
+        self.whoami=JID(self.bridge.getParamV("JabberID","Connection"))
+        self.watched=self.bridge.getParamV("Watched", "Misc").split() #TODO: put this in a plugin
 
         ## misc ##
         self.onlineContact = set()  #FIXME: temporary
--- a/frontends/sat_bridge_frontend/DBus.py	Fri Nov 06 19:48:57 2009 +0100
+++ b/frontends/sat_bridge_frontend/DBus.py	Fri Nov 06 23:31:00 2009 +0100
@@ -61,14 +61,17 @@
     def setPresence(self, to="", type="", show="", status="", priority=0):
         return self.db_comm_iface.setPresence(to, type, show, status, priority)
 
-    def setParam(self, name, value, namespace="default"):
-        return self.db_comm_iface.setParam(name, value, namespace)
+    def setParam(self, name, value, category):
+        return self.db_comm_iface.setParam(name, value, category)
         
-    def getParam(self, name, namespace="default"):
-        return self.db_comm_iface.getParam(name, namespace)
+    def getParamV(self, name, category):
+        return self.db_comm_iface.getParamV(name, category)
 
-    def getParams(self, namespace="default"):
-        return self.db_comm_iface.getParams(namespace)
+    def getParams(self):
+        return self.db_comm_iface.getParams()
+
+    def getParamsForCategory(self, category):
+        return self.db_comm_iface.getParamsForCategory(category)
 
     def getParamsCategories(self):
         return self.db_comm_iface.getParamsCategories()
--- a/frontends/wix/main_window.py	Fri Nov 06 19:48:57 2009 +0100
+++ b/frontends/wix/main_window.py	Fri Nov 06 23:31:00 2009 +0100
@@ -340,7 +340,7 @@
 
     def onParam(self, e):
         debug("Param request")
-        param=Param(self.bridge.setParam, self.bridge.getParam, self.bridge.getParams, self.bridge.getParamsCategories)
+        param=Param(self.bridge)
 
     def onExit(self, e):
         self.Close()
--- a/frontends/wix/param.py	Fri Nov 06 19:48:57 2009 +0100
+++ b/frontends/wix/param.py	Fri Nov 06 23:31:00 2009 +0100
@@ -23,17 +23,15 @@
 
 import wx
 import pdb
+from xml.dom import minidom
 from logging import debug, info, error
 
 
 class Param(wx.Frame):
-    def __init__(self, setParam, getParam, getParams, getParamsCategories, title="Configuration"):
+    def __init__(self, bridge, title="Configuration"):
         super(Param, self).__init__(None, title=title)
 
-        self.setParam=setParam
-        self.getParam=getParam
-        self.getParams=getParams
-        self.getParamsCategories=getParamsCategories
+        self.bridge = bridge
 
         self.modified={}  # dict of modified data (i.e. what we have to save)
 
@@ -48,7 +46,7 @@
         
         self.MakeModal()
 
-        for category in self.getParamsCategories():
+        for category in self.bridge.getParamsCategories():
             self.addCategory(category)
         
         self.Show()
@@ -57,17 +55,22 @@
         panel=wx.Panel(self.notebook)
         panel.sizer = wx.BoxSizer(wx.VERTICAL)
 
-        for param in self.getParams(category):
+        cat_dom = minidom.parseString(self.bridge.getParamsForCategory(category))
+        
+        for param in cat_dom.documentElement.getElementsByTagName("param"):
+            name = param.getAttribute("name")
+            type = param.getAttribute("type")
+            value = param.getAttribute("value")
             sizer = wx.BoxSizer(wx.HORIZONTAL)
-            label=wx.StaticText(panel, -1, param[0]+" ")
-            if param[2]=="string":
-                ctrl = wx.TextCtrl(panel, -1, param[1])
-            elif param[2]=="password":
-                ctrl = wx.TextCtrl(panel, -1, param[1], style=wx.TE_PASSWORD)
+            label=wx.StaticText(panel, -1, name+" ")
+            if type=="string":
+                ctrl = wx.TextCtrl(panel, -1, value)
+            elif type=="password":
+                ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
             else:
                 error("FIXME FIXME FIXME")  #FIXME !
                 raise NotImplementedError
-            ctrl.param_id=(param[0], category)
+            ctrl.param_id=(name, category)
             sizer.Add(label)
             sizer.Add(ctrl, 1, flag=wx.EXPAND)
             panel.sizer.Add(sizer, flag=wx.EXPAND)
@@ -76,6 +79,7 @@
         panel.SetSizer(panel.sizer)
         panel.SetAutoLayout(True)
         self.notebook.AddPage(panel, category)
+        cat_dom.unlink()
 
     def onTextChanged(self, event):
         """Called when a paramated is modified"""
@@ -88,7 +92,7 @@
         debug("close")
         #now we save the modifier params
         for param in self.modified:
-            self.setParam(param[0], self.modified[param], param[1])
+            self.bridge.setParam(param[0], self.modified[param], param[1])
 
         self.MakeModal(False)
         event.Skip()
--- a/sat.tac	Fri Nov 06 19:48:57 2009 +0100
+++ b/sat.tac	Fri Nov 06 23:31:00 2009 +0100
@@ -86,6 +86,7 @@
         return self.__connected
     
     def connectionLost(self, connector, unused_reason):
+        self.__connected=False
         print "********** DISCONNECTED **********"
         try:
             self.keep_alife.stop()
@@ -258,8 +259,9 @@
         self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus)
         self.bridge.register("sendMessage", self.sendMessage)
         self.bridge.register("setParam", self.setParam)
-        #self.bridge.register("getParam", self.memory.getParam)
+        self.bridge.register("getParamV", self.memory.getParamV)
         self.bridge.register("getParams", self.memory.getParams)
+        self.bridge.register("getParamsForCategory", self.memory.getParamsForCategory)
         self.bridge.register("getParamsCategories", self.memory.getParamsCategories)
         self.bridge.register("getHistory", self.memory.getHistory)
         self.bridge.register("setPresence", self.setPresence)
@@ -376,11 +378,11 @@
 
     ## Client management ##
 
-    def setParam(self, name, value, namespace):
+    def setParam(self, name, value, category):
         """set wanted paramater and notice observers"""
-        info ("setting param: %s=%s in namespace %s", name, value, namespace)
-        self.memory.setParam(name, value, namespace)
-        self.bridge.paramUpdate(name, value, namespace)
+        info ("setting param: %s=%s in category %s", name, value, category)
+        self.memory.setParam(name, value, category)
+        self.bridge.paramUpdate(name, value, category)
 
     def failed(self,xmlstream):
         debug("failed: %s", xmlstream.getErrorMessage())
--- a/sat_bridge/DBus.py	Fri Nov 06 19:48:57 2009 +0100
+++ b/sat_bridge/DBus.py	Fri Nov 06 23:31:00 2009 +0100
@@ -60,8 +60,8 @@
 
     @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
                          signature='sss')
-    def paramUpdate(self, name, value, namespace):
-        debug("param update signal: %s=%s in namespace %s", name, value, namespace)
+    def paramUpdate(self, name, value, category):
+        debug("param update signal: %s=%s in category %s", name, value, category)
 
     @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
                          signature='s')
@@ -126,15 +126,10 @@
     def setParam(self, name, value, category):
         self.cb["setParam"](name, str(value), category)
         
-    """@dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='ss', out_signature='(ss)')
-    def getParam(self, name, namespace="default"):
-        return self.cb["getParam"](name, namespace)"""
-
-    """@dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='s', out_signature='a(sss)')
-    def getParams(self, namespace):
-        return self.cb["getParams"](namespace)"""
+    @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
+                         in_signature='ss', out_signature='s')
+    def getParamV(self, name, category="default"):
+        return self.cb["getParamV"](name, category)
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
                          in_signature='', out_signature='s')
@@ -142,6 +137,11 @@
         return self.cb["getParams"]()
 
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
+                         in_signature='s', out_signature='s')
+    def getParamsForCategory(self, category):
+        return self.cb["getParamsForCategory"](category)
+
+    @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
                          in_signature='', out_signature='as')
     def getParamsCategories(self):
         return self.cb["getParamsCategories"]()
@@ -236,9 +236,9 @@
         debug("updating presence for %s",jid)
         self.dbus_bridge.presenceUpdate(jid, type, show, status, priority)
 
-    def paramUpdate(self, name, value, namespace):
-        debug("updating param [%s] %s ", namespace, name)
-        self.dbus_bridge.paramUpdate(name, value, namespace)
+    def paramUpdate(self, name, value, category):
+        debug("updating param [%s] %s ", category, name)
+        self.dbus_bridge.paramUpdate(name, value, category)
 
     def contactDeleted(self, jid):
         debug("sending contact deleted signal %s ", jid)
--- a/tools/memory.py	Fri Nov 06 19:48:57 2009 +0100
+++ b/tools/memory.py	Fri Nov 06 23:31:00 2009 +0100
@@ -38,9 +38,9 @@
     default_xml = """
     <params>
     <category name="Connection">
-        <param name="JabberID" value="goffi@jabber.goffi.int/TestScript" type="string" />
+        <param name="JabberID" value="goffi@necton2.int/TestScript" type="string" />
         <param name="Password" value="toto" type="password" />
-        <param name="Server" value="jabber.goffi.int" type="string" />
+        <param name="Server" value="necton2.int" type="string" />
     </category>
     <category name="File Transfert">
         <param name="IP" value="192.168.0.10" type="string" />
@@ -70,14 +70,15 @@
         return node.getAttribute("value")
 
     def getParams(self):
-        """Return the wold params XML"""
+        """Return the whole params XML"""
         return self.dom.toxml()
 
-
-    """def getParam(self, name, category):
-        if self.params.has_key(namespace) and self.params[namespace].has_key(name):
-            return self.params[namespace][name]
-        return ["",""]"""
+    def getParamsForCategory(self, category):
+        """Return node's xml for selected category"""
+        for node in self.dom.documentElement.childNodes:
+            if node.nodeName == "category" and node.getAttribute("name") == category:
+                return node.toxml()
+        return "<category />"
 
     def __getParamNode(self, name, category):
         for node in self.dom.documentElement.childNodes:
@@ -88,15 +89,6 @@
                         return param
         return None
         
-
-    """def getParams(self, namespace):
-        if self.params.has_key(namespace):
-            ret=[]
-            for name in self.params[namespace]:
-                ret.append([name] + self.params[namespace][name])
-            return ret
-        return [[]]"""
-
     def getParamsCategories(self):
         """return the categories availables"""
         categories=[]
@@ -108,13 +100,13 @@
         node = self.__getParamNode(name, category)
         if not node:
             return #TODO: throw an error
-        node.setAttribute(name, value)
+        node.setAttribute("value", value)
 
-    """def createParam (self, name, value, type, namespace):
+    """def createParam (self, name, value, type, category):
         ### TODO: add desciption in params
-        if not self.params.has_key(namespace):
-            self.params[namespace]={}
-        self.params[namespace][name]=[value,type];"""
+        if not self.params.has_key(category):
+            self.params[category]={}
+        self.params[category][name]=[value,type];"""
 
 class Memory:
     """This class manage all persistent informations"""
@@ -224,6 +216,9 @@
     def getParams(self):
         return self.params.getParams() 
     
+    def getParamsForCategory(self, category):
+        return self.params.getParamsForCategory(category) 
+    
     def getParamsCategories(self):
         return self.params.getParamsCategories()