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>
7 from xml
.dom
import minidom
11 # Base class for interface parameter classes
13 def __init__(self
, node
):
16 self
.node
.parentNode
.removeChild(self
.node
)
19 # Generic (text) parameter class
20 class xxxParam(xxxNode
):
21 # Standard use: for text nodes
22 def __init__(self
, node
):
23 xxxNode
.__init
__(self
, node
)
24 if not node
.hasChildNodes():
25 # If does not have child nodes, create empty text node
26 text
= g
.tree
.dom
.createTextNode('')
27 node
.appendChild(text
)
29 text
= node
.childNodes
[0] # first child must be text node
30 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
31 # Append other text nodes if present and delete them
33 for n
in node
.childNodes
[1:]:
34 if n
.nodeType
== minidom
.Node
.TEXT_NODE
:
39 if extraText
: text
.data
= text
.data
+ extraText
40 # Use convertion from unicode to current encoding
42 # Value returns string
43 if wx
.USE_UNICODE
: # no conversion is needed
45 return self
.textNode
.data
46 def update(self
, value
):
47 self
.textNode
.data
= value
51 return self
.textNode
.data
.encode(g
.currentEncoding
)
53 return self
.textNode
.data
.encode()
54 def update(self
, value
):
55 try: # handle exception if encoding is wrong
56 self
.textNode
.data
= unicode(value
, g
.currentEncoding
)
57 except UnicodeDecodeError:
58 self
.textNode
.data
= unicode(value
)
59 #wx.LogMessage("Unicode error: set encoding in file\nglobals.py to something appropriate")
62 class xxxParamInt(xxxParam
):
63 # Standard use: for text nodes
64 def __init__(self
, node
):
65 xxxParam
.__init
__(self
, node
)
66 # Value returns string
69 return int(self
.textNode
.data
)
71 return -1 # invalid value
72 def update(self
, value
):
73 self
.textNode
.data
= str(value
)
76 class xxxParamContent(xxxNode
):
77 def __init__(self
, node
):
78 xxxNode
.__init
__(self
, node
)
79 data
, l
= [], [] # data is needed to quicker value retrieval
80 nodes
= node
.childNodes
[:] # make a copy of the child list
82 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
83 assert n
.tagName
== 'item', 'bad content content'
84 if not n
.hasChildNodes():
85 # If does not have child nodes, create empty text node
86 text
= g
.tree
.dom
.createTextNode('')
87 node
.appendChild(text
)
90 text
= n
.childNodes
[0] # first child must be text node
91 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
93 data
.append(text
.data
)
97 self
.l
, self
.data
= l
, data
100 def update(self
, value
):
101 # If number if items is not the same, recreate children
102 if len(value
) != len(self
.l
): # remove first if number of items has changed
103 childNodes
= self
.node
.childNodes
[:]
105 self
.node
.removeChild(n
)
108 itemElem
= g
.tree
.dom
.createElement('item')
109 itemText
= g
.tree
.dom
.createTextNode(str)
110 itemElem
.appendChild(itemText
)
111 self
.node
.appendChild(itemElem
)
115 for i
in range(len(value
)):
116 self
.l
[i
].data
= value
[i
]
119 # Content parameter for checklist
120 class xxxParamContentCheckList(xxxNode
):
121 def __init__(self
, node
):
122 xxxNode
.__init
__(self
, node
)
123 data
, l
= [], [] # data is needed to quicker value retrieval
124 nodes
= node
.childNodes
[:] # make a copy of the child list
126 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
127 assert n
.tagName
== 'item', 'bad content content'
128 checked
= n
.getAttribute('checked')
129 if not checked
: checked
= 0
130 if not n
.hasChildNodes():
131 # If does not have child nodes, create empty text node
132 text
= g
.tree
.dom
.createTextNode('')
133 node
.appendChild(text
)
136 text
= n
.childNodes
[0] # first child must be text node
137 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
139 data
.append((str(text
.data
), int(checked
)))
143 self
.l
, self
.data
= l
, data
146 def update(self
, value
):
147 # If number if items is not the same, recreate children
148 if len(value
) != len(self
.l
): # remove first if number of items has changed
149 childNodes
= self
.node
.childNodes
[:]
151 self
.node
.removeChild(n
)
154 itemElem
= g
.tree
.dom
.createElement('item')
155 # Add checked only if True
156 if ch
: itemElem
.setAttribute('checked', '1')
157 itemText
= g
.tree
.dom
.createTextNode(s
)
158 itemElem
.appendChild(itemText
)
159 self
.node
.appendChild(itemElem
)
160 l
.append((itemText
, itemElem
))
163 for i
in range(len(value
)):
164 self
.l
[i
][0].data
= value
[i
][0]
165 self
.l
[i
][1].setAttribute('checked', str(value
[i
][1]))
169 class xxxParamBitmap(xxxParam
):
170 def __init__(self
, node
):
171 xxxParam
.__init
__(self
, node
)
172 self
.stock_id
= node
.getAttribute('stock_id')
174 return [self
.stock_id
, xxxParam
.value(self
)]
175 def update(self
, value
):
176 self
.stock_id
= value
[0]
178 self
.node
.setAttribute('stock_id', self
.stock_id
)
179 elif self
.node
.hasAttribute('stock_id'):
180 self
.node
.removeAttribute('stock_id')
181 xxxParam
.update(self
, value
[1])
183 ################################################################################
185 # Classes to interface DOM objects
188 hasChildren
= False # has children elements?
189 hasStyle
= True # almost everyone
190 hasName
= True # has name attribute?
191 isSizer
= hasChild
= False
192 allParams
= None # Some nodes have no parameters
193 # Style parameters (all optional)
194 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip']
198 bitmapTags
= ['bitmap', 'bitmap2', 'icon']
199 # Required paremeters: none by default
201 # Default parameters with default values
205 # Window styles and extended styles
209 # Construct a new xxx object from DOM element
210 # parent is parent xxx object (or None if none), element is DOM element object
211 def __init__(self
, parent
, element
, refElem
=None):
213 self
.element
= element
214 self
.refElem
= refElem
216 # Reference are dereferenced
217 if element
.tagName
== 'object_ref':
218 # Find original object
219 self
.ref
= element
.getAttribute('ref')
221 self
.className
= self
.refElem
.getAttribute('class')
223 self
.className
= 'xxxUnknown'
228 self
.className
= element
.getAttribute('class')
229 self
.subclass
= element
.getAttribute('subclass')
230 if self
.hasName
: self
.name
= element
.getAttribute('name')
231 # Set parameters (text element children)
233 nodes
= element
.childNodes
[:]
235 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
237 if tag
in ['object', 'object_ref']:
238 continue # do nothing for object children here
239 elif tag
not in self
.allParams
and tag
not in self
.styles
:
240 print 'WARNING: unknown parameter for %s: %s' % \
241 (self
.className
, tag
)
242 elif tag
in self
.specials
:
243 self
.special(tag
, node
)
244 elif tag
== 'content':
245 if self
.className
== 'wxCheckListBox':
246 self
.params
[tag
] = xxxParamContentCheckList(node
)
248 self
.params
[tag
] = xxxParamContent(node
)
249 elif tag
== 'font': # has children
250 self
.params
[tag
] = xxxParamFont(element
, node
)
251 elif tag
in self
.bitmapTags
:
252 # Can have attributes
253 self
.params
[tag
] = xxxParamBitmap(node
)
254 else: # simple parameter
255 self
.params
[tag
] = xxxParam(node
)
256 elif node
.nodeType
== minidom
.Node
.TEXT_NODE
and node
.data
.isspace():
257 # Remove empty text nodes
258 element
.removeChild(node
)
261 # Check that all required params are set
262 for param
in self
.required
:
263 if not self
.params
.has_key(param
):
264 # If default is specified, set it
265 if self
.default
.has_key(param
):
266 elem
= g
.tree
.dom
.createElement(param
)
267 if param
== 'content':
268 if self
.className
== 'wxCheckListBox':
269 self
.params
[param
] = xxxParamContentCheckList(elem
)
271 self
.params
[param
] = xxxParamContent(elem
)
273 self
.params
[param
] = xxxParam(elem
)
274 # Find place to put new element: first present element after param
276 paramStyles
= self
.allParams
+ self
.styles
277 for p
in paramStyles
[paramStyles
.index(param
) + 1:]:
278 # Content params don't have same type
279 if self
.params
.has_key(p
) and p
!= 'content':
283 nextTextElem
= self
.params
[p
].node
284 self
.element
.insertBefore(elem
, nextTextElem
)
286 self
.element
.appendChild(elem
)
288 wx
.LogWarning('Required parameter %s of %s missing' %
289 (param
, self
.className
))
290 # Returns real tree object
291 def treeObject(self
):
292 if self
.hasChild
: return self
.child
294 # Returns tree image index
296 if self
.hasChild
: return self
.child
.treeImage()
298 # Class name plus wx name
300 if self
.hasChild
: return self
.child
.treeName()
301 if self
.subclass
: className
= self
.subclass
302 else: className
= self
.className
303 if self
.hasName
and self
.name
: return className
+ ' "' + self
.name
+ '"'
305 # Class name or subclass
307 if self
.subclass
: name
= self
.subclass
+ '(' + self
.className
+ ')'
308 name
= self
.className
309 if self
.ref
: name
= 'ref: ' + self
.ref
+ ', ' + name
311 # Sets name of tree object
312 def setTreeName(self
, name
):
313 if self
.hasChild
: obj
= self
.child
316 obj
.element
.setAttribute('name', name
)
317 # Special processing for growablecols-like parameters
318 # represented by several nodes
319 def special(self
, tag
, node
):
320 if not self
.params
.has_key(tag
):
321 # Create new multi-group
322 self
.params
[tag
] = xxxParamMulti(node
)
323 self
.params
[tag
].append(xxxParamInt(node
))
324 def setSpecial(self
, param
, value
):
325 # Straightforward implementation: remove, add again
326 self
.params
[param
].remove()
327 del self
.params
[param
]
329 node
= g
.tree
.dom
.createElement(param
)
330 text
= g
.tree
.dom
.createTextNode(str(i
))
331 node
.appendChild(text
)
332 self
.element
.appendChild(node
)
333 self
.special(param
, node
)
335 # Imitation of FindResource/DoFindResource from xmlres.cpp
336 def DoFindResource(parent
, name
, classname
, recursive
):
337 for n
in parent
.childNodes
:
338 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
and \
339 n
.tagName
in ['object', 'object_ref'] and \
340 n
.getAttribute('name') == name
:
341 cls
= n
.getAttribute('class')
342 if not classname
or cls
== classname
: return n
343 if not cls
or n
.tagName
== 'object_ref':
344 refName
= n
.getAttribute('ref')
345 if not refName
: continue
346 refNode
= FindResource(refName
)
347 if refName
and refNode
.getAttribute('class') == classname
:
350 for n
in parent
.childNodes
:
351 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
and \
352 n
.tagName
in ['object', 'object_ref']:
353 found
= DoFindResource(n
, name
, classname
, True)
354 if found
: return found
355 def FindResource(name
, classname
='', recursive
=True):
356 found
= DoFindResource(g
.tree
.mainNode
, name
, classname
, recursive
)
357 if found
: return found
358 wx
.LogError('XRC resource "%s" not found!' % name
)
361 ################################################################################
363 # This is a little special: it is both xxxObject and xxxNode
364 class xxxParamFont(xxxObject
, xxxNode
):
365 allParams
= ['size', 'family', 'style', 'weight', 'underlined',
367 def __init__(self
, parent
, element
):
368 xxxObject
.__init
__(self
, parent
, element
)
369 xxxNode
.__init
__(self
, element
)
370 self
.parentNode
= parent
# required to behave similar to DOM node
372 for p
in self
.allParams
:
374 v
.append(str(self
.params
[p
].value()))
378 def update(self
, value
):
379 # `value' is a list of strings corresponding to all parameters
381 # Remove old elements first
382 childNodes
= elem
.childNodes
[:]
383 for node
in childNodes
: elem
.removeChild(node
)
387 for param
in self
.allParams
:
389 fontElem
= g
.tree
.dom
.createElement(param
)
390 textNode
= g
.tree
.dom
.createTextNode(value
[i
])
391 self
.params
[param
] = textNode
392 fontElem
.appendChild(textNode
)
393 elem
.appendChild(fontElem
)
400 ################################################################################
402 class xxxContainer(xxxObject
):
406 # Simulate normal parameter for encoding
409 return g
.currentEncoding
410 def update(self
, val
):
411 g
.currentEncoding
= val
413 # Special class for root node
414 class xxxMainNode(xxxContainer
):
415 allParams
= ['encoding']
416 hasStyle
= hasName
= False
417 def __init__(self
, dom
):
418 xxxContainer
.__init
__(self
, None, dom
.documentElement
)
419 self
.className
= 'XML tree'
420 # Reset required parameters after processing XML, because encoding is
422 self
.required
= ['encoding']
423 self
.params
['encoding'] = xxxEncoding()
425 ################################################################################
428 class xxxPanel(xxxContainer
):
429 allParams
= ['pos', 'size', 'style']
430 winStyles
= ['wxNO_3D', 'wxTAB_TRAVERSAL']
431 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
434 class xxxDialog(xxxContainer
):
435 allParams
= ['title', 'centered', 'pos', 'size', 'style']
436 paramDict
= {'centered': ParamBool}
438 default
= {'title': ''}
439 winStyles
= ['wxDEFAULT_DIALOG_STYLE', 'wxCAPTION',
440 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxTHICK_FRAME',
441 'wxRESIZE_BORDER', 'wxRESIZE_BOX', 'wxCLOSE_BOX',
442 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX',
443 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS', 'wxDIALOG_NO_PARENT'
444 'wxNO_3D', 'wxTAB_TRAVERSAL']
445 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY', 'wxDIALOG_EX_METAL']
446 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
449 class xxxFrame(xxxContainer
):
450 allParams
= ['title', 'centered', 'pos', 'size', 'style']
451 paramDict
= {'centered': ParamBool}
453 default
= {'title': ''}
454 winStyles
= ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE', 'wxCAPTION',
455 'wxSTAY_ON_TOP', 'wxSYSTEM_MENU', 'wxTHICK_FRAME',
456 'wxRESIZE_BORDER', 'wxRESIZE_BOX', 'wxCLOSE_BOX',
457 'wxMAXIMIZE_BOX', 'wxMINIMIZE_BOX',
458 'wxFRAME_NO_TASKBAR', 'wxFRAME_SHAPED', 'wxFRAME_TOOL_WINDOW',
459 'wxFRAME_FLOAT_ON_PARENT',
460 'wxNO_3D', 'wxTAB_TRAVERSAL']
461 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY', 'wxFRAME_EX_METAL']
462 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
465 class xxxTool(xxxObject
):
466 allParams
= ['bitmap', 'bitmap2', 'radio', 'toggle', 'tooltip', 'longhelp', 'label']
467 required
= ['bitmap']
468 paramDict
= {'bitmap2': ParamBitmap, 'radio': ParamBool, 'toggle': ParamBool}
471 class xxxToolBar(xxxContainer
):
472 allParams
= ['bitmapsize', 'margins', 'packing', 'separation', 'dontattachtoframe',
473 'pos', 'size', 'style']
475 paramDict
= {'bitmapsize': ParamPosSize
, 'margins': ParamPosSize
,
476 'packing': ParamUnit
, 'separation': ParamUnit
,
477 'dontattachtoframe': ParamBool
, 'style': ParamNonGenericStyle
}
478 winStyles
= ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL',
479 'wxTB_3DBUTTONS','wxTB_TEXT', 'wxTB_NOICONS', 'wxTB_NODIVIDER',
480 'wxTB_NOALIGN', 'wxTB_HORZ_LAYOUT', 'wxTB_HORZ_TEXT']
482 class xxxStatusBar(xxxObject
):
484 allParams
= ['fields', 'widths', 'styles', 'style']
485 paramDict
= {'fields': ParamIntNN
, 'widths': ParamText
, 'styles': ParamText
,
486 'style': ParamNonGenericStyle
}
487 winStyles
= ['wxST_SIZEGRIP']
489 class xxxWizard(xxxContainer
):
490 allParams
= ['title', 'bitmap', 'pos']
492 default
= {'title': ''}
494 exStyles
= ['wxWIZARD_EX_HELPBUTTON']
495 styles
= ['fg', 'bg', 'font', 'exstyle']
497 class xxxWizardPage(xxxContainer
):
498 allParams
= ['bitmap']
502 class xxxWizardPageSimple(xxxContainer
):
503 allParams
= ['bitmap']
507 ################################################################################
510 class xxxBitmap(xxxObject
):
511 allParams
= ['bitmap']
512 required
= ['bitmap']
515 class xxxIcon(xxxObject
):
518 ################################################################################
521 class xxxStaticText(xxxObject
):
522 allParams
= ['label', 'pos', 'size', 'style']
524 default
= {'label': ''}
525 winStyles
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
527 class xxxStaticLine(xxxObject
):
528 allParams
= ['pos', 'size', 'style']
529 winStyles
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
531 class xxxStaticBitmap(xxxObject
):
532 allParams
= ['bitmap', 'pos', 'size', 'style']
533 required
= ['bitmap']
535 class xxxTextCtrl(xxxObject
):
536 allParams
= ['value', 'pos', 'size', 'style']
537 winStyles
= ['wxTE_NO_VSCROLL',
539 'wxTE_PROCESS_ENTER',
555 paramDict
= {'value': ParamMultilineText}
557 class xxxChoice(xxxObject
):
558 allParams
= ['content', 'selection', 'pos', 'size', 'style']
559 required
= ['content']
560 default
= {'content': '[]'}
561 winStyles
= ['wxCB_SORT']
563 class xxxSlider(xxxObject
):
564 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style',
565 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
567 paramDict
= {'value': ParamInt
, 'tickfreq': ParamIntNN
, 'pagesize': ParamIntNN
,
568 'linesize': ParamIntNN
, 'thumb': ParamUnit
,
569 'tick': ParamInt
, 'selmin': ParamInt
, 'selmax': ParamInt
}
570 required
= ['value', 'min', 'max']
571 winStyles
= ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
572 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
573 'wxSL_BOTH', 'wxSL_SELRANGE', 'wxSL_INVERSE']
575 class xxxGauge(xxxObject
):
576 allParams
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
577 paramDict
= {'range': ParamIntNN
, 'value': ParamIntNN
,
578 'shadow': ParamIntNN
, 'bezel': ParamIntNN
}
579 winStyles
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
581 class xxxScrollBar(xxxObject
):
582 allParams
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
583 paramDict
= {'value': ParamIntNN
, 'range': ParamIntNN
, 'thumbsize': ParamIntNN
,
584 'pagesize': ParamIntNN
}
585 winStyles
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
587 class xxxListCtrl(xxxObject
):
588 allParams
= ['pos', 'size', 'style']
589 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
590 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
591 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
592 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING',
593 'wxLC_VIRTUAL', 'wxLC_HRULES', 'wxLC_VRULES', 'wxLC_NO_SORT_HEADER']
595 class xxxTreeCtrl(xxxObject
):
596 allParams
= ['pos', 'size', 'style']
597 winStyles
= ['wxTR_EDIT_LABELS',
600 'wxTR_TWIST_BUTTONS',
602 'wxTR_FULL_ROW_HIGHLIGHT',
603 'wxTR_LINES_AT_ROOT',
606 'wxTR_HAS_VARIABLE_ROW_HEIGHT',
610 'wxTR_DEFAULT_STYLE']
612 class xxxHtmlWindow(xxxObject
):
613 allParams
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
614 paramDict
= {'htmlcode':ParamMultilineText}
615 winStyles
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO', 'wxHW_NO_SELECTION']
617 class xxxCalendarCtrl(xxxObject
):
618 allParams
= ['pos', 'size', 'style']
619 winStyles
= ['wxCAL_SUNDAY_FIRST', 'wxCAL_MONDAY_FIRST', 'wxCAL_SHOW_HOLIDAYS',
620 'wxCAL_NO_YEAR_CHANGE', 'wxCAL_NO_MONTH_CHANGE',
621 'wxCAL_SEQUENTIAL_MONTH_SELECTION', 'wxCAL_SHOW_SURROUNDING_WEEKS']
623 class xxxNotebook(xxxContainer
):
624 allParams
= ['pos', 'size', 'style']
625 winStyles
= ['wxNB_TOP', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM',
626 'wxNB_FIXEDWIDTH', 'wxNB_MULTILINE', 'wxNB_NOPAGETHEME', 'wxNB_FLAT']
628 class xxxChoicebook(xxxContainer
):
629 allParams
= ['pos', 'size', 'style']
630 winStyles
= ['wxCHB_DEFAULT', 'wxCHB_LEFT', 'wxCHB_RIGHT', 'wxCHB_TOP', 'wxCHB_BOTTOM']
632 class xxxListbook(xxxContainer
):
633 allParams
= ['pos', 'size', 'style']
634 winStyles
= ['wxLB_DEFAULT', 'wxLB_LEFT', 'wxLB_RIGHT', 'wxLB_TOP', 'wxLB_BOTTOM']
636 class xxxSplitterWindow(xxxContainer
):
637 allParams
= ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style']
638 paramDict
= {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit }
639 winStyles
= ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER',
640 'wxSP_FULLSASH', 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE',
643 class xxxGenericDirCtrl(xxxObject
):
644 allParams
= ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style']
645 paramDict
= {'defaultfilter': ParamIntNN}
646 winStyles
= ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
647 'wxDIRCTRL_SHOW_FILTERS']
649 class xxxScrolledWindow(xxxContainer
):
650 allParams
= ['pos', 'size', 'style']
651 winStyles
= ['wxHSCROLL', 'wxVSCROLL', 'wxNO_3D', 'wxTAB_TRAVERSAL']
653 class xxxDateCtrl(xxxObject
):
654 allParams
= ['pos', 'size', 'style', 'borders']
655 winStyles
= ['wxDP_DEFAULT', 'wxDP_SPIN', 'wxDP_DROPDOWN',
656 'wxDP_ALLOWNONE', 'wxDP_SHOWCENTURY']
658 ################################################################################
661 class xxxButton(xxxObject
):
662 allParams
= ['label', 'default', 'pos', 'size', 'style']
663 paramDict
= {'default': ParamBool}
665 winStyles
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM', 'wxBU_EXACTFIT',
668 class xxxBitmapButton(xxxObject
):
669 allParams
= ['bitmap', 'selected', 'focus', 'disabled', 'default',
670 'pos', 'size', 'style']
671 paramDict
= {'selected': ParamBitmap
, 'focus': ParamBitmap
, 'disabled': ParamBitmap
,
672 'default': ParamBool
}
673 required
= ['bitmap']
674 winStyles
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_RIGHT',
675 'wxBU_TOP', 'wxBU_BOTTOM']
677 class xxxRadioButton(xxxObject
):
678 allParams
= ['label', 'value', 'pos', 'size', 'style']
679 paramDict
= {'value': ParamBool}
681 winStyles
= ['wxRB_GROUP', 'wxRB_SINGLE']
683 class xxxSpinButton(xxxObject
):
684 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
685 paramDict
= {'value': ParamInt}
686 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
688 class xxxSpinCtrl(xxxObject
):
689 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
690 paramDict
= {'value': ParamInt}
691 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
693 class xxxToggleButton(xxxObject
):
694 allParams
= ['label', 'checked', 'pos', 'size', 'style']
695 paramDict
= {'checked': ParamBool}
698 ################################################################################
701 class xxxStaticBox(xxxObject
):
702 allParams
= ['label', 'pos', 'size', 'style']
705 class xxxRadioBox(xxxObject
):
706 allParams
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
707 paramDict
= {'dimension': ParamIntNN}
708 required
= ['label', 'content']
709 default
= {'content': '[]'}
710 winStyles
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS', 'wxRA_HORIZONTAL',
713 class xxxCheckBox(xxxObject
):
714 allParams
= ['label', 'checked', 'pos', 'size', 'style']
715 paramDict
= {'checked': ParamBool}
716 winStyles
= ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER',
720 class xxxComboBox(xxxObject
):
721 allParams
= ['content', 'selection', 'value', 'pos', 'size', 'style']
722 required
= ['content']
723 default
= {'content': '[]'}
724 winStyles
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
726 class xxxListBox(xxxObject
):
727 allParams
= ['content', 'selection', 'pos', 'size', 'style']
728 required
= ['content']
729 default
= {'content': '[]'}
730 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
731 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
733 class xxxCheckList(xxxObject
):
734 allParams
= ['content', 'pos', 'size', 'style']
735 required
= ['content']
736 default
= {'content': '[]'}
737 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
738 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
739 paramDict
= {'content': ParamContentCheckList}
741 ################################################################################
744 class xxxSizer(xxxContainer
):
745 hasName
= hasStyle
= False
746 paramDict
= {'orient': ParamOrient}
748 itemTag
= 'sizeritem' # different for some sizers
750 class xxxBoxSizer(xxxSizer
):
751 allParams
= ['orient']
752 required
= ['orient']
753 default
= {'orient': 'wxVERTICAL'}
754 # Tree icon depends on orientation
756 if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
757 else: return self
.imageV
759 class xxxStaticBoxSizer(xxxBoxSizer
):
760 allParams
= ['label', 'orient']
761 required
= ['label', 'orient']
763 class xxxGridSizer(xxxSizer
):
764 allParams
= ['cols', 'rows', 'vgap', 'hgap']
766 default
= {'cols': '2', 'rows': '2'}
768 class xxxStdDialogButtonSizer(xxxSizer
):
772 # For repeated parameters
774 def __init__(self
, node
):
776 self
.l
, self
.data
= [], []
777 def append(self
, param
):
779 self
.data
.append(param
.value())
785 self
.l
, self
.data
= [], []
787 class xxxFlexGridSizer(xxxGridSizer
):
788 specials
= ['growablecols', 'growablerows']
789 allParams
= ['cols', 'rows', 'vgap', 'hgap'] + specials
790 paramDict
= {'growablecols': ParamIntList, 'growablerows': ParamIntList}
792 class xxxGridBagSizer(xxxSizer
):
793 specials
= ['growablecols', 'growablerows']
794 allParams
= ['vgap', 'hgap'] + specials
795 paramDict
= {'growablecols': ParamIntList, 'growablerows': ParamIntList}
797 # Container with only one child.
799 class xxxChildContainer(xxxObject
):
800 hasName
= hasStyle
= False
802 def __init__(self
, parent
, element
, refElem
=None):
803 xxxObject
.__init
__(self
, parent
, element
, refElem
)
804 # Must have one child with 'object' tag, but we don't check it
805 nodes
= element
.childNodes
[:] # create copy
807 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
808 if node
.tagName
in ['object', 'object_ref']:
809 # Create new xxx object for child node
810 self
.child
= MakeXXXFromDOM(self
, node
)
811 self
.child
.parent
= parent
812 # Copy hasChildren and isSizer attributes
813 self
.hasChildren
= self
.child
.hasChildren
814 self
.isSizer
= self
.child
.isSizer
817 element
.removeChild(node
)
819 assert 0, 'no child found'
820 def resetChild(self
, xxx
):
821 '''Reset child info (for replacing with another class).'''
823 self
.hasChildren
= xxx
.hasChildren
824 self
.isSizer
= xxx
.isSizer
826 class xxxSizerItem(xxxChildContainer
):
827 allParams
= ['option', 'flag', 'border', 'minsize', 'ratio']
828 paramDict
= {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
829 #default = {'cellspan': '1,1'}
830 def __init__(self
, parent
, element
, refElem
=None):
831 # For GridBag sizer items, extra parameters added
832 if isinstance(parent
, xxxGridBagSizer
):
833 self
.allParams
= self
.allParams
+ ['cellpos', 'cellspan']
834 xxxChildContainer
.__init
__(self
, parent
, element
, refElem
)
835 # Remove pos parameter - not needed for sizeritems
836 if 'pos' in self
.child
.allParams
:
837 self
.child
.allParams
= self
.child
.allParams
[:]
838 self
.child
.allParams
.remove('pos')
839 def resetChild(self
, xxx
):
840 xxxChildContainer
.resetChild(self
, xxx
)
841 # Remove pos parameter - not needed for sizeritems
842 if 'pos' in self
.child
.allParams
:
843 self
.child
.allParams
= self
.child
.allParams
[:]
844 self
.child
.allParams
.remove('pos')
846 class xxxSizerItemButton(xxxSizerItem
):
849 def __init__(self
, parent
, element
, refElem
=None):
850 xxxChildContainer
.__init
__(self
, parent
, element
, refElem
=None)
851 # Remove pos parameter - not needed for sizeritems
852 if 'pos' in self
.child
.allParams
:
853 self
.child
.allParams
= self
.child
.allParams
[:]
854 self
.child
.allParams
.remove('pos')
856 class xxxPage(xxxChildContainer
):
857 allParams
= ['label', 'selected']
858 paramDict
= {'selected': ParamBool}
860 def __init__(self
, parent
, element
, refElem
=None):
861 xxxChildContainer
.__init
__(self
, parent
, element
, refElem
)
862 # pos and size dont matter for notebookpages
863 if 'pos' in self
.child
.allParams
:
864 self
.child
.allParams
= self
.child
.allParams
[:]
865 self
.child
.allParams
.remove('pos')
866 if 'size' in self
.child
.allParams
:
867 self
.child
.allParams
= self
.child
.allParams
[:]
868 self
.child
.allParams
.remove('size')
870 class xxxSpacer(xxxObject
):
871 hasName
= hasStyle
= False
872 allParams
= ['size', 'option', 'flag', 'border']
873 paramDict
= {'option': ParamInt}
874 default
= {'size': '0,0'}
875 def __init__(self
, parent
, element
, refElem
=None):
876 # For GridBag sizer items, extra parameters added
877 if isinstance(parent
, xxxGridBagSizer
):
878 self
.allParams
= self
.allParams
+ ['cellpos', 'cellspan']
879 xxxObject
.__init
__(self
, parent
, element
, refElem
)
881 class xxxMenuBar(xxxContainer
):
882 allParams
= ['style']
883 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
884 winStyles
= ['wxMB_DOCKABLE']
886 class xxxMenu(xxxContainer
):
887 allParams
= ['label', 'help', 'style']
888 default
= {'label': ''}
889 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
890 winStyles
= ['wxMENU_TEAROFF']
892 class xxxMenuItem(xxxObject
):
893 allParams
= ['label', 'bitmap', 'accel', 'help',
894 'checkable', 'radio', 'enabled', 'checked']
895 default
= {'label': ''}
898 class xxxSeparator(xxxObject
):
899 hasName
= hasStyle
= False
901 ################################################################################
904 class xxxUnknown(xxxObject
):
905 allParams
= ['pos', 'size', 'style']
906 winStyles
= ['wxNO_FULL_REPAINT_ON_RESIZE']
908 ################################################################################
912 'wxDialog': xxxDialog
,
915 'wxToolBar': xxxToolBar
,
916 'wxStatusBar': xxxStatusBar
,
917 'wxWizard': xxxWizard
,
918 'wxWizardPage': xxxWizardPage
,
919 'wxWizardPageSimple': xxxWizardPageSimple
,
921 'wxBitmap': xxxBitmap
,
924 'wxButton': xxxButton
,
925 'wxBitmapButton': xxxBitmapButton
,
926 'wxRadioButton': xxxRadioButton
,
927 'wxSpinButton': xxxSpinButton
,
928 'wxToggleButton' : xxxToggleButton
,
930 'wxStaticBox': xxxStaticBox
,
931 'wxStaticBitmap': xxxStaticBitmap
,
932 'wxRadioBox': xxxRadioBox
,
933 'wxComboBox': xxxComboBox
,
934 'wxCheckBox': xxxCheckBox
,
935 'wxListBox': xxxListBox
,
937 'wxStaticText': xxxStaticText
,
938 'wxStaticLine': xxxStaticLine
,
939 'wxTextCtrl': xxxTextCtrl
,
940 'wxChoice': xxxChoice
,
941 'wxSlider': xxxSlider
,
943 'wxScrollBar': xxxScrollBar
,
944 'wxTreeCtrl': xxxTreeCtrl
,
945 'wxListCtrl': xxxListCtrl
,
946 'wxCheckListBox': xxxCheckList
,
947 'notebookpage': xxxPage
,
948 'choicebookpage': xxxPage
,
949 'listbookpage': xxxPage
,
950 'wxNotebook': xxxNotebook
,
951 'wxChoicebook': xxxChoicebook
,
952 'wxListbook': xxxListbook
,
953 'wxSplitterWindow': xxxSplitterWindow
,
954 'wxHtmlWindow': xxxHtmlWindow
,
955 'wxCalendarCtrl': xxxCalendarCtrl
,
956 'wxGenericDirCtrl': xxxGenericDirCtrl
,
957 'wxSpinCtrl': xxxSpinCtrl
,
958 'wxScrolledWindow': xxxScrolledWindow
,
959 'wxDatePickerCtrl': xxxDateCtrl
,
961 'wxBoxSizer': xxxBoxSizer
,
962 'wxStaticBoxSizer': xxxStaticBoxSizer
,
963 'wxGridSizer': xxxGridSizer
,
964 'wxFlexGridSizer': xxxFlexGridSizer
,
965 'wxGridBagSizer': xxxGridBagSizer
,
966 'wxStdDialogButtonSizer': xxxStdDialogButtonSizer
,
967 'sizeritem': xxxSizerItem
, 'button': xxxSizerItemButton
,
970 'wxMenuBar': xxxMenuBar
,
972 'wxMenuItem': xxxMenuItem
,
973 'separator': xxxSeparator
,
975 'unknown': xxxUnknown
,
978 # Create IDs for all parameters of all classes
979 paramIDs
= {'fg': wx
.NewId(), 'bg': wx
.NewId(), 'exstyle': wx
.NewId(), 'font': wx
.NewId(),
980 'enabled': wx
.NewId(), 'focused': wx
.NewId(), 'hidden': wx
.NewId(),
981 'tooltip': wx
.NewId(), 'encoding': wx
.NewId(),
982 'cellpos': wx
.NewId(), 'cellspan': wx
.NewId()
984 for cl
in xxxDict
.values():
986 for param
in cl
.allParams
+ cl
.paramDict
.keys():
987 if not paramIDs
.has_key(param
):
988 paramIDs
[param
] = wx
.NewId()
990 ################################################################################
993 # Test for object elements
995 return node
.nodeType
== minidom
.Node
.ELEMENT_NODE
and node
.tagName
in ['object', 'object_ref']
997 # Make XXX object from some DOM object, selecting correct class
998 def MakeXXXFromDOM(parent
, element
):
999 if element
.tagName
== 'object_ref':
1000 ref
= element
.getAttribute('ref')
1001 refElem
= FindResource(ref
)
1002 if refElem
: cls
= refElem
.getAttribute('class')
1003 else: return xxxUnknown(parent
, element
)
1006 cls
= element
.getAttribute('class')
1008 klass
= xxxDict
[cls
]
1010 # If we encounter a weird class, use unknown template
1011 print 'WARNING: unsupported class:', element
.getAttribute('class')
1013 return klass(parent
, element
, refElem
)
1015 # Make empty DOM element
1016 def MakeEmptyDOM(className
):
1017 elem
= g
.tree
.dom
.createElement('object')
1018 elem
.setAttribute('class', className
)
1019 # Set required and default parameters
1020 xxxClass
= xxxDict
[className
]
1021 defaultNotRequired
= filter(lambda x
, l
=xxxClass
.required
: x
not in l
,
1022 xxxClass
.default
.keys())
1023 for param
in xxxClass
.required
+ defaultNotRequired
:
1024 textElem
= g
.tree
.dom
.createElement(param
)
1026 textNode
= g
.tree
.dom
.createTextNode(xxxClass
.default
[param
])
1028 textNode
= g
.tree
.dom
.createTextNode('')
1029 textElem
.appendChild(textNode
)
1030 elem
.appendChild(textElem
)
1033 # Make empty XXX object
1034 def MakeEmptyXXX(parent
, className
):
1035 # Make corresponding DOM object first
1036 elem
= MakeEmptyDOM(className
)
1037 # If parent is a sizer, we should create sizeritem object, except for spacers
1039 if parent
.isSizer
and className
!= 'spacer':
1040 sizerItemElem
= MakeEmptyDOM(parent
.itemTag
)
1041 sizerItemElem
.appendChild(elem
)
1042 elem
= sizerItemElem
1043 elif isinstance(parent
, xxxNotebook
):
1044 pageElem
= MakeEmptyDOM('notebookpage')
1045 pageElem
.appendChild(elem
)
1047 elif isinstance(parent
, xxxChoicebook
):
1048 pageElem
= MakeEmptyDOM('choicebookpage')
1049 pageElem
.appendChild(elem
)
1051 elif isinstance(parent
, xxxListbook
):
1052 pageElem
= MakeEmptyDOM('listbookpage')
1053 pageElem
.appendChild(elem
)
1055 # Now just make object
1056 return MakeXXXFromDOM(parent
, elem
)
1058 # Make empty DOM element for reference
1059 def MakeEmptyRefDOM(ref
):
1060 elem
= g
.tree
.dom
.createElement('object_ref')
1061 elem
.setAttribute('ref', ref
)
1064 # Make empty XXX object
1065 def MakeEmptyRefXXX(parent
, ref
):
1066 # Make corresponding DOM object first
1067 elem
= MakeEmptyRefDOM(ref
)
1068 # If parent is a sizer, we should create sizeritem object, except for spacers
1071 sizerItemElem
= MakeEmptyDOM(parent
.itemTag
)
1072 sizerItemElem
.appendChild(elem
)
1073 elem
= sizerItemElem
1074 elif isinstance(parent
, xxxNotebook
):
1075 pageElem
= MakeEmptyDOM('notebookpage')
1076 pageElem
.appendChild(elem
)
1078 elif isinstance(parent
, xxxChoicebook
):
1079 pageElem
= MakeEmptyDOM('choicebookpage')
1080 pageElem
.appendChild(elem
)
1082 elif isinstance(parent
, xxxListbook
):
1083 pageElem
= MakeEmptyDOM('listbookpage')
1084 pageElem
.appendChild(elem
)
1086 # Now just make object
1087 xxx
= MakeXXXFromDOM(parent
, elem
)
1088 # Label is not used for references
1089 xxx
.allParams
= xxx
.allParams
[:]
1090 #xxx.allParams.remove('label')