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
 
  51                 return self
.textNode
.data
.encode(g
.currentEncoding
) 
  53                 return self
.textNode
.data
.encode() 
  54         def update(self
, value
): 
  55             try: # handle exception if encoding is wrong 
  56                 self
.textNode
.data 
= unicode(value
, g
.currentEncoding
) 
  57             except UnicodeDecodeError: 
  58                 self
.textNode
.data 
= unicode(value
) 
  59                 #wxLogMessage("Unicode error: set encoding in file\nglobals.py to something appropriate") 
  62 class xxxParamInt(xxxParam
): 
  63     # Standard use: for text nodes 
  64     def __init__(self
, node
): 
  65         xxxParam
.__init
__(self
, node
) 
  66     # Value returns string 
  69             return int(self
.textNode
.data
) 
  71             return -1                   # invalid value 
  72     def update(self
, value
): 
  73         self
.textNode
.data 
= str(value
) 
  76 class xxxParamContent(xxxNode
): 
  77     def __init__(self
, node
): 
  78         xxxNode
.__init
__(self
, node
) 
  79         data
, l 
= [], []                # data is needed to quicker value retrieval 
  80         nodes 
= node
.childNodes
[:]      # make a copy of the child list 
  82             if n
.nodeType 
== minidom
.Node
.ELEMENT_NODE
: 
  83                 assert n
.tagName 
== 'item', 'bad content content' 
  84                 if not n
.hasChildNodes(): 
  85                     # If does not have child nodes, create empty text node 
  86                     text 
= g
.tree
.dom
.createTextNode('') 
  87                     node
.appendChild(text
) 
  90                     text 
= n
.childNodes
[0] # first child must be text node 
  91                     assert text
.nodeType 
== minidom
.Node
.TEXT_NODE
 
  93                 data
.append(str(text
.data
)) 
  97         self
.l
, self
.data 
= l
, data
 
 100     def update(self
, value
): 
 101         # If number if items is not the same, recreate children 
 102         if len(value
) != len(self
.l
):   # remove first if number of items has changed 
 103             childNodes 
= self
.node
.childNodes
[:] 
 105                 self
.node
.removeChild(n
) 
 108                 itemElem 
= g
.tree
.dom
.createElement('item') 
 109                 itemText 
= g
.tree
.dom
.createTextNode(str) 
 110                 itemElem
.appendChild(itemText
) 
 111                 self
.node
.appendChild(itemElem
) 
 115             for i 
in range(len(value
)): 
 116                 self
.l
[i
].data 
= value
[i
] 
 119 # Content parameter for checklist 
 120 class xxxParamContentCheckList(xxxNode
): 
 121     def __init__(self
, node
): 
 122         xxxNode
.__init
__(self
, node
) 
 123         data
, l 
= [], []                # data is needed to quicker value retrieval 
 124         nodes 
= node
.childNodes
[:]      # make a copy of the child list 
 126             if n
.nodeType 
== minidom
.Node
.ELEMENT_NODE
: 
 127                 assert n
.tagName 
== 'item', 'bad content content' 
 128                 checked 
= n
.getAttribute('checked') 
 129                 if not checked
: checked 
= 0 
 130                 if not n
.hasChildNodes(): 
 131                     # If does not have child nodes, create empty text node 
 132                     text 
= g
.tree
.dom
.createTextNode('') 
 133                     node
.appendChild(text
) 
 136                     text 
= n
.childNodes
[0] # first child must be text node 
 137                     assert text
.nodeType 
== minidom
.Node
.TEXT_NODE
 
 139                 data
.append((str(text
.data
), int(checked
))) 
 143         self
.l
, self
.data 
= l
, data
 
 146     def update(self
, value
): 
 147         # If number if items is not the same, recreate children 
 148         if len(value
) != len(self
.l
):   # remove first if number of items has changed 
 149             childNodes 
= self
.node
.childNodes
[:] 
 151                 self
.node
.removeChild(n
) 
 154                 itemElem 
= g
.tree
.dom
.createElement('item') 
 155                 # Add checked only if True 
 156                 if ch
: itemElem
.setAttribute('checked', '1') 
 157                 itemText 
= g
.tree
.dom
.createTextNode(s
) 
 158                 itemElem
.appendChild(itemText
) 
 159                 self
.node
.appendChild(itemElem
) 
 160                 l
.append((itemText
, itemElem
)) 
 163             for i 
in range(len(value
)): 
 164                 self
.l
[i
][0].data 
= value
[i
][0] 
 165                 self
.l
[i
][1].setAttribute('checked', str(value
[i
][1])) 
 169 class xxxParamBitmap(xxxParam
): 
 170     def __init__(self
, node
): 
 171         xxxParam
.__init
__(self
, node
) 
 172         self
.stock_id 
= node
.getAttribute('stock_id') 
 174         return [self
.stock_id
, xxxParam
.value(self
)] 
 175     def update(self
, value
): 
 176         self
