1 # Name:         xxx.py ('xxx' is easy to distinguish from 'wx' :) ) 
   2 # Purpose:      XML interface classes 
   3 # Author:       Roman Rolinsky <rolinsky@mema.ucl.ac.be> 
   7 from xml
.dom 
import minidom
 
  11 # Base class for interface parameter classes 
  13     def __init__(self
, node
): 
  16         self
.node
.parentNode
.removeChild(self
.node
) 
  19 # Generic (text) parameter class 
  20 class xxxParam(xxxNode
): 
  21     # Standard use: for text nodes 
  22     def __init__(self
, node
): 
  23         xxxNode
.__init
__(self
, node
) 
  24         if not node
.hasChildNodes(): 
  25             # If does not have child nodes, create empty text node 
  26             text 
= g
.tree
.dom
.createTextNode('') 
  27             node
.appendChild(text
) 
  29             text 
= node
.childNodes
[0] # first child must be text node 
  30             assert text
.nodeType 
== minidom
.Node
.TEXT_NODE
 
  31             # Append other text nodes if present and delete them 
  33             for n 
in node
.childNodes
[1:]: 
  34                 if n
.nodeType 
== minidom
.Node
.TEXT_NODE
: 
  39             if extraText
: text
.data 
= text
.data 
+ extraText
 
  40         # Use convertion from unicode to current encoding 
  42     # Value returns string 
  43     if wxUSE_UNICODE
:   # no conversion is needed 
  45             return self
.textNode
.data
 
  46         def update(self
, value
): 
  47             self
.textNode
.data 
= value
 
  50             return self
.textNode
.data
.encode(g
.currentEncoding
) 
  51         def update(self
, value
): 
  52             try: # handle exception if encoding is wrong 
  53                 self
.textNode
.data 
= unicode(value
, g
.currentEncoding
) 
  54             except UnicodeDecodeError: 
  55                 wxLogMessage("Unicode error: set encoding in file\nglobals.py to something appropriate") 
  58 class xxxParamInt(xxxParam
): 
  59     # Standard use: for text nodes 
  60     def __init__(self
, node
): 
  61         xxxParam
.__init
__(self
, node
) 
  62     # Value returns string 
  65             return int(self
.textNode
.data
) 
  67             return -1                   # invalid value 
  68     def update(self
, value
): 
  69         self
.textNode
.data 
= str(value
) 
  72 class xxxParamContent(xxxNode
): 
  73     def __init__(self
, node
): 
  74         xxxNode
.__init
__(self
, node
) 
  75         data
, l 
= [], []                # data is needed to quicker value retrieval 
  76         nodes 
= node
.childNodes
[:]      # make a copy of the child list 
  78             if n
.nodeType 
== minidom
.Node
.ELEMENT_NODE
: 
  79                 assert n
.tagName 
== 'item', 'bad content content' 
  80                 if not n
.hasChildNodes(): 
  81                     # If does not have child nodes, create empty text node 
  82                     text 
= g
.tree
.dom
.createTextNode('') 
  83                     node
.appendChild(text
) 
  86                     text 
= n
.childNodes
[0] # first child must be text node 
  87                     assert text
.nodeType 
== minidom
.Node
.TEXT_NODE
 
  89                 data
.append(str(text
.data
)) 
  93         self
.l
, self
.data 
= l
, data
 
  96     def update(self
, value
): 
  97         # If number if items is not the same, recreate children 
  98         if len(value
) != len(self
.l
):   # remove first if number of items has changed 
  99             childNodes 
= self
.node
.childNodes
[:] 
 101                 self
.node
.removeChild(n
) 
 104                 itemElem 
= g
.tree
.dom
.createElement('item') 
 105                 itemText 
= g
.tree
.dom
.createTextNode(str) 
 106                 itemElem
.appendChild(itemText
) 
 107                 self
.node
.appendChild(itemElem
) 
 111             for i 
in range(len(value
)): 
 112                 self
.l
[i
].data 
= value
[i
] 
 115 # Content parameter for checklist 
 116 class xxxParamContentCheckList(xxxNode
): 
 117     def __init__(self
, node
): 
 118         xxxNode
.__init
__(self
, node
) 
 119         data
, l 
= [], []                # data is needed to quicker value retrieval 
 120         nodes 
= node
.childNodes
[:]      # make a copy of the child list 
 122             if n
.nodeType 
== minidom
.Node
.ELEMENT_NODE
: 
 123                 assert n
