]> git.saurik.com Git - wxWidgets.git/blame - wxPython/tools/XRCed/xxx.py
Nasty workaround for an incompatible low-level change in Python 2.2,
[wxWidgets.git] / wxPython / tools / XRCed / xxx.py
CommitLineData
a40b5e84 1# Name: xxx.py ('xxx' is easy to distinguish from 'wx' :) )
09f3d4e6
RD
2# Purpose: XML interface classes
3# Author: Roman Rolinsky <rolinsky@mema.ucl.ac.be>
4# Created: 22.08.2001
a40b5e84 5# RCS-ID: $Id$
09f3d4e6
RD
6
7from wxPython.wx import *
8from wxPython.xrc import *
9from xml.dom import minidom
10import wxPython.lib.wxpTag
11
12from params import *
13
32ce09e2
RD
14# Parameter value class
15class 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 str(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# Content parameter
37class xxxParamContent:
38 def __init__(self, node):
39 self.node = node
40 data, l = [], [] # data is needed to quicker value retrieval
41 nodes = node.childNodes[:] # make a copy of the child list
42 for n in nodes:
43 if n.nodeType == minidom.Node.ELEMENT_NODE:
44 assert n.tagName == 'item', 'bad content content'
45 if not n.hasChildNodes():
46 # If does not have child nodes, create empty text node
47 text = tree.dom.createTextNode('')
48 node.appendChild(text)
49 else:
50 # !!! normalize?
51 text = n.childNodes[0] # first child must be text node
52 assert text.nodeType == minidom.Node.TEXT_NODE
53 l.append(text)
54 data.append(text.data)
55 else: # remove other
56 node.removeChild(n)
57 n.unlink()
58 self.l, self.data = l, data
59 def value(self):
60 return self.data
61 def update(self, value):
62 # If number if items is not the same, recreate children
63 if len(value) != len(self.l): # remove first if number of items has changed
64 for n in self.node.childNodes:
65 self.node.removeChild(n)
66 l = []
67 for str in value:
68 itemElem = tree.dom.createElement('item')
69 itemText = tree.dom.createTextNode(str)
70 itemElem.appendChild(itemText)
71 self.node.appendChild(itemElem)
72 l.append(itemText)
73 else:
74 for i in range(len(value)):
75 self.l[i].data = value[i]
76 self.data = value
77
78################################################################################
79
09f3d4e6
RD
80# Classes to interface DOM objects
81class xxxObject:
09f3d4e6
RD
82 # Default behavior
83 hasChildren = false # has children elements?
a40b5e84 84 hasStyle = true # almost everyone
09f3d4e6
RD
85 hasName = true # has name attribute?
86 isSizer = hasChild = false
a40b5e84
RD
87 # Style parameters (all optional)
88 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip']
32ce09e2
RD
89 # Special parameters
90 specials = []
09f3d4e6
RD
91 # Required paremeters: none by default
92 required = []
93 # Default parameters with default values
94 default = {}
95 # Parameter types
96 paramDict = {}
a40b5e84
RD
97 # Window styles and extended styles
98 winStyles = []
09f3d4e6 99 # Tree icon index
a40b5e84 100 #image = -1
09f3d4e6
RD
101 # Construct a new xxx object from DOM element
102 # parent is parent xxx object (or None if none), element is DOM element object
103 def __init__(self, parent, element):
104 self.parent = parent
105 self.element = element
106 self.undo = None
107 # Get attributes
108 self.className = element.getAttribute('class')
109 if self.hasName: self.name = element.getAttribute('name')
110 # Set parameters (text element children)
111 self.params = {}
112 nodes = element.childNodes[:]
113 for node in nodes:
114 if node.nodeType == minidom.Node.ELEMENT_NODE:
32ce09e2
RD
115 tag = node.tagName
116 if tag == 'object':
09f3d4e6 117 continue # do nothing for object children here
32ce09e2 118 if not tag in self.allParams and not tag in self.styles:
09f3d4e6 119 print 'WARNING: unknown parameter for %s: %s' % \
32ce09e2
RD
120 (self.className, tag)
121 elif tag in self.specials:
122 self.special(tag, node)
123 elif tag == 'content':
124 self.params[tag] = xxxParamContent(node)
125 elif tag == 'font': # has children
126 self.params[tag] = xxxParamFont(self, node)
09f3d4e6 127 else: # simple parameter
32ce09e2 128 self.params[tag] = xxxParam(node)
09f3d4e6
RD
129 else:
130 # Remove all other nodes
131 element.removeChild(node)
132 node.unlink()
09f3d4e6
RD
133 # Generate HTML
134 def generateHtml(self, prefix=''):
135 SetCurrentXXX(self)
a40b5e84 136 html = '<table cellspacing=0 cellpadding=0><tr><td width=120>\
09f3d4e6
RD
137<font size="+1"><b>%s</b></font></td>' % self.className
138 # Has id (name) attribute
139 if self.hasName:
140 html += """\
141<td><wxp module="xxx" class="ParamText" width=150>
a40b5e84 142<param name="name" value="data_name">
32ce09e2 143</wxp></td>"""
09f3d4e6
RD
144 html += '</table><p>'
145 html += '<table cellspacing=0 cellpadding=0>\n'
146 # Add required parameters
147 for param in self.allParams:
148 # Add checkbox or just text
149 if param in self.required:
a40b5e84 150 html += '<tr><td width=20></td><td width=100>%s: </td>' % param
09f3d4e6
RD
151 else: # optional parameter
152 html += """\
153<tr><td width=20><wxp class="wxCheckBox">
154<param name="id" value="%d">
155<param name="size" value="(20,-1)">
a40b5e84 156<param name="name" value="%s">
09f3d4e6 157<param name="label" value=("")>
a40b5e84
RD
158</wxp></td><td width=100>%s: </td>
159""" % (paramIDs[param], prefix + 'check_' + param, param)
09f3d4e6
RD
160 # Get parameter type
161 try:
162 # Local or overriden type
163 typeClass = self.paramDict[param].__name__
164 except KeyError:
165 try:
166 # Standart type
167 typeClass = paramDict[param].__name__
168 except KeyError:
169 # Default
170 typeClass = 'ParamText'
171 html += """\
172<td><wxp module="xxx" class="%s">
173<param name="id" value="%d">
a40b5e84 174<param name="name" value="%s">
09f3d4e6 175</wxp></td>
32ce09e2 176""" % (typeClass, -1, prefix + 'data_' + param)
09f3d4e6
RD
177 html += '</table>\n'
178 return html
179 # Returns real tree object
180 def treeObject(self):
181 if self.hasChild: return self.child
182 return self
183 # Returns tree image index
184 def treeImage(self):
185 if self.hasChild: return self.child.treeImage()
186 return self.image
187 # Class name plus wx name
188 def treeName(self):
189 if self.hasChild: return self.child.treeName()
190 if self.hasName and self.name: return self.className + ' "' + self.name + '"'
191 return self.className
192
193################################################################################
194
32ce09e2 195class xxxParamFont(xxxParam):
a40b5e84
RD
196 allParams = ['size', 'style', 'weight', 'family', 'underlined',
197 'face', 'encoding']
198 def __init__(self, parent, element):
199 xxxObject.__init__(self, parent, element)
200 self.parentNode = element # required to behave similar to DOM node
32ce09e2
RD
201 v = []
202 for p in self.allParams:
203 try:
204 v.append(str(self.params[p].data))
205 except KeyError:
206 v.append('')
207 self.data = v
208 def update(self, value):
a40b5e84
RD
209 # `value' is a list of strings corresponding to all parameters
210 elem = self.element
211 for node in elem.childNodes:
212 elem.removeChild(node)
213 i = 0
214 self.params.clear()
32ce09e2 215 v = []
a40b5e84
RD
216 for param in self.allParams:
217 if value[i]:
218 fontElem = tree.dom.createElement(param)
219 textNode = tree.dom.createTextNode(value[i])
220 self.params[param] = textNode
221 fontElem.appendChild(textNode)
222 elem.appendChild(fontElem)
32ce09e2 223 v.append(value[i])
a40b5e84 224 i += 1
32ce09e2 225 self.data = v
a40b5e84
RD
226
227################################################################################
228
09f3d4e6
RD
229class xxxContainer(xxxObject):
230 hasChildren = true
231
232################################################################################
233# Top-level windwos
234
235class xxxPanel(xxxContainer):
236 allParams = ['pos', 'size', 'style']
a40b5e84
RD
237 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
238 'tooltip']
32ce09e2 239 winStyles = ['wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
a40b5e84 240 exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
09f3d4e6
RD
241
242class xxxDialog(xxxContainer):
243 allParams = ['title', 'pos', 'size', 'style']
244 required = ['title']
32ce09e2
RD
245 winStyles = ['wxDEFAULT_DIALOG_STYLE', 'wxSTAY_ON_TOP',
246 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS',
247 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 'wxRESIZE_BOX',
248 'wxTHICK_FRAME',
249 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
a40b5e84
RD
250 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
251 'tooltip']
252 exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
09f3d4e6
RD
253
254class xxxFrame(xxxContainer):
255 allParams = ['title', 'centered', 'pos', 'size', 'style']
256 paramDict = {'centered': ParamBool}
257 required = ['title']
32ce09e2
RD
258 winStyles = ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE',
259 'wxSTAY_ON_TOP',
260 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
261 'wxRESIZE_BOX', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX',
262 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_TOOL_WINDOW',
263 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
a40b5e84
RD
264 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
265 'tooltip']
266 exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
09f3d4e6 267
32ce09e2
RD
268class xxxTool(xxxObject):
269 allParams = ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp']
270 paramDict = {'bitmap2': ParamFile}
271 hasStyle = false
272
273class xxxToolBar(xxxContainer):
274 allParams = ['bitmapsize', 'margins', 'packing', 'separation',
275 'pos', 'size', 'style']
276 hasStyle = false
277 paramDict = {'bitmapsize': ParamPosSize, 'margins': ParamPosSize,
278 'packing': ParamInt, 'separation': ParamInt,
279 'style': ParamNonGenericStyle}
280 winStyles = ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL']
281
282################################################################################
283# Bitmap, Icon
284
285class xxxBitmap(xxxObject):
286 allParams = ['bitmap']
287 required = ['bitmap']
288
289class xxxIcon(xxxObject):
290 allParams = ['icon']
291 required = ['icon']
292
09f3d4e6
RD
293################################################################################
294# Controls
295
296class xxxStaticText(xxxObject):
297 allParams = ['label', 'pos', 'size', 'style']
298 required = ['label']
a40b5e84 299 winStyles = ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
09f3d4e6
RD
300
301class xxxStaticLine(xxxObject):
302 allParams = ['pos', 'size', 'style']
a40b5e84 303 winStyles = ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
09f3d4e6 304
32ce09e2
RD
305class xxxStaticBitmap(xxxObject):
306 allParams = ['bitmap', 'pos', 'size', 'style']
307 required = ['bitmap']
308
09f3d4e6
RD
309class xxxTextCtrl(xxxObject):
310 allParams = ['value', 'pos', 'size', 'style']
a40b5e84 311 winStyles = ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
32ce09e2 312 'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
09f3d4e6
RD
313
314class xxxChoice(xxxObject):
315 allParams = ['content', 'selection', 'pos', 'size', 'style']
316 required = ['content']
32ce09e2 317 winStyles = ['wxCB_SORT']
09f3d4e6
RD
318
319class xxxSlider(xxxObject):
320 allParams = ['value', 'min', 'max', 'pos', 'size', 'style',
321 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
322 'selmin', 'selmax']
323 paramDict = {'value': ParamInt, 'tickfreq': ParamInt, 'pagesize': ParamInt,
324 'linesize': ParamInt, 'thumb': ParamInt, 'thumb': ParamInt,
325 'tick': ParamInt, 'selmin': ParamInt, 'selmax': ParamInt}
326 required = ['value', 'min', 'max']
a40b5e84 327 winStyles = ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
32ce09e2
RD
328 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
329 'wxSL_BOTH', 'wxSL_SELRANGE']
09f3d4e6
RD
330
331class xxxGauge(xxxObject):
332 allParams = ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
333 paramDict = {'range': ParamInt, 'value': ParamInt,
334 'shadow': ParamInt, 'bezel': ParamInt}
a40b5e84 335 winStyles = ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
09f3d4e6
RD
336
337class xxxScrollBar(xxxObject):
338 allParams = ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
339 paramDict = {'value': ParamInt, 'range': ParamInt, 'thumbsize': ParamInt,
340 'pagesize': ParamInt}
a40b5e84 341 winStyles = ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
09f3d4e6
RD
342
343class xxxListCtrl(xxxObject):
344 allParams = ['pos', 'size', 'style']
a40b5e84 345 winStyles = ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
09f3d4e6
RD
346 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
347 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
348 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
349
350# !!! temporary
351xxxCheckList = xxxListCtrl
352
353class xxxTreeCtrl(xxxObject):
354 allParams = ['pos', 'size', 'style']
a40b5e84 355 winStyles = ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT',
09f3d4e6
RD
356 'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE']
357
358class xxxHtmlWindow(xxxObject):
359 allParams = ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
360 paramDict = {'borders': ParamInt}
a40b5e84 361 winStyles = ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
09f3d4e6
RD
362
363class xxxCalendar(xxxObject):
364 allParams = ['pos', 'size', 'style']
365
366class xxxNotebook(xxxContainer):
367 allParams = ['usenotebooksizer', 'pos', 'size', 'style']
368 paramDict = {'usenotebooksizer': ParamBool}
a40b5e84 369 winStyles = ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM']
09f3d4e6
RD
370
371################################################################################
372# Buttons
373
374class xxxButton(xxxObject):
375 allParams = ['label', 'default', 'pos', 'size', 'style']
376 paramDict = {'default': ParamBool}
377 required = ['label']
a40b5e84 378 winStyles = ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
09f3d4e6
RD
379
380class xxxBitmapButton(xxxObject):
381 allParams = ['bitmap', 'selected', 'focus', 'disabled', 'default',
382 'pos', 'size', 'style']
383 required = ['bitmap']
32ce09e2
RD
384 winStyles = ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP',
385 'wxBU_RIGHT', 'wxBU_BOTTOM']
09f3d4e6
RD
386
387class xxxRadioButton(xxxObject):
388 allParams = ['label', 'value', 'pos', 'size', 'style']
389 paramDict = {'value': ParamBool}
390 required = ['label']
a40b5e84 391 winStyles = ['wxRB_GROUP']
09f3d4e6
RD
392
393class xxxSpinButton(xxxObject):
394 allParams = ['pos', 'size', 'style']
a40b5e84 395 winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
09f3d4e6
RD
396
397################################################################################
398# Boxes
399
400class xxxStaticBox(xxxObject):
401 allParams = ['label', 'pos', 'size', 'style']
402 required = ['label']
403
404class xxxRadioBox(xxxObject):
405 allParams = ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
406 paramDict = {'dimension': ParamInt}
407 required = ['label', 'content']
a40b5e84 408 winStyles = ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS']
09f3d4e6
RD
409
410class xxxCheckBox(xxxObject):
411 allParams = ['label', 'pos', 'size', 'style']
412 required = ['label']
413
414class xxxComboBox(xxxObject):
415 allParams = ['content', 'selection', 'value', 'pos', 'size', 'style']
416 required = ['content']
32ce09e2 417 winStyles = ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
09f3d4e6
RD
418
419class xxxListBox(xxxObject):
420 allParams = ['content', 'selection', 'pos', 'size', 'style']
421 required = ['content']
a40b5e84 422 winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
09f3d4e6
RD
423 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
424
425################################################################################
426# Sizers
427
428class xxxSizer(xxxContainer):
a40b5e84 429 hasName = hasStyle = false
09f3d4e6
RD
430 paramDict = {'orient': ParamOrient}
431 isSizer = true
432
433class xxxBoxSizer(xxxSizer):
434 allParams = ['orient']
435 required = ['orient']
436 default = {'orient': 'wxVERTICAL'}
437 # Tree icon depends on orientation
438 def treeImage(self):
32ce09e2 439 if self.params['orient'].value() == 'wxHORIZONTAL': return self.imageH
09f3d4e6
RD
440 else: return self.imageV
441
442class xxxStaticBoxSizer(xxxBoxSizer):
443 allParams = ['label', 'orient']
444 required = ['label', 'orient']
445 default = {'orient': 'wxVERTICAL'}
446
447class xxxGridSizer(xxxSizer):
448 allParams = ['cols', 'rows', 'vgap', 'hgap']
449 required = ['cols']
450 default = {'cols': '2', 'rows': '2'}
451
32ce09e2
RD
452# For repeated parameters
453class xxxParamMulti:
454 def __init__(self):
455 self.l, self.data = [], []
456 def append(self, param):
457 self.l.append(param)
458 self.data.append(param.value())
459 def value(self):
460 return self.data
461 def remove(self):
462 for param in self.l:
463 param.remove()
464 self.l, self.data = [], []
465
09f3d4e6 466class xxxFlexGridSizer(xxxGridSizer):
32ce09e2
RD
467 specials = ['growablecols', 'growablerows']
468 allParams = ['cols', 'rows', 'vgap', 'hgap'] + specials
469 paramDict = {'growablecols':ParamContent, 'growablerows':ParamContent}
470 # Special processing for growable* parameters
471 # (they are represented by several nodes)
472 def special(self, tag, node):
473 if tag not in self.params.keys():
474 self.params[tag] = xxxParamMulti()
475 self.params[tag].append(xxxParam(node))
476 def setSpecial(self, param, value):
477 # Straightforward implementation: remove, add again
478 self.params[param].remove()
479 del self.params[param]
480 for str in value:
481 node = tree.dom.createElement(param)
482 text = tree.dom.createTextNode(str)
483 node.appendChild(text)
484 self.element.appendChild(node)
485 self.special(param, node)
09f3d4e6
RD
486
487# Container with only one child.
488# Not shown in tree.
489class xxxChildContainer(xxxObject):
a40b5e84 490 hasName = hasStyle = false
09f3d4e6
RD
491 hasChild = true
492 def __init__(self, parent, element):
493 xxxObject.__init__(self, parent, element)
494 # Must have one child with 'object' tag, but we don't check it
495 nodes = element.childNodes[:] # create copy
496 for node in nodes:
497 if node.nodeType == minidom.Node.ELEMENT_NODE:
498 if node.tagName == 'object':
499 # Create new xxx object for child node
500 self.child = MakeXXXFromDOM(self, node)
501 self.child.parent = parent
502 # Copy hasChildren and isSizer attributes
503 self.hasChildren = self.child.hasChildren
504 self.isSizer = self.child.isSizer
505 return # success
506 else:
507 element.removeChild(node)
508 node.unlink()
509 assert 0, 'no child found'
510 def generateHtml(self):
511 return xxxObject.generateHtml(self, '_') + '<hr>\n' + \
512 self.child.generateHtml()
513
514class xxxSizerItem(xxxChildContainer):
515 allParams = ['option', 'flag', 'border']
516 paramDict = {'option': ParamInt}
517 def __init__(self, parent, element):
518 xxxChildContainer.__init__(self, parent, element)
519 # Remove pos parameter - unnecessary for sizeritems
520 if 'pos' in self.child.allParams:
521 self.child.allParams = self.child.allParams[:]
522 self.child.allParams.remove('pos')
523
524class xxxNotebookPage(xxxChildContainer):
525 allParams = ['label', 'selected']
526 paramDict = {'selected': ParamBool}
527 required = ['label']
528 def __init__(self, parent, element):
529 xxxChildContainer.__init__(self, parent, element)
530 # pos and size dont matter for notebookpages
531 if 'pos' in self.child.allParams:
532 self.child.allParams = self.child.allParams[:]
533 self.child.allParams.remove('pos')
534 if 'size' in self.child.allParams:
535 self.child.allParams = self.child.allParams[:]
536 self.child.allParams.remove('size')
537
538class xxxSpacer(xxxObject):
a40b5e84 539 hasName = hasStyle = false
09f3d4e6
RD
540 allParams = ['size', 'option', 'flag', 'border']
541 paramDict = {'option': ParamInt}
542 default = {'size': '0,0'}
543
544class xxxMenuBar(xxxContainer):
545 allParams = []
546
547class xxxMenu(xxxContainer):
548 allParams = ['label']
549 default = {'label': ''}
32ce09e2
RD
550 paramDict = {'style': ParamNonGenericStyle} # no generic styles
551 winStyles = ['wxMENU_TEAROFF']
09f3d4e6
RD
552
553class xxxMenuItem(xxxObject):
554 allParams = ['checkable', 'label', 'accel', 'help']
555 default = {'label': ''}
556
557class xxxSeparator(xxxObject):
a40b5e84 558 hasName = hasStyle = false
09f3d4e6
RD
559 allParams = []
560
a40b5e84
RD
561################################################################################
562
09f3d4e6
RD
563xxxDict = {
564 'wxPanel': xxxPanel,
565 'wxDialog': xxxDialog,
566 'wxFrame': xxxFrame,
32ce09e2
RD
567 'tool': xxxTool,
568 'wxToolBar': xxxToolBar,
09f3d4e6 569
32ce09e2
RD
570 'wxBitmap': xxxBitmap,
571 'wxIcon': xxxIcon,
572
09f3d4e6
RD
573 'wxButton': xxxButton,
574 'wxBitmapButton': xxxBitmapButton,
575 'wxRadioButton': xxxRadioButton,
576 'wxSpinButton': xxxSpinButton,
577
578 'wxStaticBox': xxxStaticBox,
32ce09e2 579 'wxStaticBitmap': xxxStaticBitmap,
09f3d4e6
RD
580 'wxRadioBox': xxxRadioBox,
581 'wxComboBox': xxxComboBox,
582 'wxCheckBox': xxxCheckBox,
583 'wxListBox': xxxListBox,
584
585 'wxStaticText': xxxStaticText,
586 'wxStaticLine': xxxStaticLine,
587 'wxTextCtrl': xxxTextCtrl,
588 'wxChoice': xxxChoice,
589 'wxSlider': xxxSlider,
590 'wxGauge': xxxGauge,
591 'wxScrollBar': xxxScrollBar,
592 'wxTreeCtrl': xxxTreeCtrl,
593 'wxListCtrl': xxxListCtrl,
594 'wxCheckList': xxxCheckList,
595 'wxNotebook': xxxNotebook,
596 'notebookpage': xxxNotebookPage,
597 'wxHtmlWindow': xxxHtmlWindow,
598 'wxCalendar': xxxCalendar,
599
600 'wxBoxSizer': xxxBoxSizer,
601 'wxStaticBoxSizer': xxxStaticBoxSizer,
602 'wxGridSizer': xxxGridSizer,
603 'wxFlexGridSizer': xxxFlexGridSizer,
604 'sizeritem': xxxSizerItem,
605 'spacer': xxxSpacer,
606
607 'wxMenuBar': xxxMenuBar,
608 'wxMenu': xxxMenu,
609 'wxMenuItem': xxxMenuItem,
610 'separator': xxxSeparator,
611 }
612
a40b5e84
RD
613# Create IDs for all parameters of all classes
614paramIDs = {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(),
615 'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(),
616 'tooltip': wxNewId()
617 }
618for cl in xxxDict.values():
619 for param in cl.allParams + cl.paramDict.keys():
620 if not paramIDs.has_key(param):
621 paramIDs[param] = wxNewId()
622
623################################################################################
09f3d4e6
RD
624# Helper functions
625
626# Test for object elements
627def IsObject(node):
628 return node.nodeType == minidom.Node.ELEMENT_NODE and node.tagName == 'object'
629
630# Make XXX object from some DOM object, selecting correct class
631def MakeXXXFromDOM(parent, element):
32ce09e2
RD
632 try:
633 return xxxDict[element.getAttribute('class')](parent, element)
634 except KeyError:
635 # Verify that it's not recursive exception
636 if element.getAttribute('class') not in xxxDict.keys():
637 print 'ERROR: unknown class:', element.getAttribute('class')
638 raise
09f3d4e6
RD
639
640# Make empty DOM element
641def MakeEmptyDOM(className):
642 elem = tree.dom.createElement('object')
643 elem.setAttribute('class', className)
644 # Set required and default parameters
645 xxxClass = xxxDict[className]
646 defaultNotRequired = filter(lambda x, l=xxxClass.required: x not in l,
647 xxxClass.default.keys())
648 for param in xxxClass.required + defaultNotRequired:
649 textElem = tree.dom.createElement(param)
650 try:
651 textNode = tree.dom.createTextNode(xxxClass.default[param])
652 except KeyError:
653 textNode = tree.dom.createTextNode('')
654 textElem.appendChild(textNode)
655 elem.appendChild(textElem)
656 return elem
657
658# Make empty XXX object
659def MakeEmptyXXX(parent, className):
660 # Make corresponding DOM object first
661 elem = MakeEmptyDOM(className)
662 # If parent is a sizer, we should create sizeritem object, except for spacers
663 if parent:
664 if parent.isSizer and className != 'spacer':
665 sizerItemElem = MakeEmptyDOM('sizeritem')
666 sizerItemElem.appendChild(elem)
667 elem = sizerItemElem
668 elif isinstance(parent, xxxNotebook):
669 pageElem = MakeEmptyDOM('notebookpage')
670 pageElem.appendChild(elem)
671 elem = pageElem
672 # Now just make object
673 return MakeXXXFromDOM(parent, elem)
674