+# Base class for interface parameter classes
+class xxxNode:
+ def __init__(self, node):
+ self.node = node
+ def remove(self):
+ self.node.parentNode.removeChild(self.node)
+ self.node.unlink()
+
+# Generic (text) parameter class
+class xxxParam(xxxNode):
+ # Standard use: for text nodes
+ def __init__(self, node):
+ xxxNode.__init__(self, node)
+ if not node.hasChildNodes():
+ # If does not have child nodes, create empty text node
+ text = tree.dom.createTextNode('')
+ node.appendChild(text)
+ else:
+ text = node.childNodes[0] # first child must be text node
+ assert text.nodeType == minidom.Node.TEXT_NODE
+ self.textNode = text
+ # Value returns string
+ def value(self):
+ return self.textNode.data
+ def update(self, value):
+ self.textNode.data = value
+
+# Integer parameter
+class xxxParamInt(xxxParam):
+ # Standard use: for text nodes
+ def __init__(self, node):
+ xxxParam.__init__(self, node)
+ # Value returns string
+ def value(self):
+ try:
+ return int(self.textNode.data)
+ except ValueError:
+ return -1 # invalid value
+ def update(self, value):
+ self.textNode.data = str(value)
+
+# Content parameter
+class xxxParamContent(xxxNode):
+ def __init__(self, node):
+ xxxNode.__init__(self, node)
+ data, l = [], [] # data is needed to quicker value retrieval
+ nodes = node.childNodes[:] # make a copy of the child list
+ for n in nodes:
+ if n.nodeType == minidom.Node.ELEMENT_NODE:
+ assert n.tagName == 'item', 'bad content content'
+ if not n.hasChildNodes():
+ # If does not have child nodes, create empty text node
+ text = tree.dom.createTextNode('')
+ node.appendChild(text)
+ else:
+ # !!! normalize?
+ text = n.childNodes[0] # first child must be text node
+ assert text.nodeType == minidom.Node.TEXT_NODE
+ l.append(text)
+ data.append(str(text.data))
+ else: # remove other
+ node.removeChild(n)
+ n.unlink()
+ self.l, self.data = l, data
+ def value(self):
+ return self.data
+ def update(self, value):
+ # If number if items is not the same, recreate children
+ if len(value) != len(self.l): # remove first if number of items has changed
+ childNodes = self.node.childNodes[:]
+ for n in childNodes:
+ self.node.removeChild(n)
+ l = []
+ for str in value:
+ itemElem = tree.dom.createElement('item')
+ itemText = tree.dom.createTextNode(str)
+ itemElem.appendChild(itemText)
+ self.node.appendChild(itemElem)
+ l.append(itemText)
+ self.l = l
+ else:
+ for i in range(len(value)):
+ self.l[i].data = value[i]
+ self.data = value
+
+# Content parameter for checklist
+class xxxParamContentCheckList(xxxNode):
+ def __init__(self, node):
+ xxxNode.__init__(self, node)
+ data, l = [], [] # data is needed to quicker value retrieval
+ nodes = node.childNodes[:] # make a copy of the child list
+ for n in nodes:
+ if n.nodeType == minidom.Node.ELEMENT_NODE:
+ assert n.tagName == 'item', 'bad content content'
+ checked = n.getAttribute('checked')
+ if not n.hasChildNodes():
+ # If does not have child nodes, create empty text node
+ text = tree.dom.createTextNode('')
+ node.appendChild(text)
+ else:
+ # !!! normalize?
+ text = n.childNodes[0] # first child must be text node
+ assert text.nodeType == minidom.Node.TEXT_NODE
+ l.append((text, n))
+ data.append((str(text.data), int(checked)))
+ else: # remove other
+ node.removeChild(n)
+ n.unlink()
+ self.l, self.data = l, data
+ def value(self):
+ return self.data
+ def update(self, value):
+ # If number if items is not the same, recreate children
+ if len(value) != len(self.l): # remove first if number of items has changed
+ childNodes = self.node.childNodes[:]
+ for n in childNodes:
+ self.node.removeChild(n)
+ l = []
+ for (s,ch) in value:
+ itemElem = tree.dom.createElement('item')
+ itemElem.setAttribute('checked', str(ch))
+ itemText = tree.dom.createTextNode(s)
+ itemElem.appendChild(itemText)
+ self.node.appendChild(itemElem)
+ l.append((itemText, itemElem))
+ self.l = l
+ else:
+ for i in range(len(value)):
+ self.l[i][0].data = value[i][0]
+ self.l[i][1].setAttribute('checked', str(value[i][1]))
+ self.data = value
+
+################################################################################
+