.stock_id 
= value
[0] 
 178             self
.node
.setAttribute('stock_id', self
.stock_id
) 
 179         elif self
.node
.hasAttribute('stock_id'): 
 180             self
.node
.removeAttribute('stock_id') 
 181         xxxParam
.update(self
, value
[1]) 
 183 ################################################################################ 
 185 # Classes to interface DOM objects 
 188     hasChildren 
= False                 # has children elements? 
 189     hasStyle 
= True                     # almost everyone 
 190     hasName 
= True                      # has name attribute? 
 191     isSizer 
= hasChild 
= False 
 192     allParams 
= None                    # Some nodes have no parameters 
 193     # Style parameters (all optional) 
 194     styles 
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip'] 
 198     bitmapTags 
= ['bitmap', 'bitmap2', 'icon'] 
 199     # Required paremeters: none by default 
 201     # Default parameters with default values 
 205     # Window styles and extended styles 
 209     # Construct a new xxx object from DOM element 
 210     # parent is parent xxx object (or None if none), element is DOM element object 
 211     def __init__(self
, parent
, element
, refElem
=None): 
 213         self
.element 
= element
 
 214         self
.refElem 
= refElem
 
 216         # Reference are dereferenced 
 217         if element
.tagName 
== 'object_ref': 
 218             # Find original object 
 219             self
.ref 
= element
.getAttribute('ref') 
 221                 self
.className 
= self
.refElem
.getAttribute('class') 
 223                 self
.className 
= 'xxxUnknown' 
 228             self
.className 
= element
.getAttribute('class') 
 229         self
.subclass 
= element
.getAttribute('subclass') 
 230         if self
.hasName
: self
.name 
= element
.getAttribute('name') 
 231         # Set parameters (text element children) 
 233         nodes 
= element
.childNodes
[:] 
 235             if node
.nodeType 
== minidom
.Node
.ELEMENT_NODE
: 
 237                 if tag 
in ['object', 'object_ref']: 
 238                     continue            # do nothing for object children here 
 239                 elif tag 
not in self
.allParams 
and tag 
not in self
.styles
: 
 240                     print 'WARNING: unknown parameter for %s: %s' % \
 
 241                           (self
.className
, tag
) 
 242                 elif tag 
in self
.specials
: 
 243                     self
.special(tag
, node
) 
 244                 elif tag 
== 'content': 
 245                     if self
.className 
== 'wxCheckListBox': 
 246                         self
.params
[tag
] = xxxParamContentCheckList(node
) 
 248                         self
.params
[tag
] = xxxParamContent(node
) 
 249                 elif tag 
== 'font': # has children 
 250                     self
.params
[tag
] = xxxParamFont(element
, node
) 
 251                 elif tag 
in self
.bitmapTags
: 
 252                     # Can have attributes 
 253                     self
.params
[tag
] = xxxParamBitmap(node
) 
 254                 else:                   # simple parameter 
 255                     self
.params
[tag
] = xxxParam(node
) 
 256             elif node
.nodeType 
== minidom
.Node
.TEXT_NODE 
and node
.data
.isspace(): 
 257                 # Remove empty text nodes 
 258                 element
.removeChild(node
) 
 261         # Check that all required params are set 
 262         for param 
in self
.required
: 
 263             if not self
.params
.has_key(param
): 
 264                 # If default is specified, set it 
 265                 if self
.default
.has_key(param
): 
 266                     elem 
= g
.tree
.dom
.createElement(param
) 
 267                     if param 
== 'content': 
 268                         if self
.className 
== 'wxCheckListBox': 
 269                             self
.params
[param
] = xxxParamContentCheckList(elem
) 
 271                             self
.params
[param
] = xxxParamContent(elem
) 
 273                         self
.params
[param
] = xxxParam(elem
) 
 274                     # Find place to put new element: first present element after param 
 276                     paramStyles 
= self
.allParams 
+ self
.styles
 
 277                     for p 
in paramStyles
[paramStyles
.index(param
) + 1:]: 
 278                         # Content params don't have same type 
 279                         if self
.params
.has_key(p
) and p 
!= 'content': 
 283                         nextTextElem 
= self
.params
[p
].node
 
 284                         self
.element
.insertBefore(elem
, nextTextElem
) 
 286                         self
.element
.appendChild(elem
) 
 288                     wxLogWarning('Required parameter %s of %s missing' % 
 289                                  (param
, self
.className
)) 
 290     # Returns real tree object 
 291     def treeObject(self
): 
 292         if self
.hasChild
: return self
.child
 
 294     # Returns tree image index 
 296         if self
.hasChild
: return self
.child
.treeImage() 
 298     # Class name plus wx name 
 300         if self
.hasChild
: return self
.child
.treeName() 
 301         if self
.subclass
: className 
= self
.subclass
 
 302         else: className 
= self
.className
 
 303         if self