.tagName 
== 'item', 'bad content content' 
 124                 checked 
= n
.getAttribute('checked') 
 125                 if not checked
: checked 
= 0 
 126                 if not n
.hasChildNodes(): 
 127                     # If does not have child nodes, create empty text node 
 128                     text 
= g
.tree
.dom
.createTextNode('') 
 129                     node
.appendChild(text
) 
 132                     text 
= n
.childNodes
[0] # first child must be text node 
 133                     assert text
.nodeType 
== minidom
.Node
.TEXT_NODE
 
 135                 data
.append((str(text
.data
), int(checked
))) 
 139         self
.l
, self
.data 
= l
, data
 
 142     def update(self
, value
): 
 143         # If number if items is not the same, recreate children 
 144         if len(value
) != len(self
.l
):   # remove first if number of items has changed 
 145             childNodes 
= self
.node
.childNodes
[:] 
 147                 self
.node
.removeChild(n
) 
 150                 itemElem 
= g
.tree
.dom
.createElement('item') 
 151                 # Add checked only if True 
 152                 if ch
: itemElem
.setAttribute('checked', '1') 
 153                 itemText 
= g
.tree
.dom
.createTextNode(s
) 
 154                 itemElem
.appendChild(itemText
) 
 155                 self
.node
.appendChild(itemElem
) 
 156                 l
.append((itemText
, itemElem
)) 
 159             for i 
in range(len(value
)): 
 160                 self
.l
[i
][0].data 
= value
[i
][0] 
 161                 self
.l
[i
][1].setAttribute('checked', str(value
[i
][1])) 
 165 class xxxParamBitmap(xxxParam
): 
 166     def __init__(self
, node
): 
 167         xxxParam
.__init
__(self
, node
) 
 168         self
.stock_id 
= node
.getAttribute('stock_id') 
 170         return [self
.stock_id
, xxxParam
.value(self
)] 
 171     def update(self
, value
): 
 172         self
.stock_id 
= value
[0] 
 174             self
.node
.setAttribute('stock_id', self
.stock_id
) 
 175         elif self
.node
.hasAttribute('stock_id'): 
 176             self
.node
.removeAttribute('stock_id') 
 177         xxxParam
.update(self
, value
[1]) 
 179 ################################################################################ 
 181 # Classes to interface DOM objects 
 184     hasChildren 
= False                 # has children elements? 
 185     hasStyle 
= True                     # almost everyone 
 186     hasName 
= True                      # has name attribute? 
 187     isSizer 
= hasChild 
= False 
 188     allParams 
= None                    # Some nodes have no parameters 
 189     # Style parameters (all optional) 
 190     styles 
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip'] 
 194     bitmapTags 
= ['bitmap', 'bitmap2', 'icon'] 
 195     # Required paremeters: none by default 
 197     # Default parameters with default values 
 201     # Window styles and extended styles 
 205     # Construct a new xxx object from DOM element 
 206     # parent is parent xxx object (or None if none), element is DOM element object 
 207     def __init__(self
, parent
, element
): 
 209         self
.element 
= element
 
 212         self
.className 
= element
.getAttribute('class') 
 213         self
.subclass 
= element
.getAttribute('subclass') 
 214         if self
.hasName
: self
.name 
= element
.getAttribute('name') 
 215         # Set parameters (text element children) 
 217         nodes 
= element
.childNodes
[:] 
 219             if node
.nodeType 
== minidom
.Node
.ELEMENT_NODE
: 
 222                     continue            # do nothing for object children here 
 223                 if tag 
not in self
.allParams 
and tag 
not in self
.styles
: 
 224                     print 'WARNING: unknown parameter for %s: %s' % \
 
 225                           (self
.className
, tag
) 
 226                 elif tag 
in self
.specials
: 
 227                     self
.special(tag
, node
) 
 228                 elif tag 
== 'content': 
 229                     if self
.className 
== 'wxCheckListBox': 
 230                         self
.params
[tag
] = xxxParamContentCheckList(node
) 
 232                         self
.params
[tag
] = xxxParamContent(node
) 
 233                 elif tag 
== 'font': # has children 
 234                     self
.params
[tag
] = xxxParamFont(element
, node
) 
 235                 elif tag 
in self
.bitmapTags
: 
 236                     # Can have attributes 
 237                     self
.params
[tag
] = xxxParamBitmap(node
) 
 238                 else:                   # simple parameter 
 239                     self
