]>
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 * | |
00d15346 | 10 | import traceback, types |
d14a1e28 RD |
11 | |
12 | # Base class for interface parameter classes | |
13 | class xxxNode: | |
14 | def __init__(self, node): | |
15 | self.node = node | |
16 | def remove(self): | |
17 | self.node.parentNode.removeChild(self.node) | |
18 | self.node.unlink() | |
19 | ||
20 | # Generic (text) parameter class | |
21 | class xxxParam(xxxNode): | |
22 | # Standard use: for text nodes | |
23 | def __init__(self, node): | |
24 | xxxNode.__init__(self, node) | |
25 | if not node.hasChildNodes(): | |
26 | # If does not have child nodes, create empty text node | |
27 | text = g.tree.dom.createTextNode('') | |
28 | node.appendChild(text) | |
29 | else: | |
30 | text = node.childNodes[0] # first child must be text node | |
31 | assert text.nodeType == minidom.Node.TEXT_NODE | |
32 | # Append other text nodes if present and delete them | |
33 | extraText = '' | |
34 | for n in node.childNodes[1:]: | |
35 | if n.nodeType == minidom.Node.TEXT_NODE: | |
36 | extraText += n.data | |
37 | node.removeChild(n) | |
38 | n.unlink() | |
39 | else: break | |
40 | if extraText: text.data = text.data + extraText | |
41 | # Use convertion from unicode to current encoding | |
42 | self.textNode = text | |
43 | # Value returns string | |
29a41103 | 44 | if wx.USE_UNICODE: # no conversion is needed |
d14a1e28 RD |
45 | def value(self): |
46 | return self.textNode.data | |
47 | def update(self, value): | |
48 | self.textNode.data = value | |
49 | else: | |
50 | def value(self): | |
9a69d0aa RR |
51 | try: |
52 | return self.textNode.data.encode(g.currentEncoding) | |
53 | except LookupError: | |
54 | return self.textNode.data.encode() | |
d14a1e28 | 55 | def update(self, value): |
b81de788 | 56 | try: # handle exception if encoding is wrong |
80389ff7 | 57 | self.textNode.data = unicode(value, g.currentEncoding) |
b81de788 | 58 | except UnicodeDecodeError: |
9a69d0aa | 59 | self.textNode.data = unicode(value) |
29a41103 | 60 | #wx.LogMessage("Unicode error: set encoding in file\nglobals.py to something appropriate") |
d14a1e28 RD |
61 | |
62 | # Integer parameter | |
63 | class xxxParamInt(xxxParam): | |
64 | # Standard use: for text nodes | |
65 | def __init__(self, node): | |
66 | xxxParam.__init__(self, node) | |
67 | # Value returns string | |
68 | def value(self): | |
69 | try: | |
70 | return int(self.textNode.data) | |
71 | except ValueError: | |
72 | return -1 # invalid value | |
73 | def update(self, value): | |
74 | self.textNode.data = str(value) | |
75 | ||
76 | # Content parameter | |
77 | class xxxParamContent(xxxNode): | |
78 | def __init__(self, node): | |
79 | xxxNode.__init__(self, node) | |
80 | data, l = [], [] # data is needed to quicker value retrieval | |
81 | nodes = node.childNodes[:] # make a copy of the child list | |
82 | for n in nodes: | |
83 | if n.nodeType == minidom.Node.ELEMENT_NODE: | |
84 | assert n.tagName == 'item', 'bad content content' | |
85 | if not n.hasChildNodes(): | |
86 | # If does not have child nodes, create empty text node | |
87 | text = g.tree.dom.createTextNode('') | |
88 | node.appendChild(text) | |
89 | else: | |
90 | # !!! normalize? | |
91 | text = n.childNodes[0] # first child must be text node | |
92 | assert text.nodeType == minidom.Node.TEXT_NODE | |
93 | l.append(text) | |
e484fddf | 94 | data.append(text.data) |
d14a1e28 RD |
95 | else: # remove other |
96 | node.removeChild(n) | |
97 | n.unlink() | |
98 | self.l, self.data = l, data | |
99 | def value(self): | |
100 | return self.data | |
101 | def update(self, value): | |
102 | # If number if items is not the same, recreate children | |
103 | if len(value) != len(self.l): # remove first if number of items has changed | |
104 | childNodes = self.node.childNodes[:] | |
105 | for n in childNodes: | |
106 | self.node.removeChild(n) | |
107 | l = [] | |
108 | for str in value: | |
109 | itemElem = g.tree.dom.createElement('item') | |
110 | itemText = g.tree.dom.createTextNode(str) | |
111 | itemElem.appendChild(itemText) | |
112 | self.node.appendChild(itemElem) | |
113 | l.append(itemText) | |
114 | self.l = l | |
115 | else: | |
116 | for i in range(len(value)): | |
117 | self.l[i].data = value[i] | |
118 | self.data = value | |
119 | ||
120 | # Content parameter for checklist | |
121 | class xxxParamContentCheckList(xxxNode): | |
122 | def __init__(self, node): | |
123 | xxxNode.__init__(self, node) | |
124 | data, l = [], [] # data is needed to quicker value retrieval | |
125 | nodes = node.childNodes[:] # make a copy of the child list | |
126 | for n in nodes: | |
127 | if n.nodeType == minidom.Node.ELEMENT_NODE: | |
128 | assert n.tagName == 'item', 'bad content content' | |
129 | checked = n.getAttribute('checked') | |
130 | if not checked: checked = 0 | |
131 | if not n.hasChildNodes(): | |
132 | # If does not have child nodes, create empty text node | |
133 | text = g.tree.dom.createTextNode('') | |
134 | node.appendChild(text) | |
135 | else: | |
136 | # !!! normalize? | |
137 | text = n.childNodes[0] # first child must be text node | |
138 | assert text.nodeType == minidom.Node.TEXT_NODE | |
139 | l.append((text, n)) | |
140 | data.append((str(text.data), int(checked))) | |
141 | else: # remove other | |
142 | node.removeChild(n) | |
143 | n.unlink() | |
144 | self.l, self.data = l, data | |
145 | def value(self): | |
146 | return self.data | |
147 | def update(self, value): | |
148 | # If number if items is not the same, recreate children | |
149 | if len(value) != len(self.l): # remove first if number of items has changed | |
150 | childNodes = self.node.childNodes[:] | |
151 | for n in childNodes: | |
152 | self.node.removeChild(n) | |
153 | l = [] | |
154 | for s,ch in value: | |
155 | itemElem = g.tree.dom.createElement('item') | |
156 | # Add checked only if True | |
157 | if ch: itemElem.setAttribute('checked', '1') | |
158 | itemText = g.tree.dom.createTextNode(s) | |
159 | itemElem.appendChild(itemText) | |
160 | self.node.appendChild(itemElem) | |
161 | l.append((itemText, itemElem)) | |
162 | self.l = l | |
163 | else: | |
164 | for i in range(len(value)): | |
165 | self.l[i][0].data = value[i][0] | |
166 | self.l[i][1].setAttribute('checked', str(value[i][1])) | |
167 | self.data = value | |
168 | ||
169 | # Bitmap parameter | |
170 | class xxxParamBitmap(xxxParam): | |
171 | def __init__(self, node): | |
172 | xxxParam.__init__(self, node) | |
173 | self.stock_id = node.getAttribute('stock_id') | |
174 | def value(self): | |
175 | return [self.stock_id, xxxParam.value(self)] | |
176 | def update(self, value): | |
177 | self.stock_id = value[0] | |
178 | if self.stock_id: | |
179 | self.node.setAttribute('stock_id', self.stock_id) | |
180 | elif self.node.hasAttribute('stock_id'): | |
181 | self.node.removeAttribute('stock_id') | |
182 | xxxParam.update(self, value[1]) | |
183 | ||
184 | ################################################################################ | |
185 | ||
186 | # Classes to interface DOM objects | |
187 | class xxxObject: | |
188 | # Default behavior | |
189 | hasChildren = False # has children elements? | |
190 | hasStyle = True # almost everyone | |
191 | hasName = True # has name attribute? | |
192 | isSizer = hasChild = False | |
b372319f | 193 | isElement = True |
d14a1e28 RD |
194 | allParams = None # Some nodes have no parameters |
195 | # Style parameters (all optional) | |
196 | styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip'] | |
197 | # Special parameters | |
198 | specials = [] | |
199 | # Bitmap tags | |
200 | bitmapTags = ['bitmap', 'bitmap2', 'icon'] | |
201 | # Required paremeters: none by default | |
202 | required = [] | |
203 | # Default parameters with default values | |
204 | default = {} | |
205 | # Parameter types | |
206 | paramDict = {} | |
207 | # Window styles and extended styles | |
208 | winStyles = [] | |
209 | # Tree icon index | |
210 | #image = -1 | |
211 | # Construct a new xxx object from DOM element | |
212 | # parent is parent xxx object (or None if none), element is DOM element object | |
03319b65 | 213 | def __init__(self, parent, element, refElem=None): |
d14a1e28 | 214 | self.parent = parent |
b372319f | 215 | self.node = element |
03319b65 | 216 | self.refElem = refElem |
d14a1e28 | 217 | self.undo = None |
03319b65 RR |
218 | # Reference are dereferenced |
219 | if element.tagName == 'object_ref': | |
220 | # Find original object | |
221 | self.ref = element.getAttribute('ref') | |
222 | if refElem: | |
223 | self.className = self.refElem.getAttribute('class') | |
224 | else: | |
225 | self.className = 'xxxUnknown' | |
226 | self.required = [] | |
227 | else: | |
228 | # Get attributes | |
229 | self.ref = None | |
230 | self.className = element.getAttribute('class') | |
2481bf3c | 231 | self.subclass = element.getAttribute('subclass') |
d14a1e28 RD |
232 | if self.hasName: self.name = element.getAttribute('name') |
233 | # Set parameters (text element children) | |
234 | self.params = {} | |
b372319f RR |
235 | for n in element.childNodes[:]: |
236 | if n.nodeType == minidom.Node.ELEMENT_NODE: | |
237 | tag = n.tagName | |
03319b65 | 238 | if tag in ['object', 'object_ref']: |
d14a1e28 | 239 | continue # do nothing for object children here |
03319b65 | 240 | elif tag not in self.allParams and tag not in self.styles: |
d14a1e28 RD |
241 | print 'WARNING: unknown parameter for %s: %s' % \ |
242 | (self.className, tag) | |
243 | elif tag in self.specials: | |
b372319f | 244 | self.special(tag, n) |
d14a1e28 | 245 | elif tag == 'content': |
edfeb1b8 | 246 | if self.className == 'wxCheckListBox': |
b372319f | 247 | self.params[tag] = xxxParamContentCheckList(n) |
d14a1e28 | 248 | else: |
b372319f | 249 | self.params[tag] = xxxParamContent(n) |
d14a1e28 | 250 | elif tag == 'font': # has children |
b372319f | 251 | self.params[tag] = xxxParamFont(element, n) |
d14a1e28 RD |
252 | elif tag in self.bitmapTags: |
253 | # Can have attributes | |
b372319f | 254 | self.params[tag] = xxxParamBitmap(n) |
d14a1e28 | 255 | else: # simple parameter |
b372319f RR |
256 | self.params[tag] = xxxParam(n) |
257 | elif n.nodeType == minidom.Node.TEXT_NODE and n.data.isspace(): | |
71b1eafc | 258 | # Remove empty text nodes |
b372319f RR |
259 | element.removeChild(n) |
260 | n.unlink() | |
f19b8f11 | 261 | |
d14a1e28 RD |
262 | # Check that all required params are set |
263 | for param in self.required: | |
264 | if not self.params.has_key(param): | |
265 | # If default is specified, set it | |
266 | if self.default.has_key(param): | |
267 | elem = g.tree.dom.createElement(param) | |
268 | if param == 'content': | |
edfeb1b8 | 269 | if self.className == 'wxCheckListBox': |
d14a1e28 RD |
270 | self.params[param] = xxxParamContentCheckList(elem) |
271 | else: | |
272 | self.params[param] = xxxParamContent(elem) | |
273 | else: | |
274 | self.params[param] = xxxParam(elem) | |
275 | # Find place to put new element: first present element after param | |
276 | found = False | |
277 | paramStyles = self.allParams + self.styles | |
278 | for p in paramStyles[paramStyles.index(param) + 1:]: | |
279 | # Content params don't have same type | |
280 | if self.params.has_key(p) and p != 'content': | |
281 | found = True | |
282 | break | |
283 | if found: | |
284 | nextTextElem = self.params[p].node | |
b372319f | 285 | self.node.insertBefore(elem, nextTextElem) |
d14a1e28 | 286 | else: |
b372319f | 287 | self.node.appendChild(elem) |
d14a1e28 | 288 | else: |
29a41103 | 289 | wx.LogWarning('Required parameter %s of %s missing' % |
d14a1e28 RD |
290 | (param, self.className)) |
291 | # Returns real tree object | |
292 | def treeObject(self): | |
293 | if self.hasChild: return self.child | |
294 | return self | |
295 | # Returns tree image index | |
296 | def treeImage(self): | |
297 | if self.hasChild: return self.child.treeImage() | |
298 | return self.image | |
299 | # Class name plus wx name | |
300 | def treeName(self): | |
301 | if self.hasChild: return self.child.treeName() | |
2481bf3c RR |
302 | if self.subclass: className = self.subclass |
303 | else: className = self.className | |
304 | if self.hasName and self.name: return className + ' "' + self.name + '"' | |
305 | return className | |
306 | # Class name or subclass | |
307 | def panelName(self): | |
03319b65 RR |
308 | if self.subclass: name = self.subclass + '(' + self.className + ')' |
309 | name = self.className | |
310 | if self.ref: name = 'ref: ' + self.ref + ', ' + name | |
311 | return name | |
64b9ac75 RR |
312 | # Sets name of tree object |
313 | def setTreeName(self, name): | |
314 | if self.hasChild: obj = self.child | |
315 | else: obj = self | |
316 | obj.name = name | |
b372319f | 317 | obj.node.setAttribute('name', name) |
c1dda21b RR |
318 | # Set normal (text) params |
319 | def set(self, param, value): | |
320 | try: | |
321 | self.params[param].update(value) | |
322 | except KeyError: | |
37867b24 RR |
323 | elem = g.tree.dom.createElement(param) |
324 | p = xxxParam(elem) | |
c1dda21b RR |
325 | p.update(value) |
326 | self.params[param] = p | |
37867b24 | 327 | self.node.appendChild(elem) |
7df24e78 RR |
328 | # Special processing for growablecols-like parameters |
329 | # represented by several nodes | |
330 | def special(self, tag, node): | |
7df24e78 RR |
331 | if not self.params.has_key(tag): |
332 | # Create new multi-group | |
333 | self.params[tag] = xxxParamMulti(node) | |
334 | self.params[tag].append(xxxParamInt(node)) | |
335 | def setSpecial(self, param, value): | |
336 | # Straightforward implementation: remove, add again | |
337 | self.params[param].remove() | |
338 | del self.params[param] | |
339 | for i in value: | |
340 | node = g.tree.dom.createElement(param) | |
341 | text = g.tree.dom.createTextNode(str(i)) | |
342 | node.appendChild(text) | |
b372319f | 343 | self.node.appendChild(node) |
7df24e78 | 344 | self.special(param, node) |
d14a1e28 | 345 | |
03319b65 RR |
346 | # Imitation of FindResource/DoFindResource from xmlres.cpp |
347 | def DoFindResource(parent, name, classname, recursive): | |
348 | for n in parent.childNodes: | |
349 | if n.nodeType == minidom.Node.ELEMENT_NODE and \ | |
350 | n.tagName in ['object', 'object_ref'] and \ | |
351 | n.getAttribute('name') == name: | |
352 | cls = n.getAttribute('class') | |
353 | if not classname or cls == classname: return n | |
354 | if not cls or n.tagName == 'object_ref': | |
355 | refName = n.getAttribute('ref') | |
356 | if not refName: continue | |
357 | refNode = FindResource(refName) | |
358 | if refName and refNode.getAttribute('class') == classname: | |
359 | return n | |
360 | if recursive: | |
361 | for n in parent.childNodes: | |
362 | if n.nodeType == minidom.Node.ELEMENT_NODE and \ | |
363 | n.tagName in ['object', 'object_ref']: | |
364 | found = DoFindResource(n, name, classname, True) | |
365 | if found: return found | |
366 | def FindResource(name, classname='', recursive=True): | |
367 | found = DoFindResource(g.tree.mainNode, name, classname, recursive) | |
368 | if found: return found | |
29a41103 | 369 | wx.LogError('XRC resource "%s" not found!' % name) |
03319b65 RR |
370 | |
371 | ||
d14a1e28 RD |
372 | ################################################################################ |
373 | ||
374 | # This is a little special: it is both xxxObject and xxxNode | |
375 | class xxxParamFont(xxxObject, xxxNode): | |
0d9b8891 | 376 | allParams = ['size', 'family', 'style', 'weight', 'underlined', |
d14a1e28 RD |
377 | 'face', 'encoding'] |
378 | def __init__(self, parent, element): | |
379 | xxxObject.__init__(self, parent, element) | |
380 | xxxNode.__init__(self, element) | |
381 | self.parentNode = parent # required to behave similar to DOM node | |
382 | v = [] | |
383 | for p in self.allParams: | |
384 | try: | |
385 | v.append(str(self.params[p].value())) | |
386 | except KeyError: | |
387 | v.append('') | |
388 | self.data = v | |
389 | def update(self, value): | |
390 | # `value' is a list of strings corresponding to all parameters | |
b372319f | 391 | elem = self.node |
d14a1e28 RD |
392 | # Remove old elements first |
393 | childNodes = elem.childNodes[:] | |
394 | for node in childNodes: elem.removeChild(node) | |
395 | i = 0 | |
396 | self.params.clear() | |
397 | v = [] | |
398 | for param in self.allParams: | |
399 | if value[i]: | |
400 | fontElem = g.tree.dom.createElement(param) | |
401 | textNode = g.tree.dom.createTextNode(value[i]) | |
402 | self.params[param] = textNode | |
403 | fontElem.appendChild(textNode) | |
404 | elem.appendChild(fontElem) | |
405 | v.append(value[i]) | |
406 | i += 1 | |
407 | self.data = v | |
408 | def value(self): | |
409 | return self.data | |
410 | ||
411 | ################################################################################ | |
412 | ||
413 | class xxxContainer(xxxObject): | |
414 | hasChildren = True | |
64bce500 | 415 | exStyles = [] |
d14a1e28 RD |
416 | |
417 | # Simulate normal parameter for encoding | |
418 | class xxxEncoding: | |
d14a1e28 | 419 | def value(self): |
7353d818 | 420 | return g.currentEncoding |
d14a1e28 | 421 | def update(self, val): |
7353d818 | 422 | g.currentEncoding = val |
d14a1e28 RD |
423 | |
424 | # Special class for root node | |
425 | class xxxMainNode(xxxContainer): | |
426 | allParams = ['encoding'] | |
427 | hasStyle = hasName = False | |
428 | def __init__(self, dom): | |
429 | xxxContainer.__init__(self, None, dom.documentElement) | |
430 | self.className = 'XML tree' | |
431 | # Reset required parameters after processing XML, because encoding is | |
432 | # a little special | |
433 | self.required = ['encoding'] | |
7353d818 | 434 | self.params['encoding'] = xxxEncoding() |
d14a1e28 RD |
435 | |
436 | ################################################################################ | |
437 | # Top-level windwows | |
438 | ||
439 | class xxxPanel(xxxContainer): | |
440 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 | 441 | winStyles = ['wxNO_3D', 'wxTAB_TRAVERSAL'] |
d14a1e28 RD |
442 | styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', |
443 | 'tooltip'] | |
d14a1e28 RD |
444 | |
445 | class xxxDialog(xxxContainer): | |
446 | allParams = ['title', 'centered', 'pos', 'size', 'style'] | |
447 | paramDict = {'centered': ParamBool} | |
448 | required = ['title'] | |
449 | default = {'title': ''} | |
306b6fe9 RR |
450 | winStyles = ['wxDEFAULT_DIALOG_STYLE', 'wxCAPTION', |
451 | 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxTHICK_FRAME', | |
452 | 'wxRESIZE_BORDER', 'wxRESIZE_BOX', 'wxCLOSE_BOX', | |
453 | 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX', | |
454 | 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS', 'wxDIALOG_NO_PARENT' | |
455 | 'wxNO_3D', 'wxTAB_TRAVERSAL'] | |
456 | exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY', 'wxDIALOG_EX_METAL'] | |
d14a1e28 RD |
457 | styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', |
458 | 'tooltip'] | |
d14a1e28 RD |
459 | |
460 | class xxxFrame(xxxContainer): | |
461 | allParams = ['title', 'centered', 'pos', 'size', 'style'] | |
462 | paramDict = {'centered': ParamBool} | |
463 | required = ['title'] | |
464 | default = {'title': ''} | |
306b6fe9 RR |
465 | winStyles = ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE', 'wxCAPTION', |
466 | 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxTHICK_FRAME', | |
467 | 'wxRESIZE_BORDER', 'wxRESIZE_BOX', 'wxCLOSE_BOX', | |
468 | 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX', | |
469 | 'wxFRAME_NO_TASKBAR', 'wxFRAME_SHAPED', 'wxFRAME_TOOL_WINDOW', | |
470 | 'wxFRAME_FLOAT_ON_PARENT', | |
471 | 'wxNO_3D', 'wxTAB_TRAVERSAL'] | |
472 | exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY', 'wxFRAME_EX_METAL'] | |
d14a1e28 RD |
473 | styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', |
474 | 'tooltip'] | |
d14a1e28 RD |
475 | |
476 | class xxxTool(xxxObject): | |
71b1eafc | 477 | allParams = ['bitmap', 'bitmap2', 'radio', 'toggle', 'tooltip', 'longhelp', 'label'] |
d14a1e28 | 478 | required = ['bitmap'] |
71b1eafc | 479 | paramDict = {'bitmap2': ParamBitmap, 'radio': ParamBool, 'toggle': ParamBool} |
d14a1e28 RD |
480 | hasStyle = False |
481 | ||
482 | class xxxToolBar(xxxContainer): | |
71b1eafc | 483 | allParams = ['bitmapsize', 'margins', 'packing', 'separation', 'dontattachtoframe', |
d14a1e28 RD |
484 | 'pos', 'size', 'style'] |
485 | hasStyle = False | |
486 | paramDict = {'bitmapsize': ParamPosSize, 'margins': ParamPosSize, | |
c032d94e | 487 | 'packing': ParamUnit, 'separation': ParamUnit, |
71b1eafc RR |
488 | 'dontattachtoframe': ParamBool, 'style': ParamNonGenericStyle} |
489 | winStyles = ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL', | |
490 | 'wxTB_3DBUTTONS','wxTB_TEXT', 'wxTB_NOICONS', 'wxTB_NODIVIDER', | |
491 | 'wxTB_NOALIGN', 'wxTB_HORZ_LAYOUT', 'wxTB_HORZ_TEXT'] | |
d14a1e28 | 492 | |
306b6fe9 RR |
493 | class xxxStatusBar(xxxObject): |
494 | hasStyle = False | |
495 | allParams = ['fields', 'widths', 'styles', 'style'] | |
496 | paramDict = {'fields': ParamIntNN, 'widths': ParamText, 'styles': ParamText, | |
497 | 'style': ParamNonGenericStyle} | |
498 | winStyles = ['wxST_SIZEGRIP'] | |
499 | ||
64bce500 RR |
500 | class xxxWizard(xxxContainer): |
501 | allParams = ['title', 'bitmap', 'pos'] | |
502 | required = ['title'] | |
503 | default = {'title': ''} | |
504 | winStyles = [] | |
505 | exStyles = ['wxWIZARD_EX_HELPBUTTON'] | |
f5318530 | 506 | styles = ['fg', 'bg', 'font', 'exstyle'] |
64bce500 RR |
507 | |
508 | class xxxWizardPage(xxxContainer): | |
509 | allParams = ['bitmap'] | |
510 | winStyles = [] | |
511 | exStyles = [] | |
512 | ||
513 | class xxxWizardPageSimple(xxxContainer): | |
514 | allParams = ['bitmap'] | |
515 | winStyles = [] | |
516 | exStyles = [] | |
517 | ||
d14a1e28 RD |
518 | ################################################################################ |
519 | # Bitmap, Icon | |
520 | ||
521 | class xxxBitmap(xxxObject): | |
522 | allParams = ['bitmap'] | |
523 | required = ['bitmap'] | |
524 | ||
525 | # Just like bitmap | |
526 | class xxxIcon(xxxObject): | |
f19b8f11 | 527 | allParams = [] |
d14a1e28 RD |
528 | |
529 | ################################################################################ | |
530 | # Controls | |
531 | ||
532 | class xxxStaticText(xxxObject): | |
533 | allParams = ['label', 'pos', 'size', 'style'] | |
534 | required = ['label'] | |
535 | default = {'label': ''} | |
536 | winStyles = ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE'] | |
537 | ||
538 | class xxxStaticLine(xxxObject): | |
539 | allParams = ['pos', 'size', 'style'] | |
540 | winStyles = ['wxLI_HORIZONTAL', 'wxLI_VERTICAL'] | |
541 | ||
542 | class xxxStaticBitmap(xxxObject): | |
543 | allParams = ['bitmap', 'pos', 'size', 'style'] | |
544 | required = ['bitmap'] | |
545 | ||
546 | class xxxTextCtrl(xxxObject): | |
547 | allParams = ['value', 'pos', 'size', 'style'] | |
306b6fe9 RR |
548 | winStyles = ['wxTE_NO_VSCROLL', |
549 | 'wxTE_AUTO_SCROLL', | |
550 | 'wxTE_PROCESS_ENTER', | |
551 | 'wxTE_PROCESS_TAB', | |
552 | 'wxTE_MULTILINE', | |
553 | 'wxTE_PASSWORD', | |
554 | 'wxTE_READONLY', | |
555 | 'wxHSCROLL', | |
556 | 'wxTE_RICH', | |
557 | 'wxTE_RICH2', | |
558 | 'wxTE_AUTO_URL', | |
559 | 'wxTE_NOHIDESEL', | |
560 | 'wxTE_LEFT', | |
561 | 'wxTE_CENTRE', | |
562 | 'wxTE_RIGHT', | |
563 | 'wxTE_DONTWRAP', | |
564 | 'wxTE_LINEWRAP', | |
565 | 'wxTE_WORDWRAP'] | |
d14a1e28 RD |
566 | paramDict = {'value': ParamMultilineText} |
567 | ||
568 | class xxxChoice(xxxObject): | |
569 | allParams = ['content', 'selection', 'pos', 'size', 'style'] | |
570 | required = ['content'] | |
571 | default = {'content': '[]'} | |
572 | winStyles = ['wxCB_SORT'] | |
573 | ||
574 | class xxxSlider(xxxObject): | |
575 | allParams = ['value', 'min', 'max', 'pos', 'size', 'style', | |
576 | 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick', | |
577 | 'selmin', 'selmax'] | |
c032d94e RR |
578 | paramDict = {'value': ParamInt, 'tickfreq': ParamIntNN, 'pagesize': ParamIntNN, |
579 | 'linesize': ParamIntNN, 'thumb': ParamUnit, | |
d14a1e28 RD |
580 | 'tick': ParamInt, 'selmin': ParamInt, 'selmax': ParamInt} |
581 | required = ['value', 'min', 'max'] | |
582 | winStyles = ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS', | |
583 | 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM', | |
6e2bdf8f | 584 | 'wxSL_BOTH', 'wxSL_SELRANGE', 'wxSL_INVERSE'] |
d14a1e28 RD |
585 | |
586 | class xxxGauge(xxxObject): | |
587 | allParams = ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel'] | |
c032d94e RR |
588 | paramDict = {'range': ParamIntNN, 'value': ParamIntNN, |
589 | 'shadow': ParamIntNN, 'bezel': ParamIntNN} | |
d14a1e28 RD |
590 | winStyles = ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH'] |
591 | ||
592 | class xxxScrollBar(xxxObject): | |
593 | allParams = ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize'] | |
c032d94e RR |
594 | paramDict = {'value': ParamIntNN, 'range': ParamIntNN, 'thumbsize': ParamIntNN, |
595 | 'pagesize': ParamIntNN} | |
d14a1e28 RD |
596 | winStyles = ['wxSB_HORIZONTAL', 'wxSB_VERTICAL'] |
597 | ||
598 | class xxxListCtrl(xxxObject): | |
599 | allParams = ['pos', 'size', 'style'] | |
600 | winStyles = ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON', | |
306b6fe9 RR |
601 | 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE', |
602 | 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER', | |
603 | 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING', | |
604 | 'wxLC_VIRTUAL', 'wxLC_HRULES', 'wxLC_VRULES', 'wxLC_NO_SORT_HEADER'] | |
d14a1e28 RD |
605 | |
606 | class xxxTreeCtrl(xxxObject): | |
607 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 RR |
608 | winStyles = ['wxTR_EDIT_LABELS', |
609 | 'wxTR_NO_BUTTONS', | |
610 | 'wxTR_HAS_BUTTONS', | |
611 | 'wxTR_TWIST_BUTTONS', | |
612 | 'wxTR_NO_LINES', | |
613 | 'wxTR_FULL_ROW_HIGHLIGHT', | |
614 | 'wxTR_LINES_AT_ROOT', | |
615 | 'wxTR_HIDE_ROOT', | |
616 | 'wxTR_ROW_LINES', | |
617 | 'wxTR_HAS_VARIABLE_ROW_HEIGHT', | |
618 | 'wxTR_SINGLE', | |
619 | 'wxTR_MULTIPLE', | |
620 | 'wxTR_EXTENDED', | |
621 | 'wxTR_DEFAULT_STYLE'] | |
d14a1e28 RD |
622 | |
623 | class xxxHtmlWindow(xxxObject): | |
624 | allParams = ['pos', 'size', 'style', 'borders', 'url', 'htmlcode'] | |
306b6fe9 RR |
625 | paramDict = {'htmlcode':ParamMultilineText} |
626 | winStyles = ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO', 'wxHW_NO_SELECTION'] | |
d14a1e28 RD |
627 | |
628 | class xxxCalendarCtrl(xxxObject): | |
629 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 RR |
630 | winStyles = ['wxCAL_SUNDAY_FIRST', 'wxCAL_MONDAY_FIRST', 'wxCAL_SHOW_HOLIDAYS', |
631 | 'wxCAL_NO_YEAR_CHANGE', 'wxCAL_NO_MONTH_CHANGE', | |
632 | 'wxCAL_SEQUENTIAL_MONTH_SELECTION', 'wxCAL_SHOW_SURROUNDING_WEEKS'] | |
d14a1e28 RD |
633 | |
634 | class xxxNotebook(xxxContainer): | |
306b6fe9 | 635 | allParams = ['pos', 'size', 'style'] |
75aa1946 RR |
636 | winStyles = ['wxNB_TOP', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM', |
637 | 'wxNB_FIXEDWIDTH', 'wxNB_MULTILINE', 'wxNB_NOPAGETHEME', 'wxNB_FLAT'] | |
d14a1e28 | 638 | |
306b6fe9 RR |
639 | class xxxChoicebook(xxxContainer): |
640 | allParams = ['pos', 'size', 'style'] | |
641 | winStyles = ['wxCHB_DEFAULT', 'wxCHB_LEFT', 'wxCHB_RIGHT', 'wxCHB_TOP', 'wxCHB_BOTTOM'] | |
642 | ||
643 | class xxxListbook(xxxContainer): | |
644 | allParams = ['pos', 'size', 'style'] | |
645 | winStyles = ['wxLB_DEFAULT', 'wxLB_LEFT', 'wxLB_RIGHT', 'wxLB_TOP', 'wxLB_BOTTOM'] | |
646 | ||
68ae5821 RD |
647 | class xxxSplitterWindow(xxxContainer): |
648 | allParams = ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style'] | |
649 | paramDict = {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit } | |
306b6fe9 RR |
650 | winStyles = ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER', |
651 | 'wxSP_FULLSASH', 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE', | |
652 | 'wxSP_NO_XP_THEME' ] | |
68ae5821 | 653 | |
d14a1e28 RD |
654 | class xxxGenericDirCtrl(xxxObject): |
655 | allParams = ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style'] | |
c032d94e | 656 | paramDict = {'defaultfilter': ParamIntNN} |
d14a1e28 | 657 | winStyles = ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST', |
306b6fe9 | 658 | 'wxDIRCTRL_SHOW_FILTERS'] |
d14a1e28 RD |
659 | |
660 | class xxxScrolledWindow(xxxContainer): | |
661 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 RR |
662 | winStyles = ['wxHSCROLL', 'wxVSCROLL', 'wxNO_3D', 'wxTAB_TRAVERSAL'] |
663 | ||
664 | class xxxDateCtrl(xxxObject): | |
665 | allParams = ['pos', 'size', 'style', 'borders'] | |
666 | winStyles = ['wxDP_DEFAULT', 'wxDP_SPIN', 'wxDP_DROPDOWN', | |
667 | 'wxDP_ALLOWNONE', 'wxDP_SHOWCENTURY'] | |
d14a1e28 | 668 | |
b372319f RR |
669 | class xxxGrid(xxxObject): |
670 | allParams = ['pos', 'size', 'style'] | |
671 | ||
672 | class xxxFilePickerCtrl(xxxObject): | |
673 | allParams = ['value', 'message', 'wildcard', 'pos', 'size', 'style'] | |
674 | winStyles = ['wxFLP_OPEN', 'wxFLP_SAVE', 'wxFLP_OVERWRITE_PROMPT', | |
675 | 'wxFLP_FILE_MUST_EXIST', 'wxFLP_CHANGE_DIR', | |
676 | 'wxFLP_DEFAULT_STYLE'] | |
677 | ||
678 | ||
d14a1e28 RD |
679 | ################################################################################ |
680 | # Buttons | |
681 | ||
682 | class xxxButton(xxxObject): | |
683 | allParams = ['label', 'default', 'pos', 'size', 'style'] | |
684 | paramDict = {'default': ParamBool} | |
685 | required = ['label'] | |
75aa1946 RR |
686 | winStyles = ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM', 'wxBU_EXACTFIT', |
687 | 'wxNO_BORDER'] | |
d14a1e28 RD |
688 | |
689 | class xxxBitmapButton(xxxObject): | |
690 | allParams = ['bitmap', 'selected', 'focus', 'disabled', 'default', | |
691 | 'pos', 'size', 'style'] | |
29a41103 RD |
692 | paramDict = {'selected': ParamBitmap, 'focus': ParamBitmap, 'disabled': ParamBitmap, |
693 | 'default': ParamBool} | |
d14a1e28 | 694 | required = ['bitmap'] |
306b6fe9 | 695 | winStyles = ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_RIGHT', |
75aa1946 | 696 | 'wxBU_TOP', 'wxBU_BOTTOM'] |
d14a1e28 RD |
697 | |
698 | class xxxRadioButton(xxxObject): | |
699 | allParams = ['label', 'value', 'pos', 'size', 'style'] | |
700 | paramDict = {'value': ParamBool} | |
701 | required = ['label'] | |
306b6fe9 | 702 | winStyles = ['wxRB_GROUP', 'wxRB_SINGLE'] |
d14a1e28 RD |
703 | |
704 | class xxxSpinButton(xxxObject): | |
705 | allParams = ['value', 'min', 'max', 'pos', 'size', 'style'] | |
706 | paramDict = {'value': ParamInt} | |
707 | winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP'] | |
708 | ||
709 | class xxxSpinCtrl(xxxObject): | |
710 | allParams = ['value', 'min', 'max', 'pos', 'size', 'style'] | |
711 | paramDict = {'value': ParamInt} | |
712 | winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP'] | |
713 | ||
3d49f2fb RD |
714 | class xxxToggleButton(xxxObject): |
715 | allParams = ['label', 'checked', 'pos', 'size', 'style'] | |
716 | paramDict = {'checked': ParamBool} | |
717 | required = ['label'] | |
718 | ||
d14a1e28 RD |
719 | ################################################################################ |
720 | # Boxes | |
721 | ||
722 | class xxxStaticBox(xxxObject): | |
723 | allParams = ['label', 'pos', 'size', 'style'] | |
724 | required = ['label'] | |
725 | ||
726 | class xxxRadioBox(xxxObject): | |
727 | allParams = ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style'] | |
c032d94e | 728 | paramDict = {'dimension': ParamIntNN} |
d14a1e28 RD |
729 | required = ['label', 'content'] |
730 | default = {'content': '[]'} | |
306b6fe9 RR |
731 | winStyles = ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS', 'wxRA_HORIZONTAL', |
732 | 'wxRA_VERTICAL'] | |
d14a1e28 RD |
733 | |
734 | class xxxCheckBox(xxxObject): | |
735 | allParams = ['label', 'checked', 'pos', 'size', 'style'] | |
736 | paramDict = {'checked': ParamBool} | |
3d49f2fb RD |
737 | winStyles = ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER', |
738 | 'wxALIGN_RIGHT'] | |
d14a1e28 RD |
739 | required = ['label'] |
740 | ||
741 | class xxxComboBox(xxxObject): | |
742 | allParams = ['content', 'selection', 'value', 'pos', 'size', 'style'] | |
743 | required = ['content'] | |
744 | default = {'content': '[]'} | |
745 | winStyles = ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN'] | |
746 | ||
747 | class xxxListBox(xxxObject): | |
748 | allParams = ['content', 'selection', 'pos', 'size', 'style'] | |
749 | required = ['content'] | |
750 | default = {'content': '[]'} | |
751 | winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL', | |
306b6fe9 | 752 | 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT'] |
d14a1e28 RD |
753 | |
754 | class xxxCheckList(xxxObject): | |
755 | allParams = ['content', 'pos', 'size', 'style'] | |
756 | required = ['content'] | |
757 | default = {'content': '[]'} | |
306b6fe9 RR |
758 | winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL', |
759 | 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT'] | |
d14a1e28 RD |
760 | paramDict = {'content': ParamContentCheckList} |
761 | ||
762 | ################################################################################ | |
763 | # Sizers | |
764 | ||
765 | class xxxSizer(xxxContainer): | |
766 | hasName = hasStyle = False | |
767 | paramDict = {'orient': ParamOrient} | |
768 | isSizer = True | |
64b9ac75 | 769 | itemTag = 'sizeritem' # different for some sizers |
d14a1e28 RD |
770 | |
771 | class xxxBoxSizer(xxxSizer): | |
772 | allParams = ['orient'] | |
773 | required = ['orient'] | |
774 | default = {'orient': 'wxVERTICAL'} | |
775 | # Tree icon depends on orientation | |
776 | def treeImage(self): | |
777 | if self.params['orient'].value() == 'wxHORIZONTAL': return self.imageH | |
778 | else: return self.imageV | |
779 | ||
780 | class xxxStaticBoxSizer(xxxBoxSizer): | |
781 | allParams = ['label', 'orient'] | |
782 | required = ['label', 'orient'] | |
783 | ||
784 | class xxxGridSizer(xxxSizer): | |
785 | allParams = ['cols', 'rows', 'vgap', 'hgap'] | |
786 | required = ['cols'] | |
787 | default = {'cols': '2', 'rows': '2'} | |
788 | ||
64bce500 RR |
789 | class xxxStdDialogButtonSizer(xxxSizer): |
790 | allParams = [] | |
64b9ac75 | 791 | itemTag = 'button' |
64bce500 | 792 | |
d14a1e28 RD |
793 | # For repeated parameters |
794 | class xxxParamMulti: | |
795 | def __init__(self, node): | |
796 | self.node = node | |
797 | self.l, self.data = [], [] | |
798 | def append(self, param): | |
799 | self.l.append(param) | |
800 | self.data.append(param.value()) | |
801 | def value(self): | |
802 | return self.data | |
803 | def remove(self): | |
804 | for param in self.l: | |
805 | param.remove() | |
806 | self.l, self.data = [], [] | |
807 | ||
808 | class xxxFlexGridSizer(xxxGridSizer): | |
809 | specials = ['growablecols', 'growablerows'] | |
810 | allParams = ['cols', 'rows', 'vgap', 'hgap'] + specials | |
306b6fe9 | 811 | paramDict = {'growablecols': ParamIntList, 'growablerows': ParamIntList} |
d14a1e28 | 812 | |
a4c013b2 RR |
813 | class xxxGridBagSizer(xxxSizer): |
814 | specials = ['growablecols', 'growablerows'] | |
815 | allParams = ['vgap', 'hgap'] + specials | |
7df24e78 | 816 | paramDict = {'growablecols': ParamIntList, 'growablerows': ParamIntList} |
a4c013b2 | 817 | |
d14a1e28 RD |
818 | # Container with only one child. |
819 | # Not shown in tree. | |
820 | class xxxChildContainer(xxxObject): | |
821 | hasName = hasStyle = False | |
822 | hasChild = True | |
03319b65 RR |
823 | def __init__(self, parent, element, refElem=None): |
824 | xxxObject.__init__(self, parent, element, refElem) | |
d14a1e28 RD |
825 | # Must have one child with 'object' tag, but we don't check it |
826 | nodes = element.childNodes[:] # create copy | |
827 | for node in nodes: | |
828 | if node.nodeType == minidom.Node.ELEMENT_NODE: | |
03319b65 | 829 | if node.tagName in ['object', 'object_ref']: |
d14a1e28 RD |
830 | # Create new xxx object for child node |
831 | self.child = MakeXXXFromDOM(self, node) | |
832 | self.child.parent = parent | |
833 | # Copy hasChildren and isSizer attributes | |
834 | self.hasChildren = self.child.hasChildren | |
835 | self.isSizer = self.child.isSizer | |
836 | return # success | |
837 | else: | |
838 | element.removeChild(node) | |
839 | node.unlink() | |
840 | assert 0, 'no child found' | |
75aa1946 RR |
841 | def resetChild(self, xxx): |
842 | '''Reset child info (for replacing with another class).''' | |
843 | self.child = xxx | |
844 | self.hasChildren = xxx.hasChildren | |
845 | self.isSizer = xxx.isSizer | |
d14a1e28 RD |
846 | |
847 | class xxxSizerItem(xxxChildContainer): | |
a4c013b2 RR |
848 | allParams = ['option', 'flag', 'border', 'minsize', 'ratio'] |
849 | paramDict = {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize} | |
c1dda21b RR |
850 | defaults_panel = {} |
851 | defaults_control = {} | |
03319b65 | 852 | def __init__(self, parent, element, refElem=None): |
a4c013b2 RR |
853 | # For GridBag sizer items, extra parameters added |
854 | if isinstance(parent, xxxGridBagSizer): | |
855 | self.allParams = self.allParams + ['cellpos', 'cellspan'] | |
03319b65 | 856 | xxxChildContainer.__init__(self, parent, element, refElem) |
d14a1e28 RD |
857 | # Remove pos parameter - not needed for sizeritems |
858 | if 'pos' in self.child.allParams: | |
859 | self.child.allParams = self.child.allParams[:] | |
860 | self.child.allParams.remove('pos') | |
75aa1946 RR |
861 | def resetChild(self, xxx): |
862 | xxxChildContainer.resetChild(self, xxx) | |
863 | # Remove pos parameter - not needed for sizeritems | |
864 | if 'pos' in self.child.allParams: | |
865 | self.child.allParams = self.child.allParams[:] | |
866 | self.child.allParams.remove('pos') | |
d14a1e28 | 867 | |
64b9ac75 RR |
868 | class xxxSizerItemButton(xxxSizerItem): |
869 | allParams = [] | |
870 | paramDict = {} | |
03319b65 RR |
871 | def __init__(self, parent, element, refElem=None): |
872 | xxxChildContainer.__init__(self, parent, element, refElem=None) | |
64b9ac75 RR |
873 | # Remove pos parameter - not needed for sizeritems |
874 | if 'pos' in self.child.allParams: | |
875 | self.child.allParams = self.child.allParams[:] | |
876 | self.child.allParams.remove('pos') | |
877 | ||
306b6fe9 | 878 | class xxxPage(xxxChildContainer): |
d14a1e28 RD |
879 | allParams = ['label', 'selected'] |
880 | paramDict = {'selected': ParamBool} | |
881 | required = ['label'] | |
03319b65 RR |
882 | def __init__(self, parent, element, refElem=None): |
883 | xxxChildContainer.__init__(self, parent, element, refElem) | |
d14a1e28 RD |
884 | # pos and size dont matter for notebookpages |
885 | if 'pos' in self.child.allParams: | |
886 | self.child.allParams = self.child.allParams[:] | |
887 | self.child.allParams.remove('pos') | |
888 | if 'size' in self.child.allParams: | |
889 | self.child.allParams = self.child.allParams[:] | |
890 | self.child.allParams.remove('size') | |
891 | ||
892 | class xxxSpacer(xxxObject): | |
893 | hasName = hasStyle = False | |
894 | allParams = ['size', 'option', 'flag', 'border'] | |
895 | paramDict = {'option': ParamInt} | |
896 | default = {'size': '0,0'} | |
28e65e0f RR |
897 | def __init__(self, parent, element, refElem=None): |
898 | # For GridBag sizer items, extra parameters added | |
899 | if isinstance(parent, xxxGridBagSizer): | |
900 | self.allParams = self.allParams + ['cellpos', 'cellspan'] | |
901 | xxxObject.__init__(self, parent, element, refElem) | |
d14a1e28 RD |
902 | |
903 | class xxxMenuBar(xxxContainer): | |
904 | allParams = ['style'] | |
905 | paramDict = {'style': ParamNonGenericStyle} # no generic styles | |
906 | winStyles = ['wxMB_DOCKABLE'] | |
907 | ||
908 | class xxxMenu(xxxContainer): | |
909 | allParams = ['label', 'help', 'style'] | |
910 | default = {'label': ''} | |
911 | paramDict = {'style': ParamNonGenericStyle} # no generic styles | |
912 | winStyles = ['wxMENU_TEAROFF'] | |
913 | ||
914 | class xxxMenuItem(xxxObject): | |
915 | allParams = ['label', 'bitmap', 'accel', 'help', | |
916 | 'checkable', 'radio', 'enabled', 'checked'] | |
917 | default = {'label': ''} | |
918 | hasStyle = False | |
919 | ||
920 | class xxxSeparator(xxxObject): | |
921 | hasName = hasStyle = False | |
922 | ||
923 | ################################################################################ | |
924 | # Unknown control | |
925 | ||
926 | class xxxUnknown(xxxObject): | |
927 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 | 928 | winStyles = ['wxNO_FULL_REPAINT_ON_RESIZE'] |
d14a1e28 | 929 | |
b372319f RR |
930 | ################################################################################ |
931 | # Comment | |
932 | ||
c0d5ae74 | 933 | _handlers = [] # custom handler classes/funcs |
8c64c153 RR |
934 | def getHandlers(): |
935 | return _handlers | |
936 | def setHandlers(handlers): | |
937 | global _handlers | |
938 | _handlers = handlers | |
c0d5ae74 | 939 | _CFuncPtr = None # ctypes function type |
00d15346 RR |
940 | |
941 | def register(hndlr): | |
c0d5ae74 | 942 | """Register hndlr function or XmlResourceHandler class.""" |
00d15346 RR |
943 | if _CFuncPtr and isinstance(hndlr, _CFuncPtr): |
944 | _handlers.append(hndlr) | |
945 | return | |
946 | if not isinstance(hndlr, type): | |
947 | wx.LogError('handler is not a type: %s' % hndlr) | |
948 | elif not issubclass(hndlr, wx.xrc.XmlResourceHandler): | |
949 | wx.LogError('handler is not a XmlResourceHandler: %s' % hndlr) | |
950 | else: | |
951 | _handlers.append(hndlr) | |
952 | ||
953 | def load_dl(path, localname=''): | |
8c64c153 RR |
954 | """Load shared/dynamic library into xxx namespace. |
955 | ||
956 | If path is not absolute or relative, try to find in the module's directory. | |
957 | """ | |
c0d5ae74 RR |
958 | if not localname: |
959 | localname = os.path.basename(os.path.splitext(path)[0]) | |
00d15346 RR |
960 | try: |
961 | import ctypes | |
962 | global _CFuncPtr | |
8c64c153 RR |
963 | _CFuncPtr = ctypes._CFuncPtr # use as a flag of loaded ctypes |
964 | #if not os.path.dirname(path) and os.path.isfile(path): | |
965 | ||
00d15346 RR |
966 | except ImportError: |
967 | wx.LogError('ctypes module not found') | |
c0d5ae74 | 968 | globals()[localname] = None |
00d15346 RR |
969 | return |
970 | try: | |
971 | dl = ctypes.CDLL(path) | |
00d15346 | 972 | globals()[localname] = dl |
c0d5ae74 RR |
973 | # Register AddXmlHandlers() if exists |
974 | try: | |
975 | register(dl.AddXmlHandlers) | |
976 | except: | |
977 | pass | |
00d15346 | 978 | except: |
c0d5ae74 | 979 | wx.LogError('error loading dynamic library: %s' % path) |
00d15346 RR |
980 | print traceback.print_exc() |
981 | ||
982 | # Called when creating test window | |
c0d5ae74 | 983 | def addHandlers(): |
00d15346 RR |
984 | for h in _handlers: |
985 | if _CFuncPtr and isinstance(h, _CFuncPtr): | |
986 | try: | |
987 | apply(h, ()) | |
988 | except: | |
989 | wx.LogError('error calling DL func: "%s"' % h) | |
990 | print traceback.print_exc() | |
991 | else: | |
992 | try: | |
c0d5ae74 | 993 | xrc.XmlResource.Get().AddHandler(apply(h, ())) |
00d15346 RR |
994 | except: |
995 | wx.LogError('error adding XmlHandler: "%s"' % h) | |
996 | print traceback.print_exc() | |
997 | ||
c0d5ae74 RR |
998 | def custom(klassName, klass='unknown'): |
999 | """Define custom control based on xrcClass. | |
1000 | ||
1001 | klass: new object name | |
1002 | xrcClass: name of an existing XRC object class or | |
1003 | a class object defining class parameters. | |
1004 | """ | |
1005 | if type(klass) is str: | |
1006 | # Copy correct xxx class under new name | |
1007 | kl = xxxDict[klass] | |
1008 | xxxClass = types.ClassType('xxx' + klassName, kl.__bases__, kl.__dict__) | |
1009 | else: | |
1010 | xxxClass = klass | |
1011 | # Register param IDs | |
1012 | for param in klass.allParams + klass.paramDict.keys(): | |
1013 | if not paramIDs.has_key(param): | |
1014 | paramIDs[param] = wx.NewId() | |
1015 | # Insert in dictionaty | |
1016 | xxxDict[klassName] = xxxClass | |
1017 | # Add to menu | |
1018 | g.pullDownMenu.addCustom(klassName) | |
1019 | ||
b372319f | 1020 | class xxxParamComment(xxxParam): |
7058b794 RR |
1021 | locals = {} # namespace for comment directives |
1022 | allow = None # undefined initial state for current file | |
b372319f RR |
1023 | def __init__(self, node): |
1024 | xxxNode.__init__(self, node) | |
1025 | self.textNode = node | |
7058b794 RR |
1026 | # Parse "pragma" comments if enabled |
1027 | if node.data and node.data[0] == '%' and g.conf.allowExec != 'no' and \ | |
1028 | xxxParamComment.allow is not False: | |
1029 | # Show warning | |
1030 | if g.conf.allowExec == 'ask' and xxxParamComment.allow is None: | |
1031 | flags = wx.ICON_EXCLAMATION | wx.YES_NO | wx.CENTRE | |
1032 | dlg = wx.MessageDialog(g.frame, ''' | |
1033 | This file contains executable %comment directives. Allow to execute?''', | |
1034 | 'Warning', flags) | |
1035 | say = dlg.ShowModal() | |
1036 | dlg.Destroy() | |
1037 | if say == wx.ID_YES: | |
1038 | xxxParamComment.allow = True | |
1039 | else: | |
1040 | xxxParamComment.allow = False | |
00d15346 RR |
1041 | try: |
1042 | code = node.data[1:] | |
7058b794 | 1043 | exec code in globals(), self.locals |
00d15346 RR |
1044 | except: |
1045 | wx.LogError('exec error: "%s"' % code) | |
1046 | print traceback.print_exc() | |
b372319f RR |
1047 | |
1048 | class xxxComment(xxxObject): | |
1049 | hasStyle = hasName = False | |
1050 | allParams = required = ['comment'] | |
1051 | ||
1052 | def __init__(self, parent, node): | |
1053 | self.parent = parent | |
1054 | self.node = node | |
1055 | self.isElement = False | |
1056 | self.undo = None | |
1057 | self.className = 'comment' | |
1058 | self.ref = self.subclass = None | |
1059 | self.params = {'comment': xxxParamComment(node)} | |
1060 | ||
1061 | def treeName(self): | |
1062 | # Replace newlines by \n to avoid tree item resizing | |
1063 | return self.params['comment'].value().replace('\n', r'\n') | |
1064 | ||
d14a1e28 RD |
1065 | ################################################################################ |
1066 | ||
c0d5ae74 | 1067 | # Mapping of XRC names to xxx classes |
d14a1e28 RD |
1068 | xxxDict = { |
1069 | 'wxPanel': xxxPanel, | |
1070 | 'wxDialog': xxxDialog, | |
1071 | 'wxFrame': xxxFrame, | |
1072 | 'tool': xxxTool, | |
1073 | 'wxToolBar': xxxToolBar, | |
306b6fe9 | 1074 | 'wxStatusBar': xxxStatusBar, |
64bce500 RR |
1075 | 'wxWizard': xxxWizard, |
1076 | 'wxWizardPage': xxxWizardPage, | |
1077 | 'wxWizardPageSimple': xxxWizardPageSimple, | |
d14a1e28 RD |
1078 | |
1079 | 'wxBitmap': xxxBitmap, | |
1080 | 'wxIcon': xxxIcon, | |
1081 | ||
1082 | 'wxButton': xxxButton, | |
1083 | 'wxBitmapButton': xxxBitmapButton, | |
1084 | 'wxRadioButton': xxxRadioButton, | |
1085 | 'wxSpinButton': xxxSpinButton, | |
3d49f2fb | 1086 | 'wxToggleButton' : xxxToggleButton, |
d14a1e28 RD |
1087 | |
1088 | 'wxStaticBox': xxxStaticBox, | |
1089 | 'wxStaticBitmap': xxxStaticBitmap, | |
1090 | 'wxRadioBox': xxxRadioBox, | |
1091 | 'wxComboBox': xxxComboBox, | |
1092 | 'wxCheckBox': xxxCheckBox, | |
1093 | 'wxListBox': xxxListBox, | |
1094 | ||
1095 | 'wxStaticText': xxxStaticText, | |
1096 | 'wxStaticLine': xxxStaticLine, | |
1097 | 'wxTextCtrl': xxxTextCtrl, | |
1098 | 'wxChoice': xxxChoice, | |
1099 | 'wxSlider': xxxSlider, | |
1100 | 'wxGauge': xxxGauge, | |
1101 | 'wxScrollBar': xxxScrollBar, | |
1102 | 'wxTreeCtrl': xxxTreeCtrl, | |
1103 | 'wxListCtrl': xxxListCtrl, | |
edfeb1b8 | 1104 | 'wxCheckListBox': xxxCheckList, |
306b6fe9 RR |
1105 | 'notebookpage': xxxPage, |
1106 | 'choicebookpage': xxxPage, | |
1107 | 'listbookpage': xxxPage, | |
d14a1e28 | 1108 | 'wxNotebook': xxxNotebook, |
306b6fe9 RR |
1109 | 'wxChoicebook': xxxChoicebook, |
1110 | 'wxListbook': xxxListbook, | |
68ae5821 | 1111 | 'wxSplitterWindow': xxxSplitterWindow, |
d14a1e28 RD |
1112 | 'wxHtmlWindow': xxxHtmlWindow, |
1113 | 'wxCalendarCtrl': xxxCalendarCtrl, | |
1114 | 'wxGenericDirCtrl': xxxGenericDirCtrl, | |
1115 | 'wxSpinCtrl': xxxSpinCtrl, | |
1116 | 'wxScrolledWindow': xxxScrolledWindow, | |
b372319f RR |
1117 | 'wxGrid': xxxGrid, |
1118 | 'wxFilePickerCtrl': xxxFilePickerCtrl, | |
306b6fe9 | 1119 | 'wxDatePickerCtrl': xxxDateCtrl, |
d14a1e28 RD |
1120 | |
1121 | 'wxBoxSizer': xxxBoxSizer, | |
1122 | 'wxStaticBoxSizer': xxxStaticBoxSizer, | |
1123 | 'wxGridSizer': xxxGridSizer, | |
1124 | 'wxFlexGridSizer': xxxFlexGridSizer, | |
a4c013b2 | 1125 | 'wxGridBagSizer': xxxGridBagSizer, |
64bce500 | 1126 | 'wxStdDialogButtonSizer': xxxStdDialogButtonSizer, |
64b9ac75 | 1127 | 'sizeritem': xxxSizerItem, 'button': xxxSizerItemButton, |
d14a1e28 RD |
1128 | 'spacer': xxxSpacer, |
1129 | ||
1130 | 'wxMenuBar': xxxMenuBar, | |
1131 | 'wxMenu': xxxMenu, | |
1132 | 'wxMenuItem': xxxMenuItem, | |
1133 | 'separator': xxxSeparator, | |
1134 | ||
1135 | 'unknown': xxxUnknown, | |
b372319f | 1136 | 'comment': xxxComment, |
d14a1e28 RD |
1137 | } |
1138 | ||
1139 | # Create IDs for all parameters of all classes | |
29a41103 RD |
1140 | paramIDs = {'fg': wx.NewId(), 'bg': wx.NewId(), 'exstyle': wx.NewId(), 'font': wx.NewId(), |
1141 | 'enabled': wx.NewId(), 'focused': wx.NewId(), 'hidden': wx.NewId(), | |
1142 | 'tooltip': wx.NewId(), 'encoding': wx.NewId(), | |
b372319f RR |
1143 | 'cellpos': wx.NewId(), 'cellspan': wx.NewId(), |
1144 | 'text': wx.NewId() | |
d14a1e28 RD |
1145 | } |
1146 | for cl in xxxDict.values(): | |
1147 | if cl.allParams: | |
1148 | for param in cl.allParams + cl.paramDict.keys(): | |
1149 | if not paramIDs.has_key(param): | |
29a41103 | 1150 | paramIDs[param] = wx.NewId() |
d14a1e28 RD |
1151 | |
1152 | ################################################################################ | |
1153 | # Helper functions | |
1154 | ||
1155 | # Test for object elements | |
1156 | def IsObject(node): | |
b372319f RR |
1157 | return node.nodeType == minidom.Node.ELEMENT_NODE and \ |
1158 | node.tagName in ['object', 'object_ref'] or \ | |
1159 | node.nodeType == minidom.Node.COMMENT_NODE | |
d14a1e28 RD |
1160 | |
1161 | # Make XXX object from some DOM object, selecting correct class | |
b372319f RR |
1162 | def MakeXXXFromDOM(parent, node): |
1163 | if node.nodeType == minidom.Node.COMMENT_NODE: | |
1164 | return xxxComment(parent, node) | |
1165 | if node.tagName == 'object_ref': | |
1166 | ref = node.getAttribute('ref') | |
03319b65 RR |
1167 | refElem = FindResource(ref) |
1168 | if refElem: cls = refElem.getAttribute('class') | |
b372319f | 1169 | else: return xxxUnknown(parent, node) |
03319b65 RR |
1170 | else: |
1171 | refElem = None | |
b372319f | 1172 | cls = node.getAttribute('class') |
d14a1e28 | 1173 | try: |
03319b65 | 1174 | klass = xxxDict[cls] |
d14a1e28 RD |
1175 | except KeyError: |
1176 | # If we encounter a weird class, use unknown template | |
b372319f | 1177 | print 'WARNING: unsupported class:', node.getAttribute('class') |
d14a1e28 | 1178 | klass = xxxUnknown |
b372319f | 1179 | return klass(parent, node, refElem) |
d14a1e28 RD |
1180 | |
1181 | # Make empty DOM element | |
1182 | def MakeEmptyDOM(className): | |
1183 | elem = g.tree.dom.createElement('object') | |
1184 | elem.setAttribute('class', className) | |
1185 | # Set required and default parameters | |
1186 | xxxClass = xxxDict[className] | |
1187 | defaultNotRequired = filter(lambda x, l=xxxClass.required: x not in l, | |
1188 | xxxClass.default.keys()) | |
1189 | for param in xxxClass.required + defaultNotRequired: | |
1190 | textElem = g.tree.dom.createElement(param) | |
1191 | try: | |
1192 | textNode = g.tree.dom.createTextNode(xxxClass.default[param]) | |
1193 | except KeyError: | |
1194 | textNode = g.tree.dom.createTextNode('') | |
1195 | textElem.appendChild(textNode) | |
1196 | elem.appendChild(textElem) | |
1197 | return elem | |
1198 | ||
1199 | # Make empty XXX object | |
1200 | def MakeEmptyXXX(parent, className): | |
1201 | # Make corresponding DOM object first | |
1202 | elem = MakeEmptyDOM(className) | |
37867b24 RR |
1203 | # Special handling, e.g. if parent is a sizer, we should create |
1204 | # sizeritem object, except for spacers, etc. | |
d14a1e28 RD |
1205 | if parent: |
1206 | if parent.isSizer and className != 'spacer': | |
64b9ac75 | 1207 | sizerItemElem = MakeEmptyDOM(parent.itemTag) |
d14a1e28 RD |
1208 | sizerItemElem.appendChild(elem) |
1209 | elem = sizerItemElem | |
1210 | elif isinstance(parent, xxxNotebook): | |
1211 | pageElem = MakeEmptyDOM('notebookpage') | |
1212 | pageElem.appendChild(elem) | |
1213 | elem = pageElem | |
306b6fe9 RR |
1214 | elif isinstance(parent, xxxChoicebook): |
1215 | pageElem = MakeEmptyDOM('choicebookpage') | |
1216 | pageElem.appendChild(elem) | |
1217 | elem = pageElem | |
1218 | elif isinstance(parent, xxxListbook): | |
1219 | pageElem = MakeEmptyDOM('listbookpage') | |
1220 | pageElem.appendChild(elem) | |
1221 | elem = pageElem | |
d14a1e28 | 1222 | # Now just make object |
37867b24 RR |
1223 | xxx = MakeXXXFromDOM(parent, elem) |
1224 | # Special defaults for new panels and controls | |
1225 | if isinstance(xxx, xxxSizerItem): | |
1226 | if isinstance(xxx.child, xxxContainer) and not xxx.child.isSizer: | |
1227 | for param,v in xxxSizerItem.defaults_panel.items(): | |
1228 | xxx.set(param, v) | |
1229 | elif isinstance(xxx.child, xxxObject): | |
1230 | for param,v in xxxSizerItem.defaults_control.items(): | |
1231 | xxx.set(param, v) | |
1232 | return xxx | |
1fded56b | 1233 | |
03319b65 RR |
1234 | # Make empty DOM element for reference |
1235 | def MakeEmptyRefDOM(ref): | |
1236 | elem = g.tree.dom.createElement('object_ref') | |
1237 | elem.setAttribute('ref', ref) | |
1238 | return elem | |
1239 | ||
1240 | # Make empty XXX object | |
1241 | def MakeEmptyRefXXX(parent, ref): | |
1242 | # Make corresponding DOM object first | |
1243 | elem = MakeEmptyRefDOM(ref) | |
1244 | # If parent is a sizer, we should create sizeritem object, except for spacers | |
1245 | if parent: | |
1246 | if parent.isSizer: | |
1247 | sizerItemElem = MakeEmptyDOM(parent.itemTag) | |
1248 | sizerItemElem.appendChild(elem) | |
1249 | elem = sizerItemElem | |
1250 | elif isinstance(parent, xxxNotebook): | |
1251 | pageElem = MakeEmptyDOM('notebookpage') | |
1252 | pageElem.appendChild(elem) | |
1253 | elem = pageElem | |
306b6fe9 RR |
1254 | elif isinstance(parent, xxxChoicebook): |
1255 | pageElem = MakeEmptyDOM('choicebookpage') | |
1256 | pageElem.appendChild(elem) | |
1257 | elem = pageElem | |
1258 | elif isinstance(parent, xxxListbook): | |
1259 | pageElem = MakeEmptyDOM('listbookpage') | |
1260 | pageElem.appendChild(elem) | |
1261 | elem = pageElem | |
03319b65 | 1262 | # Now just make object |
75aa1946 RR |
1263 | xxx = MakeXXXFromDOM(parent, elem) |
1264 | # Label is not used for references | |
1265 | xxx.allParams = xxx.allParams[:] | |
1266 | #xxx.allParams.remove('label') | |
1267 | return xxx | |
03319b65 | 1268 | |
b372319f RR |
1269 | # Make empty comment node |
1270 | def MakeEmptyCommentDOM(): | |
1271 | node = g.tree.dom.createComment('') | |
1272 | return node | |
1273 | ||
1274 | # Make empty xxxComment | |
1275 | def MakeEmptyCommentXXX(parent): | |
1276 | node = MakeEmptyCommentDOM() | |
1277 | # Now just make object | |
1278 | xxx = MakeXXXFromDOM(parent, node) | |
1279 | return xxx | |
1280 |