]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/tools/XRCed/xxx.py
Inital fill in background, removed tabs, -1->wxID_ANY, TRUE->true, FALSE->false
[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 wxUSE_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 return self.textNode.data.encode(g.currentEncoding)
51 def update(self, value):
52 self.textNode.data = unicode(value, g.currentEncoding)
53
54 # Integer parameter
55 class xxxParamInt(xxxParam):
56 # Standard use: for text nodes
57 def __init__(self, node):
58 xxxParam.__init__(self, node)
59 # Value returns string
60 def value(self):
61 try:
62 return int(self.textNode.data)
63 except ValueError:
64 return -1 # invalid value
65 def update(self, value):
66 self.textNode.data = str(value)
67
68 # Content parameter
69 class xxxParamContent(xxxNode):
70 def __init__(self, node):
71 xxxNode.__init__(self, node)
72 data, l = [], [] # data is needed to quicker value retrieval
73 nodes = node.childNodes[:] # make a copy of the child list
74 for n in nodes:
75 if n.nodeType == minidom.Node.ELEMENT_NODE:
76 assert n.tagName == 'item', 'bad content content'
77 if not n.hasChildNodes():
78 # If does not have child nodes, create empty text node
79 text = g.tree.dom.createTextNode('')
80 node.appendChild(text)
81 else:
82 # !!! normalize?
83 text = n.childNodes[0] # first child must be text node
84 assert text.nodeType == minidom.Node.TEXT_NODE
85 l.append(text)
86 data.append(str(text.data))
87 else: # remove other
88 node.removeChild(n)
89 n.unlink()
90 self.l, self.data = l, data
91 def value(self):
92 return self.data
93 def update(self, value):
94 # If number if items is not the same, recreate children
95 if len(value) != len(self.l): # remove first if number of items has changed
96 childNodes = self.node.childNodes[:]
97 for n in childNodes:
98 self.node.removeChild(n)
99 l = []
100 for str in value:
101 itemElem = g.tree.dom.createElement('item')
102 itemText = g.tree.dom.createTextNode(str)
103 itemElem.appendChild(itemText)
104 self.node.appendChild(itemElem)
105 l.append(itemText)
106 self.l = l
107 else:
108 for i in range(len(value)):
109 self.l[i].data = value[i]
110 self.data = value
111
112 # Content parameter for checklist
113 class xxxParamContentCheckList(xxxNode):
114 def __init__(self, node):
115 xxxNode.__init__(self, node)
116 data, l = [], [] # data is needed to quicker value retrieval
117 nodes = node.childNodes[:] # make a copy of the child list
118 for n in nodes:
119 if n.nodeType == minidom.Node.ELEMENT_NODE:
120 assert n.tagName == 'item', 'bad content content'
121 checked = n.getAttribute('checked')
122 if not checked: checked = 0
123 if not n.hasChildNodes():
124 # If does not have child nodes, create empty text node
125 text = g.tree.dom.createTextNode('')
126 node.appendChild(text)
127 else:
128 # !!! normalize?
129 text = n.childNodes[0] # first child must be text node
130 assert text.nodeType == minidom.Node.TEXT_NODE
131 l.append((text, n))
132 data.append((str(text.data), int(checked)))
133 else: # remove other
134 node.removeChild(n)
135 n.unlink()
136 self.l, self.data = l, data
137 def value(self):
138 return self.data
139 def update(self, value):
140 # If number if items is not the same, recreate children
141 if len(value) != len(self.l): # remove first if number of items has changed
142 childNodes = self.node.childNodes[:]
143 for n in childNodes:
144 self.node.removeChild(n)
145 l = []
146 for s,ch in value:
147 itemElem = g.tree.dom.createElement('item')
148 # Add checked only if True
149 if ch: itemElem.setAttribute('checked', '1')
150 itemText = g.tree.dom.createTextNode(s)
151 itemElem.appendChild(itemText)
152 self.node.appendChild(itemElem)
153 l.append((itemText, itemElem))
154 self.l = l
155 else:
156 for i in range(len(value)):
157 self.l[i][0].data = value[i][0]
158 self.l[i][1].setAttribute('checked', str(value[i][1]))
159 self.data = value
160
161 # Bitmap parameter
162 class xxxParamBitmap(xxxParam):
163 def __init__(self, node):
164 xxxParam.__init__(self, node)
165 self.stock_id = node.getAttribute('stock_id')
166 def value(self):
167 return [self.stock_id, xxxParam.value(self)]
168 def update(self, value):
169 self.stock_id = value[0]
170 if self.stock_id:
171 self.node.setAttribute('stock_id', self.stock_id)
172 elif self.node.hasAttribute('stock_id'):
173 self.node.removeAttribute('stock_id')
174 xxxParam.update(self, value[1])
175
176 ################################################################################
177
178 # Classes to interface DOM objects
179 class xxxObject:
180 # Default behavior
181 hasChildren = False # has children elements?
182 hasStyle = True # almost everyone
183 hasName = True # has name attribute?
184 isSizer = hasChild = False
185 allParams = None # Some nodes have no parameters
186 # Style parameters (all optional)
187 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip']
188 # Special parameters
189 specials = []
190 # Bitmap tags
191 bitmapTags = ['bitmap', 'bitmap2', 'icon']
192 # Required paremeters: none by default
193 required = []
194 # Default parameters with default values
195 default = {}
196 # Parameter types
197 paramDict = {}
198 # Window styles and extended styles
199 winStyles = []
200 # Tree icon index
201 #image = -1
202 # Construct a new xxx object from DOM element
203 # parent is parent xxx object (or None if none), element is DOM element object
204 def __init__(self, parent, element):
205 self.parent = parent
206 self.element = element
207 self.undo = None
208 # Get attributes
209 self.className = element.getAttribute('class')
210 self.subclass = element.getAttribute('subclass')
211 if self.hasName: self.name = element.getAttribute('name')
212 # Set parameters (text element children)
213 self.params = {}
214 nodes = element.childNodes[:]
215 for node in nodes:
216 if node.nodeType == minidom.Node.ELEMENT_NODE:
217 tag = node.tagName
218 if tag == 'object':
219 continue # do nothing for object children here
220 if tag not in self.allParams and tag not in self.styles:
221 print 'WARNING: unknown parameter for %s: %s' % \
222 (self.className, tag)
223 elif tag in self.specials:
224 self.special(tag, node)
225 elif tag == 'content':
226 if self.className == 'wxCheckListBox':
227 self.params[tag] = xxxParamContentCheckList(node)
228 else:
229 self.params[tag] = xxxParamContent(node)
230 elif tag == 'font': # has children
231 self.params[tag] = xxxParamFont(element, node)
232 elif tag in self.bitmapTags:
233 # Can have attributes
234 self.params[tag] = xxxParamBitmap(node)
235 else: # simple parameter
236 self.params[tag] = xxxParam(node)
237 else:
238 # Remove all other nodes
239 element.removeChild(node)
240 node.unlink()
241 # Check that all required params are set
242 for param in self.required:
243 if not self.params.has_key(param):
244 # If default is specified, set it
245 if self.default.has_key(param):
246 elem = g.tree.dom.createElement(param)
247 if param == 'content':
248 if self.className == 'wxCheckListBox':
249 self.params[param] = xxxParamContentCheckList(elem)
250 else:
251 self.params[param] = xxxParamContent(elem)
252 else:
253 self.params[param] = xxxParam(elem)
254 # Find place to put new element: first present element after param
255 found = False
256 paramStyles = self.allParams + self.styles
257 for p in paramStyles[paramStyles.index(param) + 1:]:
258 # Content params don't have same type
259 if self.params.has_key(p) and p != 'content':
260 found = True
261 break
262 if found:
263 nextTextElem = self.params[p].node
264 self.element.insertBefore(elem, nextTextElem)
265 else:
266 self.element.appendChild(elem)
267 else:
268 wxLogWarning('Required parameter %s of %s missing' %
269 (param, self.className))
270 # Returns real tree object
271 def treeObject(self):
272 if self.hasChild: return self.child
273 return self
274 # Returns tree image index
275 def treeImage(self):
276 if self.hasChild: return self.child.treeImage()
277 return self.image
278 # Class name plus wx name
279 def treeName(self):
280 if self.hasChild: return self.child.treeName()
281 if self.subclass: className = self.subclass
282 else: className = self.className
283 if self.hasName and self.name: return className + ' "' + self.name + '"'
284 return className
285 # Class name or subclass
286 def panelName(self):
287 if self.subclass: return self.subclass + '(' + self.className + ')'
288 else: return self.className
289
290 ################################################################################
291
292 # This is a little special: it is both xxxObject and xxxNode
293 class xxxParamFont(xxxObject, xxxNode):
294 allParams = ['size', 'style', 'weight', 'family', 'underlined',
295 'face', 'encoding']
296 def __init__(self, parent, element):
297 xxxObject.__init__(self, parent, element)
298 xxxNode.__init__(self, element)
299 self.parentNode = parent # required to behave similar to DOM node
300 v = []
301 for p in self.allParams:
302 try:
303 v.append(str(self.params[p].value()))
304 except KeyError:
305 v.append('')
306 self.data = v
307 def update(self, value):
308 # `value' is a list of strings corresponding to all parameters
309 elem = self.element
310 # Remove old elements first
311 childNodes = elem.childNodes[:]
312 for node in childNodes: elem.removeChild(node)
313 i = 0
314 self.params.clear()
315 v = []
316 for param in self.allParams:
317 if value[i]:
318 fontElem = g.tree.dom.createElement(param)
319 textNode = g.tree.dom.createTextNode(value[i])
320 self.params[param] = textNode
321 fontElem.appendChild(textNode)
322 elem.appendChild(fontElem)
323 v.append(value[i])
324 i += 1
325 self.data = v
326 def value(self):
327 return self.data
328
329 ################################################################################
330
331 class xxxContainer(xxxObject):
332 hasChildren = True
333
334 # Simulate normal parameter for encoding
335 class xxxEncoding:
336 def __init__(self, val):
337 self.encd = val
338 def value(self):
339 return self.encd
340 def update(self, val):
341 self.encd = val
342
343 # Special class for root node
344 class xxxMainNode(xxxContainer):
345 allParams = ['encoding']
346 hasStyle = hasName = False
347 def __init__(self, dom):
348 xxxContainer.__init__(self, None, dom.documentElement)
349 self.className = 'XML tree'
350 # Reset required parameters after processing XML, because encoding is
351 # a little special
352 self.required = ['encoding']
353 self.params['encoding'] = xxxEncoding(dom.encoding)
354
355 ################################################################################
356 # Top-level windwows
357
358 class xxxPanel(xxxContainer):
359 allParams = ['pos', 'size', 'style']
360 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
361 'tooltip']
362 winStyles = ['wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
363 exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
364
365 class xxxDialog(xxxContainer):
366 allParams = ['title', 'centered', 'pos', 'size', 'style']
367 paramDict = {'centered': ParamBool}
368 required = ['title']
369 default = {'title': ''}
370 winStyles = ['wxDEFAULT_DIALOG_STYLE', 'wxSTAY_ON_TOP',
371 ## 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS',
372 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 'wxRESIZE_BOX',
373 'wxTHICK_FRAME',
374 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
375 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
376 'tooltip']
377 exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
378
379 class xxxFrame(xxxContainer):
380 allParams = ['title', 'centered', 'pos', 'size', 'style']
381 paramDict = {'centered': ParamBool}
382 required = ['title']
383 default = {'title': ''}
384 winStyles = ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE',
385 'wxSTAY_ON_TOP',
386 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
387 'wxRESIZE_BOX', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX',
388 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_TOOL_WINDOW',
389 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
390 styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
391 'tooltip']
392 exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY']
393
394 class xxxTool(xxxObject):
395 allParams = ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp']
396 required = ['bitmap']
397 paramDict = {'bitmap2': ParamBitmap, 'toggle': ParamBool}
398 hasStyle = False
399
400 class xxxToolBar(xxxContainer):
401 allParams = ['bitmapsize', 'margins', 'packing', 'separation',
402 'pos', 'size', 'style']
403 hasStyle = False
404 paramDict = {'bitmapsize': ParamPosSize, 'margins': ParamPosSize,
405 'packing': ParamInt, 'separation': ParamInt,
406 'style': ParamNonGenericStyle}
407 winStyles = ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL']
408
409 ################################################################################
410 # Bitmap, Icon
411
412 class xxxBitmap(xxxObject):
413 allParams = ['bitmap']
414 required = ['bitmap']
415
416 # Just like bitmap
417 class xxxIcon(xxxObject):
418 allParams = ['icon']
419 required = ['icon']
420
421 ################################################################################
422 # Controls
423
424 class xxxStaticText(xxxObject):
425 allParams = ['label', 'pos', 'size', 'style']
426 required = ['label']
427 default = {'label': ''}
428 winStyles = ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
429
430 class xxxStaticLine(xxxObject):
431 allParams = ['pos', 'size', 'style']
432 winStyles = ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
433
434 class xxxStaticBitmap(xxxObject):
435 allParams = ['bitmap', 'pos', 'size', 'style']
436 required = ['bitmap']
437
438 class xxxTextCtrl(xxxObject):
439 allParams = ['value', 'pos', 'size', 'style']
440 winStyles = ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
441 'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
442 paramDict = {'value': ParamMultilineText}
443
444 class xxxChoice(xxxObject):
445 allParams = ['content', 'selection', 'pos', 'size', 'style']
446 required = ['content']
447 default = {'content': '[]'}
448 winStyles = ['wxCB_SORT']
449
450 class xxxSlider(xxxObject):
451 allParams = ['value', 'min', 'max', 'pos', 'size', 'style',
452 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
453 'selmin', 'selmax']
454 paramDict = {'value': ParamInt, 'tickfreq': ParamInt, 'pagesize': ParamInt,
455 'linesize': ParamInt, 'thumb': ParamInt, 'thumb': ParamInt,
456 'tick': ParamInt, 'selmin': ParamInt, 'selmax': ParamInt}
457 required = ['value', 'min', 'max']
458 winStyles = ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
459 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
460 'wxSL_BOTH', 'wxSL_SELRANGE']
461
462 class xxxGauge(xxxObject):
463 allParams = ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
464 paramDict = {'range': ParamInt, 'value': ParamInt,
465 'shadow': ParamInt, 'bezel': ParamInt}
466 winStyles = ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
467
468 class xxxScrollBar(xxxObject):
469 allParams = ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
470 paramDict = {'value': ParamInt, 'range': ParamInt, 'thumbsize': ParamInt,
471 'pagesize': ParamInt}
472 winStyles = ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
473
474 class xxxListCtrl(xxxObject):
475 allParams = ['pos', 'size', 'style']
476 winStyles = ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
477 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
478 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
479 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
480
481 class xxxTreeCtrl(xxxObject):
482 allParams = ['pos', 'size', 'style']
483 winStyles = ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT',
484 'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE']
485
486 class xxxHtmlWindow(xxxObject):
487 allParams = ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
488 paramDict = {'borders': ParamInt, 'htmlcode':ParamMultilineText}
489 winStyles = ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
490
491 class xxxCalendarCtrl(xxxObject):
492 allParams = ['pos', 'size', 'style']
493
494 class xxxNotebook(xxxContainer):
495 allParams = ['usenotebooksizer', 'pos', 'size', 'style']
496 paramDict = {'usenotebooksizer': ParamBool}
497 winStyles = ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM']
498
499 class xxxSplitterWindow(xxxContainer):
500 allParams = ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style']
501 paramDict = {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit }
502 winStyles = ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER', 'wxSP_BORDER',
503 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE',
504 'wxSP_NO_XP_THEME' ]
505
506 class xxxGenericDirCtrl(xxxObject):
507 allParams = ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style']
508 paramDict = {'defaultfilter': ParamInt}
509 winStyles = ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
510 'wxDIRCTRL_SHOW_FILTERS', 'wxDIRCTRL_EDIT_LABELS']
511
512 class xxxScrolledWindow(xxxContainer):
513 allParams = ['pos', 'size', 'style']
514 winStyles = ['wxHSCROLL', 'wxVSCROLL']
515
516 ################################################################################
517 # Buttons
518
519 class xxxButton(xxxObject):
520 allParams = ['label', 'default', 'pos', 'size', 'style']
521 paramDict = {'default': ParamBool}
522 required = ['label']
523 winStyles = ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
524
525 class xxxBitmapButton(xxxObject):
526 allParams = ['bitmap', 'selected', 'focus', 'disabled', 'default',
527 'pos', 'size', 'style']
528 required = ['bitmap']
529 winStyles = ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP',
530 'wxBU_RIGHT', 'wxBU_BOTTOM']
531
532 class xxxRadioButton(xxxObject):
533 allParams = ['label', 'value', 'pos', 'size', 'style']
534 paramDict = {'value': ParamBool}
535 required = ['label']
536 winStyles = ['wxRB_GROUP']
537
538 class xxxSpinButton(xxxObject):
539 allParams = ['value', 'min', 'max', 'pos', 'size', 'style']
540 paramDict = {'value': ParamInt}
541 winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
542
543 class xxxSpinCtrl(xxxObject):
544 allParams = ['value', 'min', 'max', 'pos', 'size', 'style']
545 paramDict = {'value': ParamInt}
546 winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
547
548 ################################################################################
549 # Boxes
550
551 class xxxStaticBox(xxxObject):
552 allParams = ['label', 'pos', 'size', 'style']
553 required = ['label']
554
555 class xxxRadioBox(xxxObject):
556 allParams = ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
557 paramDict = {'dimension': ParamInt}
558 required = ['label', 'content']
559 default = {'content': '[]'}
560 winStyles = ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS']
561
562 class xxxCheckBox(xxxObject):
563 allParams = ['label', 'checked', 'pos', 'size', 'style']
564 paramDict = {'checked': ParamBool}
565 required = ['label']
566
567 class xxxComboBox(xxxObject):
568 allParams = ['content', 'selection', 'value', 'pos', 'size', 'style']
569 required = ['content']
570 default = {'content': '[]'}
571 winStyles = ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
572
573 class xxxListBox(xxxObject):
574 allParams = ['content', 'selection', 'pos', 'size', 'style']
575 required = ['content']
576 default = {'content': '[]'}
577 winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
578 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
579
580 class xxxCheckList(xxxObject):
581 allParams = ['content', 'pos', 'size', 'style']
582 required = ['content']
583 default = {'content': '[]'}
584 winStyles = ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
585 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
586 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
587 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
588 paramDict = {'content': ParamContentCheckList}
589
590 ################################################################################
591 # Sizers
592
593 class xxxSizer(xxxContainer):
594 hasName = hasStyle = False
595 paramDict = {'orient': ParamOrient}
596 isSizer = True
597
598 class xxxBoxSizer(xxxSizer):
599 allParams = ['orient']
600 required = ['orient']
601 default = {'orient': 'wxVERTICAL'}
602 # Tree icon depends on orientation
603 def treeImage(self):
604 if self.params['orient'].value() == 'wxHORIZONTAL': return self.imageH
605 else: return self.imageV
606
607 class xxxStaticBoxSizer(xxxBoxSizer):
608 allParams = ['label', 'orient']
609 required = ['label', 'orient']
610
611 class xxxGridSizer(xxxSizer):
612 allParams = ['cols', 'rows', 'vgap', 'hgap']
613 required = ['cols']
614 default = {'cols': '2', 'rows': '2'}
615
616 # For repeated parameters
617 class xxxParamMulti:
618 def __init__(self, node):
619 self.node = node
620 self.l, self.data = [], []
621 def append(self, param):
622 self.l.append(param)
623 self.data.append(param.value())
624 def value(self):
625 return self.data
626 def remove(self):
627 for param in self.l:
628 param.remove()
629 self.l, self.data = [], []
630
631 class xxxFlexGridSizer(xxxGridSizer):
632 specials = ['growablecols', 'growablerows']
633 allParams = ['cols', 'rows', 'vgap', 'hgap'] + specials
634 paramDict = {'growablecols':ParamIntList, 'growablerows':ParamIntList}
635 # Special processing for growable* parameters
636 # (they are represented by several nodes)
637 def special(self, tag, node):
638 if not self.params.has_key(tag):
639 # Create new multi-group
640 self.params[tag] = xxxParamMulti(node)
641 self.params[tag].append(xxxParamInt(node))
642 def setSpecial(self, param, value):
643 # Straightforward implementation: remove, add again
644 self.params[param].remove()
645 del self.params[param]
646 for i in value:
647 node = g.tree.dom.createElement(param)
648 text = g.tree.dom.createTextNode(str(i))
649 node.appendChild(text)
650 self.element.appendChild(node)
651 self.special(param, node)
652
653 class xxxGridBagSizer(xxxSizer):
654 specials = ['growablecols', 'growablerows']
655 allParams = ['vgap', 'hgap'] + specials
656 paramDict = {'growablecols':ParamIntList, 'growablerows':ParamIntList}
657 # Special processing for growable* parameters
658 # (they are represented by several nodes)
659 def special(self, tag, node):
660 if not self.params.has_key(tag):
661 # Create new multi-group
662 self.params[tag] = xxxParamMulti(node)
663 self.params[tag].append(xxxParamInt(node))
664 def setSpecial(self, param, value):
665 # Straightforward implementation: remove, add again
666 self.params[param].remove()
667 del self.params[param]
668 for i in value:
669 node = g.tree.dom.createElement(param)
670 text = g.tree.dom.createTextNode(str(i))
671 node.appendChild(text)
672 self.element.appendChild(node)
673 self.special(param, node)
674
675 # Container with only one child.
676 # Not shown in tree.
677 class xxxChildContainer(xxxObject):
678 hasName = hasStyle = False
679 hasChild = True
680 def __init__(self, parent, element):
681 xxxObject.__init__(self, parent, element)
682 # Must have one child with 'object' tag, but we don't check it
683 nodes = element.childNodes[:] # create copy
684 for node in nodes:
685 if node.nodeType == minidom.Node.ELEMENT_NODE:
686 if node.tagName == 'object':
687 # Create new xxx object for child node
688 self.child = MakeXXXFromDOM(self, node)
689 self.child.parent = parent
690 # Copy hasChildren and isSizer attributes
691 self.hasChildren = self.child.hasChildren
692 self.isSizer = self.child.isSizer
693 return # success
694 else:
695 element.removeChild(node)
696 node.unlink()
697 assert 0, 'no child found'
698
699 class xxxSizerItem(xxxChildContainer):
700 allParams = ['option', 'flag', 'border', 'minsize', 'ratio']
701 paramDict = {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
702 #default = {'cellspan': '1,1'}
703 def __init__(self, parent, element):
704 # For GridBag sizer items, extra parameters added
705 if isinstance(parent, xxxGridBagSizer):
706 self.allParams = self.allParams + ['cellpos', 'cellspan']
707 xxxChildContainer.__init__(self, parent, element)
708 # Remove pos parameter - not needed for sizeritems
709 if 'pos' in self.child.allParams:
710 self.child.allParams = self.child.allParams[:]
711 self.child.allParams.remove('pos')
712
713 class xxxNotebookPage(xxxChildContainer):
714 allParams = ['label', 'selected']
715 paramDict = {'selected': ParamBool}
716 required = ['label']
717 def __init__(self, parent, element):
718 xxxChildContainer.__init__(self, parent, element)
719 # pos and size dont matter for notebookpages
720 if 'pos' in self.child.allParams:
721 self.child.allParams = self.child.allParams[:]
722 self.child.allParams.remove('pos')
723 if 'size' in self.child.allParams:
724 self.child.allParams = self.child.allParams[:]
725 self.child.allParams.remove('size')
726
727 class xxxSpacer(xxxObject):
728 hasName = hasStyle = False
729 allParams = ['size', 'option', 'flag', 'border']
730 paramDict = {'option': ParamInt}
731 default = {'size': '0,0'}
732
733 class xxxMenuBar(xxxContainer):
734 allParams = ['style']
735 paramDict = {'style': ParamNonGenericStyle} # no generic styles
736 winStyles = ['wxMB_DOCKABLE']
737
738 class xxxMenu(xxxContainer):
739 allParams = ['label', 'help', 'style']
740 default = {'label': ''}
741 paramDict = {'style': ParamNonGenericStyle} # no generic styles
742 winStyles = ['wxMENU_TEAROFF']
743
744 class xxxMenuItem(xxxObject):
745 allParams = ['label', 'bitmap', 'accel', 'help',
746 'checkable', 'radio', 'enabled', 'checked']
747 default = {'label': ''}
748 hasStyle = False
749
750 class xxxSeparator(xxxObject):
751 hasName = hasStyle = False
752
753 ################################################################################
754 # Unknown control
755
756 class xxxUnknown(xxxObject):
757 allParams = ['pos', 'size', 'style']
758 paramDict = {'style': ParamNonGenericStyle} # no generic styles
759
760 ################################################################################
761
762 xxxDict = {
763 'wxPanel': xxxPanel,
764 'wxDialog': xxxDialog,
765 'wxFrame': xxxFrame,
766 'tool': xxxTool,
767 'wxToolBar': xxxToolBar,
768
769 'wxBitmap': xxxBitmap,
770 'wxIcon': xxxIcon,
771
772 'wxButton': xxxButton,
773 'wxBitmapButton': xxxBitmapButton,
774 'wxRadioButton': xxxRadioButton,
775 'wxSpinButton': xxxSpinButton,
776
777 'wxStaticBox': xxxStaticBox,
778 'wxStaticBitmap': xxxStaticBitmap,
779 'wxRadioBox': xxxRadioBox,
780 'wxComboBox': xxxComboBox,
781 'wxCheckBox': xxxCheckBox,
782 'wxListBox': xxxListBox,
783
784 'wxStaticText': xxxStaticText,
785 'wxStaticLine': xxxStaticLine,
786 'wxTextCtrl': xxxTextCtrl,
787 'wxChoice': xxxChoice,
788 'wxSlider': xxxSlider,
789 'wxGauge': xxxGauge,
790 'wxScrollBar': xxxScrollBar,
791 'wxTreeCtrl': xxxTreeCtrl,
792 'wxListCtrl': xxxListCtrl,
793 'wxCheckListBox': xxxCheckList,
794 'wxNotebook': xxxNotebook,
795 'wxSplitterWindow': xxxSplitterWindow,
796 'notebookpage': xxxNotebookPage,
797 'wxHtmlWindow': xxxHtmlWindow,
798 'wxCalendarCtrl': xxxCalendarCtrl,
799 'wxGenericDirCtrl': xxxGenericDirCtrl,
800 'wxSpinCtrl': xxxSpinCtrl,
801 'wxScrolledWindow': xxxScrolledWindow,
802
803 'wxBoxSizer': xxxBoxSizer,
804 'wxStaticBoxSizer': xxxStaticBoxSizer,
805 'wxGridSizer': xxxGridSizer,
806 'wxFlexGridSizer': xxxFlexGridSizer,
807 'wxGridBagSizer': xxxGridBagSizer,
808 'sizeritem': xxxSizerItem,
809 'spacer': xxxSpacer,
810
811 'wxMenuBar': xxxMenuBar,
812 'wxMenu': xxxMenu,
813 'wxMenuItem': xxxMenuItem,
814 'separator': xxxSeparator,
815
816 'unknown': xxxUnknown,
817 }
818
819 # Create IDs for all parameters of all classes
820 paramIDs = {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(),
821 'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(),
822 'tooltip': wxNewId(), 'encoding': wxNewId(),
823 'cellpos': wxNewId(), 'cellspan': wxNewId()
824 }
825 for cl in xxxDict.values():
826 if cl.allParams:
827 for param in cl.allParams + cl.paramDict.keys():
828 if not paramIDs.has_key(param):
829 paramIDs[param] = wxNewId()
830
831 ################################################################################
832 # Helper functions
833
834 # Test for object elements
835 def IsObject(node):
836 return node.nodeType == minidom.Node.ELEMENT_NODE and node.tagName == 'object'
837
838 # Make XXX object from some DOM object, selecting correct class
839 def MakeXXXFromDOM(parent, element):
840 try:
841 klass = xxxDict[element.getAttribute('class')]
842 except KeyError:
843 # If we encounter a weird class, use unknown template
844 print 'WARNING: unsupported class:', element.getAttribute('class')
845 klass = xxxUnknown
846 return klass(parent, element)
847
848 # Make empty DOM element
849 def MakeEmptyDOM(className):
850 elem = g.tree.dom.createElement('object')
851 elem.setAttribute('class', className)
852 # Set required and default parameters
853 xxxClass = xxxDict[className]
854 defaultNotRequired = filter(lambda x, l=xxxClass.required: x not in l,
855 xxxClass.default.keys())
856 for param in xxxClass.required + defaultNotRequired:
857 textElem = g.tree.dom.createElement(param)
858 try:
859 textNode = g.tree.dom.createTextNode(xxxClass.default[param])
860 except KeyError:
861 textNode = g.tree.dom.createTextNode('')
862 textElem.appendChild(textNode)
863 elem.appendChild(textElem)
864 return elem
865
866 # Make empty XXX object
867 def MakeEmptyXXX(parent, className):
868 # Make corresponding DOM object first
869 elem = MakeEmptyDOM(className)
870 # If parent is a sizer, we should create sizeritem object, except for spacers
871 if parent:
872 if parent.isSizer and className != 'spacer':
873 sizerItemElem = MakeEmptyDOM('sizeritem')
874 sizerItemElem.appendChild(elem)
875 elem = sizerItemElem
876 elif isinstance(parent, xxxNotebook):
877 pageElem = MakeEmptyDOM('notebookpage')
878 pageElem.appendChild(elem)
879 elem = pageElem
880 # Now just make object
881 return MakeXXXFromDOM(parent, elem)
882