.params
[tag
] = xxxParam(node
) 
 241                 # Remove all other nodes 
 242                 element
.removeChild(node
) 
 244         # Check that all required params are set 
 245         for param 
in self
.required
: 
 246             if not self
.params
.has_key(param
): 
 247                 # If default is specified, set it 
 248                 if self
.default
.has_key(param
): 
 249                     elem 
= g
.tree
.dom
.createElement(param
) 
 250                     if param 
== 'content': 
 251                         if self
.className 
== 'wxCheckListBox': 
 252                             self
.params
[param
] = xxxParamContentCheckList(elem
) 
 254                             self
.params
[param
] = xxxParamContent(elem
) 
 256                         self
.params
[param
] = xxxParam(elem
) 
 257                     # Find place to put new element: first present element after param 
 259                     paramStyles 
= self
.allParams 
+ self
.styles
 
 260                     for p 
in paramStyles
[paramStyles
.index(param
) + 1:]: 
 261                         # Content params don't have same type 
 262                         if self
.params
.has_key(p
) and p 
!= 'content': 
 266                         nextTextElem 
= self
.params
[p
].node
 
 267                         self
.element
.insertBefore(elem
, nextTextElem
) 
 269                         self
.element
.appendChild(elem
) 
 271                     wxLogWarning('Required parameter %s of %s missing' % 
 272                                  (param
, self
.className
)) 
 273     # Returns real tree object 
 274     def treeObject(self
): 
 275         if self
.hasChild
: return self
.child
 
 277     # Returns tree image index 
 279         if self
.hasChild
: return self
.child
.treeImage() 
 281     # Class name plus wx name 
 283         if self
.hasChild
: return self
.child
.treeName() 
 284         if self
.subclass
: className 
= self
.subclass
 
 285         else: className 
= self
.className
 
 286         if self
.hasName 
and self
.name
: return className 
+ ' "' + self
.name 
+ '"' 
 288     # Class name or subclass 
 290         if self
.subclass
: return self
.subclass 
+ '(' + self
.className 
+ ')' 
 291         else: return self
.className
 
 293 ################################################################################ 
 295 # This is a little special: it is both xxxObject and xxxNode 
 296 class xxxParamFont(xxxObject
, xxxNode
): 
 297     allParams 
= ['size', 'style', 'weight', 'family', 'underlined', 
 299     def __init__(self
, parent
, element
): 
 300         xxxObject
.__init
__(self
, parent
, element
) 
 301         xxxNode
.__init
__(self
, element
) 
 302         self
.parentNode 
= parent       
# required to behave similar to DOM node 
 304         for p 
in self
.allParams
: 
 306                 v
.append(str(self
.params
[p
].value())) 
 310     def update(self
, value
): 
 311         # `value' is a list of strings corresponding to all parameters 
 313         # Remove old elements first 
 314         childNodes 
= elem
.childNodes
[:] 
 315         for node 
in childNodes
: elem
.removeChild(node
) 
 319         for param 
in self
.allParams
: 
 321                 fontElem 
= g
.tree
.dom
.createElement(param
) 
 322                 textNode 
= g
.tree
.dom
.createTextNode(value
[i
]) 
 323                 self
.params
[param
] = textNode
 
 324                 fontElem
.appendChild(textNode
) 
 325                 elem
.appendChild(fontElem
) 
 332 ################################################################################ 
 334 class xxxContainer(xxxObject
): 
 337 # Simulate normal parameter for encoding 
 339     def __init__(self
, val
): 
 343     def update(self
, val
): 
 346 # Special class for root node 
 347 class xxxMainNode(xxxContainer
): 
 348     allParams 
= ['encoding'] 
 349     hasStyle 
= hasName 
= False 
 350     def __init__(self
, dom
): 
 351         xxxContainer
.__init
__(self
, None, dom
.documentElement
) 
 352         self
.className 
= 'XML tree' 
 353         # Reset required parameters after processing XML, because encoding is 
 355         self
.required 
= ['encoding'] 
 356         self
.params
['encoding'] = xxxEncoding(dom
.encoding
) 
 358 ################################################################################ 
 361 class xxxPanel(xxxContainer
): 
 362     allParams 
= ['pos', 'size', 'style'] 
 363     styles 
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', 
 365     winStyles 
= ['wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN'] 
 366     exStyles 
= ['wxWS_EX_VALIDATE_RECURSIVELY'] 
 368 class xxxDialog(xxxContainer
): 
 369     allParams 
= ['title', 'centered', 'pos', 'size', 'style'] 
 370     paramDict 
= {'centered': ParamBool}
 
 372     default 
= {'title': ''}
 
 373     winStyles 
= ['wxDEFAULT_DIALOG_STYLE', 'wxSTAY_ON_TOP', 
 374 ##                 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS', 
 375                  'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 'wxRESIZE_BOX', 
 377                  'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN'] 
 378     styles 
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', 
 380     exStyles 
= ['wxWS_EX_VALIDATE_RECURSIVELY'] 
 382 class xxxFrame(xxxContainer
): 
 383     allParams 
= ['title', 'centered', 'pos', 'size', 'style'] 
 384     paramDict 
= {'centered': ParamBool}
 
 386     default 
= {'title': ''}
 
 387     winStyles 
= ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE', 
 389                  'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 
 390                  'wxRESIZE_BOX', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX', 
 391                  'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_TOOL_WINDOW', 
 392                  'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN'] 
 393     styles 
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', 
 395     exStyles 
