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
)
242 # Remove all other nodes
243 # element.removeChild(node)
246 # Check that all required params are set
247 for param
in self
.required
:
248 if not self
.params
.has_key(param
):
249 # If default is specified, set it
250 if self
.default
.has_key(param
):
251 elem
= g
.tree
.dom
.createElement(param
)
252 if param
== 'content':
253 if self
.className
== 'wxCheckListBox':
254 self
.params
[param
] = xxxParamContentCheckList(elem
)
256 self
.params
[param
] = xxxParamContent(elem
)
258 self
.params
[param
] = xxxParam(elem
)
259 # Find place to put new element: first present element after param
261 paramStyles
= self
.allParams
+ self
.styles
262 for p
in paramStyles
[paramStyles
.index(param
) + 1:]:
263 # Content params don't have same type
264 if self
.params
.has_key(p
) and p
!= 'content':
268 nextTextElem
= self
.params
[p
].node
269 self
.element
.insertBefore(elem
, nextTextElem
)
271 self
.element
.appendChild(elem
)
273 wxLogWarning('Required parameter %s of %s missing' %
274 (param
, self
.className
))
275 # Returns real tree object
276 def treeObject(self
):
277 if self
.hasChild
: return self
.child
279 # Returns tree image index
281 if self
.hasChild
: return self
.child
.treeImage()
283 # Class name plus wx name
285 if self
.hasChild
: return self
.child
.treeName()
286 if self
.subclass
: className
= self
.subclass
287 else: className
= self
.className
288 if self
.hasName
and self
.name
: return className
+ ' "' + self
.name
+ '"'
290 # Class name or subclass
292 if self
.subclass
: return self
.subclass
+ '(' + self
.className
+ ')'
293 else: return self
.className
295 ################################################################################
297 # This is a little special: it is both xxxObject and xxxNode
298 class xxxParamFont(xxxObject
, xxxNode
):
299 allParams
= ['size', 'style', 'weight', 'family', 'underlined',
301 def __init__(self
, parent
, element
):
302 xxxObject
.__init
__(self
, parent
, element
)
303 xxxNode
.__init
__(self
, element
)
304 self
.parentNode
= parent
# required to behave similar to DOM node
306 for p
in self
.allParams
:
308 v
.append(str(self
.params
[p
].value()))
312 def update(self
, value
):
313 # `value' is a list of strings corresponding to all parameters
315 # Remove old elements first
316 childNodes
= elem
.childNodes
[:]
317 for node
in childNodes
: elem
.removeChild(node
)
321 for param
in self
.allParams
:
323 fontElem
= g
.tree
.dom
.createElement(param
)
324 textNode
= g
.tree
.dom
.createTextNode(value
[i
])
325 self
.params
[param
] = textNode
326 fontElem
.appendChild(textNode
)
327 elem
.appendChild(fontElem
)
334 ################################################################################
336 class xxxContainer(xxxObject
):
339 # Simulate normal parameter for encoding
342 return g
.currentEncoding
343 def update(self
, val
):
344 g
.currentEncoding
= val
346 # Special class for root node
347 class xxxMainNode(xxxContainer
):
348 allParams
= ['encoding']
349 hasStyle
= hasName
= False
350 def __init__(self
, dom
):
351 xxxContainer
.__init
__(self
, None, dom
.documentElement
)
352 self
.className
= 'XML tree'
353 # Reset required parameters after processing XML, because encoding is
355 self
.required
= ['encoding']
356 self
.params
['encoding'] = xxxEncoding()
358 ################################################################################
361 class xxxPanel(xxxContainer
):
362 allParams
= ['pos', 'size', 'style']
363 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
365 winStyles
= ['wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
366 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
368 class xxxDialog(xxxContainer
):
369 allParams
= ['title', 'centered', 'pos', 'size', 'style']
370 paramDict
= {'centered': ParamBool}
372 default
= {'title': ''}
373 winStyles
= ['wxDEFAULT_DIALOG_STYLE', 'wxSTAY_ON_TOP',
374 ## 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS',
375 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 'wxRESIZE_BOX',
377 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
378 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
380 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
382 class xxxFrame(xxxContainer
):
383 allParams
= ['title', 'centered', 'pos', 'size', 'style']
384 paramDict
= {'centered': ParamBool}
386 default
= {'title': ''}
387 winStyles
= ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE',
389 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
390 'wxRESIZE_BOX', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX',
391 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_TOOL_WINDOW',
392 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
393 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
395 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
397 class xxxTool(xxxObject
):
398 allParams
= ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp']
399 required
= ['bitmap']
400 paramDict
= {'bitmap2': ParamBitmap, 'toggle': ParamBool}
403 class xxxToolBar(xxxContainer
):
404 allParams
= ['bitmapsize', 'margins', 'packing', 'separation',
405 'pos', 'size', 'style']
407 paramDict
= {'bitmapsize': ParamPosSize
, 'margins': ParamPosSize
,
408 'packing': ParamInt
, 'separation': ParamInt
,
409 'style': ParamNonGenericStyle
}
410 winStyles
= ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL']
412 ################################################################################
415 class xxxBitmap(xxxObject
):
416 allParams
= ['bitmap']
417 required
= ['bitmap']
420 class xxxIcon(xxxObject
):
423 ################################################################################
426 class xxxStaticText(xxxObject
):
427 allParams
= ['label', 'pos', 'size', 'style']
429 default
= {'label': ''}
430 winStyles
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
432 class xxxStaticLine(xxxObject
):
433 allParams
= ['pos', 'size', 'style']
434 winStyles
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
436 class xxxStaticBitmap(xxxObject
):
437 allParams
= ['bitmap', 'pos', 'size', 'style']
438 required
= ['bitmap']
440 class xxxTextCtrl(xxxObject
):
441 allParams
= ['value', 'pos', 'size', 'style']
442 winStyles
= ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
443 'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
444 paramDict
= {'value': ParamMultilineText}
446 class xxxChoice(xxxObject
):
447 allParams
= ['content', 'selection', 'pos', 'size', 'style']
448 required
= ['content']
449 default
= {'content': '[]'}
450 winStyles
= ['wxCB_SORT']
452 class xxxSlider(xxxObject
):
453 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style',
454 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
456 paramDict
= {'value': ParamInt
, 'tickfreq': ParamInt
, 'pagesize': ParamInt
,
457 'linesize': ParamInt
, 'thumb': ParamInt
, 'thumb': ParamInt
,
458 'tick': ParamInt
, 'selmin': ParamInt
, 'selmax': ParamInt
}
459 required
= ['value', 'min', 'max']
460 winStyles
= ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
461 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
462 'wxSL_BOTH', 'wxSL_SELRANGE']
464 class xxxGauge(xxxObject
):
465 allParams
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
466 paramDict
= {'range': ParamInt
, 'value': ParamInt
,
467 'shadow': ParamInt
, 'bezel': ParamInt
}
468 winStyles
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
470 class xxxScrollBar(xxxObject
):
471 allParams
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
472 paramDict
= {'value': ParamInt
, 'range': ParamInt
, 'thumbsize': ParamInt
,
473 'pagesize': ParamInt
}
474 winStyles
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
476 class xxxListCtrl(xxxObject
):
477 allParams
= ['pos', 'size', 'style']
478 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
479 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
480 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
481 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
483 class xxxTreeCtrl(xxxObject
):
484 allParams
= ['pos', 'size', 'style']
485 winStyles
= ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT',
486 'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE']
488 class xxxHtmlWindow(xxxObject
):
489 allParams
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
490 paramDict
= {'borders': ParamInt, 'htmlcode':ParamMultilineText}
491 winStyles
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
493 class xxxCalendarCtrl(xxxObject
):
494 allParams
= ['pos', 'size', 'style']
496 class xxxNotebook(xxxContainer
):
497 allParams
= ['usenotebooksizer', 'pos', 'size', 'style']
498 paramDict
= {'usenotebooksizer': ParamBool}
499 winStyles
= ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM']
501 class xxxSplitterWindow(xxxContainer
):
502 allParams
= ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style']
503 paramDict
= {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit }
504 winStyles
= ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER', 'wxSP_BORDER',
505 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE',
508 class xxxGenericDirCtrl(xxxObject
):
509 allParams
= ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style']
510 paramDict
= {'defaultfilter': ParamInt}
511 winStyles
= ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
512 'wxDIRCTRL_SHOW_FILTERS', 'wxDIRCTRL_EDIT_LABELS']
514 class xxxScrolledWindow(xxxContainer
):
515 allParams
= ['pos', 'size', 'style']
516 winStyles
= ['wxHSCROLL', 'wxVSCROLL']
518 ################################################################################
521 class xxxButton(xxxObject
):
522 allParams
= ['label', 'default', 'pos', 'size', 'style']
523 paramDict
= {'default': ParamBool}
525 winStyles
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
527 class xxxBitmapButton(xxxObject
):
528 allParams
= ['bitmap', 'selected', 'focus', 'disabled', 'default',
529 'pos', 'size', 'style']
530 required
= ['bitmap']
531 winStyles
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP',
532 'wxBU_RIGHT', 'wxBU_BOTTOM']
534 class xxxRadioButton(xxxObject
):
535 allParams
= ['label', 'value', 'pos', 'size', 'style']
536 paramDict
= {'value': ParamBool}
538 winStyles
= ['wxRB_GROUP']
540 class xxxSpinButton(xxxObject
):
541 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
542 paramDict
= {'value': ParamInt}
543 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
545 class xxxSpinCtrl(xxxObject
):
546 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
547 paramDict
= {'value': ParamInt}
548 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
550 class xxxToggleButton(xxxObject
):
551 allParams
= ['label', 'checked', 'pos', 'size', 'style']
552 paramDict
= {'checked': ParamBool}
555 ################################################################################
558 class xxxStaticBox(xxxObject
):
559 allParams
= ['label', 'pos', 'size', 'style']
562 class xxxRadioBox(xxxObject
):
563 allParams
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
564 paramDict
= {'dimension': ParamInt}
565 required
= ['label', 'content']
566 default
= {'content': '[]'}
567 winStyles
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS']
569 class xxxCheckBox(xxxObject
):
570 allParams
= ['label', 'checked', 'pos', 'size', 'style']
571 paramDict
= {'checked': ParamBool}
572 winStyles
= ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER',
576 class xxxComboBox(xxxObject
):
577 allParams
= ['content', 'selection', 'value', 'pos', 'size', 'style']
578 required
= ['content']
579 default
= {'content': '[]'}
580 winStyles
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
582 class xxxListBox(xxxObject
):
583 allParams
= ['content', 'selection', 'pos', 'size', 'style']
584 required
= ['content']
585 default
= {'content': '[]'}
586 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
587 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
589 class xxxCheckList(xxxObject
):
590 allParams
= ['content', 'pos', 'size', 'style']
591 required
= ['content']
592 default
= {'content': '[]'}
593 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
594 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
595 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
596 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
597 paramDict
= {'content': ParamContentCheckList}
599 ################################################################################
602 class xxxSizer(xxxContainer
):
603 hasName
= hasStyle
= False
604 paramDict
= {'orient': ParamOrient}
607 class xxxBoxSizer(xxxSizer
):
608 allParams
= ['orient']
609 required
= ['orient']
610 default
= {'orient': 'wxVERTICAL'}
611 # Tree icon depends on orientation
613 if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
614 else: return self
.imageV
616 class xxxStaticBoxSizer(xxxBoxSizer
):
617 allParams
= ['label', 'orient']
618 required
= ['label', 'orient']
620 class xxxGridSizer(xxxSizer
):
621 allParams
= ['cols', 'rows', 'vgap', 'hgap']
623 default
= {'cols': '2', 'rows': '2'}
625 # For repeated parameters
627 def __init__(self
, node
):
629 self
.l
, self
.data
= [], []
630 def append(self
, param
):
632 self
.data
.append(param
.value())
638 self
.l
, self
.data
= [], []
640 class xxxFlexGridSizer(xxxGridSizer
):
641 specials
= ['growablecols', 'growablerows']
642 allParams
= ['cols', 'rows', 'vgap', 'hgap'] + specials
643 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
644 # Special processing for growable* parameters
645 # (they are represented by several nodes)
646 def special(self
, tag
, node
):
647 if not self
.params
.has_key(tag
):
648 # Create new multi-group
649 self
.params
[tag
] = xxxParamMulti(node
)
650 self
.params
[tag
].append(xxxParamInt(node
))
651 def setSpecial(self
, param
, value
):
652 # Straightforward implementation: remove, add again
653 self
.params
[param
].remove()
654 del self
.params
[param
]
656 node
= g
.tree
.dom
.createElement(param
)
657 text
= g
.tree
.dom
.createTextNode(str(i
))
658 node
.appendChild(text
)
659 self
.element
.appendChild(node
)
660 self
.special(param
, node
)
662 class xxxGridBagSizer(xxxSizer
):
663 specials
= ['growablecols', 'growablerows']
664 allParams
= ['vgap', 'hgap'] + specials
665 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
666 # Special processing for growable* parameters
667 # (they are represented by several nodes)
668 def special(self
, tag
, node
):
669 if not self
.params
.has_key(tag
):
670 # Create new multi-group
671 self
.params
[tag
] = xxxParamMulti(node
)
672 self
.params
[tag
].append(xxxParamInt(node
))
673 def setSpecial(self
, param
, value
):
674 # Straightforward implementation: remove, add again
675 self
.params
[param
].remove()
676 del self
.params
[param
]
678 node
= g
.tree
.dom
.createElement(param
)
679 text
= g
.tree
.dom
.createTextNode(str(i
))
680 node
.appendChild(text
)
681 self
.element
.appendChild(node
)
682 self
.special(param
, node
)
684 # Container with only one child.
686 class xxxChildContainer(xxxObject
):
687 hasName
= hasStyle
= False
689 def __init__(self
, parent
, element
):
690 xxxObject
.__init
__(self
, parent
, element
)
691 # Must have one child with 'object' tag, but we don't check it
692 nodes
= element
.childNodes
[:] # create copy
694 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
695 if node
.tagName
== 'object':
696 # Create new xxx object for child node
697 self
.child
= MakeXXXFromDOM(self
, node
)
698 self
.child
.parent
= parent
699 # Copy hasChildren and isSizer attributes
700 self
.hasChildren
= self
.child
.hasChildren
701 self
.isSizer
= self
.child
.isSizer
704 element
.removeChild(node
)
706 assert 0, 'no child found'
708 class xxxSizerItem(xxxChildContainer
):
709 allParams
= ['option', 'flag', 'border', 'minsize', 'ratio']
710 paramDict
= {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
711 #default = {'cellspan': '1,1'}
712 def __init__(self
, parent
, element
):
713 # For GridBag sizer items, extra parameters added
714 if isinstance(parent
, xxxGridBagSizer
):
715 self
.allParams
= self
.allParams
+ ['cellpos', 'cellspan']
716 xxxChildContainer
.__init
__(self
, parent
, element
)
717 # Remove pos parameter - not needed for sizeritems
718 if 'pos' in self
.child
.allParams
:
719 self
.child
.allParams
= self
.child
.allParams
[:]
720 self
.child
.allParams
.remove('pos')
722 class xxxNotebookPage(xxxChildContainer
):
723 allParams
= ['label', 'selected']
724 paramDict
= {'selected': ParamBool}
726 def __init__(self
, parent
, element
):
727 xxxChildContainer
.__init
__(self
, parent
, element
)
728 # pos and size dont matter for notebookpages
729 if 'pos' in self
.child
.allParams
:
730 self
.child
.allParams
= self
.child
.allParams
[:]
731 self
.child
.allParams
.remove('pos')
732 if 'size' in self
.child
.allParams
:
733 self
.child
.allParams
= self
.child
.allParams
[:]
734 self
.child
.allParams
.remove('size')
736 class xxxSpacer(xxxObject
):
737 hasName
= hasStyle
= False
738 allParams
= ['size', 'option', 'flag', 'border']
739 paramDict
= {'option': ParamInt}
740 default
= {'size': '0,0'}
742 class xxxMenuBar(xxxContainer
):
743 allParams
= ['style']
744 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
745 winStyles
= ['wxMB_DOCKABLE']
747 class xxxMenu(xxxContainer
):
748 allParams
= ['label', 'help', 'style']
749 default
= {'label': ''}
750 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
751 winStyles
= ['wxMENU_TEAROFF']
753 class xxxMenuItem(xxxObject
):
754 allParams
= ['label', 'bitmap', 'accel', 'help',
755 'checkable', 'radio', 'enabled', 'checked']
756 default
= {'label': ''}
759 class xxxSeparator(xxxObject
):
760 hasName
= hasStyle
= False
762 ################################################################################
765 class xxxUnknown(xxxObject
):
766 allParams
= ['pos', 'size', 'style']
767 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
769 ################################################################################
773 'wxDialog': xxxDialog
,
776 'wxToolBar': xxxToolBar
,
778 'wxBitmap': xxxBitmap
,
781 'wxButton': xxxButton
,
782 'wxBitmapButton': xxxBitmapButton
,
783 'wxRadioButton': xxxRadioButton
,
784 'wxSpinButton': xxxSpinButton
,
785 'wxToggleButton' : xxxToggleButton
,
787 'wxStaticBox': xxxStaticBox
,
788 'wxStaticBitmap': xxxStaticBitmap
,
789 'wxRadioBox': xxxRadioBox
,
790 'wxComboBox': xxxComboBox
,
791 'wxCheckBox': xxxCheckBox
,
792 'wxListBox': xxxListBox
,
794 'wxStaticText': xxxStaticText
,
795 'wxStaticLine': xxxStaticLine
,
796 'wxTextCtrl': xxxTextCtrl
,
797 'wxChoice': xxxChoice
,
798 'wxSlider': xxxSlider
,
800 'wxScrollBar': xxxScrollBar
,
801 'wxTreeCtrl': xxxTreeCtrl
,
802 'wxListCtrl': xxxListCtrl
,
803 'wxCheckListBox': xxxCheckList
,
804 'wxNotebook': xxxNotebook
,
805 'wxSplitterWindow': xxxSplitterWindow
,
806 'notebookpage': xxxNotebookPage
,
807 'wxHtmlWindow': xxxHtmlWindow
,
808 'wxCalendarCtrl': xxxCalendarCtrl
,
809 'wxGenericDirCtrl': xxxGenericDirCtrl
,
810 'wxSpinCtrl': xxxSpinCtrl
,
811 'wxScrolledWindow': xxxScrolledWindow
,
813 'wxBoxSizer': xxxBoxSizer
,
814 'wxStaticBoxSizer': xxxStaticBoxSizer
,
815 'wxGridSizer': xxxGridSizer
,
816 'wxFlexGridSizer': xxxFlexGridSizer
,
817 'wxGridBagSizer': xxxGridBagSizer
,
818 'sizeritem': xxxSizerItem
,
821 'wxMenuBar': xxxMenuBar
,
823 'wxMenuItem': xxxMenuItem
,
824 'separator': xxxSeparator
,
826 'unknown': xxxUnknown
,
829 # Create IDs for all parameters of all classes
830 paramIDs
= {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(),
831 'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(),
832 'tooltip': wxNewId(), 'encoding': wxNewId(),
833 'cellpos': wxNewId(), 'cellspan': wxNewId()
835 for cl
in xxxDict
.values():
837 for param
in cl
.allParams
+ cl
.paramDict
.keys():
838 if not paramIDs
.has_key(param
):
839 paramIDs
[param
] = wxNewId()
841 ################################################################################
844 # Test for object elements
846 return node
.nodeType
== minidom
.Node
.ELEMENT_NODE
and node
.tagName
== 'object'
848 # Make XXX object from some DOM object, selecting correct class
849 def MakeXXXFromDOM(parent
, element
):
851 klass
= xxxDict
[element
.getAttribute('class')]
853 # If we encounter a weird class, use unknown template
854 print 'WARNING: unsupported class:', element
.getAttribute('class')
856 return klass(parent
, element
)
858 # Make empty DOM element
859 def MakeEmptyDOM(className
):
860 elem
= g
.tree
.dom
.createElement('object')
861 elem
.setAttribute('class', className
)
862 # Set required and default parameters
863 xxxClass
= xxxDict
[className
]
864 defaultNotRequired
= filter(lambda x
, l
=xxxClass
.required
: x
not in l
,
865 xxxClass
.default
.keys())
866 for param
in xxxClass
.required
+ defaultNotRequired
:
867 textElem
= g
.tree
.dom
.createElement(param
)
869 textNode
= g
.tree
.dom
.createTextNode(xxxClass
.default
[param
])
871 textNode
= g
.tree
.dom
.createTextNode('')
872 textElem
.appendChild(textNode
)
873 elem
.appendChild(textElem
)
876 # Make empty XXX object
877 def MakeEmptyXXX(parent
, className
):
878 # Make corresponding DOM object first
879 elem
= MakeEmptyDOM(className
)
880 # If parent is a sizer, we should create sizeritem object, except for spacers
882 if parent
.isSizer
and className
!= 'spacer':
883 sizerItemElem
= MakeEmptyDOM('sizeritem')
884 sizerItemElem
.appendChild(elem
)
886 elif isinstance(parent
, xxxNotebook
):
887 pageElem
= MakeEmptyDOM('notebookpage')
888 pageElem
.appendChild(elem
)
890 # Now just make object
891 return MakeXXXFromDOM(parent
, elem
)