.hasName 
and self
.name
: return className 
+ ' "' + self
.name 
+ '"' 
 305     # Class name or subclass 
 307         if self
.subclass
: name 
= self
.subclass 
+ '(' + self
.className 
+ ')' 
 308         name 
= self
.className
 
 309         if self
.ref
: name 
= 'ref: ' + self
.ref 
+ ', ' + name
 
 311     # Sets name of tree object 
 312     def setTreeName(self
, name
): 
 313         if self
.hasChild
: obj 
= self
.child
 
 316         obj
.element
.setAttribute('name', name
) 
 318 # Imitation of FindResource/DoFindResource from xmlres.cpp 
 319 def DoFindResource(parent
, name
, classname
, recursive
): 
 320     for n 
in parent
.childNodes
: 
 321         if n
.nodeType 
== minidom
.Node
.ELEMENT_NODE 
and \
 
 322                n
.tagName 
in ['object', 'object_ref'] and \
 
 323                n
.getAttribute('name') == name
: 
 324             cls 
= n
.getAttribute('class') 
 325             if not classname 
or cls 
== classname
:  return n
 
 326             if not cls 
or n
.tagName 
== 'object_ref': 
 327                 refName 
= n
.getAttribute('ref') 
 328                 if not refName
:  continue 
 329                 refNode 
= FindResource(refName
) 
 330                 if refName 
and refNode
.getAttribute('class') == classname
: 
 333         for n 
in parent
.childNodes
: 
 334             if n
.nodeType 
== minidom
.Node
.ELEMENT_NODE 
and \
 
 335                    n
.tagName 
in ['object', 'object_ref']: 
 336                 found 
= DoFindResource(n
, name
, classname
, True) 
 337                 if found
:  return found
 
 338 def FindResource(name
, classname
='', recursive
=True): 
 339     found 
= DoFindResource(g
.tree
.mainNode
, name
, classname
, recursive
) 
 340     if found
:  return found
 
 341     wxLogError('XRC resource "%s" not found!' % name
) 
 344 ################################################################################ 
 346 # This is a little special: it is both xxxObject and xxxNode 
 347 class xxxParamFont(xxxObject
, xxxNode
): 
 348     allParams 
