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