]> git.saurik.com Git - wxWidgets.git/blob - wxPython/tools/XRCed/xxx.py
More XRCed updates from Roman
[wxWidgets.git] / wxPython / tools / XRCed / xxx.py
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>
4 # Created: 22.08.2001
5 # RCS-ID: $Id$
6
7 from wxPython.wx import *
8 from wxPython.xrc import *
9 from xml.dom import minidom
10 import wxPython.lib.wxpTag
11
12 from params import *
13
14 # Parameter value class
15 class xxxParam:
16 # Standard use: for text nodes
17 def __init__(self, node):
18 self.node = 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)
23 else:
24 text = node.childNodes[0] # first child must be text node
25 assert text.nodeType == minidom.Node.TEXT_NODE
26 self.textNode = text
27 # Value returns string
28 def value(self):
29 return self.textNode.data
30 def update(self, value):
31 self.textNode.data = value
32 def remove(self):
33 self.node.parentNode.removeChild(self.node)
34 self.node.unlink()
35
36 # Integer parameter
37 class xxxParamInt(xxxParam):
38 # Standard use: for text nodes
39 def __init__(self, node):
40 xxxParam.__init__(self, node)
41 # Value returns string
42 def value(self):
43 try:
44 return int(self.textNode.data)
45 except ValueError:
46 return -1 # invalid value
47 def update(self, value):
48 self.textNode.data = str(value)
49
50 # Content parameter
51 class xxxParamContent:
52 def __init__(self, node):
53 self.node = node
54 data, l = [], [] # data is needed to quicker value retrieval
55 nodes = node.childNodes[:] # make a copy of the child list
56 for n in nodes:
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)
63 else:
64 # !!! normalize?
65 text = n.childNodes[0] # first child must be text node
66 assert text.nodeType == minidom.Node.TEXT_NODE
67 l.append(text)
68 data.append(str(text.data))
69 else: # remove other
70 node.removeChild(n)
71 n.unlink()
72 self.l, self.data = l, data
73 def value(self):
74 return self.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[:]
79 for n in childNodes:
80 self.node.removeChild(n)
81 l = []
82 for str in value:
83 itemElem = tree.dom.createElement('item')
84 itemText = tree.dom.createTextNode(str)
85 itemElem.appendChild(itemText)
86 self.node.appendChild(itemElem)
87 l.append(itemText)
88 self.l = l
89 else:
90 for i in range(len(value)):
91 self.l[i].data = value[i]
92 self.data = value
93
94 # Content parameter for checklist
95 class xxxParamContentCheckList:
96 def __init__(self, node):
97 self.node = node
98 data, l = [], [] # data is needed to quicker value retrieval
99 nodes = node.childNodes[:] # make a copy of the child list
100 for n in nodes:
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)
108 else:
109 # !!! normalize?
110 text = n.childNodes[0] # first child must be text node
111 assert text.nodeType == minidom.Node.TEXT_NODE
112 l.append((text, n))
113 data.append((str(text.data), int(checked)))
114 else: # remove other
115 node.removeChild(n)
116 n.unlink()
117 self.l, self.data = l, data
118 def value(self):
119 return self.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[:]
124 for n in childNodes:
125 self.node.removeChild(n)
126 l = []
127 for (s,ch) in value:
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))
134 self.l = l
135 else:
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]))
139 self.data = value
140
141 ################################################################################
142
143 # Classes to interface DOM objects
144 class xxxObject:
145 # Default behavior
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']
153 # Special parameters
154 specials = []
155 # Required paremeters: none by default
156 required = []
157 # Default parameters with default values
158 default = {}
159 # Parameter types
160 paramDict = {}
161 # Window styles and extended styles
162 winStyles = []
163 # Tree icon index
164 #image = -1
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):
168 self.parent = parent
169 self.element = element
170 self.undo = None
171 # Get attributes
172 self.className = element.getAttribute('class')
173 if self.hasName: self.name = element.getAttribute('name')
174 # Set parameters (text element children)
175 self.params = {}
176 nodes = element.childNodes[:]
177 for node in nodes:
178 if node.nodeType == minidom.Node.ELEMENT_NODE:
179 tag = node.tagName
180 if tag == 'object':
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)
190 else:
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)
196 else:
197 # Remove all other nodes
198 element.removeChild(node)
199 node.unlink()
200 # Returns real tree object
201 def treeObject(self):
202 if self.hasChild: return self.child
203 return self
204 # Returns tree image index
205 def treeImage(self):
206 if self.hasChild: return self.child.treeImage()
207 return self.image
208 # Class name plus wx name
209 def treeName(self):
210 if self.hasChild: return self.child.treeName()
211 if self.hasName and self.name: return self.className + ' "' + self.name + '"'
212 return self.className
213
214 ################################################################################
215
216 # This is a little special
217 class xxxParamFont(xxxObject):
218 allParams = ['size', 'style', 'weight', 'family', 'underlined',
219 'face', 'encoding']
220 def __init__(self, parent, element):
221 xxxObject.__init__(self, parent, element)
222 self.parentNode = parent # required to behave similar to DOM node
223 v = []
224 for p in self.allParams:
225 try:
226 v.append(str(self.params[p].value()))
227 except KeyError:
228 v.append('')
229 self.data = v
230 def update(self, value):
231 # `value' is a list of strings corresponding to all parameters
232 elem = self.element
233 # Remove old elements first
234 childNodes = elem.childNodes[:]
235 for node in childNodes: elem.removeChild(node)
236 i = 0
237 self.params.clear()
238 v = []
239 for param in self.allParams:
240 if value[i]:
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)
246 v.append(value[i])
247 i += 1
248 self.data = v
249 def value(self):
250 return self.data
251 def remove(self):
252 self.parentNode.removeChild(self.element)
253 self.element.unlink()
254
255 ################################################################################
256
257 class xxxContainer(xxxObject):
258 hasChildren = true
259
260 # Special class for root node
261 class xxxMainNode(xxxContainer):
262 hasStyle = hasName = false
263
264 ################################################################################
265 # Top-level windwows
266
267 class xxxPanel(xxxContainer):
268 allParams = ['pos', 'size', 'style']
269 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
270 'tooltip']
271 winStyles = ['wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
272 exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
273
274 class xxxDialog(xxxContainer):
275 allParams = ['title', 'pos', 'size', 'style']
276 required = ['title']
277 winStyles = ['wxDEFAULT_DIALOG_STYLE', 'wxSTAY_ON_TOP',
278 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS',
279 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 'wxRESIZE_BOX',
280 'wxTHICK_FRAME',
281 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
282 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
283 'tooltip']
284 exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
285
286 class xxxFrame(xxxContainer):
287 allParams = ['title', 'centered', 'pos', 'size', 'style']
288 paramDict = {'centered': ParamBool}
289 required = ['title']
290 winStyles = ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE',
291 'wxSTAY_ON_TOP',
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',
297 'tooltip']
298 exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
299
300 class xxxTool(xxxObject):
301 allParams = ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp']
302 paramDict = {'bitmap2': ParamFile}
303 hasStyle = false
304
305 class xxxToolBar(xxxContainer):
306 allParams = ['bitmapsize', 'margins', 'packing', 'separation',
307 'pos', 'size', 'style']
308 hasStyle = false
309 paramDict = {'bitmapsize': ParamPosSize, 'margins': ParamPosSize,
310 'packing': ParamInt, 'separation': ParamInt,
311 'style': ParamNonGenericStyle}
312 winStyles = ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL']
313
314 ################################################################################
315 # Bitmap, Icon
316
317 class xxxBitmap(xxxObject):
318 allParams = ['bitmap']
319 required = ['bitmap']
320
321 class xxxIcon(xxxObject):
322 allParams = ['icon']
323 required = ['icon']
324
325 ################################################################################
326 # Controls
327
328 class xxxStaticText(xxxObject):
329 allParams = ['label', 'pos', 'size', 'style']
330 required = ['label']
331 winStyles = ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
332
333 class xxxStaticLine(xxxObject):
334 allParams = ['pos', 'size', 'style']
335 winStyles = ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
336
337 class xxxStaticBitmap(xxxObject):
338 allParams = ['bitmap', 'pos', 'size', 'style']
339 required = ['bitmap']
340
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']
345
346 class xxxChoice(xxxObject):
347 allParams = ['content', 'selection', 'pos', 'size', 'style']
348 required = ['content']
349 winStyles = ['wxCB_SORT']
350
351 class xxxSlider(xxxObject):
352 allParams = ['value', 'min', 'max', 'pos', 'size', 'style',
353 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
354 'selmin', 'selmax']
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']
362
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']
368
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']
374
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']
381
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']
386
387 class xxxHtmlWindow(xxxObject):
388 allParams = ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
389 paramDict = {'borders': ParamInt}
390 winStyles = ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
391
392 class xxxCalendar(xxxObject):
393 allParams = ['pos', 'size', 'style']
394
395 class xxxNotebook(xxxContainer):
396 allParams = ['usenotebooksizer', 'pos', 'size', 'style']
397 paramDict = {'usenotebooksizer': ParamBool}
398 winStyles = ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM']
399
400 ################################################################################
401 # Buttons
402
403 class xxxButton(xxxObject):
404 allParams = ['label', 'default', 'pos', 'size', 'style']
405 paramDict = {'default': ParamBool}
406 required = ['label']
407 winStyles = ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
408
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']
415
416 class xxxRadioButton(xxxObject):
417 allParams = ['label', 'value', 'pos', 'size', 'style']
418 paramDict = {'value': ParamBool}
419 required = ['label']
420 winStyles = ['wxRB_GROUP']
421
422 class xxxSpinButton(xxxObject):
423 allParams = ['pos', 'size', 'style']
424 winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
425
426 ################################################################################
427 # Boxes
428
429 class xxxStaticBox(xxxObject):
430 allParams = ['label', 'pos', 'size', 'style']
431 required = ['label']
432
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']
438
439 class xxxCheckBox(xxxObject):
440 allParams = ['label', 'pos', 'size', 'style']
441 required = ['label']
442
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']
447
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']
453
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}
462
463 ################################################################################
464 # Sizers
465
466 class xxxSizer(xxxContainer):
467 hasName = hasStyle = false
468 paramDict = {'orient': ParamOrient}
469 isSizer = true
470
471 class xxxBoxSizer(xxxSizer):
472 allParams = ['orient']
473 required = ['orient']
474 default = {'orient': 'wxVERTICAL'}
475 # Tree icon depends on orientation
476 def treeImage(self):
477 if self.params['orient'].value() == 'wxHORIZONTAL': return self.imageH
478 else: return self.imageV
479
480 class xxxStaticBoxSizer(xxxBoxSizer):
481 allParams = ['label', 'orient']
482 required = ['label', 'orient']
483 default = {'orient': 'wxVERTICAL'}
484
485 class xxxGridSizer(xxxSizer):
486 allParams = ['cols', 'rows', 'vgap', 'hgap']
487 required = ['cols']
488 default = {'cols': '2', 'rows': '2'}
489
490 # For repeated parameters
491 class xxxParamMulti:
492 def __init__(self):
493 self.l, self.data = [], []
494 def append(self, param):
495 self.l.append(param)
496 self.data.append(param.value())
497 def value(self):
498 return self.data
499 def remove(self):
500 for param in self.l:
501 param.remove()
502 self.l, self.data = [], []
503
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]
518 for i in value:
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)
524
525 # Container with only one child.
526 # Not shown in tree.
527 class xxxChildContainer(xxxObject):
528 hasName = hasStyle = false
529 hasChild = true
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
534 for node in nodes:
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
543 return # success
544 else:
545 element.removeChild(node)
546 node.unlink()
547 assert 0, 'no child found'
548
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')
558
559 class xxxNotebookPage(xxxChildContainer):
560 allParams = ['label', 'selected']
561 paramDict = {'selected': ParamBool}
562 required = ['label']
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')
572
573 class xxxSpacer(xxxObject):
574 hasName = hasStyle = false
575 allParams = ['size', 'option', 'flag', 'border']
576 paramDict = {'option': ParamInt}
577 default = {'size': '0,0'}
578
579 class xxxMenuBar(xxxContainer):
580 allParams = []
581
582 class xxxMenu(xxxContainer):
583 allParams = ['label']
584 default = {'label': ''}
585 paramDict = {'style': ParamNonGenericStyle} # no generic styles
586 winStyles = ['wxMENU_TEAROFF']
587
588 class xxxMenuItem(xxxObject):
589 allParams = ['checkable', 'label', 'accel', 'help']
590 default = {'label': ''}
591
592 class xxxSeparator(xxxObject):
593 hasName = hasStyle = false
594
595 ################################################################################
596
597 xxxDict = {
598 'wxPanel': xxxPanel,
599 'wxDialog': xxxDialog,
600 'wxFrame': xxxFrame,
601 'tool': xxxTool,
602 'wxToolBar': xxxToolBar,
603
604 'wxBitmap': xxxBitmap,
605 'wxIcon': xxxIcon,
606
607 'wxButton': xxxButton,
608 'wxBitmapButton': xxxBitmapButton,
609 'wxRadioButton': xxxRadioButton,
610 'wxSpinButton': xxxSpinButton,
611
612 'wxStaticBox': xxxStaticBox,
613 'wxStaticBitmap': xxxStaticBitmap,
614 'wxRadioBox': xxxRadioBox,
615 'wxComboBox': xxxComboBox,
616 'wxCheckBox': xxxCheckBox,
617 'wxListBox': xxxListBox,
618
619 'wxStaticText': xxxStaticText,
620 'wxStaticLine': xxxStaticLine,
621 'wxTextCtrl': xxxTextCtrl,
622 'wxChoice': xxxChoice,
623 'wxSlider': xxxSlider,
624 'wxGauge': xxxGauge,
625 'wxScrollBar': xxxScrollBar,
626 'wxTreeCtrl': xxxTreeCtrl,
627 'wxListCtrl': xxxListCtrl,
628 'wxCheckList': xxxCheckList,
629 'wxNotebook': xxxNotebook,
630 'notebookpage': xxxNotebookPage,
631 'wxHtmlWindow': xxxHtmlWindow,
632 'wxCalendar': xxxCalendar,
633
634 'wxBoxSizer': xxxBoxSizer,
635 'wxStaticBoxSizer': xxxStaticBoxSizer,
636 'wxGridSizer': xxxGridSizer,
637 'wxFlexGridSizer': xxxFlexGridSizer,
638 'sizeritem': xxxSizerItem,
639 'spacer': xxxSpacer,
640
641 'wxMenuBar': xxxMenuBar,
642 'wxMenu': xxxMenu,
643 'wxMenuItem': xxxMenuItem,
644 'separator': xxxSeparator,
645 }
646
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(),
650 'tooltip': wxNewId()
651 }
652 for cl in xxxDict.values():
653 if cl.allParams:
654 for param in cl.allParams + cl.paramDict.keys():
655 if not paramIDs.has_key(param):
656 paramIDs[param] = wxNewId()
657
658 ################################################################################
659 # Helper functions
660
661 # Test for object elements
662 def IsObject(node):
663 return node.nodeType == minidom.Node.ELEMENT_NODE and node.tagName == 'object'
664
665 # Make XXX object from some DOM object, selecting correct class
666 def MakeXXXFromDOM(parent, element):
667 try:
668 return xxxDict[element.getAttribute('class')](parent, element)
669 except KeyError:
670 # Verify that it's not recursive exception
671 if element.getAttribute('class') not in xxxDict:
672 print 'ERROR: unknown class:', element.getAttribute('class')
673 raise
674
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)
685 try:
686 textNode = tree.dom.createTextNode(xxxClass.default[param])
687 except KeyError:
688 textNode = tree.dom.createTextNode('')
689 textElem.appendChild(textNode)
690 elem.appendChild(textElem)
691 return elem
692
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
698 if parent:
699 if parent.isSizer and className != 'spacer':
700 sizerItemElem = MakeEmptyDOM('sizeritem')
701 sizerItemElem.appendChild(elem)
702 elem = sizerItemElem
703 elif isinstance(parent, xxxNotebook):
704 pageElem = MakeEmptyDOM('notebookpage')
705 pageElem.appendChild(elem)
706 elem = pageElem
707 # Now just make object
708 return MakeXXXFromDOM(parent, elem)
709