= ['wxWS_EX_VALIDATE_RECURSIVELY'] 
 397 class xxxTool(xxxObject
): 
 398     allParams 
= ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp'] 
 399     required 
= ['bitmap'] 
 400     paramDict 
= {'bitmap2': ParamBitmap, 'toggle': ParamBool}
 
 403 class xxxToolBar(xxxContainer
): 
 404     allParams 
= ['bitmapsize', 'margins', 'packing', 'separation', 
 405                  'pos', 'size', 'style'] 
 407     paramDict 
= {'bitmapsize': ParamPosSize
, 'margins': ParamPosSize
, 
 408                  'packing': ParamInt
, 'separation': ParamInt
, 
 409                  'style': ParamNonGenericStyle
} 
 410     winStyles 
= ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL'] 
 412 ################################################################################ 
 415 class xxxBitmap(xxxObject
): 
 416     allParams 
= ['bitmap'] 
 417     required 
= ['bitmap'] 
 420 class xxxIcon(xxxObject
): 
 424 ################################################################################ 
 427 class xxxStaticText(xxxObject
): 
 428     allParams 
= ['label', 'pos', 'size', 'style'] 
 430     default 
= {'label': ''}
 
 431     winStyles 
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE'] 
 433 class xxxStaticLine(xxxObject
): 
 434     allParams 
= ['pos', 'size', 'style'] 
 435     winStyles 
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL'] 
 437 class xxxStaticBitmap(xxxObject
): 
 438     allParams 
= ['bitmap', 'pos', 'size', 'style'] 
 439     required 
= ['bitmap'] 
 441 class xxxTextCtrl(xxxObject
): 
 442     allParams 
= ['value', 'pos', 'size', 'style'] 
 443     winStyles 
= ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE', 
 444               'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL'] 
 445     paramDict 
= {'value': ParamMultilineText}
 
 447 class xxxChoice(xxxObject
): 
 448     allParams 
= ['content', 'selection', 'pos', 'size', 'style'] 
 449     required 
= ['content'] 
 450     default 
= {'content': '[]'}
 
 451     winStyles 
= ['wxCB_SORT'] 
 453 class xxxSlider(xxxObject
): 
 454     allParams 
= ['value', 'min', 'max', 'pos', 'size', 'style', 
 455                  'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick', 
 457     paramDict 
= {'value': ParamInt
, 'tickfreq': ParamInt
, 'pagesize': ParamInt
, 
 458                  'linesize': ParamInt
, 'thumb': ParamInt
, 'thumb': ParamInt
, 
 459                  'tick': ParamInt
, 'selmin': ParamInt
, 'selmax': ParamInt
} 
 460     required 
= ['value', 'min', 'max'] 
 461     winStyles 
= ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS', 
 462                  'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM', 
 463                  'wxSL_BOTH', 'wxSL_SELRANGE'] 
 465 class xxxGauge(xxxObject
): 
 466     allParams 
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel'] 
 467     paramDict 
= {'range': ParamInt
, 'value': ParamInt
, 
 468                  'shadow': ParamInt
, 'bezel': ParamInt
} 
 469     winStyles 
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH'] 
 471 class xxxScrollBar(xxxObject
): 
 472     allParams 
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize'] 
 473     paramDict 
