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 self
.textNode
.data
= unicode(value
, g
.currentEncoding
)
55 class xxxParamInt(xxxParam
):
56 # Standard use: for text nodes
57 def __init__(self
, node
):
58 xxxParam
.__init
__(self
, node
)
59 # Value returns string
62 return int(self
.textNode
.data
)
64 return -1 # invalid value
65 def update(self
, value
):
66 self
.textNode
.data
= str(value
)
69 class xxxParamContent(xxxNode
):
70 def __init__(self
, node
):
71 xxxNode
.__init
__(self
, node
)
72 data
, l
= [], [] # data is needed to quicker value retrieval
73 nodes
= node
.childNodes
[:] # make a copy of the child list
75 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
76 assert n
.tagName
== 'item', 'bad content content'
77 if not n
.hasChildNodes():
78 # If does not have child nodes, create empty text node
79 text
= g
.tree
.dom
.createTextNode('')
80 node
.appendChild(text
)
83 text
= n
.childNodes
[0] # first child must be text node
84 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
86 data
.append(str(text
.data
))
90 self
.l
, self
.data
= l
, data
93 def update(self
, value
):
94 # If number if items is not the same, recreate children
95 if len(value
) != len(self
.l
): # remove first if number of items has changed
96 childNodes
= self
.node
.childNodes
[:]
98 self
.node
.removeChild(n
)
101 itemElem
= g
.tree
.dom
.createElement('item')
102 itemText
= g
.tree
.dom
.createTextNode(str)
103 itemElem
.appendChild(itemText
)
104 self
.node
.appendChild(itemElem
)
108 for i
in range(len(value
)):
109 self
.l
[i
].data
= value
[i
]
112 # Content parameter for checklist
113 class xxxParamContentCheckList(xxxNode
):
114 def __init__(self
, node
):
115 xxxNode
.__init
__(self
, node
)
116 data
, l
= [], [] # data is needed to quicker value retrieval
117 nodes
= node
.childNodes
[:] # make a copy of the child list
119 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
120 assert n
.tagName
== 'item', 'bad content content'
121 checked
= n
.getAttribute('checked')
122 if not checked
: checked
= 0
123 if not n
.hasChildNodes():
124 # If does not have child nodes, create empty text node
125 text
= g
.tree
.dom
.createTextNode('')
126 node
.appendChild(text
)
129 text
= n
.childNodes
[0] # first child must be text node
130 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
132 data
.append((str(text
.data
), int(checked
)))
136 self
.l
, self
.data
= l
, data
139 def update(self
, value
):
140 # If number if items is not the same, recreate children
141 if len(value
) != len(self
.l
): # remove first if number of items has changed
142 childNodes
= self
.node
.childNodes
[:]
144 self
.node
.removeChild(n
)
147 itemElem
= g
.tree
.dom
.createElement('item')
148 # Add checked only if True
149 if ch
: itemElem
.setAttribute('checked', '1')
150 itemText
= g
.tree
.dom
.createTextNode(s
)
151 itemElem
.appendChild(itemText
)
152 self
.node
.appendChild(itemElem
)
153 l
.append((itemText
, itemElem
))
156 for i
in range(len(value
)):
157 self
.l
[i
][0].data
= value
[i
][0]
158 self
.l
[i
][1].setAttribute('checked', str(value
[i
][1]))
162 class xxxParamBitmap(xxxParam
):
163 def __init__(self
, node
):
164 xxxParam
.__init
__(self
, node
)
165 self
.stock_id
= node
.getAttribute('stock_id')
167 return [self
.stock_id
, xxxParam
.value(self
)]
168 def update(self
, value
):
169 self
.stock_id
= value
[0]
171 self
.node
.setAttribute('stock_id', self
.stock_id
)
172 elif self
.node
.hasAttribute('stock_id'):
173 self
.node
.removeAttribute('stock_id')
174 xxxParam
.update(self
, value
[1])
176 ################################################################################
178 # Classes to interface DOM objects
181 hasChildren
= False # has children elements?
182 hasStyle
= True # almost everyone
183 hasName
= True # has name attribute?
184 isSizer
= hasChild
= False
185 allParams
= None # Some nodes have no parameters
186 # Style parameters (all optional)
187 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip']
191 bitmapTags
= ['bitmap', 'bitmap2', 'icon']
192 # Required paremeters: none by default
194 # Default parameters with default values
198 # Window styles and extended styles
202 # Construct a new xxx object from DOM element
203 # parent is parent xxx object (or None if none), element is DOM element object
204 def __init__(self
, parent
, element
):
206 self
.element
= element
209 self
.className
= element
.getAttribute('class')
210 if self
.hasName
: self
.name
= element
.getAttribute('name')
211 # Set parameters (text element children)
213 nodes
= element
.childNodes
[:]
215 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
218 continue # do nothing for object children here
219 if tag
not in self
.allParams
and tag
not in self
.styles
:
220 print 'WARNING: unknown parameter for %s: %s' % \
221 (self
.className
, tag
)
222 elif tag
in self
.specials
:
223 self
.special(tag
, node
)
224 elif tag
== 'content':
225 if self
.className
== 'wxCheckList':
226 self
.params
[tag
] = xxxParamContentCheckList(node
)
228 self
.params
[tag
] = xxxParamContent(node
)
229 elif tag
== 'font': # has children
230 self
.params
[tag
] = xxxParamFont(element
, node
)
231 elif tag
in self
.bitmapTags
:
232 # Can have attributes
233 self
.params
[tag
] = xxxParamBitmap(node
)
234 else: # simple parameter
235 self
.params
[tag
] = xxxParam(node
)
237 # Remove all other nodes
238 element
.removeChild(node
)
240 # Check that all required params are set
241 for param
in self
.required
:
242 if not self
.params
.has_key(param
):
243 # If default is specified, set it
244 if self
.default
.has_key(param
):
245 elem
= g
.tree
.dom
.createElement(param
)
246 if param
== 'content':
247 if self
.className
== 'wxCheckList':
248 self
.params
[param
] = xxxParamContentCheckList(elem
)
250 self
.params
[param
] = xxxParamContent(elem
)
252 self
.params
[param
] = xxxParam(elem
)
253 # Find place to put new element: first present element after param
255 paramStyles
= self
.allParams
+ self
.styles
256 for p
in paramStyles
[paramStyles
.index(param
) + 1:]:
257 # Content params don't have same type
258 if self
.params
.has_key(p
) and p
!= 'content':
262 nextTextElem
= self
.params
[p
].node
263 self
.element
.insertBefore(elem
, nextTextElem
)
265 self
.element
.appendChild(elem
)
267 wxLogWarning('Required parameter %s of %s missing' %
268 (param
, self
.className
))
269 # Returns real tree object
270 def treeObject(self
):
271 if self
.hasChild
: return self
.child
273 # Returns tree image index
275 if self
.hasChild
: return self
.child
.treeImage()
277 # Class name plus wx name
279 if self
.hasChild
: return self
.child
.treeName()
280 if self
.hasName
and self
.name
: return self
.className
+ ' "' + self
.name
+ '"'
281 return self
.className
283 ################################################################################
285 # This is a little special: it is both xxxObject and xxxNode
286 class xxxParamFont(xxxObject
, xxxNode
):
287 allParams
= ['size', 'style', 'weight', 'family', 'underlined',
289 def __init__(self
, parent
, element
):
290 xxxObject
.__init
__(self
, parent
, element
)
291 xxxNode
.__init
__(self
, element
)
292 self
.parentNode
= parent
# required to behave similar to DOM node
294 for p
in self
.allParams
:
296 v
.append(str(self
.params
[p
].value()))
300 def update(self
, value
):
301 # `value' is a list of strings corresponding to all parameters
303 # Remove old elements first
304 childNodes
= elem
.childNodes
[:]
305 for node
in childNodes
: elem
.removeChild(node
)
309 for param
in self
.allParams
:
311 fontElem
= g
.tree
.dom
.createElement(param
)
312 textNode
= g
.tree
.dom
.createTextNode(value
[i
])
313 self
.params
[param
] = textNode
314 fontElem
.appendChild(textNode
)
315 elem
.appendChild(fontElem
)
322 ################################################################################
324 class xxxContainer(xxxObject
):
327 # Simulate normal parameter for encoding
329 def __init__(self
, val
):
333 def update(self
, val
):
336 # Special class for root node
337 class xxxMainNode(xxxContainer
):
338 allParams
= ['encoding']
339 hasStyle
= hasName
= False
340 def __init__(self
, dom
):
341 xxxContainer
.__init
__(self
, None, dom
.documentElement
)
342 self
.className
= 'XML tree'
343 # Reset required parameters after processing XML, because encoding is
345 self
.required
= ['encoding']
346 self
.params
['encoding'] = xxxEncoding(dom
.encoding
)
348 ################################################################################
351 class xxxPanel(xxxContainer
):
352 allParams
= ['pos', 'size', 'style']
353 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
355 winStyles
= ['wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
356 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
358 class xxxDialog(xxxContainer
):
359 allParams
= ['title', 'centered', 'pos', 'size', 'style']
360 paramDict
= {'centered': ParamBool}
362 default
= {'title': ''}
363 winStyles
= ['wxDEFAULT_DIALOG_STYLE', 'wxSTAY_ON_TOP',
364 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS',
365 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 'wxRESIZE_BOX',
367 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
368 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
370 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
372 class xxxFrame(xxxContainer
):
373 allParams
= ['title', 'centered', 'pos', 'size', 'style']
374 paramDict
= {'centered': ParamBool}
376 default
= {'title': ''}
377 winStyles
= ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE',
379 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
380 'wxRESIZE_BOX', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX',
381 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_TOOL_WINDOW',
382 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
383 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
385 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
387 class xxxTool(xxxObject
):
388 allParams
= ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp']
389 required
= ['bitmap']
390 paramDict
= {'bitmap2': ParamBitmap, 'toggle': ParamBool}
393 class xxxToolBar(xxxContainer
):
394 allParams
= ['bitmapsize', 'margins', 'packing', 'separation',
395 'pos', 'size', 'style']
397 paramDict
= {'bitmapsize': ParamPosSize
, 'margins': ParamPosSize
,
398 'packing': ParamInt
, 'separation': ParamInt
,
399 'style': ParamNonGenericStyle
}
400 winStyles
= ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL']
402 ################################################################################
405 class xxxBitmap(xxxObject
):
406 allParams
= ['bitmap']
407 required
= ['bitmap']
410 class xxxIcon(xxxObject
):
414 ################################################################################
417 class xxxStaticText(xxxObject
):
418 allParams
= ['label', 'pos', 'size', 'style']
420 default
= {'label': ''}
421 winStyles
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
423 class xxxStaticLine(xxxObject
):
424 allParams
= ['pos', 'size', 'style']
425 winStyles
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
427 class xxxStaticBitmap(xxxObject
):
428 allParams
= ['bitmap', 'pos', 'size', 'style']
429 required
= ['bitmap']
431 class xxxTextCtrl(xxxObject
):
432 allParams
= ['value', 'pos', 'size', 'style']
433 winStyles
= ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
434 'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
435 paramDict
= {'value': ParamMultilineText}
437 class xxxChoice(xxxObject
):
438 allParams
= ['content', 'selection', 'pos', 'size', 'style']
439 required
= ['content']
440 default
= {'content': '[]'}
441 winStyles
= ['wxCB_SORT']
443 class xxxSlider(xxxObject
):
444 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style',
445 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
447 paramDict
= {'value': ParamInt
, 'tickfreq': ParamInt
, 'pagesize': ParamInt
,
448 'linesize': ParamInt
, 'thumb': ParamInt
, 'thumb': ParamInt
,
449 'tick': ParamInt
, 'selmin': ParamInt
, 'selmax': ParamInt
}
450 required
= ['value', 'min', 'max']
451 winStyles
= ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
452 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
453 'wxSL_BOTH', 'wxSL_SELRANGE']
455 class xxxGauge(xxxObject
):
456 allParams
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
457 paramDict
= {'range': ParamInt
, 'value': ParamInt
,
458 'shadow': ParamInt
, 'bezel': ParamInt
}
459 winStyles
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
461 class xxxScrollBar(xxxObject
):
462 allParams
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
463 paramDict
= {'value': ParamInt
, 'range': ParamInt
, 'thumbsize': ParamInt
,
464 'pagesize': ParamInt
}
465 winStyles
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
467 class xxxListCtrl(xxxObject
):
468 allParams
= ['pos', 'size', 'style']
469 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
470 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
471 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
472 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
474 class xxxTreeCtrl(xxxObject
):
475 allParams
= ['pos', 'size', 'style']
476 winStyles
= ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT',
477 'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE']
479 class xxxHtmlWindow(xxxObject
):
480 allParams
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
481 paramDict
= {'borders': ParamInt, 'htmlcode':ParamMultilineText}
482 winStyles
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
484 class xxxCalendarCtrl(xxxObject
):
485 allParams
= ['pos', 'size', 'style']
487 class xxxNotebook(xxxContainer
):
488 allParams
= ['usenotebooksizer', 'pos', 'size', 'style']
489 paramDict
= {'usenotebooksizer': ParamBool}
490 winStyles
= ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM']
492 class xxxGenericDirCtrl(xxxObject
):
493 allParams
= ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style']
494 paramDict
= {'defaultfilter': ParamInt}
495 winStyles
= ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
496 'wxDIRCTRL_SHOW_FILTERS', 'wxDIRCTRL_EDIT_LABELS']
498 class xxxScrolledWindow(xxxContainer
):
499 allParams
= ['pos', 'size', 'style']
500 winStyles
= ['wxHSCROLL', 'wxVSCROLL']
502 ################################################################################
505 class xxxButton(xxxObject
):
506 allParams
= ['label', 'default', 'pos', 'size', 'style']
507 paramDict
= {'default': ParamBool}
509 winStyles
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
511 class xxxBitmapButton(xxxObject
):
512 allParams
= ['bitmap', 'selected', 'focus', 'disabled', 'default',
513 'pos', 'size', 'style']
514 required
= ['bitmap']
515 winStyles
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP',
516 'wxBU_RIGHT', 'wxBU_BOTTOM']
518 class xxxRadioButton(xxxObject
):
519 allParams
= ['label', 'value', 'pos', 'size', 'style']
520 paramDict
= {'value': ParamBool}
522 winStyles
= ['wxRB_GROUP']
524 class xxxSpinButton(xxxObject
):
525 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
526 paramDict
= {'value': ParamInt}
527 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
529 class xxxSpinCtrl(xxxObject
):
530 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
531 paramDict
= {'value': ParamInt}
532 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
534 ################################################################################
537 class xxxStaticBox(xxxObject
):
538 allParams
= ['label', 'pos', 'size', 'style']
541 class xxxRadioBox(xxxObject
):
542 allParams
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
543 paramDict
= {'dimension': ParamInt}
544 required
= ['label', 'content']
545 default
= {'content': '[]'}
546 winStyles
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS']
548 class xxxCheckBox(xxxObject
):
549 allParams
= ['label', 'checked', 'pos', 'size', 'style']
550 paramDict
= {'checked': ParamBool}
553 class xxxComboBox(xxxObject
):
554 allParams
= ['content', 'selection', 'value', 'pos', 'size', 'style']
555 required
= ['content']
556 default
= {'content': '[]'}
557 winStyles
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
559 class xxxListBox(xxxObject
):
560 allParams
= ['content', 'selection', 'pos', 'size', 'style']
561 required
= ['content']
562 default
= {'content': '[]'}
563 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
564 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
566 class xxxCheckList(xxxObject
):
567 allParams
= ['content', 'pos', 'size', 'style']
568 required
= ['content']
569 default
= {'content': '[]'}
570 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
571 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
572 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
573 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
574 paramDict
= {'content': ParamContentCheckList}
576 ################################################################################
579 class xxxSizer(xxxContainer
):
580 hasName
= hasStyle
= False
581 paramDict
= {'orient': ParamOrient}
584 class xxxBoxSizer(xxxSizer
):
585 allParams
= ['orient']
586 required
= ['orient']
587 default
= {'orient': 'wxVERTICAL'}
588 # Tree icon depends on orientation
590 if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
591 else: return self
.imageV
593 class xxxStaticBoxSizer(xxxBoxSizer
):
594 allParams
= ['label', 'orient']
595 required
= ['label', 'orient']
597 class xxxGridSizer(xxxSizer
):
598 allParams
= ['cols', 'rows', 'vgap', 'hgap']
600 default
= {'cols': '2', 'rows': '2'}
602 # For repeated parameters
604 def __init__(self
, node
):
606 self
.l
, self
.data
= [], []
607 def append(self
, param
):
609 self
.data
.append(param
.value())
615 self
.l
, self
.data
= [], []
617 class xxxFlexGridSizer(xxxGridSizer
):
618 specials
= ['growablecols', 'growablerows']
619 allParams
= ['cols', 'rows', 'vgap', 'hgap'] + specials
620 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
621 # Special processing for growable* parameters
622 # (they are represented by several nodes)
623 def special(self
, tag
, node
):
624 if not self
.params
.has_key(tag
):
625 # Create new multi-group
626 self
.params
[tag
] = xxxParamMulti(node
)
627 self
.params
[tag
].append(xxxParamInt(node
))
628 def setSpecial(self
, param
, value
):
629 # Straightforward implementation: remove, add again
630 self
.params
[param
].remove()
631 del self
.params
[param
]
633 node
= g
.tree
.dom
.createElement(param
)
634 text
= g
.tree
.dom
.createTextNode(str(i
))
635 node
.appendChild(text
)
636 self
.element
.appendChild(node
)
637 self
.special(param
, node
)
639 # Container with only one child.
641 class xxxChildContainer(xxxObject
):
642 hasName
= hasStyle
= False
644 def __init__(self
, parent
, element
):
645 xxxObject
.__init
__(self
, parent
, element
)
646 # Must have one child with 'object' tag, but we don't check it
647 nodes
= element
.childNodes
[:] # create copy
649 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
650 if node
.tagName
== 'object':
651 # Create new xxx object for child node
652 self
.child
= MakeXXXFromDOM(self
, node
)
653 self
.child
.parent
= parent
654 # Copy hasChildren and isSizer attributes
655 self
.hasChildren
= self
.child
.hasChildren
656 self
.isSizer
= self
.child
.isSizer
659 element
.removeChild(node
)
661 assert 0, 'no child found'
663 class xxxSizerItem(xxxChildContainer
):
664 allParams
= ['option', 'flag', 'border', 'minsize']
665 paramDict
= {'option': ParamInt, 'minsize': ParamPosSize}
666 def __init__(self
, parent
, element
):
667 xxxChildContainer
.__init
__(self
, parent
, element
)
668 # Remove pos parameter - not needed for sizeritems
669 if 'pos' in self
.child
.allParams
:
670 self
.child
.allParams
= self
.child
.allParams
[:]
671 self
.child
.allParams
.remove('pos')
673 class xxxNotebookPage(xxxChildContainer
):
674 allParams
= ['label', 'selected']
675 paramDict
= {'selected': ParamBool}
677 def __init__(self
, parent
, element
):
678 xxxChildContainer
.__init
__(self
, parent
, element
)
679 # pos and size dont matter for notebookpages
680 if 'pos' in self
.child
.allParams
:
681 self
.child
.allParams
= self
.child
.allParams
[:]
682 self
.child
.allParams
.remove('pos')
683 if 'size' in self
.child
.allParams
:
684 self
.child
.allParams
= self
.child
.allParams
[:]
685 self
.child
.allParams
.remove('size')
687 class xxxSpacer(xxxObject
):
688 hasName
= hasStyle
= False
689 allParams
= ['size', 'option', 'flag', 'border']
690 paramDict
= {'option': ParamInt}
691 default
= {'size': '0,0'}
693 class xxxMenuBar(xxxContainer
):
694 allParams
= ['style']
695 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
696 winStyles
= ['wxMB_DOCKABLE']
698 class xxxMenu(xxxContainer
):
699 allParams
= ['label', 'help', 'style']
700 default
= {'label': ''}
701 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
702 winStyles
= ['wxMENU_TEAROFF']
704 class xxxMenuItem(xxxObject
):
705 allParams
= ['label', 'bitmap', 'accel', 'help',
706 'checkable', 'radio', 'enabled', 'checked']
707 default
= {'label': ''}
710 class xxxSeparator(xxxObject
):
711 hasName
= hasStyle
= False
713 ################################################################################
716 class xxxUnknown(xxxObject
):
717 allParams
= ['pos', 'size', 'style']
718 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
720 ################################################################################
724 'wxDialog': xxxDialog
,
727 'wxToolBar': xxxToolBar
,
729 'wxBitmap': xxxBitmap
,
732 'wxButton': xxxButton
,
733 'wxBitmapButton': xxxBitmapButton
,
734 'wxRadioButton': xxxRadioButton
,
735 'wxSpinButton': xxxSpinButton
,
737 'wxStaticBox': xxxStaticBox
,
738 'wxStaticBitmap': xxxStaticBitmap
,
739 'wxRadioBox': xxxRadioBox
,
740 'wxComboBox': xxxComboBox
,
741 'wxCheckBox': xxxCheckBox
,
742 'wxListBox': xxxListBox
,
744 'wxStaticText': xxxStaticText
,
745 'wxStaticLine': xxxStaticLine
,
746 'wxTextCtrl': xxxTextCtrl
,
747 'wxChoice': xxxChoice
,
748 'wxSlider': xxxSlider
,
750 'wxScrollBar': xxxScrollBar
,
751 'wxTreeCtrl': xxxTreeCtrl
,
752 'wxListCtrl': xxxListCtrl
,
753 'wxCheckList': xxxCheckList
,
754 'wxNotebook': xxxNotebook
,
755 'notebookpage': xxxNotebookPage
,
756 'wxHtmlWindow': xxxHtmlWindow
,
757 'wxCalendarCtrl': xxxCalendarCtrl
,
758 'wxGenericDirCtrl': xxxGenericDirCtrl
,
759 'wxSpinCtrl': xxxSpinCtrl
,
760 'wxScrolledWindow': xxxScrolledWindow
,
762 'wxBoxSizer': xxxBoxSizer
,
763 'wxStaticBoxSizer': xxxStaticBoxSizer
,
764 'wxGridSizer': xxxGridSizer
,
765 'wxFlexGridSizer': xxxFlexGridSizer
,
766 'sizeritem': xxxSizerItem
,
769 'wxMenuBar': xxxMenuBar
,
771 'wxMenuItem': xxxMenuItem
,
772 'separator': xxxSeparator
,
774 'unknown': xxxUnknown
,
777 # Create IDs for all parameters of all classes
778 paramIDs
= {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(),
779 'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(),
780 'tooltip': wxNewId(), 'encoding': wxNewId()
782 for cl
in xxxDict
.values():
784 for param
in cl
.allParams
+ cl
.paramDict
.keys():
785 if not paramIDs
.has_key(param
):
786 paramIDs
[param
] = wxNewId()
788 ################################################################################
791 # Test for object elements
793 return node
.nodeType
== minidom
.Node
.ELEMENT_NODE
and node
.tagName
== 'object'
795 # Make XXX object from some DOM object, selecting correct class
796 def MakeXXXFromDOM(parent
, element
):
798 klass
= xxxDict
[element
.getAttribute('class')]
800 # If we encounter a weird class, use unknown template
801 print 'WARNING: unsupported class:', element
.getAttribute('class')
803 return klass(parent
, element
)
805 # Make empty DOM element
806 def MakeEmptyDOM(className
):
807 elem
= g
.tree
.dom
.createElement('object')
808 elem
.setAttribute('class', className
)
809 # Set required and default parameters
810 xxxClass
= xxxDict
[className
]
811 defaultNotRequired
= filter(lambda x
, l
=xxxClass
.required
: x
not in l
,
812 xxxClass
.default
.keys())
813 for param
in xxxClass
.required
+ defaultNotRequired
:
814 textElem
= g
.tree
.dom
.createElement(param
)
816 textNode
= g
.tree
.dom
.createTextNode(xxxClass
.default
[param
])
818 textNode
= g
.tree
.dom
.createTextNode('')
819 textElem
.appendChild(textNode
)
820 elem
.appendChild(textElem
)
823 # Make empty XXX object
824 def MakeEmptyXXX(parent
, className
):
825 # Make corresponding DOM object first
826 elem
= MakeEmptyDOM(className
)
827 # If parent is a sizer, we should create sizeritem object, except for spacers
829 if parent
.isSizer
and className
!= 'spacer':
830 sizerItemElem
= MakeEmptyDOM('sizeritem')
831 sizerItemElem
.appendChild(elem
)
833 elif isinstance(parent
, xxxNotebook
):
834 pageElem
= MakeEmptyDOM('notebookpage')
835 pageElem
.appendChild(elem
)
837 # Now just make object
838 return MakeXXXFromDOM(parent
, elem
)