]>
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) |
7df24e78 RR |
318 | # Special processing for growablecols-like parameters |
319 | # represented by several nodes | |
320 | def special(self, tag, node): | |
7df24e78 RR |
321 | if not self.params.has_key(tag): |
322 | # Create new multi-group | |
323 | self.params[tag] = xxxParamMulti(node) | |
324 | self.params[tag].append(xxxParamInt(node)) | |
325 | def setSpecial(self, param, value): | |
326 | # Straightforward implementation: remove, add again | |
327 | self.params[param].remove() | |
328 | del self.params[param] | |
329 | for i in value: | |
330 | node = g.tree.dom.createElement(param) | |
331 | text = g.tree.dom.createTextNode(str(i)) | |
332 | node.appendChild(text) | |
b372319f | 333 | self.node.appendChild(node) |
7df24e78 | 334 | self.special(param, node) |
d14a1e28 | 335 | |
03319b65 RR |
336 | # Imitation of FindResource/DoFindResource from xmlres.cpp |
337 | def DoFindResource(parent, name, classname, recursive): | |
338 | for n in parent.childNodes: | |
339 | if n.nodeType == minidom.Node.ELEMENT_NODE and \ | |
340 | n.tagName in ['object', 'object_ref'] and \ | |
341 | n.getAttribute('name') == name: | |
342 | cls = n.getAttribute('class') | |
343 | if not classname or cls == classname: return n | |
344 | if not cls or n.tagName == 'object_ref': | |
345 | refName = n.getAttribute('ref') | |
346 | if not refName: continue | |
347 | refNode = FindResource(refName) | |
348 | if refName and refNode.getAttribute('class') == classname: | |
349 | return n | |
350 | if recursive: | |
351 | for n in parent.childNodes: | |
352 | if n.nodeType == minidom.Node.ELEMENT_NODE and \ | |
353 | n.tagName in ['object', 'object_ref']: | |
354 | found = DoFindResource(n, name, classname, True) | |
355 | if found: return found | |
356 | def FindResource(name, classname='', recursive=True): | |
357 | found = DoFindResource(g.tree.mainNode, name, classname, recursive) | |
358 | if found: return found | |
29a41103 | 359 | wx.LogError('XRC resource "%s" not found!' % name) |
03319b65 RR |
360 | |
361 | ||
d14a1e28 RD |
362 | ################################################################################ |
363 | ||
364 | # This is a little special: it is both xxxObject and xxxNode | |
365 | class xxxParamFont(xxxObject, xxxNode): | |
0d9b8891 | 366 | allParams = ['size', 'family', 'style', 'weight', 'underlined', |
d14a1e28 RD |
367 | 'face', 'encoding'] |
368 | def __init__(self, parent, element): | |
369 | xxxObject.__init__(self, parent, element) | |
370 | xxxNode.__init__(self, element) | |
371 | self.parentNode = parent # required to behave similar to DOM node | |
372 | v = [] | |
373 | for p in self.allParams: | |
374 | try: | |
375 | v.append(str(self.params[p].value())) | |
376 | except KeyError: | |
377 | v.append('') | |
378 | self.data = v | |
379 | def update(self, value): | |
380 | # `value' is a list of strings corresponding to all parameters | |
b372319f | 381 | elem = self.node |
d14a1e28 RD |
382 | # Remove old elements first |
383 | childNodes = elem.childNodes[:] | |
384 | for node in childNodes: elem.removeChild(node) | |
385 | i = 0 | |
386 | self.params.clear() | |
387 | v = [] | |
388 | for param in self.allParams: | |
389 | if value[i]: | |
390 | fontElem = g.tree.dom.createElement(param) | |
391 | textNode = g.tree.dom.createTextNode(value[i]) | |
392 | self.params[param] = textNode | |
393 | fontElem.appendChild(textNode) | |
394 | elem.appendChild(fontElem) | |
395 | v.append(value[i]) | |
396 | i += 1 | |
397 | self.data = v | |
398 | def value(self): | |
399 | return self.data | |
400 | ||
401 | ################################################################################ | |
402 | ||
403 | class xxxContainer(xxxObject): | |
404 | hasChildren = True | |
64bce500 | 405 | exStyles = [] |
d14a1e28 RD |
406 | |
407 | # Simulate normal parameter for encoding | |
408 | class xxxEncoding: | |
d14a1e28 | 409 | def value(self): |
7353d818 | 410 | return g.currentEncoding |
d14a1e28 | 411 | def update(self, val): |
7353d818 | 412 | g.currentEncoding = val |
d14a1e28 RD |
413 | |
414 | # Special class for root node | |
415 | class xxxMainNode(xxxContainer): | |
416 | allParams = ['encoding'] | |
417 | hasStyle = hasName = False | |
418 | def __init__(self, dom): | |
419 | xxxContainer.__init__(self, None, dom.documentElement) | |
420 | self.className = 'XML tree' | |
421 | # Reset required parameters after processing XML, because encoding is | |
422 | # a little special | |
423 | self.required = ['encoding'] | |
7353d818 | 424 | self.params['encoding'] = xxxEncoding() |
d14a1e28 RD |
425 | |
426 | ################################################################################ | |
427 | # Top-level windwows | |
428 | ||
429 | class xxxPanel(xxxContainer): | |
430 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 | 431 | winStyles = ['wxNO_3D', 'wxTAB_TRAVERSAL'] |
d14a1e28 RD |
432 | styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', |
433 | 'tooltip'] | |
d14a1e28 RD |
434 | |
435 | class xxxDialog(xxxContainer): | |
436 | allParams = ['title', 'centered', 'pos', 'size', 'style'] | |
437 | paramDict = {'centered': ParamBool} | |
438 | required = ['title'] | |
439 | default = {'title': ''} | |
306b6fe9 RR |
440 | winStyles = ['wxDEFAULT_DIALOG_STYLE', 'wxCAPTION', |
441 | 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxTHICK_FRAME', | |
442 | 'wxRESIZE_BORDER', 'wxRESIZE_BOX', 'wxCLOSE_BOX', | |
443 | 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX', | |
444 | 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS', 'wxDIALOG_NO_PARENT' | |
445 | 'wxNO_3D', 'wxTAB_TRAVERSAL'] | |
446 | exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY', 'wxDIALOG_EX_METAL'] | |
d14a1e28 RD |
447 | styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', |
448 | 'tooltip'] | |
d14a1e28 RD |
449 | |
450 | class xxxFrame(xxxContainer): | |
451 | allParams = ['title', 'centered', 'pos', 'size', 'style'] | |
452 | paramDict = {'centered': ParamBool} | |
453 | required = ['title'] | |
454 | default = {'title': ''} | |
306b6fe9 RR |
455 | winStyles = ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE', 'wxCAPTION', |
456 | 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxTHICK_FRAME', | |
457 | 'wxRESIZE_BORDER', 'wxRESIZE_BOX', 'wxCLOSE_BOX', | |
458 | 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX', | |
459 | 'wxFRAME_NO_TASKBAR', 'wxFRAME_SHAPED', 'wxFRAME_TOOL_WINDOW', | |
460 | 'wxFRAME_FLOAT_ON_PARENT', | |
461 | 'wxNO_3D', 'wxTAB_TRAVERSAL'] | |
462 | exStyles = ['wxWS_EX_VALIDATE_RECURSIVELY', 'wxFRAME_EX_METAL'] | |
d14a1e28 RD |
463 | styles = ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle', |
464 | 'tooltip'] | |
d14a1e28 RD |
465 | |
466 | class xxxTool(xxxObject): | |
71b1eafc | 467 | allParams = ['bitmap', 'bitmap2', 'radio', 'toggle', 'tooltip', 'longhelp', 'label'] |
d14a1e28 | 468 | required = ['bitmap'] |
71b1eafc | 469 | paramDict = {'bitmap2': ParamBitmap, 'radio': ParamBool, 'toggle': ParamBool} |
d14a1e28 RD |
470 | hasStyle = False |
471 | ||
472 | class xxxToolBar(xxxContainer): | |
71b1eafc | 473 | allParams = ['bitmapsize', 'margins', 'packing', 'separation', 'dontattachtoframe', |
d14a1e28 RD |
474 | 'pos', 'size', 'style'] |
475 | hasStyle = False | |
476 | paramDict = {'bitmapsize': ParamPosSize, 'margins': ParamPosSize, | |
c032d94e | 477 | 'packing': ParamUnit, 'separation': ParamUnit, |
71b1eafc RR |
478 | 'dontattachtoframe': ParamBool, 'style': ParamNonGenericStyle} |
479 | winStyles = ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL', | |
480 | 'wxTB_3DBUTTONS','wxTB_TEXT', 'wxTB_NOICONS', 'wxTB_NODIVIDER', | |
481 | 'wxTB_NOALIGN', 'wxTB_HORZ_LAYOUT', 'wxTB_HORZ_TEXT'] | |
d14a1e28 | 482 | |
306b6fe9 RR |
483 | class xxxStatusBar(xxxObject): |
484 | hasStyle = False | |
485 | allParams = ['fields', 'widths', 'styles', 'style'] | |
486 | paramDict = {'fields': ParamIntNN, 'widths': ParamText, 'styles': ParamText, | |
487 | 'style': ParamNonGenericStyle} | |
488 | winStyles = ['wxST_SIZEGRIP'] | |
489 | ||
64bce500 RR |
490 | class xxxWizard(xxxContainer): |
491 | allParams = ['title', 'bitmap', 'pos'] | |
492 | required = ['title'] | |
493 | default = {'title': ''} | |
494 | winStyles = [] | |
495 | exStyles = ['wxWIZARD_EX_HELPBUTTON'] | |
f5318530 | 496 | styles = ['fg', 'bg', 'font', 'exstyle'] |
64bce500 RR |
497 | |
498 | class xxxWizardPage(xxxContainer): | |
499 | allParams = ['bitmap'] | |
500 | winStyles = [] | |
501 | exStyles = [] | |
502 | ||
503 | class xxxWizardPageSimple(xxxContainer): | |
504 | allParams = ['bitmap'] | |
505 | winStyles = [] | |
506 | exStyles = [] | |
507 | ||
d14a1e28 RD |
508 | ################################################################################ |
509 | # Bitmap, Icon | |
510 | ||
511 | class xxxBitmap(xxxObject): | |
512 | allParams = ['bitmap'] | |
513 | required = ['bitmap'] | |
514 | ||
515 | # Just like bitmap | |
516 | class xxxIcon(xxxObject): | |
f19b8f11 | 517 | allParams = [] |
d14a1e28 RD |
518 | |
519 | ################################################################################ | |
520 | # Controls | |
521 | ||
522 | class xxxStaticText(xxxObject): | |
523 | allParams = ['label', 'pos', 'size', 'style'] | |
524 | required = ['label'] | |
525 | default = {'label': ''} | |
526 | winStyles = ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE'] | |
527 | ||
528 | class xxxStaticLine(xxxObject): | |
529 | allParams = ['pos', 'size', 'style'] | |
530 | winStyles = ['wxLI_HORIZONTAL', 'wxLI_VERTICAL'] | |
531 | ||
532 | class xxxStaticBitmap(xxxObject): | |
533 | allParams = ['bitmap', 'pos', 'size', 'style'] | |
534 | required = ['bitmap'] | |
535 | ||
536 | class xxxTextCtrl(xxxObject): | |
537 | allParams = ['value', 'pos', 'size', 'style'] | |
306b6fe9 RR |
538 | winStyles = ['wxTE_NO_VSCROLL', |
539 | 'wxTE_AUTO_SCROLL', | |
540 | 'wxTE_PROCESS_ENTER', | |
541 | 'wxTE_PROCESS_TAB', | |
542 | 'wxTE_MULTILINE', | |
543 | 'wxTE_PASSWORD', | |
544 | 'wxTE_READONLY', | |
545 | 'wxHSCROLL', | |
546 | 'wxTE_RICH', | |
547 | 'wxTE_RICH2', | |
548 | 'wxTE_AUTO_URL', | |
549 | 'wxTE_NOHIDESEL', | |
550 | 'wxTE_LEFT', | |
551 | 'wxTE_CENTRE', | |
552 | 'wxTE_RIGHT', | |
553 | 'wxTE_DONTWRAP', | |
554 | 'wxTE_LINEWRAP', | |
555 | 'wxTE_WORDWRAP'] | |
d14a1e28 RD |
556 | paramDict = {'value': ParamMultilineText} |
557 | ||
558 | class xxxChoice(xxxObject): | |
559 | allParams = ['content', 'selection', 'pos', 'size', 'style'] | |
560 | required = ['content'] | |
561 | default = {'content': '[]'} | |
562 | winStyles = ['wxCB_SORT'] | |
563 | ||
564 | class xxxSlider(xxxObject): | |
565 | allParams = ['value', 'min', 'max', 'pos', 'size', 'style', | |
566 | 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick', | |
567 | 'selmin', 'selmax'] | |
c032d94e RR |
568 | paramDict = {'value': ParamInt, 'tickfreq': ParamIntNN, 'pagesize': ParamIntNN, |
569 | 'linesize': ParamIntNN, 'thumb': ParamUnit, | |
d14a1e28 RD |
570 | 'tick': ParamInt, 'selmin': ParamInt, 'selmax': ParamInt} |
571 | required = ['value', 'min', 'max'] | |
572 | winStyles = ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS', | |
573 | 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM', | |
6e2bdf8f | 574 | 'wxSL_BOTH', 'wxSL_SELRANGE', 'wxSL_INVERSE'] |
d14a1e28 RD |
575 | |
576 | class xxxGauge(xxxObject): | |
577 | allParams = ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel'] | |
c032d94e RR |
578 | paramDict = {'range': ParamIntNN, 'value': ParamIntNN, |
579 | 'shadow': ParamIntNN, 'bezel': ParamIntNN} | |
d14a1e28 RD |
580 | winStyles = ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH'] |
581 | ||
582 | class xxxScrollBar(xxxObject): | |
583 | allParams = ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize'] | |
c032d94e RR |
584 | paramDict = {'value': ParamIntNN, 'range': ParamIntNN, 'thumbsize': ParamIntNN, |
585 | 'pagesize': ParamIntNN} | |
d14a1e28 RD |
586 | winStyles = ['wxSB_HORIZONTAL', 'wxSB_VERTICAL'] |
587 | ||
588 | class xxxListCtrl(xxxObject): | |
589 | allParams = ['pos', 'size', 'style'] | |
590 | winStyles = ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON', | |
306b6fe9 RR |
591 | 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE', |
592 | 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER', | |
593 | 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING', | |
594 | 'wxLC_VIRTUAL', 'wxLC_HRULES', 'wxLC_VRULES', 'wxLC_NO_SORT_HEADER'] | |
d14a1e28 RD |
595 | |
596 | class xxxTreeCtrl(xxxObject): | |
597 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 RR |
598 | winStyles = ['wxTR_EDIT_LABELS', |
599 | 'wxTR_NO_BUTTONS', | |
600 | 'wxTR_HAS_BUTTONS', | |
601 | 'wxTR_TWIST_BUTTONS', | |
602 | 'wxTR_NO_LINES', | |
603 | 'wxTR_FULL_ROW_HIGHLIGHT', | |
604 | 'wxTR_LINES_AT_ROOT', | |
605 | 'wxTR_HIDE_ROOT', | |
606 | 'wxTR_ROW_LINES', | |
607 | 'wxTR_HAS_VARIABLE_ROW_HEIGHT', | |
608 | 'wxTR_SINGLE', | |
609 | 'wxTR_MULTIPLE', | |
610 | 'wxTR_EXTENDED', | |
611 | 'wxTR_DEFAULT_STYLE'] | |
d14a1e28 RD |
612 | |
613 | class xxxHtmlWindow(xxxObject): | |
614 | allParams = ['pos', 'size', 'style', 'borders', 'url', 'htmlcode'] | |
306b6fe9 RR |
615 | paramDict = {'htmlcode':ParamMultilineText} |
616 | winStyles = ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO', 'wxHW_NO_SELECTION'] | |
d14a1e28 RD |
617 | |
618 | class xxxCalendarCtrl(xxxObject): | |
619 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 RR |
620 | winStyles = ['wxCAL_SUNDAY_FIRST', 'wxCAL_MONDAY_FIRST', 'wxCAL_SHOW_HOLIDAYS', |
621 | 'wxCAL_NO_YEAR_CHANGE', 'wxCAL_NO_MONTH_CHANGE', | |
622 | 'wxCAL_SEQUENTIAL_MONTH_SELECTION', 'wxCAL_SHOW_SURROUNDING_WEEKS'] | |
d14a1e28 RD |
623 | |
624 | class xxxNotebook(xxxContainer): | |
306b6fe9 | 625 | allParams = ['pos', 'size', 'style'] |
75aa1946 RR |
626 | winStyles = ['wxNB_TOP', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM', |
627 | 'wxNB_FIXEDWIDTH', 'wxNB_MULTILINE', 'wxNB_NOPAGETHEME', 'wxNB_FLAT'] | |
d14a1e28 | 628 | |
306b6fe9 RR |
629 | class xxxChoicebook(xxxContainer): |
630 | allParams = ['pos', 'size', 'style'] | |
631 | winStyles = ['wxCHB_DEFAULT', 'wxCHB_LEFT', 'wxCHB_RIGHT', 'wxCHB_TOP', 'wxCHB_BOTTOM'] | |
632 | ||
633 | class xxxListbook(xxxContainer): | |
634 | allParams = ['pos', 'size', 'style'] | |
635 | winStyles = ['wxLB_DEFAULT', 'wxLB_LEFT', 'wxLB_RIGHT', 'wxLB_TOP', 'wxLB_BOTTOM'] | |
636 | ||
68ae5821 RD |
637 | class xxxSplitterWindow(xxxContainer): |
638 | allParams = ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style'] | |
639 | paramDict = {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit } | |
306b6fe9 RR |
640 | winStyles = ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER', |
641 | 'wxSP_FULLSASH', 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE', | |
642 | 'wxSP_NO_XP_THEME' ] | |
68ae5821 | 643 | |
d14a1e28 RD |
644 | class xxxGenericDirCtrl(xxxObject): |
645 | allParams = ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style'] | |
c032d94e | 646 | paramDict = {'defaultfilter': ParamIntNN} |
d14a1e28 | 647 | winStyles = ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST', |
306b6fe9 | 648 | 'wxDIRCTRL_SHOW_FILTERS'] |
d14a1e28 RD |
649 | |
650 | class xxxScrolledWindow(xxxContainer): | |
651 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 RR |
652 | winStyles = ['wxHSCROLL', 'wxVSCROLL', 'wxNO_3D', 'wxTAB_TRAVERSAL'] |
653 | ||
654 | class xxxDateCtrl(xxxObject): | |
655 | allParams = ['pos', 'size', 'style', 'borders'] | |
656 | winStyles = ['wxDP_DEFAULT', 'wxDP_SPIN', 'wxDP_DROPDOWN', | |
657 | 'wxDP_ALLOWNONE', 'wxDP_SHOWCENTURY'] | |
d14a1e28 | 658 | |
b372319f RR |
659 | class xxxGrid(xxxObject): |
660 | allParams = ['pos', 'size', 'style'] | |
661 | ||
662 | class xxxFilePickerCtrl(xxxObject): | |
663 | allParams = ['value', 'message', 'wildcard', 'pos', 'size', 'style'] | |
664 | winStyles = ['wxFLP_OPEN', 'wxFLP_SAVE', 'wxFLP_OVERWRITE_PROMPT', | |
665 | 'wxFLP_FILE_MUST_EXIST', 'wxFLP_CHANGE_DIR', | |
666 | 'wxFLP_DEFAULT_STYLE'] | |
667 | ||
668 | ||
d14a1e28 RD |
669 | ################################################################################ |
670 | # Buttons | |
671 | ||
672 | class xxxButton(xxxObject): | |
673 | allParams = ['label', 'default', 'pos', 'size', 'style'] | |
674 | paramDict = {'default': ParamBool} | |
675 | required = ['label'] | |
75aa1946 RR |
676 | winStyles = ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM', 'wxBU_EXACTFIT', |
677 | 'wxNO_BORDER'] | |
d14a1e28 RD |
678 | |
679 | class xxxBitmapButton(xxxObject): | |
680 | allParams = ['bitmap', 'selected', 'focus', 'disabled', 'default', | |
681 | 'pos', 'size', 'style'] | |
29a41103 RD |
682 | paramDict = {'selected': ParamBitmap, 'focus': ParamBitmap, 'disabled': ParamBitmap, |
683 | 'default': ParamBool} | |
d14a1e28 | 684 | required = ['bitmap'] |
306b6fe9 | 685 | winStyles = ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_RIGHT', |
75aa1946 | 686 | 'wxBU_TOP', 'wxBU_BOTTOM'] |
d14a1e28 RD |
687 | |
688 | class xxxRadioButton(xxxObject): | |
689 | allParams = ['label', 'value', 'pos', 'size', 'style'] | |
690 | paramDict = {'value': ParamBool} | |
691 | required = ['label'] | |
306b6fe9 | 692 | winStyles = ['wxRB_GROUP', 'wxRB_SINGLE'] |
d14a1e28 RD |
693 | |
694 | class xxxSpinButton(xxxObject): | |
695 | allParams = ['value', 'min', 'max', 'pos', 'size', 'style'] | |
696 | paramDict = {'value': ParamInt} | |
697 | winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP'] | |
698 | ||
699 | class xxxSpinCtrl(xxxObject): | |
700 | allParams = ['value', 'min', 'max', 'pos', 'size', 'style'] | |
701 | paramDict = {'value': ParamInt} | |
702 | winStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP'] | |
703 | ||
3d49f2fb RD |
704 | class xxxToggleButton(xxxObject): |
705 | allParams = ['label', 'checked', 'pos', 'size', 'style'] | |
706 | paramDict = {'checked': ParamBool} | |
707 | required = ['label'] | |
708 | ||
d14a1e28 RD |
709 | ################################################################################ |
710 | # Boxes | |
711 | ||
712 | class xxxStaticBox(xxxObject): | |
713 | allParams = ['label', 'pos', 'size', 'style'] | |
714 | required = ['label'] | |
715 | ||
716 | class xxxRadioBox(xxxObject): | |
717 | allParams = ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style'] | |
c032d94e | 718 | paramDict = {'dimension': ParamIntNN} |
d14a1e28 RD |
719 | required = ['label', 'content'] |
720 | default = {'content': '[]'} | |
306b6fe9 RR |
721 | winStyles = ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS', 'wxRA_HORIZONTAL', |
722 | 'wxRA_VERTICAL'] | |
d14a1e28 RD |
723 | |
724 | class xxxCheckBox(xxxObject): | |
725 | allParams = ['label', 'checked', 'pos', 'size', 'style'] | |
726 | paramDict = {'checked': ParamBool} | |
3d49f2fb RD |
727 | winStyles = ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER', |
728 | 'wxALIGN_RIGHT'] | |
d14a1e28 RD |
729 | required = ['label'] |
730 | ||
731 | class xxxComboBox(xxxObject): | |
732 | allParams = ['content', 'selection', 'value', 'pos', 'size', 'style'] | |
733 | required = ['content'] | |
734 | default = {'content': '[]'} | |
735 | winStyles = ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN'] | |
736 | ||
737 | class xxxListBox(xxxObject): | |
738 | allParams = ['content', 'selection', 'pos', 'size', 'style'] | |
739 | required = ['content'] | |
740 | default = {'content': '[]'} | |
741 | winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL', | |
306b6fe9 | 742 | 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT'] |
d14a1e28 RD |
743 | |
744 | class xxxCheckList(xxxObject): | |
745 | allParams = ['content', 'pos', 'size', 'style'] | |
746 | required = ['content'] | |
747 | default = {'content': '[]'} | |
306b6fe9 RR |
748 | winStyles = ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL', |
749 | 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT'] | |
d14a1e28 RD |
750 | paramDict = {'content': ParamContentCheckList} |
751 | ||
752 | ################################################################################ | |
753 | # Sizers | |
754 | ||
755 | class xxxSizer(xxxContainer): | |
756 | hasName = hasStyle = False | |
757 | paramDict = {'orient': ParamOrient} | |
758 | isSizer = True | |
64b9ac75 | 759 | itemTag = 'sizeritem' # different for some sizers |
d14a1e28 RD |
760 | |
761 | class xxxBoxSizer(xxxSizer): | |
762 | allParams = ['orient'] | |
763 | required = ['orient'] | |
764 | default = {'orient': 'wxVERTICAL'} | |
765 | # Tree icon depends on orientation | |
766 | def treeImage(self): | |
767 | if self.params['orient'].value() == 'wxHORIZONTAL': return self.imageH | |
768 | else: return self.imageV | |
769 | ||
770 | class xxxStaticBoxSizer(xxxBoxSizer): | |
771 | allParams = ['label', 'orient'] | |
772 | required = ['label', 'orient'] | |
773 | ||
774 | class xxxGridSizer(xxxSizer): | |
775 | allParams = ['cols', 'rows', 'vgap', 'hgap'] | |
776 | required = ['cols'] | |
777 | default = {'cols': '2', 'rows': '2'} | |
778 | ||
64bce500 RR |
779 | class xxxStdDialogButtonSizer(xxxSizer): |
780 | allParams = [] | |
64b9ac75 | 781 | itemTag = 'button' |
64bce500 | 782 | |
d14a1e28 RD |
783 | # For repeated parameters |
784 | class xxxParamMulti: | |
785 | def __init__(self, node): | |
786 | self.node = node | |
787 | self.l, self.data = [], [] | |
788 | def append(self, param): | |
789 | self.l.append(param) | |
790 | self.data.append(param.value()) | |
791 | def value(self): | |
792 | return self.data | |
793 | def remove(self): | |
794 | for param in self.l: | |
795 | param.remove() | |
796 | self.l, self.data = [], [] | |
797 | ||
798 | class xxxFlexGridSizer(xxxGridSizer): | |
799 | specials = ['growablecols', 'growablerows'] | |
800 | allParams = ['cols', 'rows', 'vgap', 'hgap'] + specials | |
306b6fe9 | 801 | paramDict = {'growablecols': ParamIntList, 'growablerows': ParamIntList} |
d14a1e28 | 802 | |
a4c013b2 RR |
803 | class xxxGridBagSizer(xxxSizer): |
804 | specials = ['growablecols', 'growablerows'] | |
805 | allParams = ['vgap', 'hgap'] + specials | |
7df24e78 | 806 | paramDict = {'growablecols': ParamIntList, 'growablerows': ParamIntList} |
a4c013b2 | 807 | |
d14a1e28 RD |
808 | # Container with only one child. |
809 | # Not shown in tree. | |
810 | class xxxChildContainer(xxxObject): | |
811 | hasName = hasStyle = False | |
812 | hasChild = True | |
03319b65 RR |
813 | def __init__(self, parent, element, refElem=None): |
814 | xxxObject.__init__(self, parent, element, refElem) | |
d14a1e28 RD |
815 | # Must have one child with 'object' tag, but we don't check it |
816 | nodes = element.childNodes[:] # create copy | |
817 | for node in nodes: | |
818 | if node.nodeType == minidom.Node.ELEMENT_NODE: | |
03319b65 | 819 | if node.tagName in ['object', 'object_ref']: |
d14a1e28 RD |
820 | # Create new xxx object for child node |
821 | self.child = MakeXXXFromDOM(self, node) | |
822 | self.child.parent = parent | |
823 | # Copy hasChildren and isSizer attributes | |
824 | self.hasChildren = self.child.hasChildren | |
825 | self.isSizer = self.child.isSizer | |
826 | return # success | |
827 | else: | |
828 | element.removeChild(node) | |
829 | node.unlink() | |
830 | assert 0, 'no child found' | |
75aa1946 RR |
831 | def resetChild(self, xxx): |
832 | '''Reset child info (for replacing with another class).''' | |
833 | self.child = xxx | |
834 | self.hasChildren = xxx.hasChildren | |
835 | self.isSizer = xxx.isSizer | |
d14a1e28 RD |
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') | |
75aa1946 RR |
850 | def resetChild(self, xxx): |
851 | xxxChildContainer.resetChild(self, xxx) | |
852 | # Remove pos parameter - not needed for sizeritems | |
853 | if 'pos' in self.child.allParams: | |
854 | self.child.allParams = self.child.allParams[:] | |
855 | self.child.allParams.remove('pos') | |
d14a1e28 | 856 | |
64b9ac75 RR |
857 | class xxxSizerItemButton(xxxSizerItem): |
858 | allParams = [] | |
859 | paramDict = {} | |
03319b65 RR |
860 | def __init__(self, parent, element, refElem=None): |
861 | xxxChildContainer.__init__(self, parent, element, refElem=None) | |
64b9ac75 RR |
862 | # Remove pos parameter - not needed for sizeritems |
863 | if 'pos' in self.child.allParams: | |
864 | self.child.allParams = self.child.allParams[:] | |
865 | self.child.allParams.remove('pos') | |
866 | ||
306b6fe9 | 867 | class xxxPage(xxxChildContainer): |
d14a1e28 RD |
868 | allParams = ['label', 'selected'] |
869 | paramDict = {'selected': ParamBool} | |
870 | required = ['label'] | |
03319b65 RR |
871 | def __init__(self, parent, element, refElem=None): |
872 | xxxChildContainer.__init__(self, parent, element, refElem) | |
d14a1e28 RD |
873 | # pos and size dont matter for notebookpages |
874 | if 'pos' in self.child.allParams: | |
875 | self.child.allParams = self.child.allParams[:] | |
876 | self.child.allParams.remove('pos') | |
877 | if 'size' in self.child.allParams: | |
878 | self.child.allParams = self.child.allParams[:] | |
879 | self.child.allParams.remove('size') | |
880 | ||
881 | class xxxSpacer(xxxObject): | |
882 | hasName = hasStyle = False | |
883 | allParams = ['size', 'option', 'flag', 'border'] | |
884 | paramDict = {'option': ParamInt} | |
885 | default = {'size': '0,0'} | |
28e65e0f RR |
886 | def __init__(self, parent, element, refElem=None): |
887 | # For GridBag sizer items, extra parameters added | |
888 | if isinstance(parent, xxxGridBagSizer): | |
889 | self.allParams = self.allParams + ['cellpos', 'cellspan'] | |
890 | xxxObject.__init__(self, parent, element, refElem) | |
d14a1e28 RD |
891 | |
892 | class xxxMenuBar(xxxContainer): | |
893 | allParams = ['style'] | |
894 | paramDict = {'style': ParamNonGenericStyle} # no generic styles | |
895 | winStyles = ['wxMB_DOCKABLE'] | |
896 | ||
897 | class xxxMenu(xxxContainer): | |
898 | allParams = ['label', 'help', 'style'] | |
899 | default = {'label': ''} | |
900 | paramDict = {'style': ParamNonGenericStyle} # no generic styles | |
901 | winStyles = ['wxMENU_TEAROFF'] | |
902 | ||
903 | class xxxMenuItem(xxxObject): | |
904 | allParams = ['label', 'bitmap', 'accel', 'help', | |
905 | 'checkable', 'radio', 'enabled', 'checked'] | |
906 | default = {'label': ''} | |
907 | hasStyle = False | |
908 | ||
909 | class xxxSeparator(xxxObject): | |
910 | hasName = hasStyle = False | |
911 | ||
912 | ################################################################################ | |
913 | # Unknown control | |
914 | ||
915 | class xxxUnknown(xxxObject): | |
916 | allParams = ['pos', 'size', 'style'] | |
306b6fe9 | 917 | winStyles = ['wxNO_FULL_REPAINT_ON_RESIZE'] |
d14a1e28 | 918 | |
b372319f RR |
919 | ################################################################################ |
920 | # Comment | |
921 | ||
c0d5ae74 | 922 | _handlers = [] # custom handler classes/funcs |
8c64c153 RR |
923 | def getHandlers(): |
924 | return _handlers | |
925 | def setHandlers(handlers): | |
926 | global _handlers | |
927 | _handlers = handlers | |
c0d5ae74 | 928 | _CFuncPtr = None # ctypes function type |
00d15346 RR |
929 | |
930 | def register(hndlr): | |
c0d5ae74 | 931 | """Register hndlr function or XmlResourceHandler class.""" |
00d15346 RR |
932 | if _CFuncPtr and isinstance(hndlr, _CFuncPtr): |
933 | _handlers.append(hndlr) | |
934 | return | |
935 | if not isinstance(hndlr, type): | |
936 | wx.LogError('handler is not a type: %s' % hndlr) | |
937 | elif not issubclass(hndlr, wx.xrc.XmlResourceHandler): | |
938 | wx.LogError('handler is not a XmlResourceHandler: %s' % hndlr) | |
939 | else: | |
940 | _handlers.append(hndlr) | |
941 | ||
942 | def load_dl(path, localname=''): | |
8c64c153 RR |
943 | """Load shared/dynamic library into xxx namespace. |
944 | ||
945 | If path is not absolute or relative, try to find in the module's directory. | |
946 | """ | |
c0d5ae74 RR |
947 | if not localname: |
948 | localname = os.path.basename(os.path.splitext(path)[0]) | |
00d15346 RR |
949 | try: |
950 | import ctypes | |
951 | global _CFuncPtr | |
8c64c153 RR |
952 | _CFuncPtr = ctypes._CFuncPtr # use as a flag of loaded ctypes |
953 | #if not os.path.dirname(path) and os.path.isfile(path): | |
954 | ||
00d15346 RR |
955 | except ImportError: |
956 | wx.LogError('ctypes module not found') | |
c0d5ae74 | 957 | globals()[localname] = None |
00d15346 RR |
958 | return |
959 | try: | |
960 | dl = ctypes.CDLL(path) | |
00d15346 | 961 | globals()[localname] = dl |
c0d5ae74 RR |
962 | # Register AddXmlHandlers() if exists |
963 | try: | |
964 | register(dl.AddXmlHandlers) | |
965 | except: | |
966 | pass | |
00d15346 | 967 | except: |
c0d5ae74 | 968 | wx.LogError('error loading dynamic library: %s' % path) |
00d15346 RR |
969 | print traceback.print_exc() |
970 | ||
971 | # Called when creating test window | |
c0d5ae74 | 972 | def addHandlers(): |
00d15346 RR |
973 | for h in _handlers: |
974 | if _CFuncPtr and isinstance(h, _CFuncPtr): | |
975 | try: | |
976 | apply(h, ()) | |
977 | except: | |
978 | wx.LogError('error calling DL func: "%s"' % h) | |
979 | print traceback.print_exc() | |
980 | else: | |
981 | try: | |
c0d5ae74 | 982 | xrc.XmlResource.Get().AddHandler(apply(h, ())) |
00d15346 RR |
983 | except: |
984 | wx.LogError('error adding XmlHandler: "%s"' % h) | |
985 | print traceback.print_exc() | |
986 | ||
c0d5ae74 RR |
987 | def custom(klassName, klass='unknown'): |
988 | """Define custom control based on xrcClass. | |
989 | ||
990 | klass: new object name | |
991 | xrcClass: name of an existing XRC object class or | |
992 | a class object defining class parameters. | |
993 | """ | |
994 | if type(klass) is str: | |
995 | # Copy correct xxx class under new name | |
996 | kl = xxxDict[klass] | |
997 | xxxClass = types.ClassType('xxx' + klassName, kl.__bases__, kl.__dict__) | |
998 | else: | |
999 | xxxClass = klass | |
1000 | # Register param IDs | |
1001 | for param in klass.allParams + klass.paramDict.keys(): | |
1002 | if not paramIDs.has_key(param): | |
1003 | paramIDs[param] = wx.NewId() | |
1004 | # Insert in dictionaty | |
1005 | xxxDict[klassName] = xxxClass | |
1006 | # Add to menu | |
1007 | g.pullDownMenu.addCustom(klassName) | |
1008 | ||
b372319f RR |
1009 | class xxxParamComment(xxxParam): |
1010 | def __init__(self, node): | |
1011 | xxxNode.__init__(self, node) | |
1012 | self.textNode = node | |
00d15346 RR |
1013 | # Parse "pragma" comments |
1014 | if node.data and node.data[0] == '%': | |
1015 | try: | |
1016 | code = node.data[1:] | |
1017 | exec code in globals() | |
1018 | except: | |
1019 | wx.LogError('exec error: "%s"' % code) | |
1020 | print traceback.print_exc() | |
b372319f RR |
1021 | |
1022 | class xxxComment(xxxObject): | |
1023 | hasStyle = hasName = False | |
1024 | allParams = required = ['comment'] | |
1025 | ||
1026 | def __init__(self, parent, node): | |
1027 | self.parent = parent | |
1028 | self.node = node | |
1029 | self.isElement = False | |
1030 | self.undo = None | |
1031 | self.className = 'comment' | |
1032 | self.ref = self.subclass = None | |
1033 | self.params = {'comment': xxxParamComment(node)} | |
1034 | ||
1035 | def treeName(self): | |
1036 | # Replace newlines by \n to avoid tree item resizing | |
1037 | return self.params['comment'].value().replace('\n', r'\n') | |
1038 | ||
d14a1e28 RD |
1039 | ################################################################################ |
1040 | ||
c0d5ae74 | 1041 | # Mapping of XRC names to xxx classes |
d14a1e28 RD |
1042 | xxxDict = { |
1043 | 'wxPanel': xxxPanel, | |
1044 | 'wxDialog': xxxDialog, | |
1045 | 'wxFrame': xxxFrame, | |
1046 | 'tool': xxxTool, | |
1047 | 'wxToolBar': xxxToolBar, | |
306b6fe9 | 1048 | 'wxStatusBar': xxxStatusBar, |
64bce500 RR |
1049 | 'wxWizard': xxxWizard, |
1050 | 'wxWizardPage': xxxWizardPage, | |
1051 | 'wxWizardPageSimple': xxxWizardPageSimple, | |
d14a1e28 RD |
1052 | |
1053 | 'wxBitmap': xxxBitmap, | |
1054 | 'wxIcon': xxxIcon, | |
1055 | ||
1056 | 'wxButton': xxxButton, | |
1057 | 'wxBitmapButton': xxxBitmapButton, | |
1058 | 'wxRadioButton': xxxRadioButton, | |
1059 | 'wxSpinButton': xxxSpinButton, | |
3d49f2fb | 1060 | 'wxToggleButton' : xxxToggleButton, |
d14a1e28 RD |
1061 | |
1062 | 'wxStaticBox': xxxStaticBox, | |
1063 | 'wxStaticBitmap': xxxStaticBitmap, | |
1064 | 'wxRadioBox': xxxRadioBox, | |
1065 | 'wxComboBox': xxxComboBox, | |
1066 | 'wxCheckBox': xxxCheckBox, | |
1067 | 'wxListBox': xxxListBox, | |
1068 | ||
1069 | 'wxStaticText': xxxStaticText, | |
1070 | 'wxStaticLine': xxxStaticLine, | |
1071 | 'wxTextCtrl': xxxTextCtrl, | |
1072 | 'wxChoice': xxxChoice, | |
1073 | 'wxSlider': xxxSlider, | |
1074 | 'wxGauge': xxxGauge, | |
1075 | 'wxScrollBar': xxxScrollBar, | |
1076 | 'wxTreeCtrl': xxxTreeCtrl, | |
1077 | 'wxListCtrl': xxxListCtrl, | |
edfeb1b8 | 1078 | 'wxCheckListBox': xxxCheckList, |
306b6fe9 RR |
1079 | 'notebookpage': xxxPage, |
1080 | 'choicebookpage': xxxPage, | |
1081 | 'listbookpage': xxxPage, | |
d14a1e28 | 1082 | 'wxNotebook': xxxNotebook, |
306b6fe9 RR |
1083 | 'wxChoicebook': xxxChoicebook, |
1084 | 'wxListbook': xxxListbook, | |
68ae5821 | 1085 | 'wxSplitterWindow': xxxSplitterWindow, |
d14a1e28 RD |
1086 | 'wxHtmlWindow': xxxHtmlWindow, |
1087 | 'wxCalendarCtrl': xxxCalendarCtrl, | |
1088 | 'wxGenericDirCtrl': xxxGenericDirCtrl, | |
1089 | 'wxSpinCtrl': xxxSpinCtrl, | |
1090 | 'wxScrolledWindow': xxxScrolledWindow, | |
b372319f RR |
1091 | 'wxGrid': xxxGrid, |
1092 | 'wxFilePickerCtrl': xxxFilePickerCtrl, | |
306b6fe9 | 1093 | 'wxDatePickerCtrl': xxxDateCtrl, |
d14a1e28 RD |
1094 | |
1095 | 'wxBoxSizer': xxxBoxSizer, | |
1096 | 'wxStaticBoxSizer': xxxStaticBoxSizer, | |
1097 | 'wxGridSizer': xxxGridSizer, | |
1098 | 'wxFlexGridSizer': xxxFlexGridSizer, | |
a4c013b2 | 1099 | 'wxGridBagSizer': xxxGridBagSizer, |
64bce500 | 1100 | 'wxStdDialogButtonSizer': xxxStdDialogButtonSizer, |
64b9ac75 | 1101 | 'sizeritem': xxxSizerItem, 'button': xxxSizerItemButton, |
d14a1e28 RD |
1102 | 'spacer': xxxSpacer, |
1103 | ||
1104 | 'wxMenuBar': xxxMenuBar, | |
1105 | 'wxMenu': xxxMenu, | |
1106 | 'wxMenuItem': xxxMenuItem, | |
1107 | 'separator': xxxSeparator, | |
1108 | ||
1109 | 'unknown': xxxUnknown, | |
b372319f | 1110 | 'comment': xxxComment, |
d14a1e28 RD |
1111 | } |
1112 | ||
1113 | # Create IDs for all parameters of all classes | |
29a41103 RD |
1114 | paramIDs = {'fg': wx.NewId(), 'bg': wx.NewId(), 'exstyle': wx.NewId(), 'font': wx.NewId(), |
1115 | 'enabled': wx.NewId(), 'focused': wx.NewId(), 'hidden': wx.NewId(), | |
1116 | 'tooltip': wx.NewId(), 'encoding': wx.NewId(), | |
b372319f RR |
1117 | 'cellpos': wx.NewId(), 'cellspan': wx.NewId(), |
1118 | 'text': wx.NewId() | |
d14a1e28 RD |
1119 | } |
1120 | for cl in xxxDict.values(): | |
1121 | if cl.allParams: | |
1122 | for param in cl.allParams + cl.paramDict.keys(): | |
1123 | if not paramIDs.has_key(param): | |
29a41103 | 1124 | paramIDs[param] = wx.NewId() |
d14a1e28 RD |
1125 | |
1126 | ################################################################################ | |
1127 | # Helper functions | |
1128 | ||
1129 | # Test for object elements | |
1130 | def IsObject(node): | |
b372319f RR |
1131 | return node.nodeType == minidom.Node.ELEMENT_NODE and \ |
1132 | node.tagName in ['object', 'object_ref'] or \ | |
1133 | node.nodeType == minidom.Node.COMMENT_NODE | |
d14a1e28 RD |
1134 | |
1135 | # Make XXX object from some DOM object, selecting correct class | |
b372319f RR |
1136 | def MakeXXXFromDOM(parent, node): |
1137 | if node.nodeType == minidom.Node.COMMENT_NODE: | |
1138 | return xxxComment(parent, node) | |
1139 | if node.tagName == 'object_ref': | |
1140 | ref = node.getAttribute('ref') | |
03319b65 RR |
1141 | refElem = FindResource(ref) |
1142 | if refElem: cls = refElem.getAttribute('class') | |
b372319f | 1143 | else: return xxxUnknown(parent, node) |
03319b65 RR |
1144 | else: |
1145 | refElem = None | |
b372319f | 1146 | cls = node.getAttribute('class') |
d14a1e28 | 1147 | try: |
03319b65 | 1148 | klass = xxxDict[cls] |
d14a1e28 RD |
1149 | except KeyError: |
1150 | # If we encounter a weird class, use unknown template | |
b372319f | 1151 | print 'WARNING: unsupported class:', node.getAttribute('class') |
d14a1e28 | 1152 | klass = xxxUnknown |
b372319f | 1153 | return klass(parent, node, refElem) |
d14a1e28 RD |
1154 | |
1155 | # Make empty DOM element | |
1156 | def MakeEmptyDOM(className): | |
1157 | elem = g.tree.dom.createElement('object') | |
1158 | elem.setAttribute('class', className) | |
1159 | # Set required and default parameters | |
1160 | xxxClass = xxxDict[className] | |
1161 | defaultNotRequired = filter(lambda x, l=xxxClass.required: x not in l, | |
1162 | xxxClass.default.keys()) | |
1163 | for param in xxxClass.required + defaultNotRequired: | |
1164 | textElem = g.tree.dom.createElement(param) | |
1165 | try: | |
1166 | textNode = g.tree.dom.createTextNode(xxxClass.default[param]) | |
1167 | except KeyError: | |
1168 | textNode = g.tree.dom.createTextNode('') | |
1169 | textElem.appendChild(textNode) | |
1170 | elem.appendChild(textElem) | |
1171 | return elem | |
1172 | ||
1173 | # Make empty XXX object | |
1174 | def MakeEmptyXXX(parent, className): | |
1175 | # Make corresponding DOM object first | |
1176 | elem = MakeEmptyDOM(className) | |
1177 | # If parent is a sizer, we should create sizeritem object, except for spacers | |
1178 | if parent: | |
1179 | if parent.isSizer and className != 'spacer': | |
64b9ac75 | 1180 | sizerItemElem = MakeEmptyDOM(parent.itemTag) |
d14a1e28 RD |
1181 | sizerItemElem.appendChild(elem) |
1182 | elem = sizerItemElem | |
1183 | elif isinstance(parent, xxxNotebook): | |
1184 | pageElem = MakeEmptyDOM('notebookpage') | |
1185 | pageElem.appendChild(elem) | |
1186 | elem = pageElem | |
306b6fe9 RR |
1187 | elif isinstance(parent, xxxChoicebook): |
1188 | pageElem = MakeEmptyDOM('choicebookpage') | |
1189 | pageElem.appendChild(elem) | |
1190 | elem = pageElem | |
1191 | elif isinstance(parent, xxxListbook): | |
1192 | pageElem = MakeEmptyDOM('listbookpage') | |
1193 | pageElem.appendChild(elem) | |
1194 | elem = pageElem | |
d14a1e28 RD |
1195 | # Now just make object |
1196 | return MakeXXXFromDOM(parent, elem) | |
1fded56b | 1197 | |
03319b65 RR |
1198 | # Make empty DOM element for reference |
1199 | def MakeEmptyRefDOM(ref): | |
1200 | elem = g.tree.dom.createElement('object_ref') | |
1201 | elem.setAttribute('ref', ref) | |
1202 | return elem | |
1203 | ||
1204 | # Make empty XXX object | |
1205 | def MakeEmptyRefXXX(parent, ref): | |
1206 | # Make corresponding DOM object first | |
1207 | elem = MakeEmptyRefDOM(ref) | |
1208 | # If parent is a sizer, we should create sizeritem object, except for spacers | |
1209 | if parent: | |
1210 | if parent.isSizer: | |
1211 | sizerItemElem = MakeEmptyDOM(parent.itemTag) | |
1212 | sizerItemElem.appendChild(elem) | |
1213 | elem = sizerItemElem | |
1214 | elif isinstance(parent, xxxNotebook): | |
1215 | pageElem = MakeEmptyDOM('notebookpage') | |
1216 | pageElem.appendChild(elem) | |
1217 | elem = pageElem | |
306b6fe9 RR |
1218 | elif isinstance(parent, xxxChoicebook): |
1219 | pageElem = MakeEmptyDOM('choicebookpage') | |
1220 | pageElem.appendChild(elem) | |
1221 | elem = pageElem | |
1222 | elif isinstance(parent, xxxListbook): | |
1223 | pageElem = MakeEmptyDOM('listbookpage') | |
1224 | pageElem.appendChild(elem) | |
1225 | elem = pageElem | |
03319b65 | 1226 | # Now just make object |
75aa1946 RR |
1227 | xxx = MakeXXXFromDOM(parent, elem) |
1228 | # Label is not used for references | |
1229 | xxx.allParams = xxx.allParams[:] | |
1230 | #xxx.allParams.remove('label') | |
1231 | return xxx | |
03319b65 | 1232 | |
b372319f RR |
1233 | # Make empty comment node |
1234 | def MakeEmptyCommentDOM(): | |
1235 | node = g.tree.dom.createComment('') | |
1236 | return node | |
1237 | ||
1238 | # Make empty xxxComment | |
1239 | def MakeEmptyCommentXXX(parent): | |
1240 | node = MakeEmptyCommentDOM() | |
1241 | # Now just make object | |
1242 | xxx = MakeXXXFromDOM(parent, node) | |
1243 | return xxx | |
1244 |