= ['size', 'family', 'style', 'weight', 'underlined', 
 350     def __init__(self
, parent
, element
): 
 351         xxxObject
.__init
__(self
, parent
, element
) 
 352         xxxNode
.__init
__(self
, element
) 
 353         self
.parentNode 
= parent       
# required to behave similar to DOM node 
 355         for p 
in self
.allParams
: 
 357                 v
.append(str(self
.params
[p
].value())) 
 361     def update(self
, value
): 
 362         # `value' is a list of strings corresponding to all parameters 
 364         # Remove old elements first 
 365         childNodes 
= elem
.childNodes
[:] 
 366         for node 
in childNodes
: elem
.removeChild(node
) 
 370         for param 
in self
.allParams
: 
 372                 fontElem 
= g
.tree
.dom
.createElement(param
) 
 373                 textNode 
= g
.tree
.dom
.createTextNode(value
[i
]) 
 374                 self
.params
[param
] = textNode
 
 375                 fontElem
.appendChild(textNode
) 
 376                 elem
.appendChild(fontElem
) 
 383 ################################################################################ 
 385 class xxxContainer(xxxObject
): 
 389 # Simulate normal parameter for encoding 
 392         return g
.currentEncoding
 
 393     def update(self
, val
): 
 394         g
.currentEncoding 
= val
 
 396 # Special class for root node 
 397 class xxxMainNode(xxxContainer
): 
 398     allParams 
= ['encoding'] 
 399     hasStyle 
= hasName 
= False 
 400     def __init__(self
, dom
): 
 401         xxxContainer
.__init
__(self
, None, dom
.documentElement
) 
 402         self
.className 
= 'XML tree' 
 403         # Reset required parameters after processing XML, because encoding is 
 405         self
.required 
= ['encoding'] 
 406         self
.params
['encoding'] = xxxEncoding() 
 408 ################################################################################ 
 411 class xxxPanel(xxxContainer
): 
 412     allParams 
= ['pos', 'size', 'style'] 
 413     styles 
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', 
 416 class xxxDialog(xxxContainer
): 
 417     allParams 
= ['title', 'centered', 'pos', 'size', 'style'] 
 418     paramDict 
= {'centered': ParamBool}
 
 420     default 
= {'title': ''}
 
 421     winStyles 
= ['wxDEFAULT_DIALOG_STYLE',  
 422                  'wxCAPTION', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX', 'wxCLOSE_BOX', 
 425                  'wxNO_3D', 'wxDIALOG_NO_PARENT'] 
 426     styles 
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', 
 429 class xxxFrame(xxxContainer
): 
 430     allParams 
= ['title', 'centered', 'pos', 'size', 'style'] 
 431     paramDict 
= {'centered': ParamBool}
 
 433     default 
= {'title': ''}
 
 434     winStyles 
= ['wxDEFAULT_FRAME_STYLE', 
 435                  'wxCAPTION', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX', 'wxCLOSE_BOX', 
 437                  'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 
 438                  'wxFRAME_TOOL_WINDOW', 'wxFRAME_NO_TASKBAR', 
 439                  'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_SHAPED' 
 441     styles 
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', 
 444 class xxxTool(xxxObject
): 
 445     allParams 
= ['bitmap', 'bitmap2', 'radio', 'toggle', 'tooltip', 'longhelp', 'label'] 
 446     required 
= ['bitmap'] 
 447     paramDict 
= {'bitmap2': ParamBitmap, 'radio': ParamBool, 'toggle': ParamBool}
 
 450 class xxxToolBar(xxxContainer
): 
 451     allParams 
= ['bitmapsize', 'margins', 'packing', 'separation', 'dontattachtoframe', 
 452                  'pos', 'size', 'style'] 
 454     paramDict 
= {'bitmapsize': ParamPosSize
, 'margins': ParamPosSize
, 
 455                  'packing': ParamUnit
, 'separation': ParamUnit
, 
 456                  'dontattachtoframe': ParamBool
, 'style': ParamNonGenericStyle
} 
 457     winStyles 
= ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL', 
 458                  'wxTB_3DBUTTONS','wxTB_TEXT', 'wxTB_NOICONS', 'wxTB_NODIVIDER', 
 459                  'wxTB_NOALIGN', 'wxTB_HORZ_LAYOUT', 'wxTB_HORZ_TEXT'] 
 461 class xxxWizard(xxxContainer
): 
 462     allParams 
= ['title', 'bitmap', 'pos'] 
 464     default 
= {'title': ''}
 
 466     exStyles 
= ['wxWIZARD_EX_HELPBUTTON'] 
 468 class xxxWizardPage(xxxContainer
): 
 469     allParams 
= ['bitmap'] 
 473 class xxxWizardPageSimple(xxxContainer
): 
 474     allParams 
= ['bitmap'] 
 478 ################################################################################ 
 481 class xxxBitmap(xxxObject
): 
 482     allParams 
= ['bitmap'] 
 483     required 
= ['bitmap'] 
 486 class xxxIcon(xxxObject
): 
 489 ################################################################################ 
 492 class xxxStaticText(xxxObject
): 
 493     allParams 
= ['label', 'pos', 'size', 'style'] 
 495     default 
= {'label': ''}
 
 496     winStyles 
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE'] 
 498 class xxxStaticLine(xxxObject
): 
 499     allParams 
= ['pos', 'size', 'style'] 
 500     winStyles 
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL'] 
 502 class xxxStaticBitmap(xxxObject
): 
 503     allParams 
= ['bitmap', 'pos', 'size', 'style'] 
 504     required 
= ['bitmap'] 
 506 class xxxTextCtrl(xxxObject
): 
 507     allParams 
= ['value', 'pos', 'size', 'style'] 
 508     winStyles 
= ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE', 
 509               'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL'] 
 510     paramDict 
= {'value': ParamMultilineText}
 
 512 class xxxChoice(xxxObject
): 
 513     allParams 
= ['content', 'selection', 'pos', 'size', 'style'] 
 514     required 
= ['content'] 
 515     default 
= {'content': '[]'}
 
 516     winStyles 
= ['wxCB_SORT'] 
 518 class xxxSlider(xxxObject
): 
 519     allParams 
= ['value', 'min', 'max', 'pos', 'size', 'style', 
 520                  'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick', 
 522     paramDict 
= {'value': ParamInt
, 'tickfreq': ParamIntNN
, 'pagesize': ParamIntNN
, 
 523                  'linesize': ParamIntNN
, 'thumb': ParamUnit
,  
 524                  'tick': ParamInt
, 'selmin': ParamInt
, 'selmax': ParamInt
} 
 525     required 
= ['value', 'min', 'max'] 
 526     winStyles 
= ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS', 
 527                  'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM', 
 528                  'wxSL_BOTH', 'wxSL_SELRANGE', 'wxSL_INVERSE'] 
 530 class xxxGauge(xxxObject
): 
 531     allParams 
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel'] 
 532     paramDict 
= {'range': ParamIntNN
, 'value': ParamIntNN
, 
 533                  'shadow': ParamIntNN
, 'bezel': ParamIntNN
} 
 534     winStyles 
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH'] 
 536 class xxxScrollBar(xxxObject
): 
 537     allParams 
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize'] 
 538     paramDict 
= {'value': ParamIntNN
, 'range': ParamIntNN
, 'thumbsize': ParamIntNN
, 
 539                  'pagesize': ParamIntNN
} 
 540     winStyles 
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL'] 
 542 class xxxListCtrl(xxxObject
): 
 543     allParams 
= ['pos', 'size', 'style'] 
 544     winStyles 
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON', 
 545               'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE', 
 546               'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER', 
 547               'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING'] 
 549 class xxxTreeCtrl(xxxObject
): 
 550     allParams 
