from params import *
+# 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
+
+################################################################################
+
# Classes to interface DOM objects
class xxxObject:
# Default behavior
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
+ specials = []
# Required paremeters: none by default
required = []
# Default parameters with default values
nodes = element.childNodes[:]
for node in nodes:
if node.nodeType == minidom.Node.ELEMENT_NODE:
- if node.tagName == 'object':
+ tag = node.tagName
+ if tag == 'object':
continue # do nothing for object children here
- if not node.tagName in self.allParams and not node.tagName in self.styles:
+ if not tag in self.allParams and not tag in self.styles:
print 'WARNING: unknown parameter for %s: %s' % \
- (self.className, node.tagName)
- continue
- if node.tagName == 'content': # has items
- # Param value is a list of text nodes
- l = []
- nodes = node.childNodes[:]
- 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)
- else:
- node.removeChild(n)
- n.unlink()
- self.params[node.tagName] = l
- elif node.tagName == 'font': # has children
- # we read and write all font parameters at once
- self.params[node.tagName] = xxxFont(self, node)
- else: # simple parameter
- if not node.hasChildNodes():
- # If does not have child nodes, create empty text node
- text = tree.dom.createTextNode('')
- node.appendChild(text)
+ (self.className, tag)
+ elif tag in self.specials:
+ self.special(tag, node)
+ elif tag == 'content':
+ if self.className == 'wxCheckList':
+ self.params[tag] = xxxParamContentCheckList(node)
else:
- text = node.childNodes[0] # first child must be text node
- assert text.nodeType == minidom.Node.TEXT_NODE
- self.params[node.tagName] = text
+ self.params[tag] = xxxParamContent(node)
+ elif tag == 'font': # has children
+ 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="id" value="%d">
-<param name="name" value="data_name">
-<param name="value" value='("%s")'>
-</wxp></td>""" % (-1, self.name)
- 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)
- # Add value part
- if self.params.has_key(param):
- if param == 'content':
- l = []
- for text in self.params[param]:
- l.append(str(text.data)) # convert from unicode
- value = str(l)
- else:
- value = "('" + self.params[param].data + "')"
- else:
- value = "('')"
- # 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">
-<param name="value" value="%s">
-</wxp></td>
-""" % (typeClass, -1, prefix + 'data_' + param, value)
- html += '</table>\n'
- return html
# Returns real tree object
def treeObject(self):
if self.hasChild: return self.child
################################################################################
-class xxxFont(xxxObject):
+# 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
- self.data = self.value()
- def updateXML(self, value):
+ 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].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 = []
for param in self.allParams:
if value[i]:
fontElem = tree.dom.createElement(param)
self.params[param] = textNode
fontElem.appendChild(textNode)
elem.appendChild(fontElem)
+ v.append(value[i])
i += 1
- # Update data
- self.data = self.value()
+ self.data = v
def value(self):
- v = []
- for p in self.allParams:
- try:
- v.append(str(self.params[p].data))
- except KeyError:
- v.append('')
- return v
+ 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']
styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
'tooltip']
+ winStyles = ['wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
class xxxDialog(xxxContainer):
allParams = ['title', 'pos', 'size', 'style']
required = ['title']
- winStyles = ['wxDIALOG_MODAL', 'wxCAPTION', 'wxDEFAULT_DIALOG_STYLE',
- 'wxRESIZE_BORDER', 'wxSYSTEM_MENU', 'wxTHICK_FRAME', 'wxSTAY_ON_TOP']
+ winStyles = ['wxDEFAULT_DIALOG_STYLE', 'wxSTAY_ON_TOP',
+ 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS',
+ 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 'wxRESIZE_BOX',
+ 'wxTHICK_FRAME',
+ 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
'tooltip']
exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
allParams = ['title', 'centered', 'pos', 'size', 'style']
paramDict = {'centered': ParamBool}
required = ['title']
- winStyles = ['wxDEFAULT_FRAME_STYLE', 'wxICONIZE', 'wxCAPTION', 'wxMINIMIZE',
- 'wxICONIZE', 'wxMINIMIZE_BOX', 'wxMAXIMIZE', 'wxMAXIMIZE_BOX',
- 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
- 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_TOOL_WINDOW']
+ winStyles = ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE',
+ 'wxSTAY_ON_TOP',
+ 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
+ 'wxRESIZE_BOX', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX',
+ 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_TOOL_WINDOW',
+ 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
'tooltip']
exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
+class xxxTool(xxxObject):
+ allParams = ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp']
+ paramDict = {'bitmap2': ParamFile}
+ hasStyle = false
+
+class xxxToolBar(xxxContainer):
+ allParams = ['bitmapsize', 'margins', 'packing', 'separation',
+ 'pos', 'size', 'style']
+ hasStyle = false
+ paramDict = {'bitmapsize': ParamPosSize, 'margins': ParamPosSize,
+ 'packing': ParamInt, 'separation': ParamInt,
+ 'style': ParamNonGenericStyle}
+ winStyles = ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL']
+
+################################################################################
+# Bitmap, Icon
+
+class xxxBitmap(xxxObject):
+ allParams = ['bitmap']
+ required = ['bitmap']
+
+class xxxIcon(xxxObject):
+ allParams = ['icon']
+ required = ['icon']
+
################################################################################
# Controls
allParams = ['pos', 'size', 'style']
winStyles = ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
+class xxxStaticBitmap(xxxObject):
+ allParams = ['bitmap', 'pos', 'size', 'style']
+ required = ['bitmap']
+
class xxxTextCtrl(xxxObject):
allParams = ['value', 'pos', 'size', 'style']
winStyles = ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
- 'wxTE_PASSWORD', 'wxTE_READONLY']
+ 'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
class xxxChoice(xxxObject):
allParams = ['content', 'selection', 'pos', 'size', 'style']
required = ['content']
+ winStyles = ['wxCB_SORT']
class xxxSlider(xxxObject):
allParams = ['value', 'min', 'max', 'pos', 'size', 'style',
'tick': ParamInt, 'selmin': ParamInt, 'selmax': ParamInt}
required = ['value', 'min', 'max']
winStyles = ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
- 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_SELRANGE']
+ 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
+ 'wxSL_BOTH', 'wxSL_SELRANGE']
class xxxGauge(xxxObject):
allParams = ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
'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',
allParams = ['bitmap', 'selected', 'focus', 'disabled', 'default',
'pos', 'size', 'style']
required = ['bitmap']
- winStyles = ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
+ winStyles = ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP',
+ 'wxBU_RIGHT', 'wxBU_BOTTOM']
class xxxRadioButton(xxxObject):
allParams = ['label', 'value', 'pos', 'size', 'style']
class xxxComboBox(xxxObject):
allParams = ['content', 'selection', 'value', 'pos', 'size', 'style']
required = ['content']
- winStyles = ['wxCB_SIMPLE', 'wxCB_DROPDOWN', 'wxCB_READONLY', 'wxCB_DROPDOWN',
- 'wxCB_SORT']
+ winStyles = ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
class xxxListBox(xxxObject):
allParams = ['content', 'selection', 'pos', 'size', 'style']
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
default = {'orient': 'wxVERTICAL'}
# Tree icon depends on orientation
def treeImage(self):
- if self.params['orient'].data == 'wxHORIZONTAL': return self.imageH
+ if self.params['orient'].value() == 'wxHORIZONTAL': return self.imageH
else: return self.imageV
class xxxStaticBoxSizer(xxxBoxSizer):
required = ['cols']
default = {'cols': '2', 'rows': '2'}
+# For repeated parameters
+class xxxParamMulti:
+ def __init__(self):
+ self.l, self.data = [], []
+ def append(self, param):
+ self.l.append(param)
+ self.data.append(param.value())
+ def value(self):
+ return self.data
+ def remove(self):
+ for param in self.l:
+ param.remove()
+ self.l, self.data = [], []
+
class xxxFlexGridSizer(xxxGridSizer):
- pass
+ specials = ['growablecols', 'growablerows']
+ allParams = ['cols', 'rows', 'vgap', 'hgap'] + specials
+ 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:
+ self.params[tag] = xxxParamMulti()
+ 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 i in value:
+ node = tree.dom.createElement(param)
+ text = tree.dom.createTextNode(str(i))
+ node.appendChild(text)
+ self.element.appendChild(node)
+ self.special(param, node)
# Container with only one child.
# Not shown in tree.
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 xxxMenu(xxxContainer):
allParams = ['label']
default = {'label': ''}
+ paramDict = {'style': ParamNonGenericStyle} # no generic styles
+ winStyles = ['wxMENU_TEAROFF']
class xxxMenuItem(xxxObject):
allParams = ['checkable', 'label', 'accel', 'help']
class xxxSeparator(xxxObject):
hasName = hasStyle = false
- allParams = []
################################################################################
'wxPanel': xxxPanel,
'wxDialog': xxxDialog,
'wxFrame': xxxFrame,
+ 'tool': xxxTool,
+ 'wxToolBar': xxxToolBar,
+ 'wxBitmap': xxxBitmap,
+ 'wxIcon': xxxIcon,
+
'wxButton': xxxButton,
'wxBitmapButton': xxxBitmapButton,
'wxRadioButton': xxxRadioButton,
'wxSpinButton': xxxSpinButton,
'wxStaticBox': xxxStaticBox,
+ 'wxStaticBitmap': xxxStaticBitmap,
'wxRadioBox': xxxRadioBox,
'wxComboBox': xxxComboBox,
'wxCheckBox': xxxCheckBox,
'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
# Make XXX object from some DOM object, selecting correct class
def MakeXXXFromDOM(parent, element):
- return xxxDict[element.getAttribute('class')](parent, element)
+ try:
+ return xxxDict[element.getAttribute('class')](parent, element)
+ except KeyError:
+ # Verify that it's not recursive exception
+ if element.getAttribute('class') not in xxxDict:
+ print 'ERROR: unknown class:', element.getAttribute('class')
+ raise
# Make empty DOM element
def MakeEmptyDOM(className):