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