= {'value': ParamInt
, 'range': ParamInt
, 'thumbsize': ParamInt
, 
 474                  'pagesize': ParamInt
} 
 475     winStyles 
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL'] 
 477 class xxxListCtrl(xxxObject
): 
 478     allParams 
= ['pos', 'size', 'style'] 
 479     winStyles 
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON', 
 480               'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE', 
 481               'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER', 
 482               'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING'] 
 484 class xxxTreeCtrl(xxxObject
): 
 485     allParams 
= ['pos', 'size', 'style'] 
 486     winStyles 
= ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT', 
 487               'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE'] 
 489 class xxxHtmlWindow(xxxObject
): 
 490     allParams 
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode'] 
 491     paramDict 
= {'borders': ParamInt, 'htmlcode':ParamMultilineText}
 
 492     winStyles 
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO'] 
 494 class xxxCalendarCtrl(xxxObject
): 
 495     allParams 
= ['pos', 'size', 'style'] 
 497 class xxxNotebook(xxxContainer
): 
 498     allParams 
= ['usenotebooksizer', 'pos', 'size', 'style'] 
 499     paramDict 
= {'usenotebooksizer': ParamBool}
 
 500     winStyles 
= ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM'] 
 502 class xxxSplitterWindow(xxxContainer
): 
 503     allParams 
= ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style'] 
 504     paramDict 
= {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit }
 
 505     winStyles 
= ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER', 'wxSP_BORDER', 
 506                          'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE', 
 509 class xxxGenericDirCtrl(xxxObject
): 
 510     allParams 
= ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style'] 
 511     paramDict 
= {'defaultfilter': ParamInt}
 
 512     winStyles 
= ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST', 
 513                  'wxDIRCTRL_SHOW_FILTERS', 'wxDIRCTRL_EDIT_LABELS'] 
 515 class xxxScrolledWindow(xxxContainer
): 
 516     allParams 
= ['pos', 'size', 'style'] 
 517     winStyles 
= ['wxHSCROLL', 'wxVSCROLL'] 
 519 ################################################################################ 
 522 class xxxButton(xxxObject
): 
 523     allParams 
= ['label', 'default', 'pos', 'size', 'style'] 
 524     paramDict 
= {'default': ParamBool}
 
 526     winStyles 
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM'] 
 528 class xxxBitmapButton(xxxObject
): 
 529     allParams 
= ['bitmap', 'selected', 'focus', 'disabled', 'default', 
 530                  'pos', 'size', 'style'] 
 531     required 
= ['bitmap'] 
 532     winStyles 
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP', 
 533                  'wxBU_RIGHT', 'wxBU_BOTTOM'] 
 535 class xxxRadioButton(xxxObject
): 
 536     allParams 
= ['label', 'value', 'pos', 'size', 'style'] 
 537     paramDict 
= {'value': ParamBool}
 
 539     winStyles 
= ['wxRB_GROUP'] 
 541 class xxxSpinButton(xxxObject
): 
 542     allParams 
= ['value', 'min', 'max', 'pos', 'size', 'style'] 
 543     paramDict 
= {'value': ParamInt}
 
 544     winStyles 
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP'] 
 546 class xxxSpinCtrl(xxxObject
): 
 547     allParams 
= ['value', 'min', 'max', 'pos', 'size', 'style'] 
 548     paramDict 
= {'value': ParamInt}
 
 549     winStyles 
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP'] 
 551 class xxxToggleButton(xxxObject
): 
 552     allParams 
= ['label', 'checked', 'pos', 'size', 'style'] 
 553     paramDict 
= {'checked': ParamBool}
 
 556 ################################################################################ 
 559 class xxxStaticBox(xxxObject
): 
 560     allParams 
= ['label', 'pos', 'size', 'style'] 
 563 class xxxRadioBox(xxxObject
): 
 564     allParams 
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style'] 
 565     paramDict 
= {'dimension': ParamInt}
 
 566     required 
= ['label', 'content'] 
 567     default 
= {'content': '[]'}
 
 568     winStyles 
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS'] 
 570 class xxxCheckBox(xxxObject
): 
 571     allParams 
= ['label', 'checked', 'pos', 'size', 'style'] 
 572     paramDict 
= {'checked': ParamBool}
 
 573     winStyles 
= ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER', 
 577 class xxxComboBox(xxxObject
): 
 578     allParams 
= ['content', 'selection', 'value', 'pos', 'size', 'style'] 
 579     required 
= ['content'] 
 580     default 
