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 wxUSE_UNICODE
: # no conversion is needed
45 return self
.textNode
.data
46 def update(self
, value
):
47 self
.textNode
.data
= value
50 return self
.textNode
.data
.encode(g
.currentEncoding
)
51 def update(self
, value
):
52 try: # handle exception if encoding is wrong
53 self
.textNode
.data
= unicode(value
, g
.currentEncoding
)
54 except UnicodeDecodeError:
55 wxLogMessage("Unicode error: set encoding in file\nglobals.py to something appropriate")
58 class xxxParamInt(xxxParam
):
59 # Standard use: for text nodes
60 def __init__(self
, node
):
61 xxxParam
.__init
__(self
, node
)
62 # Value returns string
65 return int(self
.textNode
.data
)
67 return -1 # invalid value
68 def update(self
, value
):
69 self
.textNode
.data
= str(value
)
72 class xxxParamContent(xxxNode
):
73 def __init__(self
, node
):
74 xxxNode
.__init
__(self
, node
)
75 data
, l
= [], [] # data is needed to quicker value retrieval
76 nodes
= node
.childNodes
[:] # make a copy of the child list
78 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
79 assert n
.tagName
== 'item', 'bad content content'
80 if not n
.hasChildNodes():
81 # If does not have child nodes, create empty text node
82 text
= g
.tree
.dom
.createTextNode('')
83 node
.appendChild(text
)
86 text
= n
.childNodes
[0] # first child must be text node
87 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
89 data
.append(str(text
.data
))
93 self
.l
, self
.data
= l
, data
96 def update(self
, value
):
97 # If number if items is not the same, recreate children
98 if len(value
) != len(self
.l
): # remove first if number of items has changed
99 childNodes
= self
.node
.childNodes
[:]
101 self
.node
.removeChild(n
)
104 itemElem
= g
.tree
.dom
.createElement('item')
105 itemText
= g
.tree
.dom
.createTextNode(str)
106 itemElem
.appendChild(itemText
)
107 self
.node
.appendChild(itemElem
)
111 for i
in range(len(value
)):
112 self
.l
[i
].data
= value
[i
]
115 # Content parameter for checklist
116 class xxxParamContentCheckList(xxxNode
):
117 def __init__(self
, node
):
118 xxxNode
.__init
__(self
, node
)
119 data
, l
= [], [] # data is needed to quicker value retrieval
120 nodes
= node
.childNodes
[:] # make a copy of the child list
122 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
123 assert n
.tagName
== 'item', 'bad content content'
124 checked
= n
.getAttribute('checked')
125 if not checked
: checked
= 0
126 if not n
.hasChildNodes():
127 # If does not have child nodes, create empty text node
128 text
= g
.tree
.dom
.createTextNode('')
129 node
.appendChild(text
)
132 text
= n
.childNodes
[0] # first child must be text node
133 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
135 data
.append((str(text
.data
), int(checked
)))
139 self
.l
, self
.data
= l
, data
142 def update(self
, value
):
143 # If number if items is not the same, recreate children
144 if len(value
) != len(self
.l
): # remove first if number of items has changed
145 childNodes
= self
.node
.childNodes
[:]
147 self
.node
.removeChild(n
)
150 itemElem
= g
.tree
.dom
.createElement('item')
151 # Add checked only if True
152 if ch
: itemElem
.setAttribute('checked', '1')
153 itemText
= g
.tree
.dom
.createTextNode(s
)
154 itemElem
.appendChild(itemText
)
155 self
.node
.appendChild(itemElem
)
156 l
.append((itemText
, itemElem
))
159 for i
in range(len(value
)):
160 self
.l
[i
][0].data
= value
[i
][0]
161 self
.l
[i
][1].setAttribute('checked', str(value
[i
][1]))
165 class xxxParamBitmap(xxxParam
):
166 def __init__(self
, node
):
167 xxxParam
.__init
__(self
, node
)
168 self
.stock_id
= node
.getAttribute('stock_id')
170 return [self
.stock_id
, xxxParam
.value(self
)]
171 def update(self
, value
):
172 self
.stock_id
= value
[0]
174 self
.node
.setAttribute('stock_id', self
.stock_id
)
175 elif self
.node
.hasAttribute('stock_id'):
176 self
.node
.removeAttribute('stock_id')
177 xxxParam
.update(self
, value
[1])
179 ################################################################################
181 # Classes to interface DOM objects
184 hasChildren
= False # has children elements?
185 hasStyle
= True # almost everyone
186 hasName
= True # has name attribute?
187 isSizer
= hasChild
= False
188 allParams
= None # Some nodes have no parameters
189 # Style parameters (all optional)
190 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip']
194 bitmapTags
= ['bitmap', 'bitmap2', 'icon']
195 # Required paremeters: none by default
197 # Default parameters with default values
201 # Window styles and extended styles
205 # Construct a new xxx object from DOM element
206 # parent is parent xxx object (or None if none), element is DOM element object
207 def __init__(self
, parent
, element
):
209 self
.element
= element
212 self
.className
= element
.getAttribute('class')
213 self
.subclass
= element
.getAttribute('subclass')
214 if self
.hasName
: self
.name
= element
.getAttribute('name')
215 # Set parameters (text element children)
217 nodes
= element
.childNodes
[:]
219 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
222 continue # do nothing for object children here
223 if tag
not in self
.allParams
and tag
not in self
.styles
:
224 print 'WARNING: unknown parameter for %s: %s' % \
225 (self
.className
, tag
)
226 elif tag
in self
.specials
:
227 self
.special(tag
, node
)
228 elif tag
== 'content':
229 if self
.className
== 'wxCheckListBox':
230 self
.params
[tag
] = xxxParamContentCheckList(node
)
232 self
.params
[tag
] = xxxParamContent(node
)
233 elif tag
== 'font': # has children
234 self
.params
[tag
] = xxxParamFont(element
, node
)
235 elif tag
in self
.bitmapTags
:
236 # Can have attributes
237 self
.params
[tag
] = xxxParamBitmap(node
)
238 else: # simple parameter
239 self
.params
[tag
] = xxxParam(node
)
241 # Remove all other nodes
242 element
.removeChild(node
)
244 # Check that all required params are set
245 for param
in self
.required
:
246 if not self
.params
.has_key(param
):
247 # If default is specified, set it
248 if self
.default
.has_key(param
):
249 elem
= g
.tree
.dom
.createElement(param
)
250 if param
== 'content':
251 if self
.className
== 'wxCheckListBox':
252 self
.params
[param
] = xxxParamContentCheckList(elem
)
254 self
.params
[param
] = xxxParamContent(elem
)
256 self
.params
[param
] = xxxParam(elem
)
257 # Find place to put new element: first present element after param
259 paramStyles
= self
.allParams
+ self
.styles
260 for p
in paramStyles
[paramStyles
.index(param
) + 1:]:
261 # Content params don't have same type
262 if self
.params
.has_key(p
) and p
!= 'content':
266 nextTextElem
= self
.params
[p
].node
267 self
.element
.insertBefore(elem
, nextTextElem
)
269 self
.element
.appendChild(elem
)
271 wxLogWarning('Required parameter %s of %s missing' %
272 (param
, self
.className
))
273 # Returns real tree object
274 def treeObject(self
):
275 if self
.hasChild
: return self
.child
277 # Returns tree image index
279 if self
.hasChild
: return self
.child
.treeImage()
281 # Class name plus wx name
283 if self
.hasChild
: return self
.child
.treeName()
284 if self
.subclass
: className
= self
.subclass
285 else: className
= self
.className
286 if self
.hasName
and self
.name
: return className
+ ' "' + self
.name
+ '"'
288 # Class name or subclass
290 if self
.subclass
: return self
.subclass
+ '(' + self
.className
+ ')'
291 else: return self
.className
293 ################################################################################
295 # This is a little special: it is both xxxObject and xxxNode
296 class xxxParamFont(xxxObject
, xxxNode
):
297 allParams
= ['size', 'style', 'weight', 'family', 'underlined',
299 def __init__(self
, parent
, element
):
300 xxxObject
.__init
__(self
, parent
, element
)
301 xxxNode
.__init
__(self
, element
)
302 self
.parentNode
= parent
# required to behave similar to DOM node
304 for p
in self
.allParams
:
306 v
.append(str(self
.params
[p
].value()))
310 def update(self
, value
):
311 # `value' is a list of strings corresponding to all parameters
313 # Remove old elements first
314 childNodes
= elem
.childNodes
[:]
315 for node
in childNodes
: elem
.removeChild(node
)
319 for param
in self
.allParams
:
321 fontElem
= g
.tree
.dom
.createElement(param
)
322 textNode
= g
.tree
.dom
.createTextNode(value
[i
])
323 self
.params
[param
] = textNode
324 fontElem
.appendChild(textNode
)
325 elem
.appendChild(fontElem
)
332 ################################################################################
334 class xxxContainer(xxxObject
):
337 # Simulate normal parameter for encoding
340 return g
.currentEncoding
341 def update(self
, val
):
342 g
.currentEncoding
= val
344 # Special class for root node
345 class xxxMainNode(xxxContainer
):
346 allParams
= ['encoding']
347 hasStyle
= hasName
= False
348 def __init__(self
, dom
):
349 xxxContainer
.__init
__(self
, None, dom
.documentElement
)
350 self
.className
= 'XML tree'
351 # Reset required parameters after processing XML, because encoding is
353 self
.required
= ['encoding']
354 self
.params
['encoding'] = xxxEncoding()
356 ################################################################################
359 class xxxPanel(xxxContainer
):
360 allParams
= ['pos', 'size', 'style']
361 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
363 winStyles
= ['wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
364 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
366 class xxxDialog(xxxContainer
):
367 allParams
= ['title', 'centered', 'pos', 'size', 'style']
368 paramDict
= {'centered': ParamBool}
370 default
= {'title': ''}
371 winStyles
= ['wxDEFAULT_DIALOG_STYLE', 'wxSTAY_ON_TOP',
372 ## 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS',
373 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 'wxRESIZE_BOX',
375 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
376 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
378 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
380 class xxxFrame(xxxContainer
):
381 allParams
= ['title', 'centered', 'pos', 'size', 'style']
382 paramDict
= {'centered': ParamBool}
384 default
= {'title': ''}
385 winStyles
= ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE',
387 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
388 'wxRESIZE_BOX', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX',
389 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_TOOL_WINDOW',
390 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
391 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
393 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
395 class xxxTool(xxxObject
):
396 allParams
= ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp']
397 required
= ['bitmap']
398 paramDict
= {'bitmap2': ParamBitmap, 'toggle': ParamBool}
401 class xxxToolBar(xxxContainer
):
402 allParams
= ['bitmapsize', 'margins', 'packing', 'separation',
403 'pos', 'size', 'style']
405 paramDict
= {'bitmapsize': ParamPosSize
, 'margins': ParamPosSize
,
406 'packing': ParamInt
, 'separation': ParamInt
,
407 'style': ParamNonGenericStyle
}
408 winStyles
= ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL']
410 ################################################################################
413 class xxxBitmap(xxxObject
):
414 allParams
= ['bitmap']
415 required
= ['bitmap']
418 class xxxIcon(xxxObject
):
422 ################################################################################
425 class xxxStaticText(xxxObject
):
426 allParams
= ['label', 'pos', 'size', 'style']
428 default
= {'label': ''}
429 winStyles
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
431 class xxxStaticLine(xxxObject
):
432 allParams
= ['pos', 'size', 'style']
433 winStyles
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
435 class xxxStaticBitmap(xxxObject
):
436 allParams
= ['bitmap', 'pos', 'size', 'style']
437 required
= ['bitmap']
439 class xxxTextCtrl(xxxObject
):
440 allParams
= ['value', 'pos', 'size', 'style']
441 winStyles
= ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
442 'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
443 paramDict
= {'value': ParamMultilineText}
445 class xxxChoice(xxxObject
):
446 allParams
= ['content', 'selection', 'pos', 'size', 'style']
447 required
= ['content']
448 default
= {'content': '[]'}
449 winStyles
= ['wxCB_SORT']
451 class xxxSlider(xxxObject
):
452 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style',
453 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
455 paramDict
= {'value': ParamInt
, 'tickfreq': ParamInt
, 'pagesize': ParamInt
,
456 'linesize': ParamInt
, 'thumb': ParamInt
, 'thumb': ParamInt
,
457 'tick': ParamInt
, 'selmin': ParamInt
, 'selmax': ParamInt
}
458 required
= ['value', 'min', 'max']
459 winStyles
= ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
460 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
461 'wxSL_BOTH', 'wxSL_SELRANGE']
463 class xxxGauge(xxxObject
):
464 allParams
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
465 paramDict
= {'range': ParamInt
, 'value': ParamInt
,
466 'shadow': ParamInt
, 'bezel': ParamInt
}
467 winStyles
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
469 class xxxScrollBar(xxxObject
):
470 allParams
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
471 paramDict
= {'value': ParamInt
, 'range': ParamInt
, 'thumbsize': ParamInt
,
472 'pagesize': ParamInt
}
473 winStyles
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
475 class xxxListCtrl(xxxObject
):
476 allParams
= ['pos', 'size', 'style']
477 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
478 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
479 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
480 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
482 class xxxTreeCtrl(xxxObject
):
483 allParams
= ['pos', 'size', 'style']
484 winStyles
= ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT',
485 'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE']
487 class xxxHtmlWindow(xxxObject
):
488 allParams
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
489 paramDict
= {'borders': ParamInt, 'htmlcode':ParamMultilineText}
490 winStyles
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
492 class xxxCalendarCtrl(xxxObject
):
493 allParams
= ['pos', 'size', 'style']
495 class xxxNotebook(xxxContainer
):
496 allParams
= ['usenotebooksizer', 'pos', 'size', 'style']
497 paramDict
= {'usenotebooksizer': ParamBool}
498 winStyles
= ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM']
500 class xxxSplitterWindow(xxxContainer
):
501 allParams
= ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style']
502 paramDict
= {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit }
503 winStyles
= ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER', 'wxSP_BORDER',
504 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE',
507 class xxxGenericDirCtrl(xxxObject
):
508 allParams
= ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style']
509 paramDict
= {'defaultfilter': ParamInt}
510 winStyles
= ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
511 'wxDIRCTRL_SHOW_FILTERS', 'wxDIRCTRL_EDIT_LABELS']
513 class xxxScrolledWindow(xxxContainer
):
514 allParams
= ['pos', 'size', 'style']
515 winStyles
= ['wxHSCROLL', 'wxVSCROLL']
517 ################################################################################
520 class xxxButton(xxxObject
):
521 allParams
= ['label', 'default', 'pos', 'size', 'style']
522 paramDict
= {'default': ParamBool}
524 winStyles
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
526 class xxxBitmapButton(xxxObject
):
527 allParams
= ['bitmap', 'selected', 'focus', 'disabled', 'default',
528 'pos', 'size', 'style']
529 required
= ['bitmap']
530 winStyles
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP',
531 'wxBU_RIGHT', 'wxBU_BOTTOM']
533 class xxxRadioButton(xxxObject
):
534 allParams
= ['label', 'value', 'pos', 'size', 'style']
535 paramDict
= {'value': ParamBool}
537 winStyles
= ['wxRB_GROUP']
539 class xxxSpinButton(xxxObject
):
540 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
541 paramDict
= {'value': ParamInt}
542 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
544 class xxxSpinCtrl(xxxObject
):
545 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
546 paramDict
= {'value': ParamInt}
547 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
549 class xxxToggleButton(xxxObject
):
550 allParams
= ['label', 'checked', 'pos', 'size', 'style']
551 paramDict
= {'checked': ParamBool}
554 ################################################################################
557 class xxxStaticBox(xxxObject
):
558 allParams
= ['label', 'pos', 'size', 'style']
561 class xxxRadioBox(xxxObject
):
562 allParams
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
563 paramDict
= {'dimension': ParamInt}
564 required
= ['label', 'content']
565 default
= {'content': '[]'}
566 winStyles
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS']
568 class xxxCheckBox(xxxObject
):
569 allParams
= ['label', 'checked', 'pos', 'size', 'style']
570 paramDict
= {'checked': ParamBool}
571 winStyles
= ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER',
575 class xxxComboBox(xxxObject
):
576 allParams
= ['content', 'selection', 'value', 'pos', 'size', 'style']
577 required
= ['content']
578 default
= {'content': '[]'}
579 winStyles
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
581 class xxxListBox(xxxObject
):
582 allParams
= ['content', 'selection', 'pos', 'size', 'style']
583 required
= ['content']
584 default
= {'content': '[]'}
585 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
586 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
588 class xxxCheckList(xxxObject
):
589 allParams
= ['content', 'pos', 'size', 'style']
590 required
= ['content']
591 default
= {'content': '[]'}
592 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
593 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
594 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
595 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
596 paramDict
= {'content': ParamContentCheckList}
598 ################################################################################
601 class xxxSizer(xxxContainer
):
602 hasName
= hasStyle
= False
603 paramDict
= {'orient': ParamOrient}
606 class xxxBoxSizer(xxxSizer
):
607 allParams
= ['orient']
608 required
= ['orient']
609 default
= {'orient': 'wxVERTICAL'}
610 # Tree icon depends on orientation
612 if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
613 else: return self
.imageV
615 class xxxStaticBoxSizer(xxxBoxSizer
):
616 allParams
= ['label', 'orient']
617 required
= ['label', 'orient']
619 class xxxGridSizer(xxxSizer
):
620 allParams
= ['cols', 'rows', 'vgap', 'hgap']
622 default
= {'cols': '2', 'rows': '2'}
624 # For repeated parameters
626 def __init__(self
, node
):
628 self
.l
, self
.data
= [], []
629 def append(self
, param
):
631 self
.data
.append(param
.value())
637 self
.l
, self
.data
= [], []
639 class xxxFlexGridSizer(xxxGridSizer
):
640 specials
= ['growablecols', 'growablerows']
641 allParams
= ['cols', 'rows', 'vgap', 'hgap'] + specials
642 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
643 # Special processing for growable* parameters
644 # (they are represented by several nodes)
645 def special(self
, tag
, node
):
646 if not self
.params
.has_key(tag
):
647 # Create new multi-group
648 self
.params
[tag
] = xxxParamMulti(node
)
649 self
.params
[tag
].append(xxxParamInt(node
))
650 def setSpecial(self
, param
, value
):
651 # Straightforward implementation: remove, add again
652 self
.params
[param
].remove()
653 del self
.params
[param
]
655 node
= g
.tree
.dom
.createElement(param
)
656 text
= g
.tree
.dom
.createTextNode(str(i
))
657 node
.appendChild(text
)
658 self
.element
.appendChild(node
)
659 self
.special(param
, node
)
661 class xxxGridBagSizer(xxxSizer
):
662 specials
= ['growablecols', 'growablerows']
663 allParams
= ['vgap', 'hgap'] + specials
664 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
665 # Special processing for growable* parameters
666 # (they are represented by several nodes)
667 def special(self
, tag
, node
):
668 if not self
.params
.has_key(tag
):
669 # Create new multi-group
670 self
.params
[tag
] = xxxParamMulti(node
)
671 self
.params
[tag
].append(xxxParamInt(node
))
672 def setSpecial(self
, param
, value
):
673 # Straightforward implementation: remove, add again
674 self
.params
[param
].remove()
675 del self
.params
[param
]
677 node
= g
.tree
.dom
.createElement(param
)
678 text
= g
.tree
.dom
.createTextNode(str(i
))
679 node
.appendChild(text
)
680 self
.element
.appendChild(node
)
681 self
.special(param
, node
)
683 # Container with only one child.
685 class xxxChildContainer(xxxObject
):
686 hasName
= hasStyle
= False
688 def __init__(self
, parent
, element
):
689 xxxObject
.__init
__(self
, parent
, element
)
690 # Must have one child with 'object' tag, but we don't check it
691 nodes
= element
.childNodes
[:] # create copy
693 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
694 if node
.tagName
== 'object':
695 # Create new xxx object for child node
696 self
.child
= MakeXXXFromDOM(self
, node
)
697 self
.child
.parent
= parent
698 # Copy hasChildren and isSizer attributes
699 self
.hasChildren
= self
.child
.hasChildren
700 self
.isSizer
= self
.child
.isSizer
703 element
.removeChild(node
)
705 assert 0, 'no child found'
707 class xxxSizerItem(xxxChildContainer
):
708 allParams
= ['option', 'flag', 'border', 'minsize', 'ratio']
709 paramDict
= {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
710 #default = {'cellspan': '1,1'}
711 def __init__(self
, parent
, element
):
712 # For GridBag sizer items, extra parameters added
713 if isinstance(parent
, xxxGridBagSizer
):
714 self
.allParams
= self
.allParams
+ ['cellpos', 'cellspan']
715 xxxChildContainer
.__init
__(self
, parent
, element
)
716 # Remove pos parameter - not needed for sizeritems
717 if 'pos' in self
.child
.allParams
:
718 self
.child
.allParams
= self
.child
.allParams
[:]
719 self
.child
.allParams
.remove('pos')
721 class xxxNotebookPage(xxxChildContainer
):
722 allParams
= ['label', 'selected']
723 paramDict
= {'selected': ParamBool}
725 def __init__(self
, parent
, element
):
726 xxxChildContainer
.__init
__(self
, parent
, element
)
727 # pos and size dont matter for notebookpages
728 if 'pos' in self
.child
.allParams
:
729 self
.child
.allParams
= self
.child
.allParams
[:]
730 self
.child
.allParams
.remove('pos')
731 if 'size' in self
.child
.allParams
:
732 self
.child
.allParams
= self
.child
.allParams
[:]
733 self
.child
.allParams
.remove('size')
735 class xxxSpacer(xxxObject
):
736 hasName
= hasStyle
= False
737 allParams
= ['size', 'option', 'flag', 'border']
738 paramDict
= {'option': ParamInt}
739 default
= {'size': '0,0'}
741 class xxxMenuBar(xxxContainer
):
742 allParams
= ['style']
743 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
744 winStyles
= ['wxMB_DOCKABLE']
746 class xxxMenu(xxxContainer
):
747 allParams
= ['label', 'help', 'style']
748 default
= {'label': ''}
749 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
750 winStyles
= ['wxMENU_TEAROFF']
752 class xxxMenuItem(xxxObject
):
753 allParams
= ['label', 'bitmap', 'accel', 'help',
754 'checkable', 'radio', 'enabled', 'checked']
755 default
= {'label': ''}
758 class xxxSeparator(xxxObject
):
759 hasName
= hasStyle
= False
761 ################################################################################
764 class xxxUnknown(xxxObject
):
765 allParams
= ['pos', 'size', 'style']
766 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
768 ################################################################################
772 'wxDialog': xxxDialog
,
775 'wxToolBar': xxxToolBar
,
777 'wxBitmap': xxxBitmap
,
780 'wxButton': xxxButton
,
781 'wxBitmapButton': xxxBitmapButton
,
782 'wxRadioButton': xxxRadioButton
,
783 'wxSpinButton': xxxSpinButton
,
784 'wxToggleButton' : xxxToggleButton
,
786 'wxStaticBox': xxxStaticBox
,
787 'wxStaticBitmap': xxxStaticBitmap
,
788 'wxRadioBox': xxxRadioBox
,
789 'wxComboBox': xxxComboBox
,
790 'wxCheckBox': xxxCheckBox
,
791 'wxListBox': xxxListBox
,
793 'wxStaticText': xxxStaticText
,
794 'wxStaticLine': xxxStaticLine
,
795 'wxTextCtrl': xxxTextCtrl
,
796 'wxChoice': xxxChoice
,
797 'wxSlider': xxxSlider
,
799 'wxScrollBar': xxxScrollBar
,
800 'wxTreeCtrl': xxxTreeCtrl
,
801 'wxListCtrl': xxxListCtrl
,
802 'wxCheckListBox': xxxCheckList
,
803 'wxNotebook': xxxNotebook
,
804 'wxSplitterWindow': xxxSplitterWindow
,
805 'notebookpage': xxxNotebookPage
,
806 'wxHtmlWindow': xxxHtmlWindow
,
807 'wxCalendarCtrl': xxxCalendarCtrl
,
808 'wxGenericDirCtrl': xxxGenericDirCtrl
,
809 'wxSpinCtrl': xxxSpinCtrl
,
810 'wxScrolledWindow': xxxScrolledWindow
,
812 'wxBoxSizer': xxxBoxSizer
,
813 'wxStaticBoxSizer': xxxStaticBoxSizer
,
814 'wxGridSizer': xxxGridSizer
,
815 'wxFlexGridSizer': xxxFlexGridSizer
,
816 'wxGridBagSizer': xxxGridBagSizer
,
817 'sizeritem': xxxSizerItem
,
820 'wxMenuBar': xxxMenuBar
,
822 'wxMenuItem': xxxMenuItem
,
823 'separator': xxxSeparator
,
825 'unknown': xxxUnknown
,
828 # Create IDs for all parameters of all classes
829 paramIDs
= {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(),
830 'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(),
831 'tooltip': wxNewId(), 'encoding': wxNewId(),
832 'cellpos': wxNewId(), 'cellspan': wxNewId()
834 for cl
in xxxDict
.values():
836 for param
in cl
.allParams
+ cl
.paramDict
.keys():
837 if not paramIDs
.has_key(param
):
838 paramIDs
[param
] = wxNewId()
840 ################################################################################
843 # Test for object elements
845 return node
.nodeType
== minidom
.Node
.ELEMENT_NODE
and node
.tagName
== 'object'
847 # Make XXX object from some DOM object, selecting correct class
848 def MakeXXXFromDOM(parent
, element
):
850 klass
= xxxDict
[element
.getAttribute('class')]
852 # If we encounter a weird class, use unknown template
853 print 'WARNING: unsupported class:', element
.getAttribute('class')
855 return klass(parent
, element
)
857 # Make empty DOM element
858 def MakeEmptyDOM(className
):
859 elem
= g
.tree
.dom
.createElement('object')
860 elem
.setAttribute('class', className
)
861 # Set required and default parameters
862 xxxClass
= xxxDict
[className
]
863 defaultNotRequired
= filter(lambda x
, l
=xxxClass
.required
: x
not in l
,
864 xxxClass
.default
.keys())
865 for param
in xxxClass
.required
+ defaultNotRequired
:
866 textElem
= g
.tree
.dom
.createElement(param
)
868 textNode
= g
.tree
.dom
.createTextNode(xxxClass
.default
[param
])
870 textNode
= g
.tree
.dom
.createTextNode('')
871 textElem
.appendChild(textNode
)
872 elem
.appendChild(textElem
)
875 # Make empty XXX object
876 def MakeEmptyXXX(parent
, className
):
877 # Make corresponding DOM object first
878 elem
= MakeEmptyDOM(className
)
879 # If parent is a sizer, we should create sizeritem object, except for spacers
881 if parent
.isSizer
and className
!= 'spacer':
882 sizerItemElem
= MakeEmptyDOM('sizeritem')
883 sizerItemElem
.appendChild(elem
)
885 elif isinstance(parent
, xxxNotebook
):
886 pageElem
= MakeEmptyDOM('notebookpage')
887 pageElem
.appendChild(elem
)
889 # Now just make object
890 return MakeXXXFromDOM(parent
, elem
)