from params import *
-# Parameter value class
-class xxxParam:
- # Standard use: for text nodes
+# 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('')
self.textNode = text
# Value returns string
def value(self):
- return str(self.textNode.data)
+ return self.textNode.data
def update(self, value):
self.textNode.data = value
- def remove(self):
- self.node.parentNode.removeChild(self.node)
- self.node.unlink()
+
+# 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:
+class xxxParamContent(xxxNode):
def __init__(self, node):
- self.node = 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:
text = n.childNodes[0] # first child must be text node
assert text.nodeType == minidom.Node.TEXT_NODE
l.append(text)
- data.append(text.data)
+ data.append(str(text.data))
else: # remove other
node.removeChild(n)
n.unlink()
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
- for n in self.node.childNodes:
+ childNodes = self.node.childNodes[:]
+ for n in childNodes:
self.node.removeChild(n)
l = []
for str in value:
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
+
################################################################################
# Classes to interface DOM objects
hasStyle = true # almost everyone
hasName = true # has name attribute?
isSizer = hasChild = false
+ allParams = None # Some nodes have no parameters
# Style parameters (all optional)
styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip']
# Special parameters
elif tag in self.specials:
self.special(tag, node)
elif tag == 'content':
- self.params[tag] = xxxParamContent(node)
+ if self.className == 'wxCheckList':
+ self.params[tag] = xxxParamContentCheckList(node)
+ else:
+ self.params[tag] = xxxParamContent(node)
elif tag == 'font': # has children
- self.params[tag] = xxxParamFont(self, node)
+ self.params[tag] = xxxParamFont(element, node)
else: # simple parameter
self.params[tag] = xxxParam(node)
else:
# Remove all other nodes
element.removeChild(node)
node.unlink()
- # Generate HTML
- def generateHtml(self, prefix=''):
- SetCurrentXXX(self)
- html = '<table cellspacing=0 cellpadding=0><tr><td width=120>\
-<font size="+1"><b>%s</b></font></td>' % self.className
- # Has id (name) attribute
- if self.hasName:
- html += """\
-<td><wxp module="xxx" class="ParamText" width=150>
-<param name="name" value="data_name">
-</wxp></td>"""
- html += '</table><p>'
- html += '<table cellspacing=0 cellpadding=0>\n'
- # Add required parameters
- for param in self.allParams:
- # Add checkbox or just text
- if param in self.required:
- html += '<tr><td width=20></td><td width=100>%s: </td>' % param
- else: # optional parameter
- html += """\
-<tr><td width=20><wxp class="wxCheckBox">
-<param name="id" value="%d">
-<param name="size" value="(20,-1)">
-<param name="name" value="%s">
-<param name="label" value=("")>
-</wxp></td><td width=100>%s: </td>
-""" % (paramIDs[param], prefix + 'check_' + param, param)
- # Get parameter type
- try:
- # Local or overriden type
- typeClass = self.paramDict[param].__name__
- except KeyError:
- try:
- # Standart type
- typeClass = paramDict[param].__name__
- except KeyError:
- # Default
- typeClass = 'ParamText'
- html += """\
-<td><wxp module="xxx" class="%s">
-<param name="id" value="%d">
-<param name="name" value="%s">
-</wxp></td>
-""" % (typeClass, -1, prefix + 'data_' + param)
- html += '</table>\n'
- return html
# Returns real tree object
def treeObject(self):
if self.hasChild: return self.child
################################################################################
-class xxxParamFont(xxxParam):
+# This is a little special: it is both xxxObject and xxxNode
+class xxxParamFont(xxxObject, xxxNode):
allParams = ['size', 'style', 'weight', 'family', 'underlined',
'face', 'encoding']
def __init__(self, parent, element):
xxxObject.__init__(self, parent, element)
- self.parentNode = element # required to behave similar to DOM node
+ xxxNode.__init__(self, element)
+ self.parentNode = parent # required to behave similar to DOM node
v = []
for p in self.allParams:
try:
- v.append(str(self.params[p].data))
+ v.append(str(self.params[p].value()))
except KeyError:
v.append('')
self.data = v
def update(self, value):
# `value' is a list of strings corresponding to all parameters
elem = self.element
- for node in elem.childNodes:
- elem.removeChild(node)
+ # Remove old elements first
+ childNodes = elem.childNodes[:]
+ for node in childNodes: elem.removeChild(node)
i = 0
self.params.clear()
v = []
v.append(value[i])
i += 1
self.data = v
+ def value(self):
+ return self.data
################################################################################
class xxxContainer(xxxObject):
hasChildren = true
+# Special class for root node
+class xxxMainNode(xxxContainer):
+ hasStyle = hasName = false
+
################################################################################
-# Top-level windwos
+# Top-level windwows
class xxxPanel(xxxContainer):
allParams = ['pos', 'size', 'style']
'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
-# !!! temporary
-xxxCheckList = xxxListCtrl
-
class xxxTreeCtrl(xxxObject):
allParams = ['pos', 'size', 'style']
winStyles = ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT',
winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
+class xxxCheckList(xxxObject):
+ allParams = ['content', 'pos', 'size', 'style']
+ required = ['content']
+ winStyles = ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
+ 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
+ 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
+ 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
+ paramDict = {'content': ParamContentCheckList}
+
################################################################################
# Sizers
class xxxFlexGridSizer(xxxGridSizer):
specials = ['growablecols', 'growablerows']
allParams = ['cols', 'rows', 'vgap', 'hgap'] + specials
- paramDict = {'growablecols':ParamContent, 'growablerows':ParamContent}
+ paramDict = {'growablecols':ParamIntList, 'growablerows':ParamIntList}
# Special processing for growable* parameters
# (they are represented by several nodes)
def special(self, tag, node):
- if tag not in self.params.keys():
+ if tag not in self.params:
self.params[tag] = xxxParamMulti()
- self.params[tag].append(xxxParam(node))
+ self.params[tag].append(xxxParamInt(node))
def setSpecial(self, param, value):
# Straightforward implementation: remove, add again
self.params[param].remove()
del self.params[param]
- for str in value:
+ for i in value:
node = tree.dom.createElement(param)
- text = tree.dom.createTextNode(str)
+ text = tree.dom.createTextNode(str(i))
node.appendChild(text)
self.element.appendChild(node)
self.special(param, node)
element.removeChild(node)
node.unlink()
assert 0, 'no child found'
- def generateHtml(self):
- return xxxObject.generateHtml(self, '_') + '<hr>\n' + \
- self.child.generateHtml()
class xxxSizerItem(xxxChildContainer):
allParams = ['option', 'flag', 'border']
paramDict = {'option': ParamInt}
def __init__(self, parent, element):
xxxChildContainer.__init__(self, parent, element)
- # Remove pos parameter - unnecessary for sizeritems
+ # Remove pos parameter - not needed for sizeritems
if 'pos' in self.child.allParams:
self.child.allParams = self.child.allParams[:]
self.child.allParams.remove('pos')
class xxxSeparator(xxxObject):
hasName = hasStyle = false
- allParams = []
################################################################################
'tooltip': wxNewId()
}
for cl in xxxDict.values():
- for param in cl.allParams + cl.paramDict.keys():
- if not paramIDs.has_key(param):
- paramIDs[param] = wxNewId()
+ if cl.allParams:
+ for param in cl.allParams + cl.paramDict.keys():
+ if not paramIDs.has_key(param):
+ paramIDs[param] = wxNewId()
################################################################################
# Helper functions
return xxxDict[element.getAttribute('class')](parent, element)
except KeyError:
# Verify that it's not recursive exception
- if element.getAttribute('class') not in xxxDict.keys():
+ if element.getAttribute('class') not in xxxDict:
print 'ERROR: unknown class:', element.getAttribute('class')
raise