= {'content': '[]'}
 
 581     winStyles 
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN'] 
 583 class xxxListBox(xxxObject
): 
 584     allParams 
= ['content', 'selection', 'pos', 'size', 'style'] 
 585     required 
= ['content'] 
 586     default 
= {'content': '[]'}
 
 587     winStyles 
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL', 
 588               'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT'] 
 590 class xxxCheckList(xxxObject
): 
 591     allParams 
= ['content', 'pos', 'size', 'style'] 
 592     required 
= ['content'] 
 593     default 
= {'content': '[]'}
 
 594     winStyles 
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON', 
 595               'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE', 
 596               'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER', 
 597               'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING'] 
 598     paramDict 
= {'content': ParamContentCheckList}
 
 600 ################################################################################ 
 603 class xxxSizer(xxxContainer
): 
 604     hasName 
= hasStyle 
= False 
 605     paramDict 
= {'orient': ParamOrient}
 
 608 class xxxBoxSizer(xxxSizer
): 
 609     allParams 
= ['orient'] 
 610     required 
= ['orient'] 
 611     default 
= {'orient': 'wxVERTICAL'}
 
 612     # Tree icon depends on orientation 
 614         if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
 
 615         else: return self
.imageV
 
 617 class xxxStaticBoxSizer(xxxBoxSizer
): 
 618     allParams 
= ['label', 'orient'] 
 619     required 
= ['label', 'orient'] 
 621 class xxxGridSizer(xxxSizer
): 
 622     allParams 
= ['cols', 'rows', 'vgap', 'hgap'] 
 624     default 
= {'cols': '2', 'rows': '2'}
 
 626 # For repeated parameters 
 628     def __init__(self
, node
): 
 630         self
.l
, self
.data 
= [], [] 
 631     def append(self
, param
): 
 633         self
.data
.append(param
.value()) 
 639         self
.l
, self
.data 
= [], [] 
 641 class xxxFlexGridSizer(xxxGridSizer
): 
 642     specials 
= ['growablecols', 'growablerows'] 
 643     allParams 
= ['cols', 'rows', 'vgap', 'hgap'] + specials
 
 644     paramDict 
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
 
 645     # Special processing for growable* parameters 
 646     # (they are represented by several nodes) 
 647     def special(self
, tag
, node
): 
 648         if not self
.params
.has_key(tag
): 
 649             # Create new multi-group 
 650             self
.params
[tag
] = xxxParamMulti(node
) 
 651         self
.params
[tag
].append(xxxParamInt(node
)) 
 652     def setSpecial(self
, param
, value
): 
 653         # Straightforward implementation: remove, add again 
 654         self
.params
[param
].remove() 
 655         del self
.params
[param
] 
 657             node 
= g
.tree
.dom
.createElement(param
) 
 658             text 
= g
.tree
.dom
.createTextNode(str(i
)) 
 659             node
.appendChild(text
) 
 660             self
.element
.appendChild(node
) 
 661             self
.special(param
, node
) 
 663 class xxxGridBagSizer(xxxSizer
): 
 664     specials 
= ['growablecols', 'growablerows'] 
 665     allParams 
= ['vgap', 'hgap'] + specials
 
 666     paramDict 
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
 
 667     # Special processing for growable* parameters 
 668     # (they are represented by several nodes) 
 669     def special(self
, tag
, node
): 
 670         if not self
.params
.has_key(tag
): 
 671             # Create new multi-group 
 672             self
.params
[tag
] = xxxParamMulti(node
) 
 673         self
.params
[tag
].append(xxxParamInt(node
)) 
 674     def setSpecial(self
, param
, value
): 
 675         # Straightforward implementation: remove, add again 
 676         self
.params
[param
].remove() 
 677         del self
.params
[param
] 
 679             node 
= g
.tree
.dom
.createElement(param
) 
 680             text 
= g
.tree
.dom
.createTextNode(str(i
)) 
 681             node
.appendChild(text
) 
 682             self
.element
.appendChild(node
) 
 683             self
.special(param
, node
) 
 685 # Container with only one child. 
 687 class xxxChildContainer(xxxObject
): 
 688     hasName 
= hasStyle 
= False 
 690     def __init__(self
, parent
, element
): 
 691         xxxObject
.__init
__(self
, parent
, element
) 
 692         # Must have one child with 'object' tag, but we don't check it 
 693         nodes 
= element
.childNodes
[:]   # create copy 
 695             if node
