]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/tools/XRCed/xxx.py
moved custom menu up
[wxWidgets.git] / wxPython / wx / 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 xml.dom import minidom
8 from globals import *
9 from params import *
10 import traceback, types
11
12 # Base class for interface parameter classes
13 class xxxNode:
14 def __init__(self, node):
15 self.node = node
16 def remove(self):
17 self.node.parentNode.removeChild(self.node)
18 self.node.unlink()
19
20 # Generic (text) parameter class
21 class xxxParam(xxxNode):
22 # Standard use: for text nodes
23 def __init__(self, node):
24 xxxNode.__init__(self, node)
25 if not node.hasChildNodes():
26 # If does not have child nodes, create empty text node
27 text = g.tree.dom.createTextNode('')
28 node.appendChild(text)
29 else:
30 text = node.childNodes[0] # first child must be text node
31 assert text.nodeType == minidom.Node.TEXT_NODE
32 # Append other text nodes if present and delete them
33 extraText = ''
34 for n in node.childNodes[1:]:
35 if n.nodeType == minidom.Node.TEXT_NODE:
36 extraText += n.data
37 node.removeChild(n)
38 n.unlink()
39 else: break
40 if extraText: text.data = text.data + extraText
41 # Use convertion from unicode to current encoding
42 self.textNode = text
43 # Value returns string
44 if wx.USE_UNICODE: # no conversion is needed
45 def value(self):
46 return self.textNode.data
47 def update(self, value):
48 self.textNode.data = value
49 else:
50 def value(self):
51 try:
52 return self.textNode.data.encode(g.currentEncoding)
53 except LookupError:
54 return self.textNode.data.encode()
55 def update(self, value):
56 try: # handle exception if encoding is wrong
57 self.textNode.data = unicode(value, g.currentEncoding)
58 except UnicodeDecodeError:
59 self.textNode.data = unicode(value)
60 #wx.LogMessage("Unicode error: set encoding in file\nglobals.py to something appropriate")
61
62 # Integer parameter
63 class xxxParamInt(xxxParam):
64 # Standard use: for text nodes
65 def __init__(self, node):
66 xxxParam.__init__(self, node)
67 # Value returns string
68 def value(self):
69 try:
70 return int(self.textNode.data)
71 except ValueError:
72 return -1 # invalid value
73 def update(self, value):
74 self.textNode.data = str(value)
75
76 # Content parameter
77 class xxxParamContent(xxxNode):
78 def __init__(self, node):
79 xxxNode.__init__(self, node)
80 data, l = [], [] # data is needed to quicker value retrieval
81 nodes = node.childNodes[:] # make a copy of the child list
82 for n in nodes:
83 if n.nodeType == minidom.Node.ELEMENT_NODE:
84 assert n.tagName == 'item', 'bad content content'
85 if not n.hasChildNodes():
86 # If does not have child nodes, create empty text node
87 text = g.tree.dom.createTextNode('')
88 node.appendChild(text)
89 else:
90 # !!! normalize?
91 text = n.childNodes[0] # first child must be text node
92 assert text.nodeType == minidom.Node.TEXT_NODE
93 l.append(text)
94 data.append(text.data)
95 else: # remove other
96 node.removeChild(n)
97 n.unlink()
98 self.l, self.data = l, data
99 def value(self):
100 return self.data
101 def update(self, value):
102 # If number if items is not the same, recreate children
103 if len(value) != len(self.l): # remove first if number of items has changed
104 childNodes = self.node.childNodes[:]
105 for n in childNodes:
106 self.node.removeChild(n)
107 l = []
108 for str in value:
109 itemElem = g.tree.dom.createElement('item')
110 itemText = g.tree.dom.createTextNode(str)
111 itemElem.appendChild(itemText)
112 self.node.appendChild(itemElem)
113 l.append(itemText)
114 self.l = l
115 else:
116 for i in range(len(value)):
117 self.l[i].data = value[i]
118 self.data = value
119
120 # Content parameter for checklist
121 class xxxParamContentCheckList(xxxNode):
122 def __init__(self, node):
123 xxxNode.__init__(self, node)
124 data, l = [], [] # data is needed to quicker value retrieval
125 nodes = node.childNodes[:] # make a copy of the child list
126 for n in nodes:
127 if n.nodeType == minidom.Node.ELEMENT_NODE:
128 assert n.tagName == 'item', 'bad content content'
129 checked = n.getAttribute('checked')
130 if not checked: checked = 0
131 if not n.hasChildNodes():
132 # If does not have child nodes, create empty text node
133 text = g.tree.dom.createTextNode('')
134 node.appendChild(text)
135 else:
136 # !!! normalize?
137 text = n.childNodes[0] # first child must be text node
138 assert text.nodeType == minidom.Node.TEXT_NODE
139 l.append((text, n))
140 data.append((str(text.data), int(checked)))
141 else: # remove other
142 node.removeChild(n)
143 n.unlink()
144 self.l, self.data = l, data
145 def value(self):
146 return self.data
147 def update(self, value):
148 # If number if items is not the same, recreate children
149 if len(value) != len(self.l): # remove first if number of items has changed
150 childNodes = self.node.childNodes[:]
151 for n in childNodes:
152 self.node.removeChild(n)
153 l = []
154 for s,ch in value:
155 itemElem = g.tree.dom.createElement('item')
156 # Add checked only if True
157 if ch: itemElem.setAttribute('checked', '1')
158 itemText = g.tree.dom.createTextNode(s)
159 itemElem.appendChild(itemText)
160 self.node.appendChild(itemElem)
161 l.append((itemText, itemElem))
162 self.l = l
163 else:
164 for i in range(len(value)):
165 self.l[i][0].data = value[i][0]
166 self.l[i][1].setAttribute('checked', str(value[i][1]))
167 self.data = value
168
169 # Bitmap parameter
170 class xxxParamBitmap(xxxParam):
171 def __init__(self, node):
172 xxxParam.__init__(self, node)
173 self.stock_id = node.getAttribute('stock_id')
174 def value(self):
175 return [self.stock_id, xxxParam.value(self)]
176 def update(self, value):
177 self.stock_id = value[0]
178 if self.stock_id:
179 self.node.setAttribute('stock_id', self.stock_id)
180 elif self.node.hasAttribute('stock_id'):
181 self.node.removeAttribute('stock_id')
182 xxxParam.update(self, value[1])
183
184 ################################################################################
185
186 # Classes to interface DOM objects
187 class xxxObject:
188 # Default behavior
189 hasChildren = False # has children elements?
190 hasStyle = True # almost everyone
191 hasName = True # has name attribute?
192 isSizer = hasChild = False
193 isElement = True
194 allParams = None # Some nodes have no parameters
195 # Style parameters (all optional)
196 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip']
197 # Special parameters
198 specials = []
199 # Bitmap tags
200 bitmapTags = ['bitmap', 'bitmap2', 'icon']
201 # Required paremeters: none by default
202 required = []
203 # Default parameters with default values
204 default = {}
205 # Parameter types
206 paramDict = {}
207 # Window styles and extended styles
208 winStyles = []
209 # Tree icon index
210 #image = -1
211 # Construct a new xxx object from DOM element
212 # parent is parent xxx object (or None if none), element is DOM element object
213 def __init__(self, parent, element, refElem=None):
214 self.parent = parent
215 self.node = element
216 self.refElem = refElem
217 self.undo = None
218 # Reference are dereferenced
219 if element.tagName == 'object_ref':
220 # Find original object
221 self.ref = element.getAttribute('ref')
222 if refElem:
223 self.className = self.refElem.getAttribute('class')
224 else:
225 self.className = 'xxxUnknown'
226 self.required = []
227 else:
228 # Get attributes
229 self.ref = None
230 self.className = element.getAttribute('class')
231 self.subclass = element.getAttribute('subclass')
232 if self.hasName: self.name = element.getAttribute('name')
233 # Set parameters (text element children)
234 self.params = {}
235 for n in element.childNodes[:]:
236 if n.nodeType == minidom.Node.ELEMENT_NODE:
237 tag = n.tagName
238 if tag in ['object', 'object_ref']:
239 continue # do nothing for object children here
240 elif tag not in self.allParams and tag not in self.styles:
241 print 'WARNING: unknown parameter for %s: %s' % \
242 (self.className, tag)
243 elif tag in self.specials:
244 self.special(tag, n)
245 elif tag == 'content':
246 if self.className == 'wxCheckListBox':
247 self.params[tag] = xxxParamContentCheckList(n)
248 else:
249 self.params[tag] = xxxParamContent(n)
250 elif tag == 'font': # has children
251 self.params[tag] = xxxParamFont(element, n)
252 elif tag in self.bitmapTags:
253 # Can have attributes
254 self.params[tag] = xxxParamBitmap(n)
255 else: # simple parameter
256 self.params[tag] = xxxParam(n)
257 elif n.nodeType == minidom.Node.TEXT_NODE and n.data.isspace():
258 # Remove empty text nodes
259 element.removeChild(n)
260 n.unlink()
261
262 # Check that all required params are set
263 for param in self.required:
264 if not self.params.has_key(param):
265 # If default is specified, set it
266 if self.default.has_key(param):
267 elem = g.tree.dom.createElement(param)
268 if param == 'content':
269 if self.className == 'wxCheckListBox':
270 self.params[param] = xxxParamContentCheckList(elem)
271 else:
272 self.params[param] = xxxParamContent(elem)
273 else:
274 self.params[param] = xxxParam(elem)
275 # Find place to put new element: first present element after param
276 found = False
277 paramStyles = self.allParams + self.styles
278 for p in paramStyles[paramStyles.index(param) + 1:]:
279 # Content params don't have same type
280 if self.params.has_key(p) and p != 'content':
281 found = True
282 break
283 if found:
284 nextTextElem = self.params[p].node
285 self.node.insertBefore(elem, nextTextElem)
286 else:
287 self.node.appendChild(elem)
288 else:
289 wx.LogWarning('Required parameter %s of %s missing' %
290 (param, self.className))
291 # Returns real tree object
292 def treeObject(self):
293 if self.hasChild: return self.child
294 return self
295 # Returns tree image index
296 def treeImage(self):
297 if self.hasChild: return self.child.treeImage()
298 return self.image
299 # Class name plus wx name
300 def treeName(self):
301 if self.hasChild: return self.child.treeName()
302 if self.subclass: className = self.subclass
303 else: className = self.className
304 if self.hasName and self.name: return className + ' "' + self.name + '"'
305 return className
306 # Class name or subclass
307 def panelName(self):
308 if self.subclass: name = self.subclass + '(' + self.className + ')'
309 name = self.className
310 if self.ref: name = 'ref: ' + self.ref + ', ' + name
311 return name
312 # Sets name of tree object
313 def setTreeName(self, name):
314 if self.hasChild: obj = self.child
315 else: obj = self
316 obj.name = name
317 obj.node.setAttribute('name', name)
318 # Special processing for growablecols-like parameters
319 # represented by several nodes
320 def special(self, tag, node):
321 if not self.params.has_key(tag):
322 # Create new multi-group
323 self.params[tag] = xxxParamMulti(node)
324 self.params[tag].append(xxxParamInt(node))
325 def setSpecial(self, param, value):
326 # Straightforward implementation: remove, add again
327 self.params[param].remove()
328 del self.params[param]
329 for i in value:
330 node = g.tree.dom.createElement(param)
331 text = g.tree.dom.createTextNode(str(i))
332 node.appendChild(text)
333 self.node.appendChild(node)
334 self.special(param, node)
335
336 # Imitation of FindResource/DoFindResource from xmlres.cpp
337 def DoFindResource(parent, name, classname, recursive):
338 for n in parent.childNodes:
339 if n.nodeType == minidom.Node.ELEMENT_NODE and \
340 n.tagName in ['object', 'object_ref'] and \
341 n.getAttribute('name') == name:
342 cls = n.getAttribute('class')
343 if not classname or cls == classname: return n
344 if not cls or n.tagName == 'object_ref':
345 refName = n.getAttribute('ref')
346 if not refName: continue
347 refNode = FindResource(refName)
348 if refName and refNode.getAttribute('class') == classname:
349 return n
350 if recursive:
351 for n in parent.childNodes:
352 if n.nodeType == minidom.Node.ELEMENT_NODE and \
353 n.tagName in ['object', 'object_ref']:
354 found = DoFindResource(n, name, classname, True)
355 if found: return found
356 def FindResource(name, classname='', recursive=True):
357 found = DoFindResource(g.tree.mainNode, name, classname, recursive)
358 if found: return found
359 wx.LogError('XRC resource "%s" not found!' % name)
360
361
362 ################################################################################
363
364 # This is a little special: it is both xxxObject and xxxNode
365 class xxxParamFont(xxxObject, xxxNode):
366 allParams = ['size', 'family', 'style', 'weight', 'underlined',
367 'face', 'encoding']
368 def __init__(self, parent, element):
369 xxxObject.__init__(self, parent, element)
370 xxxNode.__init__(self, element)
371 self.parentNode = parent # required to behave similar to DOM node
372 v = []
373 for p in self.allParams:
374 try:
375 v.append(str(self.params[p].value()))
376 except KeyError:
377 v.append('')
378 self.data = v
379 def update(self, value):
380 # `value' is a list of strings corresponding to all parameters
381 elem = self.node
382 # Remove old elements first
383 childNodes = elem.childNodes[:]
384 for node in childNodes: elem.removeChild(node)
385 i = 0
386 self.params.clear()
387 v = []
388 for param in self.allParams:
389 if value[i]:
390 fontElem = g.tree.dom.createElement(param)
391 textNode = g.tree.dom.createTextNode(value[i])
392 self.params[param] = textNode
393 fontElem.appendChild(textNode)
394 elem.appendChild(fontElem)
395 v.append(value[i])
396 i += 1
397 self.data = v
398 def value(self):
399 return self.data
400
401 ################################################################################
402
403 class xxxContainer(xxxObject):
404 hasChildren = True
405 exStyles = []
406
407 # Simulate normal parameter for encoding
408 class xxxEncoding:
409 def value(self):
410 return g.currentEncoding
411 def update(self, val):
412 g.currentEncoding = val
413
414 # Special class for root node
415 class xxxMainNode(xxxContainer):
416 allParams = ['encoding']
417 hasStyle = hasName = False
418 def __init__(self, dom):
419 xxxContainer.__init__(self, None, dom.documentElement)
420 self.className = 'XML tree'
421 # Reset required parameters after processing XML, because encoding is
422 # a little special
423 self.required = ['encoding']
424 self.params['encoding'] = xxxEncoding()
425
426 ################################################################################
427 # Top-level windwows
428
429 class xxxPanel(xxxContainer):
430 allParams = ['pos', 'size', 'style']
431 winStyles = ['wxNO_3D', 'wxTAB_TRAVERSAL']
432 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
433 'tooltip']
434
435 class xxxDialog(xxxContainer):
436 allParams = ['title', 'centered', 'pos', 'size', 'style']
437 paramDict = {'centered': ParamBool}
438 required = ['title']
439 default = {'title': ''}
440 winStyles = ['wxDEFAULT_DIALOG_STYLE', 'wxCAPTION',
441 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxTHICK_FRAME',
442 'wxRESIZE_BORDER', 'wxRESIZE_BOX', 'wxCLOSE_BOX',
443 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX',
444 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS', 'wxDIALOG_NO_PARENT'
445 'wxNO_3D', 'wxTAB_TRAVERSAL']
446 exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY', 'wxDIALOG_EX_METAL']
447 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
448 'tooltip']
449
450 class xxxFrame(xxxContainer):
451 allParams = ['title', 'centered', 'pos', 'size', 'style']
452 paramDict = {'centered': ParamBool}
453 required = ['title']
454 default = {'title': ''}
455 winStyles = ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE', 'wxCAPTION',
456 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxTHICK_FRAME',
457 'wxRESIZE_BORDER', 'wxRESIZE_BOX', 'wxCLOSE_BOX',
458 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX',
459 'wxFRAME_NO_TASKBAR', 'wxFRAME_SHAPED', 'wxFRAME_TOOL_WINDOW',
460 'wxFRAME_FLOAT_ON_PARENT',
461 'wxNO_3D', 'wxTAB_TRAVERSAL']
462 exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY', 'wxFRAME_EX_METAL']
463 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
464 'tooltip']
465
466 class xxxTool(xxxObject):
467 allParams = ['bitmap', 'bitmap2', 'radio', 'toggle', 'tooltip', 'longhelp', 'label']
468 required = ['bitmap']
469 paramDict = {'bitmap2': ParamBitmap, 'radio': ParamBool, 'toggle': ParamBool}
470 hasStyle = False
471
472 class xxxToolBar(xxxContainer):
473 allParams = ['bitmapsize', 'margins', 'packing', 'separation', 'dontattachtoframe',
474 'pos', 'size', 'style']
475 hasStyle = False
476 paramDict = {'bitmapsize': ParamPosSize, 'margins': ParamPosSize,
477 'packing': ParamUnit, 'separation': ParamUnit,
478 'dontattachtoframe': ParamBool, 'style': ParamNonGenericStyle}
479 winStyles = ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL',
480 'wxTB_3DBUTTONS','wxTB_TEXT', 'wxTB_NOICONS', 'wxTB_NODIVIDER',
481 'wxTB_NOALIGN', 'wxTB_HORZ_LAYOUT', 'wxTB_HORZ_TEXT']
482
483 class xxxStatusBar(xxxObject):
484 hasStyle = False
485 allParams = ['fields', 'widths', 'styles', 'style']
486 paramDict = {'fields': ParamIntNN, 'widths': ParamText, 'styles': ParamText,
487 'style': ParamNonGenericStyle}
488 winStyles = ['wxST_SIZEGRIP']
489
490 class xxxWizard(xxxContainer):
491 allParams = ['title', 'bitmap', 'pos']
492 required = ['title']
493 default = {'title': ''}
494 winStyles = []
495 exStyles = ['wxWIZARD_EX_HELPBUTTON']
496 styles = ['fg', 'bg', 'font', 'exstyle']
497
498 class xxxWizardPage(xxxContainer):
499 allParams = ['bitmap']
500 winStyles = []
501 exStyles = []
502
503 class xxxWizardPageSimple(xxxContainer):
504 allParams = ['bitmap']
505 winStyles = []
506 exStyles = []
507
508 ################################################################################
509 # Bitmap, Icon
510
511 class xxxBitmap(xxxObject):
512 allParams = ['bitmap']
513 required = ['bitmap']
514
515 # Just like bitmap
516 class xxxIcon(xxxObject):
517 allParams = []
518
519 ################################################################################
520 # Controls
521
522 class xxxStaticText(xxxObject):
523 allParams = ['label', 'pos', 'size', 'style']
524 required = ['label']
525 default = {'label': ''}
526 winStyles = ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
527
528 class xxxStaticLine(xxxObject):
529 allParams = ['pos', 'size', 'style']
530 winStyles = ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
531
532 class xxxStaticBitmap(xxxObject):
533 allParams = ['bitmap', 'pos', 'size', 'style']
534 required = ['bitmap']
535
536 class xxxTextCtrl(xxxObject):
537 allParams = ['value', 'pos', 'size', 'style']
538 winStyles = ['wxTE_NO_VSCROLL',
539 'wxTE_AUTO_SCROLL',
540 'wxTE_PROCESS_ENTER',
541 'wxTE_PROCESS_TAB',
542 'wxTE_MULTILINE',
543 'wxTE_PASSWORD',
544 'wxTE_READONLY',
545 'wxHSCROLL',
546 'wxTE_RICH',
547 'wxTE_RICH2',
548 'wxTE_AUTO_URL',
549 'wxTE_NOHIDESEL',
550 'wxTE_LEFT',
551 'wxTE_CENTRE',
552 'wxTE_RIGHT',
553 'wxTE_DONTWRAP',
554 'wxTE_LINEWRAP',
555 'wxTE_WORDWRAP']
556 paramDict = {'value': ParamMultilineText}
557
558 class xxxChoice(xxxObject):
559 allParams = ['content', 'selection', 'pos', 'size', 'style']
560 required = ['content']
561 default = {'content': '[]'}
562 winStyles = ['wxCB_SORT']
563
564 class xxxSlider(xxxObject):
565 allParams = ['value', 'min', 'max', 'pos', 'size', 'style',
566 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
567 'selmin', 'selmax']
568 paramDict = {'value': ParamInt, 'tickfreq': ParamIntNN, 'pagesize': ParamIntNN,
569 'linesize': ParamIntNN, 'thumb': ParamUnit,
570 'tick': ParamInt, 'selmin': ParamInt, 'selmax': ParamInt}
571 required = ['value', 'min', 'max']
572 winStyles = ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
573 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
574 'wxSL_BOTH', 'wxSL_SELRANGE', 'wxSL_INVERSE']
575
576 class xxxGauge(xxxObject):
577 allParams = ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
578 paramDict = {'range': ParamIntNN, 'value': ParamIntNN,
579 'shadow': ParamIntNN, 'bezel': ParamIntNN}
580 winStyles = ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
581
582 class xxxScrollBar(xxxObject):
583 allParams = ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
584 paramDict = {'value': ParamIntNN, 'range': ParamIntNN, 'thumbsize': ParamIntNN,
585 'pagesize': ParamIntNN}
586 winStyles = ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
587
588 class xxxListCtrl(xxxObject):
589 allParams = ['pos', 'size', 'style']
590 winStyles = ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
591 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
592 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
593 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING',
594 'wxLC_VIRTUAL', 'wxLC_HRULES', 'wxLC_VRULES', 'wxLC_NO_SORT_HEADER']
595
596 class xxxTreeCtrl(xxxObject):
597 allParams = ['pos', 'size', 'style']
598 winStyles = ['wxTR_EDIT_LABELS',
599 'wxTR_NO_BUTTONS',
600 'wxTR_HAS_BUTTONS',
601 'wxTR_TWIST_BUTTONS',
602 'wxTR_NO_LINES',
603 'wxTR_FULL_ROW_HIGHLIGHT',
604 'wxTR_LINES_AT_ROOT',
605 'wxTR_HIDE_ROOT',
606 'wxTR_ROW_LINES',
607 'wxTR_HAS_VARIABLE_ROW_HEIGHT',
608 'wxTR_SINGLE',
609 'wxTR_MULTIPLE',
610 'wxTR_EXTENDED',
611 'wxTR_DEFAULT_STYLE']
612
613 class xxxHtmlWindow(xxxObject):
614 allParams = ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
615 paramDict = {'htmlcode':ParamMultilineText}
616 winStyles = ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO', 'wxHW_NO_SELECTION']
617
618 class xxxCalendarCtrl(xxxObject):
619 allParams = ['pos', 'size', 'style']
620 winStyles = ['wxCAL_SUNDAY_FIRST', 'wxCAL_MONDAY_FIRST', 'wxCAL_SHOW_HOLIDAYS',
621 'wxCAL_NO_YEAR_CHANGE', 'wxCAL_NO_MONTH_CHANGE',
622 'wxCAL_SEQUENTIAL_MONTH_SELECTION', 'wxCAL_SHOW_SURROUNDING_WEEKS']
623
624 class xxxNotebook(xxxContainer):
625 allParams = ['pos', 'size', 'style']
626 winStyles = ['wxNB_TOP', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM',
627 'wxNB_FIXEDWIDTH', 'wxNB_MULTILINE', 'wxNB_NOPAGETHEME', 'wxNB_FLAT']
628
629 class xxxChoicebook(xxxContainer):
630 allParams = ['pos', 'size', 'style']
631 winStyles = ['wxCHB_DEFAULT', 'wxCHB_LEFT', 'wxCHB_RIGHT', 'wxCHB_TOP', 'wxCHB_BOTTOM']
632
633 class xxxListbook(xxxContainer):
634 allParams = ['pos', 'size', 'style']
635 winStyles = ['wxLB_DEFAULT', 'wxLB_LEFT', 'wxLB_RIGHT', 'wxLB_TOP', 'wxLB_BOTTOM']
636
637 class xxxSplitterWindow(xxxContainer):
638 allParams = ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style']
639 paramDict = {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit }
640 winStyles = ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER',
641 'wxSP_FULLSASH', 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE',
642 'wxSP_NO_XP_THEME' ]
643
644 class xxxGenericDirCtrl(xxxObject):
645 allParams = ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style']
646 paramDict = {'defaultfilter': ParamIntNN}
647 winStyles = ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
648 'wxDIRCTRL_SHOW_FILTERS']
649
650 class xxxScrolledWindow(xxxContainer):
651 allParams = ['pos', 'size', 'style']
652 winStyles = ['wxHSCROLL', 'wxVSCROLL', 'wxNO_3D', 'wxTAB_TRAVERSAL']
653
654 class xxxDateCtrl(xxxObject):
655 allParams = ['pos', 'size', 'style', 'borders']
656 winStyles = ['wxDP_DEFAULT', 'wxDP_SPIN', 'wxDP_DROPDOWN',
657 'wxDP_ALLOWNONE', 'wxDP_SHOWCENTURY']
658
659 class xxxGrid(xxxObject):
660 allParams = ['pos', 'size', 'style']
661
662 class xxxFilePickerCtrl(xxxObject):
663 allParams = ['value', 'message', 'wildcard', 'pos', 'size', 'style']
664 winStyles = ['wxFLP_OPEN', 'wxFLP_SAVE', 'wxFLP_OVERWRITE_PROMPT',
665 'wxFLP_FILE_MUST_EXIST', 'wxFLP_CHANGE_DIR',
666 'wxFLP_DEFAULT_STYLE']
667
668
669 ################################################################################
670 # Buttons
671
672 class xxxButton(xxxObject):
673 allParams = ['label', 'default', 'pos', 'size', 'style']
674 paramDict = {'default': ParamBool}
675 required = ['label']
676 winStyles = ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM', 'wxBU_EXACTFIT',
677 'wxNO_BORDER']
678
679 class xxxBitmapButton(xxxObject):
680 allParams = ['bitmap', 'selected', 'focus', 'disabled', 'default',
681 'pos', 'size', 'style']
682 paramDict = {'selected': ParamBitmap, 'focus': ParamBitmap, 'disabled': ParamBitmap,
683 'default': ParamBool}
684 required = ['bitmap']
685 winStyles = ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_RIGHT',
686 'wxBU_TOP', 'wxBU_BOTTOM']
687
688 class xxxRadioButton(xxxObject):
689 allParams = ['label', 'value', 'pos', 'size', 'style']
690 paramDict = {'value': ParamBool}
691 required = ['label']
692 winStyles = ['wxRB_GROUP', 'wxRB_SINGLE']
693
694 class xxxSpinButton(xxxObject):
695 allParams = ['value', 'min', 'max', 'pos', 'size', 'style']
696 paramDict = {'value': ParamInt}
697 winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
698
699 class xxxSpinCtrl(xxxObject):
700 allParams = ['value', 'min', 'max', 'pos', 'size', 'style']
701 paramDict = {'value': ParamInt}
702 winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
703
704 class xxxToggleButton(xxxObject):
705 allParams = ['label', 'checked', 'pos', 'size', 'style']
706 paramDict = {'checked': ParamBool}
707 required = ['label']
708
709 ################################################################################
710 # Boxes
711
712 class xxxStaticBox(xxxObject):
713 allParams = ['label', 'pos', 'size', 'style']
714 required = ['label']
715
716 class xxxRadioBox(xxxObject):
717 allParams = ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
718 paramDict = {'dimension': ParamIntNN}
719 required = ['label', 'content']
720 default = {'content': '[]'}
721 winStyles = ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS', 'wxRA_HORIZONTAL',
722 'wxRA_VERTICAL']
723
724 class xxxCheckBox(xxxObject):
725 allParams = ['label', 'checked', 'pos', 'size', 'style']
726 paramDict = {'checked': ParamBool}
727 winStyles = ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER',
728 'wxALIGN_RIGHT']
729 required = ['label']
730
731 class xxxComboBox(xxxObject):
732 allParams = ['content', 'selection', 'value', 'pos', 'size', 'style']
733 required = ['content']
734 default = {'content': '[]'}
735 winStyles = ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
736
737 class xxxListBox(xxxObject):
738 allParams = ['content', 'selection', 'pos', 'size', 'style']
739 required = ['content']
740 default = {'content': '[]'}
741 winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
742 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
743
744 class xxxCheckList(xxxObject):
745 allParams = ['content', 'pos', 'size', 'style']
746 required = ['content']
747 default = {'content': '[]'}
748 winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
749 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
750 paramDict = {'content': ParamContentCheckList}
751
752 ################################################################################
753 # Sizers
754
755 class xxxSizer(xxxContainer):
756 hasName = hasStyle = False
757 paramDict = {'orient': ParamOrient}
758 isSizer = True
759 itemTag = 'sizeritem' # different for some sizers
760
761 class xxxBoxSizer(xxxSizer):
762 allParams = ['orient']
763 required = ['orient']
764 default = {'orient': 'wxVERTICAL'}
765 # Tree icon depends on orientation
766 def treeImage(self):
767 if self.params['orient'].value() == 'wxHORIZONTAL': return self.imageH
768 else: return self.imageV
769
770 class xxxStaticBoxSizer(xxxBoxSizer):
771 allParams = ['label', 'orient']
772 required = ['label', 'orient']
773
774 class xxxGridSizer(xxxSizer):
775 allParams = ['cols', 'rows', 'vgap', 'hgap']
776 required = ['cols']
777 default = {'cols': '2', 'rows': '2'}
778
779 class xxxStdDialogButtonSizer(xxxSizer):
780 allParams = []
781 itemTag = 'button'
782
783 # For repeated parameters
784 class xxxParamMulti:
785 def __init__(self, node):
786 self.node = node
787 self.l, self.data = [], []
788 def append(self, param):
789 self.l.append(param)
790 self.data.append(param.value())
791 def value(self):
792 return self.data
793 def remove(self):
794 for param in self.l:
795 param.remove()
796 self.l, self.data = [], []
797
798 class xxxFlexGridSizer(xxxGridSizer):
799 specials = ['growablecols', 'growablerows']
800 allParams = ['cols', 'rows', 'vgap', 'hgap'] + specials
801 paramDict = {'growablecols': ParamIntList, 'growablerows': ParamIntList}
802
803 class xxxGridBagSizer(xxxSizer):
804 specials = ['growablecols', 'growablerows']
805 allParams = ['vgap', 'hgap'] + specials
806 paramDict = {'growablecols': ParamIntList, 'growablerows': ParamIntList}
807
808 # Container with only one child.
809 # Not shown in tree.
810 class xxxChildContainer(xxxObject):
811 hasName = hasStyle = False
812 hasChild = True
813 def __init__(self, parent, element, refElem=None):
814 xxxObject.__init__(self, parent, element, refElem)
815 # Must have one child with 'object' tag, but we don't check it
816 nodes = element.childNodes[:] # create copy
817 for node in nodes:
818 if node.nodeType == minidom.Node.ELEMENT_NODE:
819 if node.tagName in ['object', 'object_ref']:
820 # Create new xxx object for child node
821 self.child = MakeXXXFromDOM(self, node)
822 self.child.parent = parent
823 # Copy hasChildren and isSizer attributes
824 self.hasChildren = self.child.hasChildren
825 self.isSizer = self.child.isSizer
826 return # success
827 else:
828 element.removeChild(node)
829 node.unlink()
830 assert 0, 'no child found'
831 def resetChild(self, xxx):
832 '''Reset child info (for replacing with another class).'''
833 self.child = xxx
834 self.hasChildren = xxx.hasChildren
835 self.isSizer = xxx.isSizer
836
837 class xxxSizerItem(xxxChildContainer):
838 allParams = ['option', 'flag', 'border', 'minsize', 'ratio']
839 paramDict = {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
840 #default = {'cellspan': '1,1'}
841 def __init__(self, parent, element, refElem=None):
842 # For GridBag sizer items, extra parameters added
843 if isinstance(parent, xxxGridBagSizer):
844 self.allParams = self.allParams + ['cellpos', 'cellspan']
845 xxxChildContainer.__init__(self, parent, element, refElem)
846 # Remove pos parameter - not needed for sizeritems
847 if 'pos' in self.child.allParams:
848 self.child.allParams = self.child.allParams[:]
849 self.child.allParams.remove('pos')
850 def resetChild(self, xxx):
851 xxxChildContainer.resetChild(self, xxx)
852 # Remove pos parameter - not needed for sizeritems
853 if 'pos' in self.child.allParams:
854 self.child.allParams = self.child.allParams[:]
855 self.child.allParams.remove('pos')
856
857 class xxxSizerItemButton(xxxSizerItem):
858 allParams = []
859 paramDict = {}
860 def __init__(self, parent, element, refElem=None):
861 xxxChildContainer.__init__(self, parent, element, refElem=None)
862 # Remove pos parameter - not needed for sizeritems
863 if 'pos' in self.child.allParams:
864 self.child.allParams = self.child.allParams[:]
865 self.child.allParams.remove('pos')
866
867 class xxxPage(xxxChildContainer):
868 allParams = ['label', 'selected']
869 paramDict = {'selected': ParamBool}
870 required = ['label']
871 def __init__(self, parent, element, refElem=None):
872 xxxChildContainer.__init__(self, parent, element, refElem)
873 # pos and size dont matter for notebookpages
874 if 'pos' in self.child.allParams:
875 self.child.allParams = self.child.allParams[:]
876 self.child.allParams.remove('pos')
877 if 'size' in self.child.allParams:
878 self.child.allParams = self.child.allParams[:]
879 self.child.allParams.remove('size')
880
881 class xxxSpacer(xxxObject):
882 hasName = hasStyle = False
883 allParams = ['size', 'option', 'flag', 'border']
884 paramDict = {'option': ParamInt}
885 default = {'size': '0,0'}
886 def __init__(self, parent, element, refElem=None):
887 # For GridBag sizer items, extra parameters added
888 if isinstance(parent, xxxGridBagSizer):
889 self.allParams = self.allParams + ['cellpos', 'cellspan']
890 xxxObject.__init__(self, parent, element, refElem)
891
892 class xxxMenuBar(xxxContainer):
893 allParams = ['style']
894 paramDict = {'style': ParamNonGenericStyle} # no generic styles
895 winStyles = ['wxMB_DOCKABLE']
896
897 class xxxMenu(xxxContainer):
898 allParams = ['label', 'help', 'style']
899 default = {'label': ''}
900 paramDict = {'style': ParamNonGenericStyle} # no generic styles
901 winStyles = ['wxMENU_TEAROFF']
902
903 class xxxMenuItem(xxxObject):
904 allParams = ['label', 'bitmap', 'accel', 'help',
905 'checkable', 'radio', 'enabled', 'checked']
906 default = {'label': ''}
907 hasStyle = False
908
909 class xxxSeparator(xxxObject):
910 hasName = hasStyle = False
911
912 ################################################################################
913 # Unknown control
914
915 class xxxUnknown(xxxObject):
916 allParams = ['pos', 'size', 'style']
917 winStyles = ['wxNO_FULL_REPAINT_ON_RESIZE']
918
919 ################################################################################
920 # Comment
921
922 _handlers = [] # custom handler classes/funcs
923 _CFuncPtr = None # ctypes function type
924
925 def register(hndlr):
926 """Register hndlr function or XmlResourceHandler class."""
927 if _CFuncPtr and isinstance(hndlr, _CFuncPtr):
928 _handlers.append(hndlr)
929 return
930 if not isinstance(hndlr, type):
931 wx.LogError('handler is not a type: %s' % hndlr)
932 elif not issubclass(hndlr, wx.xrc.XmlResourceHandler):
933 wx.LogError('handler is not a XmlResourceHandler: %s' % hndlr)
934 else:
935 _handlers.append(hndlr)
936
937 def load_dl(path, localname=''):
938 """Load shared/dynamic library into xxx namespace."""
939 if not localname:
940 localname = os.path.basename(os.path.splitext(path)[0])
941 try:
942 import ctypes
943 global _CFuncPtr
944 _CFuncPtr = ctypes._CFuncPtr
945 except ImportError:
946 wx.LogError('ctypes module not found')
947 globals()[localname] = None
948 return
949 try:
950 dl = ctypes.CDLL(path)
951 globals()[localname] = dl
952 # Register AddXmlHandlers() if exists
953 try:
954 register(dl.AddXmlHandlers)
955 except:
956 pass
957 except:
958 wx.LogError('error loading dynamic library: %s' % path)
959 print traceback.print_exc()
960
961 # Called when creating test window
962 def addHandlers():
963 for h in _handlers:
964 if _CFuncPtr and isinstance(h, _CFuncPtr):
965 try:
966 apply(h, ())
967 except:
968 wx.LogError('error calling DL func: "%s"' % h)
969 print traceback.print_exc()
970 else:
971 try:
972 xrc.XmlResource.Get().AddHandler(apply(h, ()))
973 except:
974 wx.LogError('error adding XmlHandler: "%s"' % h)
975 print traceback.print_exc()
976
977 def clearHandlers():
978 global _handlers
979 _handlers = []
980
981 def custom(klassName, klass='unknown'):
982 """Define custom control based on xrcClass.
983
984 klass: new object name
985 xrcClass: name of an existing XRC object class or
986 a class object defining class parameters.
987 """
988 if type(klass) is str:
989 # Copy correct xxx class under new name
990 kl = xxxDict[klass]
991 xxxClass = types.ClassType('xxx' + klassName, kl.__bases__, kl.__dict__)
992 else:
993 xxxClass = klass
994 # Register param IDs
995 for param in klass.allParams + klass.paramDict.keys():
996 if not paramIDs.has_key(param):
997 paramIDs[param] = wx.NewId()
998 # Insert in dictionaty
999 xxxDict[klassName] = xxxClass
1000 # Add to menu
1001 g.pullDownMenu.addCustom(klassName)
1002
1003 class xxxParamComment(xxxParam):
1004 def __init__(self, node):
1005 xxxNode.__init__(self, node)
1006 self.textNode = node
1007 # Parse "pragma" comments
1008 if node.data and node.data[0] == '%':
1009 try:
1010 code = node.data[1:]
1011 exec code in globals()
1012 except:
1013 wx.LogError('exec error: "%s"' % code)
1014 print traceback.print_exc()
1015
1016 class xxxComment(xxxObject):
1017 hasStyle = hasName = False
1018 allParams = required = ['comment']
1019
1020 def __init__(self, parent, node):
1021 self.parent = parent
1022 self.node = node
1023 self.isElement = False
1024 self.undo = None
1025 self.className = 'comment'
1026 self.ref = self.subclass = None
1027 self.params = {'comment': xxxParamComment(node)}
1028
1029 def treeName(self):
1030 # Replace newlines by \n to avoid tree item resizing
1031 return self.params['comment'].value().replace('\n', r'\n')
1032
1033 ################################################################################
1034
1035 # Mapping of XRC names to xxx classes
1036 xxxDict = {
1037 'wxPanel': xxxPanel,
1038 'wxDialog': xxxDialog,
1039 'wxFrame': xxxFrame,
1040 'tool': xxxTool,
1041 'wxToolBar': xxxToolBar,
1042 'wxStatusBar': xxxStatusBar,
1043 'wxWizard': xxxWizard,
1044 'wxWizardPage': xxxWizardPage,
1045 'wxWizardPageSimple': xxxWizardPageSimple,
1046
1047 'wxBitmap': xxxBitmap,
1048 'wxIcon': xxxIcon,
1049
1050 'wxButton': xxxButton,
1051 'wxBitmapButton': xxxBitmapButton,
1052 'wxRadioButton': xxxRadioButton,
1053 'wxSpinButton': xxxSpinButton,
1054 'wxToggleButton' : xxxToggleButton,
1055
1056 'wxStaticBox': xxxStaticBox,
1057 'wxStaticBitmap': xxxStaticBitmap,
1058 'wxRadioBox': xxxRadioBox,
1059 'wxComboBox': xxxComboBox,
1060 'wxCheckBox': xxxCheckBox,
1061 'wxListBox': xxxListBox,
1062
1063 'wxStaticText': xxxStaticText,
1064 'wxStaticLine': xxxStaticLine,
1065 'wxTextCtrl': xxxTextCtrl,
1066 'wxChoice': xxxChoice,
1067 'wxSlider': xxxSlider,
1068 'wxGauge': xxxGauge,
1069 'wxScrollBar': xxxScrollBar,
1070 'wxTreeCtrl': xxxTreeCtrl,
1071 'wxListCtrl': xxxListCtrl,
1072 'wxCheckListBox': xxxCheckList,
1073 'notebookpage': xxxPage,
1074 'choicebookpage': xxxPage,
1075 'listbookpage': xxxPage,
1076 'wxNotebook': xxxNotebook,
1077 'wxChoicebook': xxxChoicebook,
1078 'wxListbook': xxxListbook,
1079 'wxSplitterWindow': xxxSplitterWindow,
1080 'wxHtmlWindow': xxxHtmlWindow,
1081 'wxCalendarCtrl': xxxCalendarCtrl,
1082 'wxGenericDirCtrl': xxxGenericDirCtrl,
1083 'wxSpinCtrl': xxxSpinCtrl,
1084 'wxScrolledWindow': xxxScrolledWindow,
1085 'wxGrid': xxxGrid,
1086 'wxFilePickerCtrl': xxxFilePickerCtrl,
1087 'wxDatePickerCtrl': xxxDateCtrl,
1088
1089 'wxBoxSizer': xxxBoxSizer,
1090 'wxStaticBoxSizer': xxxStaticBoxSizer,
1091 'wxGridSizer': xxxGridSizer,
1092 'wxFlexGridSizer': xxxFlexGridSizer,
1093 'wxGridBagSizer': xxxGridBagSizer,
1094 'wxStdDialogButtonSizer': xxxStdDialogButtonSizer,
1095 'sizeritem': xxxSizerItem, 'button': xxxSizerItemButton,
1096 'spacer': xxxSpacer,
1097
1098 'wxMenuBar': xxxMenuBar,
1099 'wxMenu': xxxMenu,
1100 'wxMenuItem': xxxMenuItem,
1101 'separator': xxxSeparator,
1102
1103 'unknown': xxxUnknown,
1104 'comment': xxxComment,
1105 }
1106
1107 # Create IDs for all parameters of all classes
1108 paramIDs = {'fg': wx.NewId(), 'bg': wx.NewId(), 'exstyle': wx.NewId(), 'font': wx.NewId(),
1109 'enabled': wx.NewId(), 'focused': wx.NewId(), 'hidden': wx.NewId(),
1110 'tooltip': wx.NewId(), 'encoding': wx.NewId(),
1111 'cellpos': wx.NewId(), 'cellspan': wx.NewId(),
1112 'text': wx.NewId()
1113 }
1114 for cl in xxxDict.values():
1115 if cl.allParams:
1116 for param in cl.allParams + cl.paramDict.keys():
1117 if not paramIDs.has_key(param):
1118 paramIDs[param] = wx.NewId()
1119
1120 ################################################################################
1121 # Helper functions
1122
1123 # Test for object elements
1124 def IsObject(node):
1125 return node.nodeType == minidom.Node.ELEMENT_NODE and \
1126 node.tagName in ['object', 'object_ref'] or \
1127 node.nodeType == minidom.Node.COMMENT_NODE
1128
1129 # Make XXX object from some DOM object, selecting correct class
1130 def MakeXXXFromDOM(parent, node):
1131 if node.nodeType == minidom.Node.COMMENT_NODE:
1132 return xxxComment(parent, node)
1133 if node.tagName == 'object_ref':
1134 ref = node.getAttribute('ref')
1135 refElem = FindResource(ref)
1136 if refElem: cls = refElem.getAttribute('class')
1137 else: return xxxUnknown(parent, node)
1138 else:
1139 refElem = None
1140 cls = node.getAttribute('class')
1141 try:
1142 klass = xxxDict[cls]
1143 except KeyError:
1144 # If we encounter a weird class, use unknown template
1145 print 'WARNING: unsupported class:', node.getAttribute('class')
1146 klass = xxxUnknown
1147 return klass(parent, node, refElem)
1148
1149 # Make empty DOM element
1150 def MakeEmptyDOM(className):
1151 elem = g.tree.dom.createElement('object')
1152 elem.setAttribute('class', className)
1153 # Set required and default parameters
1154 xxxClass = xxxDict[className]
1155 defaultNotRequired = filter(lambda x, l=xxxClass.required: x not in l,
1156 xxxClass.default.keys())
1157 for param in xxxClass.required + defaultNotRequired:
1158 textElem = g.tree.dom.createElement(param)
1159 try:
1160 textNode = g.tree.dom.createTextNode(xxxClass.default[param])
1161 except KeyError:
1162 textNode = g.tree.dom.createTextNode('')
1163 textElem.appendChild(textNode)
1164 elem.appendChild(textElem)
1165 return elem
1166
1167 # Make empty XXX object
1168 def MakeEmptyXXX(parent, className):
1169 # Make corresponding DOM object first
1170 elem = MakeEmptyDOM(className)
1171 # If parent is a sizer, we should create sizeritem object, except for spacers
1172 if parent:
1173 if parent.isSizer and className != 'spacer':
1174 sizerItemElem = MakeEmptyDOM(parent.itemTag)
1175 sizerItemElem.appendChild(elem)
1176 elem = sizerItemElem
1177 elif isinstance(parent, xxxNotebook):
1178 pageElem = MakeEmptyDOM('notebookpage')
1179 pageElem.appendChild(elem)
1180 elem = pageElem
1181 elif isinstance(parent, xxxChoicebook):
1182 pageElem = MakeEmptyDOM('choicebookpage')
1183 pageElem.appendChild(elem)
1184 elem = pageElem
1185 elif isinstance(parent, xxxListbook):
1186 pageElem = MakeEmptyDOM('listbookpage')
1187 pageElem.appendChild(elem)
1188 elem = pageElem
1189 # Now just make object
1190 return MakeXXXFromDOM(parent, elem)
1191
1192 # Make empty DOM element for reference
1193 def MakeEmptyRefDOM(ref):
1194 elem = g.tree.dom.createElement('object_ref')
1195 elem.setAttribute('ref', ref)
1196 return elem
1197
1198 # Make empty XXX object
1199 def MakeEmptyRefXXX(parent, ref):
1200 # Make corresponding DOM object first
1201 elem = MakeEmptyRefDOM(ref)
1202 # If parent is a sizer, we should create sizeritem object, except for spacers
1203 if parent:
1204 if parent.isSizer:
1205 sizerItemElem = MakeEmptyDOM(parent.itemTag)
1206 sizerItemElem.appendChild(elem)
1207 elem = sizerItemElem
1208 elif isinstance(parent, xxxNotebook):
1209 pageElem = MakeEmptyDOM('notebookpage')
1210 pageElem.appendChild(elem)
1211 elem = pageElem
1212 elif isinstance(parent, xxxChoicebook):
1213 pageElem = MakeEmptyDOM('choicebookpage')
1214 pageElem.appendChild(elem)
1215 elem = pageElem
1216 elif isinstance(parent, xxxListbook):
1217 pageElem = MakeEmptyDOM('listbookpage')
1218 pageElem.appendChild(elem)
1219 elem = pageElem
1220 # Now just make object
1221 xxx = MakeXXXFromDOM(parent, elem)
1222 # Label is not used for references
1223 xxx.allParams = xxx.allParams[:]
1224 #xxx.allParams.remove('label')
1225 return xxx
1226
1227 # Make empty comment node
1228 def MakeEmptyCommentDOM():
1229 node = g.tree.dom.createComment('')
1230 return node
1231
1232 # Make empty xxxComment
1233 def MakeEmptyCommentXXX(parent):
1234 node = MakeEmptyCommentDOM()
1235 # Now just make object
1236 xxx = MakeXXXFromDOM(parent, node)
1237 return xxx
1238