diff tools/memory.py @ 22:bb72c29f3432

added action cb mechanism for buttons. Tested with a temporary new user registration button.
author Goffi <goffi@goffi.org>
date Tue, 01 Dec 2009 04:56:08 +0100
parents 633c5ed65701
children a544b376b6f0
line wrap: on
line diff
--- a/tools/memory.py	Sun Nov 08 01:49:08 2009 +0100
+++ b/tools/memory.py	Tue Dec 01 04:56:08 2009 +0100
@@ -54,9 +54,11 @@
     def load_default_params(self):
         self.dom = minidom.parseString(Param.default_xml)
     
-    def __init__(self):
+    def __init__(self, host):
         debug("Parameters init")
+        self.host = host
         self.load_default_params()
+        host.registerGeneralCB("registerNewAccount", host.registerNewAccountCB)
 
     def __get_unique_node(self, parent, tag, name):
         """return node with given tag, create a new one if the node doesn't exist
@@ -79,7 +81,6 @@
         src_dom = minidom.parseString(xml)
 
         def import_node(tgt_parent, src_parent):
-            print "import_node [%s, %s]" % (tgt_parent.nodeName, src_parent.nodeName)
             for child in src_parent.childNodes:
                 if child.nodeName == '#text':
                     continue
@@ -105,6 +106,7 @@
         @param callback: must return a string with the value (use deferred if needed)
         @param errback: must manage the error with args failure, name, category
         """
+        #TODO: send signal param update if value changed
         node =  self.__getParamNode(name, category)
         if not node:
             error("Requested param [%s] in category [%s] doesn't exist !" , name, category)
@@ -115,14 +117,18 @@
             d.addCallback(self.__default_ok, name, category)
             d.addErrback(errback or self.__default_ko, name, category)
 
-    def getParamV(self, name, category):
-        """Helper method to get the value in the good type
-           getParamV stands for GetParamValue"""
+    def getParamA(self, name, category, attr="value"):
+        """Helper method to get a specific attribute
+           @param name: name of the parameter
+           @param category: category of the parameter
+           @param attr: name of the attribute (default: "value")
+           
+           @return: attribute"""
         node = self.__getParamNode(name, category)
         if not node:
             error("Requested param [%s] in category [%s] doesn't exist !" , name, category)
             return None
-        return node.getAttribute("value")
+        return node.getAttribute(attr)
 
     def getParams(self):
         """Return the whole params XML"""
@@ -155,16 +161,21 @@
         node = self.__getParamNode(name, category)
         if not node:
             return #TODO: throw an error
-        node.setAttribute("value", value)
+        type = node.getAttribute("type")
+        if type=="button":
+            print "clique",node.toxml()
+        else:
+            node.setAttribute("value", value)
+            self.host.bridge.paramUpdate(name, value, category)
 
 class Memory:
     """This class manage all persistent informations"""
 
-    def __init__(self):
+    def __init__(self, host):
         info ("Memory manager init")
         self.contact={}
         self.presenceStatus={}
-        self.params=Param()
+        self.params=Param(host)
         self.history={}
         self.disco={}  #XXX: maybe best in a separate class
         self.features={}
@@ -176,6 +187,7 @@
         #first parameters
         if os.path.exists(const_SAVEFILE_PARAM):
             try:
+                #gof: FIXME FIXME FIXME: sauver l'xml et non plus le pickle !!!!!!!
                 with open(const_SAVEFILE_PARAM, 'r') as params_pickle:
                     self.params=pickle.load(params_pickle)
                 debug("params loaded")
@@ -260,8 +272,8 @@
         debug ("Memory getPresenceStatus (%s)", status)
         return status
 
-    def getParamV(self, name, category):
-        return self.params.getParamV(name, category)
+    def getParamA(self, name, category, attr="value"):
+        return self.params.getParamA(name, category, attr)
     
     def getParams(self):
         return self.params.getParams()