.nodeType 
== minidom
.Node
.ELEMENT_NODE
: 
 696                 if node
.tagName 
== 'object': 
 697                     # Create new xxx object for child node 
 698                     self
.child 
= MakeXXXFromDOM(self
, node
) 
 699                     self
.child
.parent 
= parent
 
 700                     # Copy hasChildren and isSizer attributes 
 701                     self
.hasChildren 
= self
.child
.hasChildren
 
 702                     self
.isSizer 
= self
.child
.isSizer
 
 705                 element
.removeChild(node
) 
 707         assert 0, 'no child found' 
 709 class xxxSizerItem(xxxChildContainer
): 
 710     allParams 
= ['option', 'flag', 'border', 'minsize', 'ratio'] 
 711     paramDict 
= {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
 
 712     #default = {'cellspan': '1,1'} 
 713     def __init__(self
, parent
, element
): 
 714         # For GridBag sizer items, extra parameters added 
 715         if isinstance(parent
, xxxGridBagSizer
): 
 716             self
.allParams 
= self
.allParams 
+ ['cellpos', 'cellspan'] 
 717         xxxChildContainer
.__init
__(self
, parent
, element
) 
 718         # Remove pos parameter - not needed for sizeritems 
 719         if 'pos' in self
.child
.allParams
: 
 720             self
.child
.allParams 
= self
.child
.allParams
[:] 
 721             self
.child
.allParams
.remove('pos') 
 723 class xxxNotebookPage(xxxChildContainer
): 
 724     allParams 
= ['label', 'selected'] 
 725     paramDict 
= {'selected': ParamBool}
 
 727     def __init__(self
, parent
, element
): 
 728         xxxChildContainer
.__init
__(self
, parent
, element
) 
 729         # pos and size dont matter for notebookpages 
 730         if 'pos' in self
.child
.allParams
: 
 731             self
.child
.allParams 
= self
.child
.allParams
[:] 
 732             self
.child
.allParams
.remove('pos') 
 733         if 'size' in self
.child
.allParams
: 
 734             self
.child
.allParams 
= self
.child
.allParams
[:] 
 735             self
.child
.allParams
.remove('size') 
 737 class xxxSpacer(xxxObject
): 
 738     hasName 
= hasStyle 
= False 
 739     allParams 
= ['size', 'option', 'flag', 'border'] 
 740     paramDict 
= {'option': ParamInt}
 
 741     default 
= {'size': '0,0'}
 
 743 class xxxMenuBar(xxxContainer
): 
 744     allParams 
= ['style'] 
 745     paramDict 
= {'style': ParamNonGenericStyle}    
# no generic styles 
 746     winStyles 
= ['wxMB_DOCKABLE'] 
 748 class xxxMenu(xxxContainer
): 
 749     allParams 
= ['label', 'help', 'style'] 
 750     default 
= {'label': ''}
 
 751     paramDict 
= {'style': ParamNonGenericStyle}    
# no generic styles 
 752     winStyles 
= ['wxMENU_TEAROFF'] 
 754 class xxxMenuItem(xxxObject
): 
 755     allParams 
= ['label', 'bitmap', 'accel', 'help', 
 756                  'checkable', 'radio', 'enabled', 'checked'] 
 757     default 
= {'label': ''}
 
 760 class xxxSeparator(xxxObject
): 
 761     hasName 
= hasStyle 
= False 
 763 ################################################################################ 
 766 class xxxUnknown(xxxObject
): 
 767     allParams 
= ['pos', 'size', 'style'] 
 768     paramDict 
= {'style': ParamNonGenericStyle}    
# no generic styles 
 770 ################################################################################ 
 774     'wxDialog': xxxDialog
, 
 777     'wxToolBar': xxxToolBar
, 
 779     'wxBitmap': xxxBitmap
, 
 782     'wxButton': xxxButton
, 
 783     'wxBitmapButton': xxxBitmapButton
, 
 784     'wxRadioButton': xxxRadioButton
, 
 785     'wxSpinButton': xxxSpinButton
, 
 786     'wxToggleButton' : xxxToggleButton
, 
 788     'wxStaticBox': xxxStaticBox
, 
 789     'wxStaticBitmap': xxxStaticBitmap
, 
 790     'wxRadioBox': xxxRadioBox
, 
 791     'wxComboBox': xxxComboBox
, 
 792     'wxCheckBox': xxxCheckBox
, 
 793     'wxListBox': xxxListBox
, 
 795     'wxStaticText': xxxStaticText
, 
 796     'wxStaticLine': xxxStaticLine
, 
 797     'wxTextCtrl': xxxTextCtrl
, 
 798     'wxChoice': xxxChoice
, 
 799     'wxSlider': xxxSlider
, 
 801     'wxScrollBar': xxxScrollBar
, 
 802     'wxTreeCtrl': xxxTreeCtrl
, 
 803     'wxListCtrl': xxxListCtrl
, 
 804     'wxCheckListBox': xxxCheckList
, 
 805     'wxNotebook': xxxNotebook
, 
 806     'wxSplitterWindow': xxxSplitterWindow
, 
 807     'notebookpage': xxxNotebookPage
, 
 808     'wxHtmlWindow': xxxHtmlWindow
, 
 809     'wxCalendarCtrl': xxxCalendarCtrl
, 
 810     'wxGenericDirCtrl': xxxGenericDirCtrl
, 
 811     'wxSpinCtrl': xxxSpinCtrl
, 
 812     'wxScrolledWindow': xxxScrolledWindow
, 
 814     'wxBoxSizer': xxxBoxSizer
, 
 815     'wxStaticBoxSizer': xxxStaticBoxSizer
, 
 816     'wxGridSizer': xxxGridSizer
, 
 817     'wxFlexGridSizer': xxxFlexGridSizer
, 
 818     'wxGridBagSizer': xxxGridBagSizer
, 
 819     'sizeritem': xxxSizerItem
, 
 822     'wxMenuBar': xxxMenuBar
, 
 824     'wxMenuItem': xxxMenuItem
, 
 825     'separator': xxxSeparator
, 
 827     'unknown': xxxUnknown
, 
 830 # Create IDs for all parameters of all classes 
 831 paramIDs 
= {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(), 
 832             'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(), 
 833             'tooltip': wxNewId(), 'encoding': wxNewId(), 
 834             'cellpos': wxNewId(), 'cellspan': wxNewId() 
 836 for cl 
in xxxDict
.values(): 
 838         for param 
in cl
.allParams 
+ cl
.paramDict
.keys(): 
 839             if not paramIDs
.has_key(param
): 
 840                 paramIDs
[param
] = wxNewId() 
 842 ################################################################################ 
 845 # Test for object elements 
 847     return node
.nodeType 
== minidom
.Node
.ELEMENT_NODE 
and node
.tagName 
== 'object' 
 849 # Make XXX object from some DOM object, selecting correct class 
 850 def MakeXXXFromDOM(parent
, element
): 
 852         klass 
= xxxDict
[element
.getAttribute('class')] 
 854         # If we encounter a weird class, use unknown template 
 855         print 'WARNING: unsupported class:', element
.getAttribute('class') 
 857     return klass(parent
, element
) 
 859 # Make empty DOM element 
 860 def MakeEmptyDOM(className
): 
 861     elem 
= g
.tree
.dom
.createElement('object') 
 862     elem
.setAttribute('class', className
) 
 863     # Set required and default parameters 
 864     xxxClass 
= xxxDict
[className
] 
 865     defaultNotRequired 
= filter(lambda x
, l
=xxxClass
.required
: x 
not in l
, 
 866                                 xxxClass
.default
.keys()) 
 867     for param 
in xxxClass
.required 
+ defaultNotRequired
: 
 868         textElem 
= g
.tree
.dom
.createElement(param
) 
 870             textNode 
= g
.tree
.dom
.createTextNode(xxxClass
.default
[param
]) 
 872             textNode 
= g
.tree
.dom
.createTextNode('') 
 873         textElem
.appendChild(textNode
) 
 874         elem
.appendChild(textElem
) 
 877 # Make empty XXX object 
 878 def MakeEmptyXXX(parent
, className
): 
 879     # Make corresponding DOM object first 
 880     elem 
= MakeEmptyDOM(className
) 
 881     # If parent is a sizer, we should create sizeritem object, except for spacers 
 883         if parent
.isSizer 
and className 
!= 'spacer': 
 884             sizerItemElem 
= MakeEmptyDOM('sizeritem') 
 885             sizerItemElem
.appendChild(elem
) 
 887         elif isinstance(parent
, xxxNotebook
): 
 888             pageElem 
= MakeEmptyDOM('notebookpage') 
 889             pageElem
.appendChild(elem
) 
 891     # Now just make object 
 892     return MakeXXXFromDOM(parent
, elem
)