= ['pos', 'size', 'style'] 
 551     winStyles 
= ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT', 
 552               'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE'] 
 554 class xxxHtmlWindow(xxxObject
): 
 555     allParams 
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode'] 
 556     paramDict 
= {'borders': ParamUnit, 'htmlcode':ParamMultilineText}
 
 557     winStyles 
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO'] 
 559 class xxxCalendarCtrl(xxxObject
): 
 560     allParams 
= ['pos', 'size', 'style'] 
 562 class xxxNotebook(xxxContainer
): 
 563     allParams 
= ['usenotebooksizer', 'pos', 'size', 'style'] 
 564     paramDict 
= {'usenotebooksizer': ParamBool}
 
 565     winStyles 
= ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM'] 
 567 class xxxSplitterWindow(xxxContainer
): 
 568     allParams 
= ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style'] 
 569     paramDict 
= {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit }
 
 570     winStyles 
= ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER', 'wxSP_BORDER', 
 571                          'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE', 
 574 class xxxGenericDirCtrl(xxxObject
): 
 575     allParams 
= ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style'] 
 576     paramDict 
= {'defaultfilter': ParamIntNN}
 
 577     winStyles 
= ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST', 
 578                  'wxDIRCTRL_SHOW_FILTERS', 'wxDIRCTRL_EDIT_LABELS'] 
 580 class xxxScrolledWindow(xxxContainer
): 
 581     allParams 
= ['pos', 'size', 'style'] 
 582     winStyles 
= ['wxHSCROLL', 'wxVSCROLL'] 
 584 ################################################################################ 
 587 class xxxButton(xxxObject
): 
 588     allParams 
= ['label', 'default', 'pos', 'size', 'style'] 
 589     paramDict 
= {'default': ParamBool}
 
 591     winStyles 
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM'] 
 593 class xxxBitmapButton(xxxObject
): 
 594     allParams 
= ['bitmap', 'selected', 'focus', 'disabled', 'default', 
 595                  'pos', 'size', 'style'] 
 596     required 
= ['bitmap'] 
 597     winStyles 
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP', 
 598                  'wxBU_RIGHT', 'wxBU_BOTTOM'] 
 600 class xxxRadioButton(xxxObject
): 
 601     allParams 
= ['label', 'value', 'pos', 'size', 'style'] 
 602     paramDict 
= {'value': ParamBool}
 
 604     winStyles 
= ['wxRB_GROUP'] 
 606 class xxxSpinButton(xxxObject
): 
 607     allParams 
= ['value', 'min', 'max', 'pos', 'size', 'style'] 
 608     paramDict 
= {'value': ParamInt}
 
 609     winStyles 
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP'] 
 611 class xxxSpinCtrl(xxxObject
): 
 612     allParams 
= ['value', 'min', 'max', 'pos', 'size', 'style'] 
 613     paramDict 
= {'value': ParamInt}
 
 614     winStyles 
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP'] 
 616 class xxxToggleButton(xxxObject
): 
 617     allParams 
= ['label', 'checked', 'pos', 'size', 'style'] 
 618     paramDict 
= {'checked': ParamBool}
 
 621 ################################################################################ 
 624 class xxxStaticBox(xxxObject
): 
 625     allParams 
= ['label', 'pos', 'size', 'style'] 
 628 class xxxRadioBox(xxxObject
): 
 629     allParams 
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style'] 
 630     paramDict 
= {'dimension': ParamIntNN}
 
 631     required 
= ['label', 'content'] 
 632     default 
= {'content': '[]'}
 
 633     winStyles 
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS'] 
 635 class xxxCheckBox(xxxObject
): 
 636     allParams 
= ['label', 'checked', 'pos', 'size', 'style'] 
 637     paramDict 
= {'checked': ParamBool}
 
 638     winStyles 
= ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER', 
 642 class xxxComboBox(xxxObject
): 
 643     allParams 
= ['content', 'selection', 'value', 'pos', 'size', 'style'] 
 644     required 
= ['content'] 
 645     default 
= {'content': '[]'}
 
 646     winStyles 
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN'] 
 648 class xxxListBox(xxxObject
): 
 649     allParams 
= ['content', 'selection', 'pos', 'size', 'style'] 
 650     required 
= ['content'] 
 651     default 
= {'content': '[]'}
 
 652     winStyles 
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL', 
 653               'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT'] 
 655 class xxxCheckList(xxxObject
): 
 656     allParams 
= ['content', 'pos', 'size', 'style'] 
 657     required 
= ['content'] 
 658     default 
= {'content': '[]'}
 
 659     winStyles 
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON', 
 660               'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE', 
 661               'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER', 
 662               'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING'] 
 663     paramDict 
= {'content': ParamContentCheckList}
 
 665 ################################################################################ 
 668 class xxxSizer(xxxContainer
): 
 669     hasName 
