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