]>
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 | |
29a41103 | 43 | if wx.USE_UNICODE: # no conversion is needed |
d14a1e28 RD |
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 | 58 | self.textNode.data = unicode(value) |
29a41103 | 59 | #wx.LogMessage("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) | |
e484fddf | 93 | data.append(text.data) |
d14a1e28 RD |
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: | |
29a41103 | 288 | wx.LogWarning('Required parameter %s of %s missing' % |
d14a1e28 RD |
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 | |
29a41103 | 341 | wx.LogError('XRC resource "%s" not found!' % name) |
03319b65 RR |
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'] | |
306b6fe9 | 413 | winStyles = ['wxNO_3D', 'wxTAB_TRAVERSAL'] |
d14a1e28 RD |
414 | styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', |
415 | 'tooltip'] | |
d14a1e28 RD |
416 | |
417 | class xxxDialog(xxxContainer): | |
418 | allParams = ['title', 'centered', 'pos', 'size', 'style'] | |
419 | paramDict = {'centered': ParamBool} | |
420 | required = ['title'] | |
421 | default = {'title': ''} | |
306b6fe9 RR |
422 | winStyles = ['wxDEFAULT_DIALOG_STYLE', 'wxCAPTION', |
423 | 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxTHICK_FRAME', | |
424 | 'wxRESIZE_BORDER', 'wxRESIZE_BOX', 'wxCLOSE_BOX', | |
425 | 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX', | |
426 | 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS', 'wxDIALOG_NO_PARENT' | |
427 | 'wxNO_3D', 'wxTAB_TRAVERSAL'] | |
428 | exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY', 'wxDIALOG_EX_METAL'] | |
d14a1e28 RD |
429 | styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', |
430 | 'tooltip'] | |
d14a1e28 RD |
431 | |
432 | class xxxFrame(xxxContainer): | |
433 | allParams = ['title', 'centered', 'pos', 'size', 'style'] | |
434 | paramDict = {'centered': ParamBool} | |
435 | required = ['title'] | |
436 | default = {'title': ''} | |
306b6fe9 RR |
437 | winStyles = ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE', 'wxCAPTION', |
438 | 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxTHICK_FRAME', | |
439 | 'wxRESIZE_BORDER', 'wxRESIZE_BOX', 'wxCLOSE_BOX', | |
440 | 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX', | |
441 | 'wxFRAME_NO_TASKBAR', 'wxFRAME_SHAPED', 'wxFRAME_TOOL_WINDOW', | |
442 | 'wxFRAME_FLOAT_ON_PARENT', | |
443 | 'wxNO_3D', 'wxTAB_TRAVERSAL'] | |
444 | exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY', 'wxFRAME_EX_METAL'] | |
d14a1e28 RD |
445 | styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', |
446 | 'tooltip'] | |
d14a1e28 RD |
447 | |
448 | class xxxTool(xxxObject): | |
71b1eafc | 449 | allParams = ['bitmap', 'bitmap2', 'radio', 'toggle', 'tooltip', 'longhelp', 'label'] |
d14a1e28 | 450 | required = ['bitmap'] |
71b1eafc | 451 | paramDict = {'bitmap2': ParamBitmap, 'radio': ParamBool, 'toggle': ParamBool} |
d14a1e28 RD |
452 | hasStyle = False |
453 | ||
454 | class xxxToolBar(xxxContainer): | |
71b1eafc | 455 | allParams = ['bitmapsize', 'margins', 'packing', 'separation', 'dontattachtoframe', |
d14a1e28 RD |
456 | 'pos', 'size', 'style'] |
457 | hasStyle = False | |
458 | paramDict = {'bitmapsize': ParamPosSize, 'margins': ParamPosSize, | |
c032d94e | 459 | 'packing': ParamUnit, 'separation': ParamUnit, |
71b1eafc RR |
460 | 'dontattachtoframe': ParamBool, 'style': ParamNonGenericStyle} |
461 | winStyles = ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL', | |
462 | 'wxTB_3DBUTTONS','wxTB_TEXT', 'wxTB_NOICONS', 'wxTB_NODIVIDER', | |
463 | 'wxTB_NOALIGN', 'wxTB_HORZ_LAYOUT', 'wxTB_HORZ_TEXT'] | |
d14a1e28 | 464 | |
306b6fe9 RR |
465 | class xxxStatusBar(xxxObject): |
466 | hasStyle = False | |
467 | allParams = ['fields', 'widths', 'styles', 'style'] | |
468 | paramDict = {'fields': ParamIntNN, 'widths': ParamText, 'styles': ParamText, | |
469 | 'style': ParamNonGenericStyle} | |
470 | winStyles = ['wxST_SIZEGRIP'] | |
471 | ||
64bce500 RR |
472 | class xxxWizard(xxxContainer): |
473 | allParams = ['title', 'bitmap', 'pos'] | |
474 | required = ['title'] | |
475 | default = {'title': ''} | |
476 | winStyles = [] | |
477 | exStyles = ['wxWIZARD_EX_HELPBUTTON'] | |
f5318530 | 478 | styles = ['fg', 'bg', 'font', 'exstyle'] |
64bce500 RR |
479 | |
480 | class xxxWizardPage(xxxContainer): | |
481 | allParams = ['bitmap'] | |
482 | winStyles = [] | |
483 | exStyles = [] | |
484 | ||
485 | class xxxWizardPageSimple(xxxContainer): | |
486 | allParams = ['bitmap'] | |
487 | winStyles = [] | |
488 | exStyles = [] | |
489 | ||
d14a1e28 RD |
490 | ################################################################################ |
491 | # Bitmap, Icon | |
492 | ||
493 | class xxxBitmap(xxxObject): | |
494 | allParams = ['bitmap'] | |
495 | required = ['bitmap'] | |
496 | ||
497 | # Just like bitmap | |
498 | class xxxIcon(xxxObject): | |
f19b8f11 | 499 | allParams = [] |
d14a1e28 RD |
500 | |
501 | ################################################################################ | |
502 | # Controls | |
503 | ||
504 | class xxxStaticText(xxxObject): | |
505 | allParams = ['label', 'pos', 'size', 'style'] | |
506 | required = ['label'] | |
507 | default = {'label': ''} | |
508 | winStyles = ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE'] | |
509 | ||
510 | class xxxStaticLine(xxxObject): | |
511 | allParams = ['pos', 'size', 'style'] | |
512 | winStyles = ['wxLI_HORIZONTAL', 'wxLI_VERTICAL'] | |
513 | ||
514 | class xxxStaticBitmap(xxxObject): | |
515 | allParams = ['bitmap', 'pos', 'size', 'style'] | |
516 | required = ['bitmap'] | |
517 | ||
518 | class xxxTextCtrl(xxxObject): | |
519 | allParams = ['value', 'pos', 'size', 'style'] | |
306b6fe9 RR |
520 | winStyles = ['wxTE_NO_VSCROLL', |
521 | 'wxTE_AUTO_SCROLL', | |
522 | 'wxTE_PROCESS_ENTER', | |
523 | 'wxTE_PROCESS_TAB', | |
524 | 'wxTE_MULTILINE', | |
525 | 'wxTE_PASSWORD', | |
526 | 'wxTE_READONLY', | |
527 | 'wxHSCROLL', | |
528 | 'wxTE_RICH', | |
529 | 'wxTE_RICH2', | |
530 | 'wxTE_AUTO_URL', | |
531 | 'wxTE_NOHIDESEL', | |
532 | 'wxTE_LEFT', | |
533 | 'wxTE_CENTRE', | |
534 | 'wxTE_RIGHT', | |
535 | 'wxTE_DONTWRAP', | |
536 | 'wxTE_LINEWRAP', | |
537 | 'wxTE_WORDWRAP'] | |
d14a1e28 RD |
538 | paramDict = {'value': ParamMultilineText} |
539 | ||
540 | class xxxChoice(xxxObject): | |
541 | allParams = ['content', 'selection', 'pos', 'size', 'style'] | |
542 | required = ['content'] | |
543 | default = {'content': '[]'} | |
544 | winStyles = ['wxCB_SORT'] | |
545 | ||
546 | class xxxSlider(xxxObject): | |
547 | allParams = ['value', 'min', 'max', 'pos', 'size', 'style', | |
548 | 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick', | |
549 | 'selmin', 'selmax'] | |
c032d94e RR |
550 | paramDict = {'value': ParamInt, 'tickfreq': ParamIntNN, 'pagesize': ParamIntNN, |
551 | 'linesize': ParamIntNN, 'thumb': ParamUnit, | |
d14a1e28 RD |
552 | 'tick': ParamInt, 'selmin': ParamInt, 'selmax': ParamInt} |
553 | required = ['value', 'min', 'max'] | |
554 | winStyles = ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS', | |
555 | 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM', | |
6e2bdf8f | 556 | 'wxSL_BOTH', 'wxSL_SELRANGE', 'wxSL_INVERSE'] |
d14a1e28 RD |
557 | |
558 | class xxxGauge(xxxObject): | |
559 | allParams = ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel'] | |
c032d94e RR |
560 | paramDict = {'range': ParamIntNN, 'value': ParamIntNN, |
561 | 'shadow': ParamIntNN, 'bezel': ParamIntNN} | |
d14a1e28 RD |
562 | winStyles = ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH'] |
563 | ||
564 | class xxxScrollBar(xxxObject): | |
565 | allParams = ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize'] | |
c032d94e RR |
566 | paramDict = {'value': ParamIntNN, 'range': ParamIntNN, 'thumbsize': ParamIntNN, |
567 | 'pagesize': ParamIntNN} | |
d14a1e28 RD |
568 | winStyles = ['wxSB_HORIZONTAL', 'wxSB_VERTICAL'] |
569 | ||
570 | class xxxListCtrl(xxxObject): | |
571 | allParams = ['pos', 'size', 'style'] | |
572 | winStyles = ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON', | |
306b6fe9 RR |
573 | 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE', |
574 | 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER', | |
575 | 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING', | |
576 | 'wxLC_VIRTUAL', 'wxLC_HRULES', 'wxLC_VRULES', 'wxLC_NO_SORT_HEADER'] | |
d14a1e28 RD |
577 | |
578 | class xxxTreeCtrl(xxxObject): | |
579 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 RR |
580 | winStyles = ['wxTR_EDIT_LABELS', |
581 | 'wxTR_NO_BUTTONS', | |
582 | 'wxTR_HAS_BUTTONS', | |
583 | 'wxTR_TWIST_BUTTONS', | |
584 | 'wxTR_NO_LINES', | |
585 | 'wxTR_FULL_ROW_HIGHLIGHT', | |
586 | 'wxTR_LINES_AT_ROOT', | |
587 | 'wxTR_HIDE_ROOT', | |
588 | 'wxTR_ROW_LINES', | |
589 | 'wxTR_HAS_VARIABLE_ROW_HEIGHT', | |
590 | 'wxTR_SINGLE', | |
591 | 'wxTR_MULTIPLE', | |
592 | 'wxTR_EXTENDED', | |
593 | 'wxTR_DEFAULT_STYLE'] | |
d14a1e28 RD |
594 | |
595 | class xxxHtmlWindow(xxxObject): | |
596 | allParams = ['pos', 'size', 'style', 'borders', 'url', 'htmlcode'] | |
306b6fe9 RR |
597 | paramDict = {'htmlcode':ParamMultilineText} |
598 | winStyles = ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO', 'wxHW_NO_SELECTION'] | |
d14a1e28 RD |
599 | |
600 | class xxxCalendarCtrl(xxxObject): | |
601 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 RR |
602 | winStyles = ['wxCAL_SUNDAY_FIRST', 'wxCAL_MONDAY_FIRST', 'wxCAL_SHOW_HOLIDAYS', |
603 | 'wxCAL_NO_YEAR_CHANGE', 'wxCAL_NO_MONTH_CHANGE', | |
604 | 'wxCAL_SEQUENTIAL_MONTH_SELECTION', 'wxCAL_SHOW_SURROUNDING_WEEKS'] | |
d14a1e28 RD |
605 | |
606 | class xxxNotebook(xxxContainer): | |
306b6fe9 RR |
607 | allParams = ['pos', 'size', 'style'] |
608 | winStyles = ['wxNB_DEFAULT', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM', | |
609 | 'wxNB_FIXEDWIDTH', 'wxNB_MULTILINE', 'wxNB_NOPAGETHEME'] | |
d14a1e28 | 610 | |
306b6fe9 RR |
611 | class xxxChoicebook(xxxContainer): |
612 | allParams = ['pos', 'size', 'style'] | |
613 | winStyles = ['wxCHB_DEFAULT', 'wxCHB_LEFT', 'wxCHB_RIGHT', 'wxCHB_TOP', 'wxCHB_BOTTOM'] | |
614 | ||
615 | class xxxListbook(xxxContainer): | |
616 | allParams = ['pos', 'size', 'style'] | |
617 | winStyles = ['wxLB_DEFAULT', 'wxLB_LEFT', 'wxLB_RIGHT', 'wxLB_TOP', 'wxLB_BOTTOM'] | |
618 | ||
68ae5821 RD |
619 | class xxxSplitterWindow(xxxContainer): |
620 | allParams = ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style'] | |
621 | paramDict = {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit } | |
306b6fe9 RR |
622 | winStyles = ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER', |
623 | 'wxSP_FULLSASH', 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE', | |
624 | 'wxSP_NO_XP_THEME' ] | |
68ae5821 | 625 | |
d14a1e28 RD |
626 | class xxxGenericDirCtrl(xxxObject): |
627 | allParams = ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style'] | |
c032d94e | 628 | paramDict = {'defaultfilter': ParamIntNN} |
d14a1e28 | 629 | winStyles = ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST', |
306b6fe9 | 630 | 'wxDIRCTRL_SHOW_FILTERS'] |
d14a1e28 RD |
631 | |
632 | class xxxScrolledWindow(xxxContainer): | |
633 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 RR |
634 | winStyles = ['wxHSCROLL', 'wxVSCROLL', 'wxNO_3D', 'wxTAB_TRAVERSAL'] |
635 | ||
636 | class xxxDateCtrl(xxxObject): | |
637 | allParams = ['pos', 'size', 'style', 'borders'] | |
638 | winStyles = ['wxDP_DEFAULT', 'wxDP_SPIN', 'wxDP_DROPDOWN', | |
639 | 'wxDP_ALLOWNONE', 'wxDP_SHOWCENTURY'] | |
d14a1e28 RD |
640 | |
641 | ################################################################################ | |
642 | # Buttons | |
643 | ||
644 | class xxxButton(xxxObject): | |
645 | allParams = ['label', 'default', 'pos', 'size', 'style'] | |
646 | paramDict = {'default': ParamBool} | |
647 | required = ['label'] | |
306b6fe9 | 648 | winStyles = ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM', 'wxBU_EXACTFIT'] |
d14a1e28 RD |
649 | |
650 | class xxxBitmapButton(xxxObject): | |
651 | allParams = ['bitmap', 'selected', 'focus', 'disabled', 'default', | |
652 | 'pos', 'size', 'style'] | |
29a41103 RD |
653 | paramDict = {'selected': ParamBitmap, 'focus': ParamBitmap, 'disabled': ParamBitmap, |
654 | 'default': ParamBool} | |
d14a1e28 | 655 | required = ['bitmap'] |
306b6fe9 RR |
656 | winStyles = ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_RIGHT', |
657 | 'wxBU_TOP', 'wxBU_BOTTOM', 'wxBU_EXACTFIT'] | |
d14a1e28 RD |
658 | |
659 | class xxxRadioButton(xxxObject): | |
660 | allParams = ['label', 'value', 'pos', 'size', 'style'] | |
661 | paramDict = {'value': ParamBool} | |
662 | required = ['label'] | |
306b6fe9 | 663 | winStyles = ['wxRB_GROUP', 'wxRB_SINGLE'] |
d14a1e28 RD |
664 | |
665 | class xxxSpinButton(xxxObject): | |
666 | allParams = ['value', 'min', 'max', 'pos', 'size', 'style'] | |
667 | paramDict = {'value': ParamInt} | |
668 | winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP'] | |
669 | ||
670 | class xxxSpinCtrl(xxxObject): | |
671 | allParams = ['value', 'min', 'max', 'pos', 'size', 'style'] | |
672 | paramDict = {'value': ParamInt} | |
673 | winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP'] | |
674 | ||
3d49f2fb RD |
675 | class xxxToggleButton(xxxObject): |
676 | allParams = ['label', 'checked', 'pos', 'size', 'style'] | |
677 | paramDict = {'checked': ParamBool} | |
678 | required = ['label'] | |
679 | ||
d14a1e28 RD |
680 | ################################################################################ |
681 | # Boxes | |
682 | ||
683 | class xxxStaticBox(xxxObject): | |
684 | allParams = ['label', 'pos', 'size', 'style'] | |
685 | required = ['label'] | |
686 | ||
687 | class xxxRadioBox(xxxObject): | |
688 | allParams = ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style'] | |
c032d94e | 689 | paramDict = {'dimension': ParamIntNN} |
d14a1e28 RD |
690 | required = ['label', 'content'] |
691 | default = {'content': '[]'} | |
306b6fe9 RR |
692 | winStyles = ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS', 'wxRA_HORIZONTAL', |
693 | 'wxRA_VERTICAL'] | |
d14a1e28 RD |
694 | |
695 | class xxxCheckBox(xxxObject): | |
696 | allParams = ['label', 'checked', 'pos', 'size', 'style'] | |
697 | paramDict = {'checked': ParamBool} | |
3d49f2fb RD |
698 | winStyles = ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER', |
699 | 'wxALIGN_RIGHT'] | |
d14a1e28 RD |
700 | required = ['label'] |
701 | ||
702 | class xxxComboBox(xxxObject): | |
703 | allParams = ['content', 'selection', 'value', 'pos', 'size', 'style'] | |
704 | required = ['content'] | |
705 | default = {'content': '[]'} | |
706 | winStyles = ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN'] | |
707 | ||
708 | class xxxListBox(xxxObject): | |
709 | allParams = ['content', 'selection', 'pos', 'size', 'style'] | |
710 | required = ['content'] | |
711 | default = {'content': '[]'} | |
712 | winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL', | |
306b6fe9 | 713 | 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT'] |
d14a1e28 RD |
714 | |
715 | class xxxCheckList(xxxObject): | |
716 | allParams = ['content', 'pos', 'size', 'style'] | |
717 | required = ['content'] | |
718 | default = {'content': '[]'} | |
306b6fe9 RR |
719 | winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL', |
720 | 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT'] | |
d14a1e28 RD |
721 | paramDict = {'content': ParamContentCheckList} |
722 | ||
723 | ################################################################################ | |
724 | # Sizers | |
725 | ||
726 | class xxxSizer(xxxContainer): | |
727 | hasName = hasStyle = False | |
728 | paramDict = {'orient': ParamOrient} | |
729 | isSizer = True | |
64b9ac75 | 730 | itemTag = 'sizeritem' # different for some sizers |
d14a1e28 RD |
731 | |
732 | class xxxBoxSizer(xxxSizer): | |
733 | allParams = ['orient'] | |
734 | required = ['orient'] | |
735 | default = {'orient': 'wxVERTICAL'} | |
736 | # Tree icon depends on orientation | |
737 | def treeImage(self): | |
738 | if self.params['orient'].value() == 'wxHORIZONTAL': return self.imageH | |
739 | else: return self.imageV | |
740 | ||
741 | class xxxStaticBoxSizer(xxxBoxSizer): | |
742 | allParams = ['label', 'orient'] | |
743 | required = ['label', 'orient'] | |
744 | ||
745 | class xxxGridSizer(xxxSizer): | |
746 | allParams = ['cols', 'rows', 'vgap', 'hgap'] | |
747 | required = ['cols'] | |
748 | default = {'cols': '2', 'rows': '2'} | |
749 | ||
64bce500 RR |
750 | class xxxStdDialogButtonSizer(xxxSizer): |
751 | allParams = [] | |
64b9ac75 | 752 | itemTag = 'button' |
64bce500 | 753 | |
d14a1e28 RD |
754 | # For repeated parameters |
755 | class xxxParamMulti: | |
756 | def __init__(self, node): | |
757 | self.node = node | |
758 | self.l, self.data = [], [] | |
759 | def append(self, param): | |
760 | self.l.append(param) | |
761 | self.data.append(param.value()) | |
762 | def value(self): | |
763 | return self.data | |
764 | def remove(self): | |
765 | for param in self.l: | |
766 | param.remove() | |
767 | self.l, self.data = [], [] | |
768 | ||
769 | class xxxFlexGridSizer(xxxGridSizer): | |
770 | specials = ['growablecols', 'growablerows'] | |
771 | allParams = ['cols', 'rows', 'vgap', 'hgap'] + specials | |
306b6fe9 | 772 | paramDict = {'growablecols': ParamIntList, 'growablerows': ParamIntList} |
d14a1e28 RD |
773 | # Special processing for growable* parameters |
774 | # (they are represented by several nodes) | |
775 | def special(self, tag, node): | |
776 | if not self.params.has_key(tag): | |
777 | # Create new multi-group | |
778 | self.params[tag] = xxxParamMulti(node) | |
779 | self.params[tag].append(xxxParamInt(node)) | |
780 | def setSpecial(self, param, value): | |
781 | # Straightforward implementation: remove, add again | |
782 | self.params[param].remove() | |
783 | del self.params[param] | |
784 | for i in value: | |
785 | node = g.tree.dom.createElement(param) | |
786 | text = g.tree.dom.createTextNode(str(i)) | |
787 | node.appendChild(text) | |
788 | self.element.appendChild(node) | |
789 | self.special(param, node) | |
790 | ||
a4c013b2 RR |
791 | class xxxGridBagSizer(xxxSizer): |
792 | specials = ['growablecols', 'growablerows'] | |
793 | allParams = ['vgap', 'hgap'] + specials | |
794 | paramDict = {'growablecols':ParamIntList, 'growablerows':ParamIntList} | |
795 | # Special processing for growable* parameters | |
796 | # (they are represented by several nodes) | |
797 | def special(self, tag, node): | |
798 | if not self.params.has_key(tag): | |
799 | # Create new multi-group | |
800 | self.params[tag] = xxxParamMulti(node) | |
801 | self.params[tag].append(xxxParamInt(node)) | |
802 | def setSpecial(self, param, value): | |
803 | # Straightforward implementation: remove, add again | |
804 | self.params[param].remove() | |
805 | del self.params[param] | |
806 | for i in value: | |
807 | node = g.tree.dom.createElement(param) | |
808 | text = g.tree.dom.createTextNode(str(i)) | |
809 | node.appendChild(text) | |
810 | self.element.appendChild(node) | |
811 | self.special(param, node) | |
812 | ||
d14a1e28 RD |
813 | # Container with only one child. |
814 | # Not shown in tree. | |
815 | class xxxChildContainer(xxxObject): | |
816 | hasName = hasStyle = False | |
817 | hasChild = True | |
03319b65 RR |
818 | def __init__(self, parent, element, refElem=None): |
819 | xxxObject.__init__(self, parent, element, refElem) | |
d14a1e28 RD |
820 | # Must have one child with 'object' tag, but we don't check it |
821 | nodes = element.childNodes[:] # create copy | |
822 | for node in nodes: | |
823 | if node.nodeType == minidom.Node.ELEMENT_NODE: | |
03319b65 | 824 | if node.tagName in ['object', 'object_ref']: |
d14a1e28 RD |
825 | # Create new xxx object for child node |
826 | self.child = MakeXXXFromDOM(self, node) | |
827 | self.child.parent = parent | |
828 | # Copy hasChildren and isSizer attributes | |
829 | self.hasChildren = self.child.hasChildren | |
830 | self.isSizer = self.child.isSizer | |
831 | return # success | |
832 | else: | |
833 | element.removeChild(node) | |
834 | node.unlink() | |
835 | assert 0, 'no child found' | |
836 | ||
837 | class xxxSizerItem(xxxChildContainer): | |
a4c013b2 RR |
838 | allParams = ['option', 'flag', 'border', 'minsize', 'ratio'] |
839 | paramDict = {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize} | |
840 | #default = {'cellspan': '1,1'} | |
03319b65 | 841 | def __init__(self, parent, element, refElem=None): |
a4c013b2 RR |
842 | # For GridBag sizer items, extra parameters added |
843 | if isinstance(parent, xxxGridBagSizer): | |
844 | self.allParams = self.allParams + ['cellpos', 'cellspan'] | |
03319b65 | 845 | xxxChildContainer.__init__(self, parent, element, refElem) |
d14a1e28 RD |
846 | # Remove pos parameter - not needed for sizeritems |
847 | if 'pos' in self.child.allParams: | |
848 | self.child.allParams = self.child.allParams[:] | |
849 | self.child.allParams.remove('pos') | |
850 | ||
64b9ac75 RR |
851 | class xxxSizerItemButton(xxxSizerItem): |
852 | allParams = [] | |
853 | paramDict = {} | |
03319b65 RR |
854 | def __init__(self, parent, element, refElem=None): |
855 | xxxChildContainer.__init__(self, parent, element, refElem=None) | |
64b9ac75 RR |
856 | # Remove pos parameter - not needed for sizeritems |
857 | if 'pos' in self.child.allParams: | |
858 | self.child.allParams = self.child.allParams[:] | |
859 | self.child.allParams.remove('pos') | |
860 | ||
306b6fe9 | 861 | class xxxPage(xxxChildContainer): |
d14a1e28 RD |
862 | allParams = ['label', 'selected'] |
863 | paramDict = {'selected': ParamBool} | |
864 | required = ['label'] | |
03319b65 RR |
865 | def __init__(self, parent, element, refElem=None): |
866 | xxxChildContainer.__init__(self, parent, element, refElem) | |
d14a1e28 RD |
867 | # pos and size dont matter for notebookpages |
868 | if 'pos' in self.child.allParams: | |
869 | self.child.allParams = self.child.allParams[:] | |
870 | self.child.allParams.remove('pos') | |
871 | if 'size' in self.child.allParams: | |
872 | self.child.allParams = self.child.allParams[:] | |
873 | self.child.allParams.remove('size') | |
874 | ||
875 | class xxxSpacer(xxxObject): | |
876 | hasName = hasStyle = False | |
877 | allParams = ['size', 'option', 'flag', 'border'] | |
878 | paramDict = {'option': ParamInt} | |
879 | default = {'size': '0,0'} | |
28e65e0f RR |
880 | def __init__(self, parent, element, refElem=None): |
881 | # For GridBag sizer items, extra parameters added | |
882 | if isinstance(parent, xxxGridBagSizer): | |
883 | self.allParams = self.allParams + ['cellpos', 'cellspan'] | |
884 | xxxObject.__init__(self, parent, element, refElem) | |
d14a1e28 RD |
885 | |
886 | class xxxMenuBar(xxxContainer): | |
887 | allParams = ['style'] | |
888 | paramDict = {'style': ParamNonGenericStyle} # no generic styles | |
889 | winStyles = ['wxMB_DOCKABLE'] | |
890 | ||
891 | class xxxMenu(xxxContainer): | |
892 | allParams = ['label', 'help', 'style'] | |
893 | default = {'label': ''} | |
894 | paramDict = {'style': ParamNonGenericStyle} # no generic styles | |
895 | winStyles = ['wxMENU_TEAROFF'] | |
896 | ||
897 | class xxxMenuItem(xxxObject): | |
898 | allParams = ['label', 'bitmap', 'accel', 'help', | |
899 | 'checkable', 'radio', 'enabled', 'checked'] | |
900 | default = {'label': ''} | |
901 | hasStyle = False | |
902 | ||
903 | class xxxSeparator(xxxObject): | |
904 | hasName = hasStyle = False | |
905 | ||
906 | ################################################################################ | |
907 | # Unknown control | |
908 | ||
909 | class xxxUnknown(xxxObject): | |
910 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 | 911 | winStyles = ['wxNO_FULL_REPAINT_ON_RESIZE'] |
d14a1e28 RD |
912 | |
913 | ################################################################################ | |
914 | ||
915 | xxxDict = { | |
916 | 'wxPanel': xxxPanel, | |
917 | 'wxDialog': xxxDialog, | |
918 | 'wxFrame': xxxFrame, | |
919 | 'tool': xxxTool, | |
920 | 'wxToolBar': xxxToolBar, | |
306b6fe9 | 921 | 'wxStatusBar': xxxStatusBar, |
64bce500 RR |
922 | 'wxWizard': xxxWizard, |
923 | 'wxWizardPage': xxxWizardPage, | |
924 | 'wxWizardPageSimple': xxxWizardPageSimple, | |
d14a1e28 RD |
925 | |
926 | 'wxBitmap': xxxBitmap, | |
927 | 'wxIcon': xxxIcon, | |
928 | ||
929 | 'wxButton': xxxButton, | |
930 | 'wxBitmapButton': xxxBitmapButton, | |
931 | 'wxRadioButton': xxxRadioButton, | |
932 | 'wxSpinButton': xxxSpinButton, | |
3d49f2fb | 933 | 'wxToggleButton' : xxxToggleButton, |
d14a1e28 RD |
934 | |
935 | 'wxStaticBox': xxxStaticBox, | |
936 | 'wxStaticBitmap': xxxStaticBitmap, | |
937 | 'wxRadioBox': xxxRadioBox, | |
938 | 'wxComboBox': xxxComboBox, | |
939 | 'wxCheckBox': xxxCheckBox, | |
940 | 'wxListBox': xxxListBox, | |
941 | ||
942 | 'wxStaticText': xxxStaticText, | |
943 | 'wxStaticLine': xxxStaticLine, | |
944 | 'wxTextCtrl': xxxTextCtrl, | |
945 | 'wxChoice': xxxChoice, | |
946 | 'wxSlider': xxxSlider, | |
947 | 'wxGauge': xxxGauge, | |
948 | 'wxScrollBar': xxxScrollBar, | |
949 | 'wxTreeCtrl': xxxTreeCtrl, | |
950 | 'wxListCtrl': xxxListCtrl, | |
edfeb1b8 | 951 | 'wxCheckListBox': xxxCheckList, |
306b6fe9 RR |
952 | 'notebookpage': xxxPage, |
953 | 'choicebookpage': xxxPage, | |
954 | 'listbookpage': xxxPage, | |
d14a1e28 | 955 | 'wxNotebook': xxxNotebook, |
306b6fe9 RR |
956 | 'wxChoicebook': xxxChoicebook, |
957 | 'wxListbook': xxxListbook, | |
68ae5821 | 958 | 'wxSplitterWindow': xxxSplitterWindow, |
d14a1e28 RD |
959 | 'wxHtmlWindow': xxxHtmlWindow, |
960 | 'wxCalendarCtrl': xxxCalendarCtrl, | |
961 | 'wxGenericDirCtrl': xxxGenericDirCtrl, | |
962 | 'wxSpinCtrl': xxxSpinCtrl, | |
963 | 'wxScrolledWindow': xxxScrolledWindow, | |
306b6fe9 | 964 | 'wxDatePickerCtrl': xxxDateCtrl, |
d14a1e28 RD |
965 | |
966 | 'wxBoxSizer': xxxBoxSizer, | |
967 | 'wxStaticBoxSizer': xxxStaticBoxSizer, | |
968 | 'wxGridSizer': xxxGridSizer, | |
969 | 'wxFlexGridSizer': xxxFlexGridSizer, | |
a4c013b2 | 970 | 'wxGridBagSizer': xxxGridBagSizer, |
64bce500 | 971 | 'wxStdDialogButtonSizer': xxxStdDialogButtonSizer, |
64b9ac75 | 972 | 'sizeritem': xxxSizerItem, 'button': xxxSizerItemButton, |
d14a1e28 RD |
973 | 'spacer': xxxSpacer, |
974 | ||
975 | 'wxMenuBar': xxxMenuBar, | |
976 | 'wxMenu': xxxMenu, | |
977 | 'wxMenuItem': xxxMenuItem, | |
978 | 'separator': xxxSeparator, | |
979 | ||
980 | 'unknown': xxxUnknown, | |
981 | } | |
982 | ||
983 | # Create IDs for all parameters of all classes | |
29a41103 RD |
984 | paramIDs = {'fg': wx.NewId(), 'bg': wx.NewId(), 'exstyle': wx.NewId(), 'font': wx.NewId(), |
985 | 'enabled': wx.NewId(), 'focused': wx.NewId(), 'hidden': wx.NewId(), | |
986 | 'tooltip': wx.NewId(), 'encoding': wx.NewId(), | |
987 | 'cellpos': wx.NewId(), 'cellspan': wx.NewId() | |
d14a1e28 RD |
988 | } |
989 | for cl in xxxDict.values(): | |
990 | if cl.allParams: | |
991 | for param in cl.allParams + cl.paramDict.keys(): | |
992 | if not paramIDs.has_key(param): | |
29a41103 | 993 | paramIDs[param] = wx.NewId() |
d14a1e28 RD |
994 | |
995 | ################################################################################ | |
996 | # Helper functions | |
997 | ||
998 | # Test for object elements | |
999 | def IsObject(node): | |
03319b65 | 1000 | return node.nodeType == minidom.Node.ELEMENT_NODE and node.tagName in ['object', 'object_ref'] |
d14a1e28 RD |
1001 | |
1002 | # Make XXX object from some DOM object, selecting correct class | |
1003 | def MakeXXXFromDOM(parent, element): | |
03319b65 RR |
1004 | if element.tagName == 'object_ref': |
1005 | ref = element.getAttribute('ref') | |
1006 | refElem = FindResource(ref) | |
1007 | if refElem: cls = refElem.getAttribute('class') | |
1008 | else: return xxxUnknown(parent, element) | |
1009 | else: | |
1010 | refElem = None | |
1011 | cls = element.getAttribute('class') | |
d14a1e28 | 1012 | try: |
03319b65 | 1013 | klass = xxxDict[cls] |
d14a1e28 RD |
1014 | except KeyError: |
1015 | # If we encounter a weird class, use unknown template | |
1016 | print 'WARNING: unsupported class:', element.getAttribute('class') | |
1017 | klass = xxxUnknown | |
03319b65 | 1018 | return klass(parent, element, refElem) |
d14a1e28 RD |
1019 | |
1020 | # Make empty DOM element | |
1021 | def MakeEmptyDOM(className): | |
1022 | elem = g.tree.dom.createElement('object') | |
1023 | elem.setAttribute('class', className) | |
1024 | # Set required and default parameters | |
1025 | xxxClass = xxxDict[className] | |
1026 | defaultNotRequired = filter(lambda x, l=xxxClass.required: x not in l, | |
1027 | xxxClass.default.keys()) | |
1028 | for param in xxxClass.required + defaultNotRequired: | |
1029 | textElem = g.tree.dom.createElement(param) | |
1030 | try: | |
1031 | textNode = g.tree.dom.createTextNode(xxxClass.default[param]) | |
1032 | except KeyError: | |
1033 | textNode = g.tree.dom.createTextNode('') | |
1034 | textElem.appendChild(textNode) | |
1035 | elem.appendChild(textElem) | |
1036 | return elem | |
1037 | ||
1038 | # Make empty XXX object | |
1039 | def MakeEmptyXXX(parent, className): | |
1040 | # Make corresponding DOM object first | |
1041 | elem = MakeEmptyDOM(className) | |
1042 | # If parent is a sizer, we should create sizeritem object, except for spacers | |
1043 | if parent: | |
1044 | if parent.isSizer and className != 'spacer': | |
64b9ac75 | 1045 | sizerItemElem = MakeEmptyDOM(parent.itemTag) |
d14a1e28 RD |
1046 | sizerItemElem.appendChild(elem) |
1047 | elem = sizerItemElem | |
1048 | elif isinstance(parent, xxxNotebook): | |
1049 | pageElem = MakeEmptyDOM('notebookpage') | |
1050 | pageElem.appendChild(elem) | |
1051 | elem = pageElem | |
306b6fe9 RR |
1052 | elif isinstance(parent, xxxChoicebook): |
1053 | pageElem = MakeEmptyDOM('choicebookpage') | |
1054 | pageElem.appendChild(elem) | |
1055 | elem = pageElem | |
1056 | elif isinstance(parent, xxxListbook): | |
1057 | pageElem = MakeEmptyDOM('listbookpage') | |
1058 | pageElem.appendChild(elem) | |
1059 | elem = pageElem | |
d14a1e28 RD |
1060 | # Now just make object |
1061 | return MakeXXXFromDOM(parent, elem) | |
1fded56b | 1062 | |
03319b65 RR |
1063 | # Make empty DOM element for reference |
1064 | def MakeEmptyRefDOM(ref): | |
1065 | elem = g.tree.dom.createElement('object_ref') | |
1066 | elem.setAttribute('ref', ref) | |
1067 | return elem | |
1068 | ||
1069 | # Make empty XXX object | |
1070 | def MakeEmptyRefXXX(parent, ref): | |
1071 | # Make corresponding DOM object first | |
1072 | elem = MakeEmptyRefDOM(ref) | |
1073 | # If parent is a sizer, we should create sizeritem object, except for spacers | |
1074 | if parent: | |
1075 | if parent.isSizer: | |
1076 | sizerItemElem = MakeEmptyDOM(parent.itemTag) | |
1077 | sizerItemElem.appendChild(elem) | |
1078 | elem = sizerItemElem | |
1079 | elif isinstance(parent, xxxNotebook): | |
1080 | pageElem = MakeEmptyDOM('notebookpage') | |
1081 | pageElem.appendChild(elem) | |
1082 | elem = pageElem | |
306b6fe9 RR |
1083 | elif isinstance(parent, xxxChoicebook): |
1084 | pageElem = MakeEmptyDOM('choicebookpage') | |
1085 | pageElem.appendChild(elem) | |
1086 | elem = pageElem | |
1087 | elif isinstance(parent, xxxListbook): | |
1088 | pageElem = MakeEmptyDOM('listbookpage') | |
1089 | pageElem.appendChild(elem) | |
1090 | elem = pageElem | |
03319b65 RR |
1091 | # Now just make object |
1092 | return MakeXXXFromDOM(parent, elem) | |
1093 |