= hasStyle 
= False 
 670     paramDict 
= {'orient': ParamOrient}
 
 672     itemTag 
= 'sizeritem'               # different for some sizers 
 674 class xxxBoxSizer(xxxSizer
): 
 675     allParams 
= ['orient'] 
 676     required 
= ['orient'] 
 677     default 
= {'orient': 'wxVERTICAL'}
 
 678     # Tree icon depends on orientation 
 680         if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
 
 681         else: return self
.imageV
 
 683 class xxxStaticBoxSizer(xxxBoxSizer
): 
 684     allParams 
= ['label', 'orient'] 
 685     required 
= ['label', 'orient'] 
 687 class xxxGridSizer(xxxSizer
): 
 688     allParams 
= ['cols', 'rows', 'vgap', 'hgap'] 
 690     default 
= {'cols': '2', 'rows': '2'}
 
 692 class xxxStdDialogButtonSizer(xxxSizer
): 
 696 # For repeated parameters 
 698     def __init__(self
, node
): 
 700         self
.l
, self
.data 
= [], [] 
 701     def append(self
, param
): 
 703         self
.data
.append(param
.value()) 
 709         self
.l
, self
.data 
= [], [] 
 711 class xxxFlexGridSizer(xxxGridSizer
): 
 712     specials 
= ['growablecols', 'growablerows'] 
 713     allParams 
= ['cols', 'rows', 'vgap', 'hgap'] + specials
 
 714     paramDict 
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
 
 715     # Special processing for growable* parameters 
 716     # (they are represented by several nodes) 
 717     def special(self
, tag
, node
): 
 718         if not self
.params
.has_key(tag
): 
 719             # Create new multi-group 
 720             self
.params
[tag
] = xxxParamMulti(node
) 
 721         self
.params
[tag
].append(xxxParamInt(node
)) 
 722     def setSpecial(self
, param
, value
): 
 723         # Straightforward implementation: remove, add again 
 724         self
.params
[param
].remove() 
 725         del self
.params
[param
] 
 727             node 
= g
.tree
.dom
.createElement(param
) 
 728             text 
= g
.tree
.dom
.createTextNode(str(i
)) 
 729             node
.appendChild(text
) 
 730             self
.element
.appendChild(node
) 
 731             self
.special(param
, node
) 
 733 class xxxGridBagSizer(xxxSizer
): 
 734     specials 
= ['growablecols', 'growablerows'] 
 735     allParams 
= ['vgap', 'hgap'] + specials
 
 736     paramDict 
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
 
 737     # Special processing for growable* parameters 
 738     # (they are represented by several nodes) 
 739     def special(self
, tag
, node
): 
 740         if not self
.params
.has_key(tag
): 
 741             # Create new multi-group 
 742             self
.params
[tag
] = xxxParamMulti(node
) 
 743         self
.params
[tag
].append(xxxParamInt(node
)) 
 744     def setSpecial(self
, param
, value
): 
 745         # Straightforward implementation: remove, add again 
 746         self
.params
[param
].remove() 
 747         del self
.params
[param
] 
 749             node 
= g
.tree
.dom
.createElement(param
) 
 750             text 
= g
.tree
.dom
.createTextNode(str(i
)) 
 751             node
.appendChild(text
) 
 752             self
.element
.appendChild(node
) 
 753             self
.special(param
, node
) 
 755 # Container with only one child. 
 757 class xxxChildContainer(xxxObject
): 
 758     hasName 
= hasStyle 
= False 
 760     def __init__(self
, parent
, element
, refElem
=None): 
 761         xxxObject
.__init
__(self
, parent
, element
, refElem
) 
 762         # Must have one child with 'object' tag, but we don't check it 
 763         nodes 
= element
.childNodes
[:]   # create copy 
 765             if node
.nodeType 
== minidom
.Node
.ELEMENT_NODE
: 
 766                 if node
.tagName 
in ['object', 'object_ref']: 
 767                     # Create new xxx object for child node 
 768                     self
.child 
= MakeXXXFromDOM(self
, node
) 
 769                     self
.child
.parent 
= parent
 
 770                     # Copy hasChildren and isSizer attributes 
 771                     self
.hasChildren 
= self
.child
.hasChildren
 
 772                     self
.isSizer 
= self
.child
.isSizer
 
 775                 element
.removeChild(node
) 
 777         assert 0, 'no child found' 
 779 class xxxSizerItem(xxxChildContainer
): 
 780     allParams 
= ['option', 'flag', 'border', 'minsize', 'ratio'] 
 781     paramDict 
