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
):
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
]
330 node
= g
.tree
.dom
.createElement(param
)
331 text
= g
.tree
.dom
.createTextNode(str(i
))
332 node
.appendChild(text
)
333 self
.element
.appendChild(node
)
334 self
.special(param
, node
)
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
:
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
359 wx
.LogError('XRC resource "%s" not found!' % name
)
362 ################################################################################
364 # This is a little special: it is both xxxObject and xxxNode
365 class xxxParamFont(xxxObject
, xxxNode
):
366 allParams
= ['size', 'family', 'style', 'weight', 'underlined',
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
373 for p
in self
.allParams
:
375 v
.append(str(self
.params
[p
].value()))
379 def update(self
, value
):
380 # `value' is a list of strings corresponding to all parameters
382 # Remove old elements first
383 childNodes
= elem
.childNodes
[:]
384 for node
in childNodes
: elem
.removeChild(node
)
388 for param
in self
.allParams
:
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
)
401 ################################################################################
403 class xxxContainer(xxxObject
):
407 # Simulate normal parameter for encoding
410 return g
.currentEncoding
411 def update(self
, val
):
412 g
.currentEncoding
= val
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
423 self
.required
= ['encoding']
424 self
.params
['encoding'] = xxxEncoding()
426 ################################################################################
429 class xxxPanel(xxxContainer
):
430 allParams
= ['pos', 'size', 'style']
431 winStyles
= ['wxNO_3D', 'wxTAB_TRAVERSAL']
432 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
435 class xxxDialog(xxxContainer
):
436 allParams
= ['title', 'centered', 'pos', 'size', 'style']
437 paramDict
= {'centered': ParamBool}
439 default
= {'title': ''}
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']
447 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
450 class xxxFrame(xxxContainer
):
451 allParams
= ['title', 'centered', 'pos', 'size', 'style']
452 paramDict
= {'centered': ParamBool}
454 default
= {'title': ''}
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']
463 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
466 class xxxTool(xxxObject
):
467 allParams
= ['bitmap', 'bitmap2', 'radio', 'toggle', 'tooltip', 'longhelp', 'label']
468 required
= ['bitmap']
469 paramDict
= {'bitmap2': ParamBitmap, 'radio': ParamBool, 'toggle': ParamBool}
472 class xxxToolBar(xxxContainer
):
473 allParams
= ['bitmapsize', 'margins', 'packing', 'separation', 'dontattachtoframe',
474 'pos', 'size', 'style']
476 paramDict
= {'bitmapsize': ParamPosSize
, 'margins': ParamPosSize
,
477 'packing': ParamUnit
, 'separation': ParamUnit
,
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']
483 class xxxStatusBar(xxxObject
):
485 allParams
= ['fields', 'widths', 'styles', 'style']
486 paramDict
= {'fields': ParamIntNN
, 'widths': ParamText
, 'styles': ParamText
,
487 'style': ParamNonGenericStyle
}
488 winStyles
= ['wxST_SIZEGRIP']
490 class xxxWizard(xxxContainer
):
491 allParams
= ['title', 'bitmap', 'pos']
493 default
= {'title': ''}
495 exStyles
= ['wxWIZARD_EX_HELPBUTTON']
496 styles
= ['fg', 'bg', 'font', 'exstyle']
498 class xxxWizardPage(xxxContainer
):
499 allParams
= ['bitmap']
503 class xxxWizardPageSimple(xxxContainer
):
504 allParams
= ['bitmap']
508 ################################################################################
511 class xxxBitmap(xxxObject
):
512 allParams
= ['bitmap']
513 required
= ['bitmap']
516 class xxxIcon(xxxObject
):
519 ################################################################################
522 class xxxStaticText(xxxObject
):
523 allParams
= ['label', 'pos', 'size', 'style']
525 default
= {'label': ''}
526 winStyles
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
528 class xxxStaticLine(xxxObject
):
529 allParams
= ['pos', 'size', 'style']
530 winStyles
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
532 class xxxStaticBitmap(xxxObject
):
533 allParams
= ['bitmap', 'pos', 'size', 'style']
534 required
= ['bitmap']
536 class xxxTextCtrl(xxxObject
):
537 allParams
= ['value', 'pos', 'size', 'style']
538 winStyles
= ['wxTE_NO_VSCROLL',
540 'wxTE_PROCESS_ENTER',
556 paramDict
= {'value': ParamMultilineText}
558 class xxxChoice(xxxObject
):
559 allParams
= ['content', 'selection', 'pos', 'size', 'style']
560 required
= ['content']
561 default
= {'content': '[]'}
562 winStyles
= ['wxCB_SORT']
564 class xxxSlider(xxxObject
):
565 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style',
566 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
568 paramDict
= {'value': ParamInt
, 'tickfreq': ParamIntNN
, 'pagesize': ParamIntNN
,
569 'linesize': ParamIntNN
, 'thumb': ParamUnit
,
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',
574 'wxSL_BOTH', 'wxSL_SELRANGE', 'wxSL_INVERSE']
576 class xxxGauge(xxxObject
):
577 allParams
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
578 paramDict
= {'range': ParamIntNN
, 'value': ParamIntNN
,
579 'shadow': ParamIntNN
, 'bezel': ParamIntNN
}
580 winStyles
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
582 class xxxScrollBar(xxxObject
):
583 allParams
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
584 paramDict
= {'value': ParamIntNN
, 'range': ParamIntNN
, 'thumbsize': ParamIntNN
,
585 'pagesize': ParamIntNN
}
586 winStyles
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
588 class xxxListCtrl(xxxObject
):
589 allParams
= ['pos', 'size', 'style']
590 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
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']
596 class xxxTreeCtrl(xxxObject
):
597 allParams
= ['pos', 'size', 'style']
598 winStyles
= ['wxTR_EDIT_LABELS',
601 'wxTR_TWIST_BUTTONS',
603 'wxTR_FULL_ROW_HIGHLIGHT',
604 'wxTR_LINES_AT_ROOT',
607 'wxTR_HAS_VARIABLE_ROW_HEIGHT',
611 'wxTR_DEFAULT_STYLE']
613 class xxxHtmlWindow(xxxObject
):
614 allParams
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
615 paramDict
= {'htmlcode':ParamMultilineText}
616 winStyles
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO', 'wxHW_NO_SELECTION']
618 class xxxCalendarCtrl(xxxObject
):
619 allParams
= ['pos', 'size', 'style']
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']
624 class xxxNotebook(xxxContainer
):
625 allParams
= ['pos', 'size', 'style']
626 winStyles
= ['wxNB_TOP', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM',
627 'wxNB_FIXEDWIDTH', 'wxNB_MULTILINE', 'wxNB_NOPAGETHEME', 'wxNB_FLAT']
629 class xxxChoicebook(xxxContainer
):
630 allParams
= ['pos', 'size', 'style']
631 winStyles
= ['wxCHB_DEFAULT', 'wxCHB_LEFT', 'wxCHB_RIGHT', 'wxCHB_TOP', 'wxCHB_BOTTOM']
633 class xxxListbook(xxxContainer
):
634 allParams
= ['pos', 'size', 'style']
635 winStyles
= ['wxLB_DEFAULT', 'wxLB_LEFT', 'wxLB_RIGHT', 'wxLB_TOP', 'wxLB_BOTTOM']
637 class xxxSplitterWindow(xxxContainer
):
638 allParams
= ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style']
639 paramDict
= {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit }
640 winStyles
= ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER',
641 'wxSP_FULLSASH', 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE',
644 class xxxGenericDirCtrl(xxxObject
):
645 allParams
= ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style']
646 paramDict
= {'defaultfilter': ParamIntNN}
647 winStyles
= ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
648 'wxDIRCTRL_SHOW_FILTERS']
650 class xxxScrolledWindow(xxxContainer
):
651 allParams
= ['pos', 'size', 'style']
652 winStyles
= ['wxHSCROLL', 'wxVSCROLL', 'wxNO_3D', 'wxTAB_TRAVERSAL']
654 class xxxDateCtrl(xxxObject
):
655 allParams
= ['pos', 'size', 'style', 'borders']
656 winStyles
= ['wxDP_DEFAULT', 'wxDP_SPIN', 'wxDP_DROPDOWN',
657 'wxDP_ALLOWNONE', 'wxDP_SHOWCENTURY']
659 ################################################################################
662 class xxxButton(xxxObject
):
663 allParams
= ['label', 'default', 'pos', 'size', 'style']
664 paramDict
= {'default': ParamBool}
666 winStyles
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM', 'wxBU_EXACTFIT',
669 class xxxBitmapButton(xxxObject
):
670 allParams
= ['bitmap', 'selected', 'focus', 'disabled', 'default',
671 'pos', 'size', 'style']
672 paramDict
= {'selected': ParamBitmap
, 'focus': ParamBitmap
, 'disabled': ParamBitmap
,
673 'default': ParamBool
}
674 required
= ['bitmap']
675 winStyles
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_RIGHT',
676 'wxBU_TOP', 'wxBU_BOTTOM']
678 class xxxRadioButton(xxxObject
):
679 allParams
= ['label', 'value', 'pos', 'size', 'style']
680 paramDict
= {'value': ParamBool}
682 winStyles
= ['wxRB_GROUP', 'wxRB_SINGLE']
684 class xxxSpinButton(xxxObject
):
685 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
686 paramDict
= {'value': ParamInt}
687 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
689 class xxxSpinCtrl(xxxObject
):
690 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
691 paramDict
= {'value': ParamInt}
692 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
694 class xxxToggleButton(xxxObject
):
695 allParams
= ['label', 'checked', 'pos', 'size', 'style']
696 paramDict
= {'checked': ParamBool}
699 ################################################################################
702 class xxxStaticBox(xxxObject
):
703 allParams
= ['label', 'pos', 'size', 'style']
706 class xxxRadioBox(xxxObject
):
707 allParams
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
708 paramDict
= {'dimension': ParamIntNN}
709 required
= ['label', 'content']
710 default
= {'content': '[]'}
711 winStyles
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS', 'wxRA_HORIZONTAL',
714 class xxxCheckBox(xxxObject
):
715 allParams
= ['label', 'checked', 'pos', 'size', 'style']
716 paramDict
= {'checked': ParamBool}
717 winStyles
= ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER',
721 class xxxComboBox(xxxObject
):
722 allParams
= ['content', 'selection', 'value', 'pos', 'size', 'style']
723 required
= ['content']
724 default
= {'content': '[]'}
725 winStyles
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
727 class xxxListBox(xxxObject
):
728 allParams
= ['content', 'selection', 'pos', 'size', 'style']
729 required
= ['content']
730 default
= {'content': '[]'}
731 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
732 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
734 class xxxCheckList(xxxObject
):
735 allParams
= ['content', 'pos', 'size', 'style']
736 required
= ['content']
737 default
= {'content': '[]'}
738 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
739 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
740 paramDict
= {'content': ParamContentCheckList}
742 ################################################################################
745 class xxxSizer(xxxContainer
):
746 hasName
= hasStyle
= False
747 paramDict
= {'orient': ParamOrient}
749 itemTag
= 'sizeritem' # different for some sizers
751 class xxxBoxSizer(xxxSizer
):
752 allParams
= ['orient']
753 required
= ['orient']
754 default
= {'orient': 'wxVERTICAL'}
755 # Tree icon depends on orientation
757 if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
758 else: return self
.imageV
760 class xxxStaticBoxSizer(xxxBoxSizer
):
761 allParams
= ['label', 'orient']
762 required
= ['label', 'orient']
764 class xxxGridSizer(xxxSizer
):
765 allParams
= ['cols', 'rows', 'vgap', 'hgap']
767 default
= {'cols': '2', 'rows': '2'}
769 class xxxStdDialogButtonSizer(xxxSizer
):
773 # For repeated parameters
775 def __init__(self
, node
):
777 self
.l
, self
.data
= [], []
778 def append(self
, param
):
780 self
.data
.append(param
.value())
786 self
.l
, self
.data
= [], []
788 class xxxFlexGridSizer(xxxGridSizer
):
789 specials
= ['growablecols', 'growablerows']
790 allParams
= ['cols', 'rows', 'vgap', 'hgap'] + specials
791 paramDict
= {'growablecols': ParamIntList, 'growablerows': ParamIntList}
793 class xxxGridBagSizer(xxxSizer
):
794 specials
= ['growablecols', 'growablerows']
795 allParams
= ['vgap', 'hgap'] + specials
796 paramDict
= {'growablecols': ParamIntList, 'growablerows': ParamIntList}
798 # Container with only one child.
800 class xxxChildContainer(xxxObject
):
801 hasName
= hasStyle
= False
803 def __init__(self
, parent
, element
, refElem
=None):
804 xxxObject
.__init
__(self
, parent
, element
, refElem
)
805 # Must have one child with 'object' tag, but we don't check it
806 nodes
= element
.childNodes
[:] # create copy
808 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
809 if node
.tagName
in ['object', 'object_ref']:
810 # Create new xxx object for child node
811 self
.child
= MakeXXXFromDOM(self
, node
)
812 self
.child
.parent
= parent
813 # Copy hasChildren and isSizer attributes
814 self
.hasChildren
= self
.child
.hasChildren
815 self
.isSizer
= self
.child
.isSizer
818 element
.removeChild(node
)
820 assert 0, 'no child found'
821 def resetChild(self
, xxx
):
822 '''Reset child info (for replacing with another class).'''
824 self
.hasChildren
= xxx
.hasChildren
825 self
.isSizer
= xxx
.isSizer
827 class xxxSizerItem(xxxChildContainer
):
828 allParams
= ['option', 'flag', 'border', 'minsize', 'ratio']
829 paramDict
= {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
830 #default = {'cellspan': '1,1'}
831 def __init__(self
, parent
, element
, refElem
=None):
832 # For GridBag sizer items, extra parameters added
833 if isinstance(parent
, xxxGridBagSizer
):
834 self
.allParams
= self
.allParams
+ ['cellpos', 'cellspan']
835 xxxChildContainer
.__init
__(self
, parent
, element
, refElem
)
836 # Remove pos parameter - not needed for sizeritems
837 if 'pos' in self
.child
.allParams
:
838 self
.child
.allParams
= self
.child
.allParams
[:]
839 self
.child
.allParams
.remove('pos')
840 def resetChild(self
, xxx
):
841 xxxChildContainer
.resetChild(self
, xxx
)
842 # Remove pos parameter - not needed for sizeritems
843 if 'pos' in self
.child
.allParams
:
844 self
.child
.allParams
= self
.child
.allParams
[:]
845 self
.child
.allParams
.remove('pos')
847 class xxxSizerItemButton(xxxSizerItem
):
850 def __init__(self
, parent
, element
, refElem
=None):
851 xxxChildContainer
.__init
__(self
, parent
, element
, refElem
=None)
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')
857 class xxxPage(xxxChildContainer
):
858 allParams
= ['label', 'selected']
859 paramDict
= {'selected': ParamBool}
861 def __init__(self
, parent
, element
, refElem
=None):
862 xxxChildContainer
.__init
__(self
, parent
, element
, refElem
)
863 # pos and size dont matter for notebookpages
864 if 'pos' in self
.child
.allParams
:
865 self
.child
.allParams
= self
.child
.allParams
[:]
866 self
.child
.allParams
.remove('pos')
867 if 'size' in self
.child
.allParams
:
868 self
.child
.allParams
= self
.child
.allParams
[:]
869 self
.child
.allParams
.remove('size')
871 class xxxSpacer(xxxObject
):
872 hasName
= hasStyle
= False
873 allParams
= ['size', 'option', 'flag', 'border']
874 paramDict
= {'option': ParamInt}
875 default
= {'size': '0,0'}
876 def __init__(self
, parent
, element
, refElem
=None):
877 # For GridBag sizer items, extra parameters added
878 if isinstance(parent
, xxxGridBagSizer
):
879 self
.allParams
= self
.allParams
+ ['cellpos', 'cellspan']
880 xxxObject
.__init
__(self
, parent
, element
, refElem
)
882 class xxxMenuBar(xxxContainer
):
883 allParams
= ['style']
884 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
885 winStyles
= ['wxMB_DOCKABLE']
887 class xxxMenu(xxxContainer
):
888 allParams
= ['label', 'help', 'style']
889 default
= {'label': ''}
890 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
891 winStyles
= ['wxMENU_TEAROFF']
893 class xxxMenuItem(xxxObject
):
894 allParams
= ['label', 'bitmap', 'accel', 'help',
895 'checkable', 'radio', 'enabled', 'checked']
896 default
= {'label': ''}
899 class xxxSeparator(xxxObject
):
900 hasName
= hasStyle
= False
902 ################################################################################
905 class xxxUnknown(xxxObject
):
906 allParams
= ['pos', 'size', 'style']
907 winStyles
= ['wxNO_FULL_REPAINT_ON_RESIZE']
909 ################################################################################
913 'wxDialog': xxxDialog
,
916 'wxToolBar': xxxToolBar
,
917 'wxStatusBar': xxxStatusBar
,
918 'wxWizard': xxxWizard
,
919 'wxWizardPage': xxxWizardPage
,
920 'wxWizardPageSimple': xxxWizardPageSimple
,
922 'wxBitmap': xxxBitmap
,
925 'wxButton': xxxButton
,
926 'wxBitmapButton': xxxBitmapButton
,
927 'wxRadioButton': xxxRadioButton
,
928 'wxSpinButton': xxxSpinButton
,
929 'wxToggleButton' : xxxToggleButton
,
931 'wxStaticBox': xxxStaticBox
,
932 'wxStaticBitmap': xxxStaticBitmap
,
933 'wxRadioBox': xxxRadioBox
,
934 'wxComboBox': xxxComboBox
,
935 'wxCheckBox': xxxCheckBox
,
936 'wxListBox': xxxListBox
,
938 'wxStaticText': xxxStaticText
,
939 'wxStaticLine': xxxStaticLine
,
940 'wxTextCtrl': xxxTextCtrl
,
941 'wxChoice': xxxChoice
,
942 'wxSlider': xxxSlider
,
944 'wxScrollBar': xxxScrollBar
,
945 'wxTreeCtrl': xxxTreeCtrl
,
946 'wxListCtrl': xxxListCtrl
,
947 'wxCheckListBox': xxxCheckList
,
948 'notebookpage': xxxPage
,
949 'choicebookpage': xxxPage
,
950 'listbookpage': xxxPage
,
951 'wxNotebook': xxxNotebook
,
952 'wxChoicebook': xxxChoicebook
,
953 'wxListbook': xxxListbook
,
954 'wxSplitterWindow': xxxSplitterWindow
,
955 'wxHtmlWindow': xxxHtmlWindow
,
956 'wxCalendarCtrl': xxxCalendarCtrl
,
957 'wxGenericDirCtrl': xxxGenericDirCtrl
,
958 'wxSpinCtrl': xxxSpinCtrl
,
959 'wxScrolledWindow': xxxScrolledWindow
,
960 'wxDatePickerCtrl': xxxDateCtrl
,
962 'wxBoxSizer': xxxBoxSizer
,
963 'wxStaticBoxSizer': xxxStaticBoxSizer
,
964 'wxGridSizer': xxxGridSizer
,
965 'wxFlexGridSizer': xxxFlexGridSizer
,
966 'wxGridBagSizer': xxxGridBagSizer
,
967 'wxStdDialogButtonSizer': xxxStdDialogButtonSizer
,
968 'sizeritem': xxxSizerItem
, 'button': xxxSizerItemButton
,
971 'wxMenuBar': xxxMenuBar
,
973 'wxMenuItem': xxxMenuItem
,
974 'separator': xxxSeparator
,
976 'unknown': xxxUnknown
,
979 # Create IDs for all parameters of all classes
980 paramIDs
= {'fg': wx
.NewId(), 'bg': wx
.NewId(), 'exstyle': wx
.NewId(), 'font': wx
.NewId(),
981 'enabled': wx
.NewId(), 'focused': wx
.NewId(), 'hidden': wx
.NewId(),
982 'tooltip': wx
.NewId(), 'encoding': wx
.NewId(),
983 'cellpos': wx
.NewId(), 'cellspan': wx
.NewId()
985 for cl
in xxxDict
.values():
987 for param
in cl
.allParams
+ cl
.paramDict
.keys():
988 if not paramIDs
.has_key(param
):
989 paramIDs
[param
] = wx
.NewId()
991 ################################################################################
994 # Test for object elements
996 return node
.nodeType
== minidom
.Node
.ELEMENT_NODE
and node
.tagName
in ['object', 'object_ref']
998 # Make XXX object from some DOM object, selecting correct class
999 def MakeXXXFromDOM(parent
, element
):
1000 if element
.tagName
== 'object_ref':
1001 ref
= element
.getAttribute('ref')
1002 refElem
= FindResource(ref
)
1003 if refElem
: cls
= refElem
.getAttribute('class')
1004 else: return xxxUnknown(parent
, element
)
1007 cls
= element
.getAttribute('class')
1009 klass
= xxxDict
[cls
]
1011 # If we encounter a weird class, use unknown template
1012 print 'WARNING: unsupported class:', element
.getAttribute('class')
1014 return klass(parent
, element
, refElem
)
1016 # Make empty DOM element
1017 def MakeEmptyDOM(className
):
1018 elem
= g
.tree
.dom
.createElement('object')
1019 elem
.setAttribute('class', className
)
1020 # Set required and default parameters
1021 xxxClass
= xxxDict
[className
]
1022 defaultNotRequired
= filter(lambda x
, l
=xxxClass
.required
: x
not in l
,
1023 xxxClass
.default
.keys())
1024 for param
in xxxClass
.required
+ defaultNotRequired
:
1025 textElem
= g
.tree
.dom
.createElement(param
)
1027 textNode
= g
.tree
.dom
.createTextNode(xxxClass
.default
[param
])
1029 textNode
= g
.tree
.dom
.createTextNode('')
1030 textElem
.appendChild(textNode
)
1031 elem
.appendChild(textElem
)
1034 # Make empty XXX object
1035 def MakeEmptyXXX(parent
, className
):
1036 # Make corresponding DOM object first
1037 elem
= MakeEmptyDOM(className
)
1038 # If parent is a sizer, we should create sizeritem object, except for spacers
1040 if parent
.isSizer
and className
!= 'spacer':
1041 sizerItemElem
= MakeEmptyDOM(parent
.itemTag
)
1042 sizerItemElem
.appendChild(elem
)
1043 elem
= sizerItemElem
1044 elif isinstance(parent
, xxxNotebook
):
1045 pageElem
= MakeEmptyDOM('notebookpage')
1046 pageElem
.appendChild(elem
)
1048 elif isinstance(parent
, xxxChoicebook
):
1049 pageElem
= MakeEmptyDOM('choicebookpage')
1050 pageElem
.appendChild(elem
)
1052 elif isinstance(parent
, xxxListbook
):
1053 pageElem
= MakeEmptyDOM('listbookpage')
1054 pageElem
.appendChild(elem
)
1056 # Now just make object
1057 return MakeXXXFromDOM(parent
, elem
)
1059 # Make empty DOM element for reference
1060 def MakeEmptyRefDOM(ref
):
1061 elem
= g
.tree
.dom
.createElement('object_ref')
1062 elem
.setAttribute('ref', ref
)
1065 # Make empty XXX object
1066 def MakeEmptyRefXXX(parent
, ref
):
1067 # Make corresponding DOM object first
1068 elem
= MakeEmptyRefDOM(ref
)
1069 # If parent is a sizer, we should create sizeritem object, except for spacers
1072 sizerItemElem
= MakeEmptyDOM(parent
.itemTag
)
1073 sizerItemElem
.appendChild(elem
)
1074 elem
= sizerItemElem
1075 elif isinstance(parent
, xxxNotebook
):
1076 pageElem
= MakeEmptyDOM('notebookpage')
1077 pageElem
.appendChild(elem
)
1079 elif isinstance(parent
, xxxChoicebook
):
1080 pageElem
= MakeEmptyDOM('choicebookpage')
1081 pageElem
.appendChild(elem
)
1083 elif isinstance(parent
, xxxListbook
):
1084 pageElem
= MakeEmptyDOM('listbookpage')
1085 pageElem
.appendChild(elem
)
1087 # Now just make object
1088 xxx
= MakeXXXFromDOM(parent
, elem
)
1089 # Label is not used for references
1090 xxx
.allParams
= xxx
.allParams
[:]
1091 #xxx.allParams.remove('label')