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