= {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
 
 782     #default = {'cellspan': '1,1'} 
 783     def __init__(self
, parent
, element
, refElem
=None): 
 784         # For GridBag sizer items, extra parameters added 
 785         if isinstance(parent
, xxxGridBagSizer
): 
 786             self
.allParams 
= self
.allParams 
+ ['cellpos', 'cellspan'] 
 787         xxxChildContainer
.__init
__(self
, parent
, element
, refElem
) 
 788         # Remove pos parameter - not needed for sizeritems 
 789         if 'pos' in self
.child
.allParams
: 
 790             self
.child
.allParams 
= self
.child
.allParams
[:] 
 791             self
.child
.allParams
.remove('pos') 
 793 class xxxSizerItemButton(xxxSizerItem
): 
 796     def __init__(self
, parent
, element
, refElem
=None): 
 797         xxxChildContainer
.__init
__(self
, parent
, element
, refElem
=None) 
 798         # Remove pos parameter - not needed for sizeritems 
 799         if 'pos' in self
.child
.allParams
: 
 800             self
.child
.allParams 
= self
.child
.allParams
[:] 
 801             self
.child
.allParams
.remove('pos') 
 803 class xxxNotebookPage(xxxChildContainer
): 
 804     allParams 
= ['label', 'selected'] 
 805     paramDict 
= {'selected': ParamBool}
 
 807     def __init__(self
, parent
, element
, refElem
=None): 
 808         xxxChildContainer
.__init
__(self
, parent
, element
, refElem
) 
 809         # pos and size dont matter for notebookpages 
 810         if 'pos' in self
.child
.allParams
: 
 811             self
.child
.allParams 
= self
.child
.allParams
[:] 
 812             self
.child
.allParams
.remove('pos') 
 813         if 'size' in self
.child
.allParams
: 
 814             self
.child
.allParams 
= self
.child
.allParams
[:] 
 815             self
.child
.allParams
.remove('size') 
 817 class xxxSpacer(xxxObject
): 
 818     hasName 
= hasStyle 
= False 
 819     allParams 
= ['size', 'option', 'flag', 'border'] 
 820     paramDict 
= {'option': ParamInt}
 
 821     default 
= {'size': '0,0'}
 
 823 class xxxMenuBar(xxxContainer
): 
 824     allParams 
= ['style'] 
 825     paramDict 
= {'style': ParamNonGenericStyle}    
# no generic styles 
 826     winStyles 
= ['wxMB_DOCKABLE'] 
 828 class xxxMenu(xxxContainer
): 
 829     allParams 
= ['label', 'help', 'style'] 
 830     default 
= {'label': ''}
 
 831     paramDict 
= {'style': ParamNonGenericStyle}    
# no generic styles 
 832     winStyles 
= ['wxMENU_TEAROFF'] 
 834 class xxxMenuItem(xxxObject
): 
 835     allParams 
= ['label', 'bitmap', 'accel', 'help', 
 836                  'checkable', 'radio', 'enabled', 'checked'] 
 837     default 
= {'label': ''}
 
 840 class xxxSeparator(xxxObject
): 
 841     hasName 
= hasStyle 
= False 
 843 ################################################################################ 
 846 class xxxUnknown(xxxObject
): 
 847     allParams 
= ['pos', 'size', 'style'] 
 849 ################################################################################ 
 853     'wxDialog': xxxDialog
, 
 856     'wxToolBar': xxxToolBar
, 
 857     'wxWizard': xxxWizard
, 
 858     'wxWizardPage': xxxWizardPage
, 
 859     'wxWizardPageSimple': xxxWizardPageSimple
, 
 861     'wxBitmap': xxxBitmap
, 
 864     'wxButton': xxxButton
, 
 865     'wxBitmapButton': xxxBitmapButton
, 
 866     'wxRadioButton': xxxRadioButton
, 
 867     'wxSpinButton': xxxSpinButton
, 
 868     'wxToggleButton' : xxxToggleButton
, 
 870     'wxStaticBox': xxxStaticBox
, 
 871     'wxStaticBitmap': xxxStaticBitmap
, 
 872     'wxRadioBox': xxxRadioBox
, 
 873     'wxComboBox': xxxComboBox
, 
 874     'wxCheckBox': xxxCheckBox
, 
 875     'wxListBox': xxxListBox
, 
 877     'wxStaticText': xxxStaticText
, 
 878     'wxStaticLine': xxxStaticLine
, 
 879     'wxTextCtrl': xxxTextCtrl
, 
 880     'wxChoice': xxxChoice
, 
 881     'wxSlider': xxxSlider
, 
 883     'wxScrollBar': xxxScrollBar
, 
 884     'wxTreeCtrl': xxxTreeCtrl
, 
 885     'wxListCtrl': xxxListCtrl
, 
 886     'wxCheckListBox': xxxCheckList
, 
 887     'wxNotebook': xxxNotebook
, 
 888     'wxSplitterWindow': xxxSplitterWindow
, 
 889     'notebookpage': xxxNotebookPage
, 
 890     'wxHtmlWindow': xxxHtmlWindow
, 
 891     'wxCalendarCtrl': xxxCalendarCtrl
, 
 892     'wxGenericDirCtrl': xxxGenericDirCtrl
, 
 893     'wxSpinCtrl': xxxSpinCtrl
, 
 894     'wxScrolledWindow': xxxScrolledWindow
, 
 896     'wxBoxSizer': xxxBoxSizer
, 
 897     'wxStaticBoxSizer': xxxStaticBoxSizer
, 
 898     'wxGridSizer': xxxGridSizer
, 
 899     'wxFlexGridSizer': xxxFlexGridSizer
, 
 900     'wxGridBagSizer': xxxGridBagSizer
, 
 901     'wxStdDialogButtonSizer': xxxStdDialogButtonSizer
, 
 902     'sizeritem': xxxSizerItem
, 'button': xxxSizerItemButton
, 
 905     'wxMenuBar': xxxMenuBar
, 
 907     'wxMenuItem': xxxMenuItem
, 
 908     'separator': xxxSeparator
, 
 910     'unknown': xxxUnknown
, 
 913 # Create IDs for all parameters of all classes 
 914 paramIDs 
= {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(), 
 915             'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(), 
 916             'tooltip': wxNewId(), 'encoding': wxNewId(), 
 917             'cellpos': wxNewId(), 'cellspan': wxNewId() 
 919 for cl 
in xxxDict
.values(): 
 921         for param 
in cl
.allParams 
+ cl
.paramDict
.keys(): 
 922             if not paramIDs
.has_key(param
): 
 923                 paramIDs
[param
] = wxNewId() 
 925 ################################################################################ 
 928 # Test for object elements 
 930     return node
.nodeType 
== minidom
.Node
.ELEMENT_NODE 
and node
.tagName 
in ['object', 'object_ref'] 
 932 # Make XXX object from some DOM object, selecting correct class 
 933 def MakeXXXFromDOM(parent
, element
): 
 934     if element
.tagName 
== 'object_ref': 
 935         ref 
= element
.getAttribute('ref') 
 936         refElem 
= FindResource(ref
) 
 937         if refElem
: cls 
= refElem
.getAttribute('class') 
 938         else: return xxxUnknown(parent
, element
) 
 941         cls 
= element
.getAttribute('class') 
 945         # If we encounter a weird class, use unknown template 
 946         print 'WARNING: unsupported class:', element
.getAttribute('class') 
 948     return klass(parent
, element
, refElem
) 
 950 # Make empty DOM element 
 951 def MakeEmptyDOM(className
): 
 952     elem 
= g
.tree
.dom
.createElement('object') 
 953     elem
.setAttribute('class', className
) 
 954     # Set required and default parameters 
 955     xxxClass 
= xxxDict
[className
] 
 956     defaultNotRequired 
= filter(lambda x
, l
=xxxClass
.required
: x 
not in l
, 
 957                                 xxxClass
.default
.keys()) 
 958     for param 
in xxxClass
.required 
+ defaultNotRequired
: 
 959         textElem 
= g
.tree
.dom
.createElement(param
) 
 961             textNode 
= g
.tree
.dom
.createTextNode(xxxClass
.default
[param
]) 
 963             textNode 
= g
.tree
.dom
.createTextNode('') 
 964         textElem
.appendChild(textNode
) 
 965         elem
.appendChild(textElem
) 
 968 # Make empty XXX object 
 969 def MakeEmptyXXX(parent
, className
): 
 970     # Make corresponding DOM object first 
 971     elem 
= MakeEmptyDOM(className
) 
 972     # If parent is a sizer, we should create sizeritem object, except for spacers 
 974         if parent
.isSizer 
and className 
!= 'spacer': 
 975             sizerItemElem 
= MakeEmptyDOM(parent
.itemTag
) 
 976             sizerItemElem
.appendChild(elem
) 
 978         elif isinstance(parent
, xxxNotebook
): 
 979             pageElem 
= MakeEmptyDOM('notebookpage') 
 980             pageElem
.appendChild(elem
) 
 982     # Now just make object 
 983     return MakeXXXFromDOM(parent
, elem
) 
 985 # Make empty DOM element for reference 
 986 def MakeEmptyRefDOM(ref
): 
 987     elem 
= g
.tree
.dom
.createElement('object_ref') 
 988     elem
.setAttribute('ref', ref
) 
 991 # Make empty XXX object 
 992 def MakeEmptyRefXXX(parent
, ref
): 
 993     # Make corresponding DOM object first 
 994     elem 
= MakeEmptyRefDOM(ref
) 
 995     # If parent is a sizer, we should create sizeritem object, except for spacers 
 998             sizerItemElem 
= MakeEmptyDOM(parent
.itemTag
) 
 999             sizerItemElem
.appendChild(elem
) 
1000             elem 
= sizerItemElem
 
1001         elif isinstance(parent
, xxxNotebook
): 
1002             pageElem 
= MakeEmptyDOM('notebookpage') 
1003             pageElem
.appendChild(elem
) 
1005     # Now just make object 
1006     return MakeXXXFromDOM(parent
, elem
)