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 wxPython
.wx
import *
8 from wxPython
.xrc
import *
9 from xml
.dom
import minidom
10 import wxPython
.lib
.wxpTag
14 # Parameter value class
16 # Standard use: for text nodes
17 def __init__(self
, node
):
19 if not node
.hasChildNodes():
20 # If does not have child nodes, create empty text node
21 text
= tree
.dom
.createTextNode('')
22 node
.appendChild(text
)
24 text
= node
.childNodes
[0] # first child must be text node
25 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
27 # Value returns string
29 return self
.textNode
.data
30 def update(self
, value
):
31 self
.textNode
.data
= value
33 self
.node
.parentNode
.removeChild(self
.node
)
37 class xxxParamInt(xxxParam
):
38 # Standard use: for text nodes
39 def __init__(self
, node
):
40 xxxParam
.__init
__(self
, node
)
41 # Value returns string
44 return int(self
.textNode
.data
)
46 return -1 # invalid value
47 def update(self
, value
):
48 self
.textNode
.data
= str(value
)
51 class xxxParamContent
:
52 def __init__(self
, node
):
54 data
, l
= [], [] # data is needed to quicker value retrieval
55 nodes
= node
.childNodes
[:] # make a copy of the child list
57 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
58 assert n
.tagName
== 'item', 'bad content content'
59 if not n
.hasChildNodes():
60 # If does not have child nodes, create empty text node
61 text
= tree
.dom
.createTextNode('')
62 node
.appendChild(text
)
65 text
= n
.childNodes
[0] # first child must be text node
66 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
68 data
.append(str(text
.data
))
72 self
.l
, self
.data
= l
, data
75 def update(self
, value
):
76 # If number if items is not the same, recreate children
77 if len(value
) != len(self
.l
): # remove first if number of items has changed
78 childNodes
= self
.node
.childNodes
[:]
80 self
.node
.removeChild(n
)
83 itemElem
= tree
.dom
.createElement('item')
84 itemText
= tree
.dom
.createTextNode(str)
85 itemElem
.appendChild(itemText
)
86 self
.node
.appendChild(itemElem
)
90 for i
in range(len(value
)):
91 self
.l
[i
].data
= value
[i
]
94 # Content parameter for checklist
95 class xxxParamContentCheckList
:
96 def __init__(self
, node
):
98 data
, l
= [], [] # data is needed to quicker value retrieval
99 nodes
= node
.childNodes
[:] # make a copy of the child list
101 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
102 assert n
.tagName
== 'item', 'bad content content'
103 checked
= n
.getAttribute('checked')
104 if not n
.hasChildNodes():
105 # If does not have child nodes, create empty text node
106 text
= tree
.dom
.createTextNode('')
107 node
.appendChild(text
)
110 text
= n
.childNodes
[0] # first child must be text node
111 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
113 data
.append((str(text
.data
), int(checked
)))
117 self
.l
, self
.data
= l
, data
120 def update(self
, value
):
121 # If number if items is not the same, recreate children
122 if len(value
) != len(self
.l
): # remove first if number of items has changed
123 childNodes
= self
.node
.childNodes
[:]
125 self
.node
.removeChild(n
)
128 itemElem
= tree
.dom
.createElement('item')
129 itemElem
.setAttribute('checked', str(ch
))
130 itemText
= tree
.dom
.createTextNode(s
)
131 itemElem
.appendChild(itemText
)
132 self
.node
.appendChild(itemElem
)
133 l
.append((itemText
, itemElem
))
136 for i
in range(len(value
)):
137 self
.l
[i
][0].data
= value
[i
][0]
138 self
.l
[i
][1].setAttribute('checked', str(value
[i
][1]))
141 ################################################################################
143 # Classes to interface DOM objects
146 hasChildren
= false
# has children elements?
147 hasStyle
= true
# almost everyone
148 hasName
= true
# has name attribute?
149 isSizer
= hasChild
= false
150 allParams
= None # Some nodes have no parameters
151 # Style parameters (all optional)
152 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip']
155 # Required paremeters: none by default
157 # Default parameters with default values
161 # Window styles and extended styles
165 # Construct a new xxx object from DOM element
166 # parent is parent xxx object (or None if none), element is DOM element object
167 def __init__(self
, parent
, element
):
169 self
.element
= element
172 self
.className
= element
.getAttribute('class')
173 if self
.hasName
: self
.name
= element
.getAttribute('name')
174 # Set parameters (text element children)
176 nodes
= element
.childNodes
[:]
178 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
181 continue # do nothing for object children here
182 if not tag
in self
.allParams
and not tag
in self
.styles
:
183 print 'WARNING: unknown parameter for %s: %s' % \
184 (self
.className
, tag
)
185 elif tag
in self
.specials
:
186 self
.special(tag
, node
)
187 elif tag
== 'content':
188 if self
.className
== 'wxCheckList':
189 self
.params
[tag
] = xxxParamContentCheckList(node
)
191 self
.params
[tag
] = xxxParamContent(node
)
192 elif tag
== 'font': # has children
193 self
.params
[tag
] = xxxParamFont(element
, node
)
194 else: # simple parameter
195 self
.params
[tag
] = xxxParam(node
)
197 # Remove all other nodes
198 element
.removeChild(node
)
200 # Returns real tree object
201 def treeObject(self
):
202 if self
.hasChild
: return self
.child
204 # Returns tree image index
206 if self
.hasChild
: return self
.child
.treeImage()
208 # Class name plus wx name
210 if self
.hasChild
: return self
.child
.treeName()
211 if self
.hasName
and self
.name
: return self
.className
+ ' "' + self
.name
+ '"'
212 return self
.className
214 ################################################################################
216 # This is a little special
217 class xxxParamFont(xxxObject
):
218 allParams
= ['size', 'style', 'weight', 'family', 'underlined',
220 def __init__(self
, parent
, element
):
221 xxxObject
.__init
__(self
, parent
, element
)
222 self
.parentNode
= parent
# required to behave similar to DOM node
224 for p
in self
.allParams
:
226 v
.append(str(self
.params
[p
].value()))
230 def update(self
, value
):
231 # `value' is a list of strings corresponding to all parameters
233 # Remove old elements first
234 childNodes
= elem
.childNodes
[:]
235 for node
in childNodes
: elem
.removeChild(node
)
239 for param
in self
.allParams
:
241 fontElem
= tree
.dom
.createElement(param
)
242 textNode
= tree
.dom
.createTextNode(value
[i
])
243 self
.params
[param
] = textNode
244 fontElem
.appendChild(textNode
)
245 elem
.appendChild(fontElem
)
252 self
.parentNode
.removeChild(self
.element
)
253 self
.element
.unlink()
255 ################################################################################
257 class xxxContainer(xxxObject
):
260 # Special class for root node
261 class xxxMainNode(xxxContainer
):
262 hasStyle
= hasName
= false
264 ################################################################################
267 class xxxPanel(xxxContainer
):
268 allParams
= ['pos', 'size', 'style']
269 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
271 winStyles
= ['wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
272 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
274 class xxxDialog(xxxContainer
):
275 allParams
= ['title', 'pos', 'size', 'style']
277 winStyles
= ['wxDEFAULT_DIALOG_STYLE', 'wxSTAY_ON_TOP',
278 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS',
279 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 'wxRESIZE_BOX',
281 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
282 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
284 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
286 class xxxFrame(xxxContainer
):
287 allParams
= ['title', 'centered', 'pos', 'size', 'style']
288 paramDict
= {'centered': ParamBool}
290 winStyles
= ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE',
292 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
293 'wxRESIZE_BOX', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX',
294 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_TOOL_WINDOW',
295 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
296 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
298 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
300 class xxxTool(xxxObject
):
301 allParams
= ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp']
302 paramDict
= {'bitmap2': ParamFile}
305 class xxxToolBar(xxxContainer
):
306 allParams
= ['bitmapsize', 'margins', 'packing', 'separation',
307 'pos', 'size', 'style']
309 paramDict
= {'bitmapsize': ParamPosSize
, 'margins': ParamPosSize
,
310 'packing': ParamInt
, 'separation': ParamInt
,
311 'style': ParamNonGenericStyle
}
312 winStyles
= ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL']
314 ################################################################################
317 class xxxBitmap(xxxObject
):
318 allParams
= ['bitmap']
319 required
= ['bitmap']
321 class xxxIcon(xxxObject
):
325 ################################################################################
328 class xxxStaticText(xxxObject
):
329 allParams
= ['label', 'pos', 'size', 'style']
331 winStyles
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
333 class xxxStaticLine(xxxObject
):
334 allParams
= ['pos', 'size', 'style']
335 winStyles
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
337 class xxxStaticBitmap(xxxObject
):
338 allParams
= ['bitmap', 'pos', 'size', 'style']
339 required
= ['bitmap']
341 class xxxTextCtrl(xxxObject
):
342 allParams
= ['value', 'pos', 'size', 'style']
343 winStyles
= ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
344 'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
346 class xxxChoice(xxxObject
):
347 allParams
= ['content', 'selection', 'pos', 'size', 'style']
348 required
= ['content']
349 winStyles
= ['wxCB_SORT']
351 class xxxSlider(xxxObject
):
352 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style',
353 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
355 paramDict
= {'value': ParamInt
, 'tickfreq': ParamInt
, 'pagesize': ParamInt
,
356 'linesize': ParamInt
, 'thumb': ParamInt
, 'thumb': ParamInt
,
357 'tick': ParamInt
, 'selmin': ParamInt
, 'selmax': ParamInt
}
358 required
= ['value', 'min', 'max']
359 winStyles
= ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
360 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
361 'wxSL_BOTH', 'wxSL_SELRANGE']
363 class xxxGauge(xxxObject
):
364 allParams
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
365 paramDict
= {'range': ParamInt
, 'value': ParamInt
,
366 'shadow': ParamInt
, 'bezel': ParamInt
}
367 winStyles
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
369 class xxxScrollBar(xxxObject
):
370 allParams
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
371 paramDict
= {'value': ParamInt
, 'range': ParamInt
, 'thumbsize': ParamInt
,
372 'pagesize': ParamInt
}
373 winStyles
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
375 class xxxListCtrl(xxxObject
):
376 allParams
= ['pos', 'size', 'style']
377 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
378 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
379 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
380 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
382 class xxxTreeCtrl(xxxObject
):
383 allParams
= ['pos', 'size', 'style']
384 winStyles
= ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT',
385 'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE']
387 class xxxHtmlWindow(xxxObject
):
388 allParams
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
389 paramDict
= {'borders': ParamInt}
390 winStyles
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
392 class xxxCalendar(xxxObject
):
393 allParams
= ['pos', 'size', 'style']
395 class xxxNotebook(xxxContainer
):
396 allParams
= ['usenotebooksizer', 'pos', 'size', 'style']
397 paramDict
= {'usenotebooksizer': ParamBool}
398 winStyles
= ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM']
400 ################################################################################
403 class xxxButton(xxxObject
):
404 allParams
= ['label', 'default', 'pos', 'size', 'style']
405 paramDict
= {'default': ParamBool}
407 winStyles
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
409 class xxxBitmapButton(xxxObject
):
410 allParams
= ['bitmap', 'selected', 'focus', 'disabled', 'default',
411 'pos', 'size', 'style']
412 required
= ['bitmap']
413 winStyles
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP',
414 'wxBU_RIGHT', 'wxBU_BOTTOM']
416 class xxxRadioButton(xxxObject
):
417 allParams
= ['label', 'value', 'pos', 'size', 'style']
418 paramDict
= {'value': ParamBool}
420 winStyles
= ['wxRB_GROUP']
422 class xxxSpinButton(xxxObject
):
423 allParams
= ['pos', 'size', 'style']
424 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
426 ################################################################################
429 class xxxStaticBox(xxxObject
):
430 allParams
= ['label', 'pos', 'size', 'style']
433 class xxxRadioBox(xxxObject
):
434 allParams
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
435 paramDict
= {'dimension': ParamInt}
436 required
= ['label', 'content']
437 winStyles
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS']
439 class xxxCheckBox(xxxObject
):
440 allParams
= ['label', 'pos', 'size', 'style']
443 class xxxComboBox(xxxObject
):
444 allParams
= ['content', 'selection', 'value', 'pos', 'size', 'style']
445 required
= ['content']
446 winStyles
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
448 class xxxListBox(xxxObject
):
449 allParams
= ['content', 'selection', 'pos', 'size', 'style']
450 required
= ['content']
451 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
452 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
454 class xxxCheckList(xxxObject
):
455 allParams
= ['content', 'pos', 'size', 'style']
456 required
= ['content']
457 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
458 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
459 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
460 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
461 paramDict
= {'content': ParamContentCheckList}
463 ################################################################################
466 class xxxSizer(xxxContainer
):
467 hasName
= hasStyle
= false
468 paramDict
= {'orient': ParamOrient}
471 class xxxBoxSizer(xxxSizer
):
472 allParams
= ['orient']
473 required
= ['orient']
474 default
= {'orient': 'wxVERTICAL'}
475 # Tree icon depends on orientation
477 if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
478 else: return self
.imageV
480 class xxxStaticBoxSizer(xxxBoxSizer
):
481 allParams
= ['label', 'orient']
482 required
= ['label', 'orient']
483 default
= {'orient': 'wxVERTICAL'}
485 class xxxGridSizer(xxxSizer
):
486 allParams
= ['cols', 'rows', 'vgap', 'hgap']
488 default
= {'cols': '2', 'rows': '2'}
490 # For repeated parameters
493 self
.l
, self
.data
= [], []
494 def append(self
, param
):
496 self
.data
.append(param
.value())
502 self
.l
, self
.data
= [], []
504 class xxxFlexGridSizer(xxxGridSizer
):
505 specials
= ['growablecols', 'growablerows']
506 allParams
= ['cols', 'rows', 'vgap', 'hgap'] + specials
507 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
508 # Special processing for growable* parameters
509 # (they are represented by several nodes)
510 def special(self
, tag
, node
):
511 if tag
not in self
.params
:
512 self
.params
[tag
] = xxxParamMulti()
513 self
.params
[tag
].append(xxxParamInt(node
))
514 def setSpecial(self
, param
, value
):
515 # Straightforward implementation: remove, add again
516 self
.params
[param
].remove()
517 del self
.params
[param
]
519 node
= tree
.dom
.createElement(param
)
520 text
= tree
.dom
.createTextNode(str(i
))
521 node
.appendChild(text
)
522 self
.element
.appendChild(node
)
523 self
.special(param
, node
)
525 # Container with only one child.
527 class xxxChildContainer(xxxObject
):
528 hasName
= hasStyle
= false
530 def __init__(self
, parent
, element
):
531 xxxObject
.__init
__(self
, parent
, element
)
532 # Must have one child with 'object' tag, but we don't check it
533 nodes
= element
.childNodes
[:] # create copy
535 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
536 if node
.tagName
== 'object':
537 # Create new xxx object for child node
538 self
.child
= MakeXXXFromDOM(self
, node
)
539 self
.child
.parent
= parent
540 # Copy hasChildren and isSizer attributes
541 self
.hasChildren
= self
.child
.hasChildren
542 self
.isSizer
= self
.child
.isSizer
545 element
.removeChild(node
)
547 assert 0, 'no child found'
549 class xxxSizerItem(xxxChildContainer
):
550 allParams
= ['option', 'flag', 'border']
551 paramDict
= {'option': ParamInt}
552 def __init__(self
, parent
, element
):
553 xxxChildContainer
.__init
__(self
, parent
, element
)
554 # Remove pos parameter - not needed for sizeritems
555 if 'pos' in self
.child
.allParams
:
556 self
.child
.allParams
= self
.child
.allParams
[:]
557 self
.child
.allParams
.remove('pos')
559 class xxxNotebookPage(xxxChildContainer
):
560 allParams
= ['label', 'selected']
561 paramDict
= {'selected': ParamBool}
563 def __init__(self
, parent
, element
):
564 xxxChildContainer
.__init
__(self
, parent
, element
)
565 # pos and size dont matter for notebookpages
566 if 'pos' in self
.child
.allParams
:
567 self
.child
.allParams
= self
.child
.allParams
[:]
568 self
.child
.allParams
.remove('pos')
569 if 'size' in self
.child
.allParams
:
570 self
.child
.allParams
= self
.child
.allParams
[:]
571 self
.child
.allParams
.remove('size')
573 class xxxSpacer(xxxObject
):
574 hasName
= hasStyle
= false
575 allParams
= ['size', 'option', 'flag', 'border']
576 paramDict
= {'option': ParamInt}
577 default
= {'size': '0,0'}
579 class xxxMenuBar(xxxContainer
):
582 class xxxMenu(xxxContainer
):
583 allParams
= ['label']
584 default
= {'label': ''}
585 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
586 winStyles
= ['wxMENU_TEAROFF']
588 class xxxMenuItem(xxxObject
):
589 allParams
= ['checkable', 'label', 'accel', 'help']
590 default
= {'label': ''}
592 class xxxSeparator(xxxObject
):
593 hasName
= hasStyle
= false
595 ################################################################################
599 'wxDialog': xxxDialog
,
602 'wxToolBar': xxxToolBar
,
604 'wxBitmap': xxxBitmap
,
607 'wxButton': xxxButton
,
608 'wxBitmapButton': xxxBitmapButton
,
609 'wxRadioButton': xxxRadioButton
,
610 'wxSpinButton': xxxSpinButton
,
612 'wxStaticBox': xxxStaticBox
,
613 'wxStaticBitmap': xxxStaticBitmap
,
614 'wxRadioBox': xxxRadioBox
,
615 'wxComboBox': xxxComboBox
,
616 'wxCheckBox': xxxCheckBox
,
617 'wxListBox': xxxListBox
,
619 'wxStaticText': xxxStaticText
,
620 'wxStaticLine': xxxStaticLine
,
621 'wxTextCtrl': xxxTextCtrl
,
622 'wxChoice': xxxChoice
,
623 'wxSlider': xxxSlider
,
625 'wxScrollBar': xxxScrollBar
,
626 'wxTreeCtrl': xxxTreeCtrl
,
627 'wxListCtrl': xxxListCtrl
,
628 'wxCheckList': xxxCheckList
,
629 'wxNotebook': xxxNotebook
,
630 'notebookpage': xxxNotebookPage
,
631 'wxHtmlWindow': xxxHtmlWindow
,
632 'wxCalendar': xxxCalendar
,
634 'wxBoxSizer': xxxBoxSizer
,
635 'wxStaticBoxSizer': xxxStaticBoxSizer
,
636 'wxGridSizer': xxxGridSizer
,
637 'wxFlexGridSizer': xxxFlexGridSizer
,
638 'sizeritem': xxxSizerItem
,
641 'wxMenuBar': xxxMenuBar
,
643 'wxMenuItem': xxxMenuItem
,
644 'separator': xxxSeparator
,
647 # Create IDs for all parameters of all classes
648 paramIDs
= {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(),
649 'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(),
652 for cl
in xxxDict
.values():
654 for param
in cl
.allParams
+ cl
.paramDict
.keys():
655 if not paramIDs
.has_key(param
):
656 paramIDs
[param
] = wxNewId()
658 ################################################################################
661 # Test for object elements
663 return node
.nodeType
== minidom
.Node
.ELEMENT_NODE
and node
.tagName
== 'object'
665 # Make XXX object from some DOM object, selecting correct class
666 def MakeXXXFromDOM(parent
, element
):
668 return xxxDict
[element
.getAttribute('class')](parent
, element
)
670 # Verify that it's not recursive exception
671 if element
.getAttribute('class') not in xxxDict
:
672 print 'ERROR: unknown class:', element
.getAttribute('class')
675 # Make empty DOM element
676 def MakeEmptyDOM(className
):
677 elem
= tree
.dom
.createElement('object')
678 elem
.setAttribute('class', className
)
679 # Set required and default parameters
680 xxxClass
= xxxDict
[className
]
681 defaultNotRequired
= filter(lambda x
, l
=xxxClass
.required
: x
not in l
,
682 xxxClass
.default
.keys())
683 for param
in xxxClass
.required
+ defaultNotRequired
:
684 textElem
= tree
.dom
.createElement(param
)
686 textNode
= tree
.dom
.createTextNode(xxxClass
.default
[param
])
688 textNode
= tree
.dom
.createTextNode('')
689 textElem
.appendChild(textNode
)
690 elem
.appendChild(textElem
)
693 # Make empty XXX object
694 def MakeEmptyXXX(parent
, className
):
695 # Make corresponding DOM object first
696 elem
= MakeEmptyDOM(className
)
697 # If parent is a sizer, we should create sizeritem object, except for spacers
699 if parent
.isSizer
and className
!= 'spacer':
700 sizerItemElem
= MakeEmptyDOM('sizeritem')
701 sizerItemElem
.appendChild(elem
)
703 elif isinstance(parent
, xxxNotebook
):
704 pageElem
= MakeEmptyDOM('notebookpage')
705 pageElem
.appendChild(elem
)
707 # Now just make object
708 return MakeXXXFromDOM(parent
, elem
)