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