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