added action cb mechanism for buttons. Tested with a temporary new user registration button.
This commit is contained in:
parent
bd70d6d7b6
commit
a103e8b41b
1 changed files with 226 additions and 66 deletions
|
|
@ -54,9 +54,11 @@ class Param():
|
|||
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 @@ class Param():
|
|||
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 @@ class Param():
|
|||
@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 @@ class Param():
|
|||
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 @@ class Param():
|
|||
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 @@ class Memory:
|
|||
#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 @@ class Memory:
|
|||
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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue