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
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 #wxLogMessage("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(str(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
):
213 self
.element
= element
216 self
.className
= element
.getAttribute('class')
217 self
.subclass
= element
.getAttribute('subclass')
218 if self
.hasName
: self
.name
= element
.getAttribute('name')
219 # Set parameters (text element children)
221 nodes
= element
.childNodes
[:]
223 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
226 continue # do nothing for object children here
227 if tag
not in self
.allParams
and tag
not in self
.styles
:
228 print 'WARNING: unknown parameter for %s: %s' % \
229 (self
.className
, tag
)
230 elif tag
in self
.specials
:
231 self
.special(tag
, node
)
232 elif tag
== 'content':
233 if self
.className
== 'wxCheckListBox':
234 self
.params
[tag
] = xxxParamContentCheckList(node
)
236 self
.params
[tag
] = xxxParamContent(node
)
237 elif tag
== 'font': # has children
238 self
.params
[tag
] = xxxParamFont(element
, node
)
239 elif tag
in self
.bitmapTags
:
240 # Can have attributes
241 self
.params
[tag
] = xxxParamBitmap(node
)
242 else: # simple parameter
243 self
.params
[tag
] = xxxParam(node
)
244 elif node
.nodeType
== minidom
.Node
.TEXT_NODE
and node
.data
.isspace():
245 # Remove empty text nodes
246 element
.removeChild(node
)
249 # Check that all required params are set
250 for param
in self
.required
:
251 if not self
.params
.has_key(param
):
252 # If default is specified, set it
253 if self
.default
.has_key(param
):
254 elem
= g
.tree
.dom
.createElement(param
)
255 if param
== 'content':
256 if self
.className
== 'wxCheckListBox':
257 self
.params
[param
] = xxxParamContentCheckList(elem
)
259 self
.params
[param
] = xxxParamContent(elem
)
261 self
.params
[param
] = xxxParam(elem
)
262 # Find place to put new element: first present element after param
264 paramStyles
= self
.allParams
+ self
.styles
265 for p
in paramStyles
[paramStyles
.index(param
) + 1:]:
266 # Content params don't have same type
267 if self
.params
.has_key(p
) and p
!= 'content':
271 nextTextElem
= self
.params
[p
].node
272 self
.element
.insertBefore(elem
, nextTextElem
)
274 self
.element
.appendChild(elem
)
276 wxLogWarning('Required parameter %s of %s missing' %
277 (param
, self
.className
))
278 # Returns real tree object
279 def treeObject(self
):
280 if self
.hasChild
: return self
.child
282 # Returns tree image index
284 if self
.hasChild
: return self
.child
.treeImage()
286 # Class name plus wx name
288 if self
.hasChild
: return self
.child
.treeName()
289 if self
.subclass
: className
= self
.subclass
290 else: className
= self
.className
291 if self
.hasName
and self
.name
: return className
+ ' "' + self
.name
+ '"'
293 # Class name or subclass
295 if self
.subclass
: return self
.subclass
+ '(' + self
.className
+ ')'
296 else: return self
.className
298 ################################################################################
300 # This is a little special: it is both xxxObject and xxxNode
301 class xxxParamFont(xxxObject
, xxxNode
):
302 allParams
= ['size', 'family', 'style', 'weight', 'underlined',
304 def __init__(self
, parent
, element
):
305 xxxObject
.__init
__(self
, parent
, element
)
306 xxxNode
.__init
__(self
, element
)
307 self
.parentNode
= parent
# required to behave similar to DOM node
309 for p
in self
.allParams
:
311 v
.append(str(self
.params
[p
].value()))
315 def update(self
, value
):
316 # `value' is a list of strings corresponding to all parameters
318 # Remove old elements first
319 childNodes
= elem
.childNodes
[:]
320 for node
in childNodes
: elem
.removeChild(node
)
324 for param
in self
.allParams
:
326 fontElem
= g
.tree
.dom
.createElement(param
)
327 textNode
= g
.tree
.dom
.createTextNode(value
[i
])
328 self
.params
[param
] = textNode
329 fontElem
.appendChild(textNode
)
330 elem
.appendChild(fontElem
)
337 ################################################################################
339 class xxxContainer(xxxObject
):
343 # Simulate normal parameter for encoding
346 return g
.currentEncoding
347 def update(self
, val
):
348 g
.currentEncoding
= val
350 # Special class for root node
351 class xxxMainNode(xxxContainer
):
352 allParams
= ['encoding']
353 hasStyle
= hasName
= False
354 def __init__(self
, dom
):
355 xxxContainer
.__init
__(self
, None, dom
.documentElement
)
356 self
.className
= 'XML tree'
357 # Reset required parameters after processing XML, because encoding is
359 self
.required
= ['encoding']
360 self
.params
['encoding'] = xxxEncoding()
362 ################################################################################
365 class xxxPanel(xxxContainer
):
366 allParams
= ['pos', 'size', 'style']
367 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
370 class xxxDialog(xxxContainer
):
371 allParams
= ['title', 'centered', 'pos', 'size', 'style']
372 paramDict
= {'centered': ParamBool}
374 default
= {'title': ''}
375 winStyles
= ['wxDEFAULT_DIALOG_STYLE',
376 'wxCAPTION', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX', 'wxCLOSE_BOX',
379 'wxNO_3D', 'wxDIALOG_NO_PARENT']
380 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
383 class xxxFrame(xxxContainer
):
384 allParams
= ['title', 'centered', 'pos', 'size', 'style']
385 paramDict
= {'centered': ParamBool}
387 default
= {'title': ''}
388 winStyles
= ['wxDEFAULT_FRAME_STYLE',
389 'wxCAPTION', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX', 'wxCLOSE_BOX',
391 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
392 'wxFRAME_TOOL_WINDOW', 'wxFRAME_NO_TASKBAR',
393 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_SHAPED'
395 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
398 class xxxTool(xxxObject
):
399 allParams
= ['bitmap', 'bitmap2', 'radio', 'toggle', 'tooltip', 'longhelp', 'label']
400 required
= ['bitmap']
401 paramDict
= {'bitmap2': ParamBitmap, 'radio': ParamBool, 'toggle': ParamBool}
404 class xxxToolBar(xxxContainer
):
405 allParams
= ['bitmapsize', 'margins', 'packing', 'separation', 'dontattachtoframe',
406 'pos', 'size', 'style']
408 paramDict
= {'bitmapsize': ParamPosSize
, 'margins': ParamPosSize
,
409 'packing': ParamInt
, 'separation': ParamInt
,
410 'dontattachtoframe': ParamBool
, 'style': ParamNonGenericStyle
}
411 winStyles
= ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL',
412 'wxTB_3DBUTTONS','wxTB_TEXT', 'wxTB_NOICONS', 'wxTB_NODIVIDER',
413 'wxTB_NOALIGN', 'wxTB_HORZ_LAYOUT', 'wxTB_HORZ_TEXT']
415 class xxxWizard(xxxContainer
):
416 allParams
= ['title', 'bitmap', 'pos']
418 default
= {'title': ''}
420 exStyles
= ['wxWIZARD_EX_HELPBUTTON']
422 class xxxWizardPage(xxxContainer
):
423 allParams
= ['bitmap']
427 class xxxWizardPageSimple(xxxContainer
):
428 allParams
= ['bitmap']
432 ################################################################################
435 class xxxBitmap(xxxObject
):
436 allParams
= ['bitmap']
437 required
= ['bitmap']
440 class xxxIcon(xxxObject
):
443 ################################################################################
446 class xxxStaticText(xxxObject
):
447 allParams
= ['label', 'pos', 'size', 'style']
449 default
= {'label': ''}
450 winStyles
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
452 class xxxStaticLine(xxxObject
):
453 allParams
= ['pos', 'size', 'style']
454 winStyles
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
456 class xxxStaticBitmap(xxxObject
):
457 allParams
= ['bitmap', 'pos', 'size', 'style']
458 required
= ['bitmap']
460 class xxxTextCtrl(xxxObject
):
461 allParams
= ['value', 'pos', 'size', 'style']
462 winStyles
= ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
463 'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
464 paramDict
= {'value': ParamMultilineText}
466 class xxxChoice(xxxObject
):
467 allParams
= ['content', 'selection', 'pos', 'size', 'style']
468 required
= ['content']
469 default
= {'content': '[]'}
470 winStyles
= ['wxCB_SORT']
472 class xxxSlider(xxxObject
):
473 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style',
474 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
476 paramDict
= {'value': ParamInt
, 'tickfreq': ParamInt
, 'pagesize': ParamInt
,
477 'linesize': ParamInt
, 'thumb': ParamInt
, 'thumb': ParamInt
,
478 'tick': ParamInt
, 'selmin': ParamInt
, 'selmax': ParamInt
}
479 required
= ['value', 'min', 'max']
480 winStyles
= ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
481 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
482 'wxSL_BOTH', 'wxSL_SELRANGE', 'wxSL_INVERSE']
484 class xxxGauge(xxxObject
):
485 allParams
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
486 paramDict
= {'range': ParamInt
, 'value': ParamInt
,
487 'shadow': ParamInt
, 'bezel': ParamInt
}
488 winStyles
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
490 class xxxScrollBar(xxxObject
):
491 allParams
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
492 paramDict
= {'value': ParamInt
, 'range': ParamInt
, 'thumbsize': ParamInt
,
493 'pagesize': ParamInt
}
494 winStyles
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
496 class xxxListCtrl(xxxObject
):
497 allParams
= ['pos', 'size', 'style']
498 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
499 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
500 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
501 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
503 class xxxTreeCtrl(xxxObject
):
504 allParams
= ['pos', 'size', 'style']
505 winStyles
= ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT',
506 'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE']
508 class xxxHtmlWindow(xxxObject
):
509 allParams
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
510 paramDict
= {'borders': ParamInt, 'htmlcode':ParamMultilineText}
511 winStyles
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
513 class xxxCalendarCtrl(xxxObject
):
514 allParams
= ['pos', 'size', 'style']
516 class xxxNotebook(xxxContainer
):
517 allParams
= ['usenotebooksizer', 'pos', 'size', 'style']
518 paramDict
= {'usenotebooksizer': ParamBool}
519 winStyles
= ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM']
521 class xxxSplitterWindow(xxxContainer
):
522 allParams
= ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style']
523 paramDict
= {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit }
524 winStyles
= ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER', 'wxSP_BORDER',
525 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE',
528 class xxxGenericDirCtrl(xxxObject
):
529 allParams
= ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style']
530 paramDict
= {'defaultfilter': ParamInt}
531 winStyles
= ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
532 'wxDIRCTRL_SHOW_FILTERS', 'wxDIRCTRL_EDIT_LABELS']
534 class xxxScrolledWindow(xxxContainer
):
535 allParams
= ['pos', 'size', 'style']
536 winStyles
= ['wxHSCROLL', 'wxVSCROLL']
538 ################################################################################
541 class xxxButton(xxxObject
):
542 allParams
= ['label', 'default', 'pos', 'size', 'style']
543 paramDict
= {'default': ParamBool}
545 winStyles
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
547 class xxxBitmapButton(xxxObject
):
548 allParams
= ['bitmap', 'selected', 'focus', 'disabled', 'default',
549 'pos', 'size', 'style']
550 required
= ['bitmap']
551 winStyles
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP',
552 'wxBU_RIGHT', 'wxBU_BOTTOM']
554 class xxxRadioButton(xxxObject
):
555 allParams
= ['label', 'value', 'pos', 'size', 'style']
556 paramDict
= {'value': ParamBool}
558 winStyles
= ['wxRB_GROUP']
560 class xxxSpinButton(xxxObject
):
561 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
562 paramDict
= {'value': ParamInt}
563 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
565 class xxxSpinCtrl(xxxObject
):
566 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
567 paramDict
= {'value': ParamInt}
568 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
570 class xxxToggleButton(xxxObject
):
571 allParams
= ['label', 'checked', 'pos', 'size', 'style']
572 paramDict
= {'checked': ParamBool}
575 ################################################################################
578 class xxxStaticBox(xxxObject
):
579 allParams
= ['label', 'pos', 'size', 'style']
582 class xxxRadioBox(xxxObject
):
583 allParams
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
584 paramDict
= {'dimension': ParamInt}
585 required
= ['label', 'content']
586 default
= {'content': '[]'}
587 winStyles
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS']
589 class xxxCheckBox(xxxObject
):
590 allParams
= ['label', 'checked', 'pos', 'size', 'style']
591 paramDict
= {'checked': ParamBool}
592 winStyles
= ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER',
596 class xxxComboBox(xxxObject
):
597 allParams
= ['content', 'selection', 'value', 'pos', 'size', 'style']
598 required
= ['content']
599 default
= {'content': '[]'}
600 winStyles
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
602 class xxxListBox(xxxObject
):
603 allParams
= ['content', 'selection', 'pos', 'size', 'style']
604 required
= ['content']
605 default
= {'content': '[]'}
606 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
607 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
609 class xxxCheckList(xxxObject
):
610 allParams
= ['content', 'pos', 'size', 'style']
611 required
= ['content']
612 default
= {'content': '[]'}
613 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
614 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
615 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
616 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
617 paramDict
= {'content': ParamContentCheckList}
619 ################################################################################
622 class xxxSizer(xxxContainer
):
623 hasName
= hasStyle
= False
624 paramDict
= {'orient': ParamOrient}
627 class xxxBoxSizer(xxxSizer
):
628 allParams
= ['orient']
629 required
= ['orient']
630 default
= {'orient': 'wxVERTICAL'}
631 # Tree icon depends on orientation
633 if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
634 else: return self
.imageV
636 class xxxStaticBoxSizer(xxxBoxSizer
):
637 allParams
= ['label', 'orient']
638 required
= ['label', 'orient']
640 class xxxGridSizer(xxxSizer
):
641 allParams
= ['cols', 'rows', 'vgap', 'hgap']
643 default
= {'cols': '2', 'rows': '2'}
645 class xxxStdDialogButtonSizer(xxxSizer
):
648 # For repeated parameters
650 def __init__(self
, node
):
652 self
.l
, self
.data
= [], []
653 def append(self
, param
):
655 self
.data
.append(param
.value())
661 self
.l
, self
.data
= [], []
663 class xxxFlexGridSizer(xxxGridSizer
):
664 specials
= ['growablecols', 'growablerows']
665 allParams
= ['cols', 'rows', 'vgap', 'hgap'] + specials
666 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
667 # Special processing for growable* parameters
668 # (they are represented by several nodes)
669 def special(self
, tag
, node
):
670 if not self
.params
.has_key(tag
):
671 # Create new multi-group
672 self
.params
[tag
] = xxxParamMulti(node
)
673 self
.params
[tag
].append(xxxParamInt(node
))
674 def setSpecial(self
, param
, value
):
675 # Straightforward implementation: remove, add again
676 self
.params
[param
].remove()
677 del self
.params
[param
]
679 node
= g
.tree
.dom
.createElement(param
)
680 text
= g
.tree
.dom
.createTextNode(str(i
))
681 node
.appendChild(text
)
682 self
.element
.appendChild(node
)
683 self
.special(param
, node
)
685 class xxxGridBagSizer(xxxSizer
):
686 specials
= ['growablecols', 'growablerows']
687 allParams
= ['vgap', 'hgap'] + specials
688 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
689 # Special processing for growable* parameters
690 # (they are represented by several nodes)
691 def special(self
, tag
, node
):
692 if not self
.params
.has_key(tag
):
693 # Create new multi-group
694 self
.params
[tag
] = xxxParamMulti(node
)
695 self
.params
[tag
].append(xxxParamInt(node
))
696 def setSpecial(self
, param
, value
):
697 # Straightforward implementation: remove, add again
698 self
.params
[param
].remove()
699 del self
.params
[param
]
701 node
= g
.tree
.dom
.createElement(param
)
702 text
= g
.tree
.dom
.createTextNode(str(i
))
703 node
.appendChild(text
)
704 self
.element
.appendChild(node
)
705 self
.special(param
, node
)
707 # Container with only one child.
709 class xxxChildContainer(xxxObject
):
710 hasName
= hasStyle
= False
712 def __init__(self
, parent
, element
):
713 xxxObject
.__init
__(self
, parent
, element
)
714 # Must have one child with 'object' tag, but we don't check it
715 nodes
= element
.childNodes
[:] # create copy
717 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
718 if node
.tagName
== 'object':
719 # Create new xxx object for child node
720 self
.child
= MakeXXXFromDOM(self
, node
)
721 self
.child
.parent
= parent
722 # Copy hasChildren and isSizer attributes
723 self
.hasChildren
= self
.child
.hasChildren
724 self
.isSizer
= self
.child
.isSizer
727 element
.removeChild(node
)
729 assert 0, 'no child found'
731 class xxxSizerItem(xxxChildContainer
):
732 allParams
= ['option', 'flag', 'border', 'minsize', 'ratio']
733 paramDict
= {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
734 #default = {'cellspan': '1,1'}
735 def __init__(self
, parent
, element
):
736 # For GridBag sizer items, extra parameters added
737 if isinstance(parent
, xxxGridBagSizer
):
738 self
.allParams
= self
.allParams
+ ['cellpos', 'cellspan']
739 xxxChildContainer
.__init
__(self
, parent
, element
)
740 # Remove pos parameter - not needed for sizeritems
741 if 'pos' in self
.child
.allParams
:
742 self
.child
.allParams
= self
.child
.allParams
[:]
743 self
.child
.allParams
.remove('pos')
745 class xxxNotebookPage(xxxChildContainer
):
746 allParams
= ['label', 'selected']
747 paramDict
= {'selected': ParamBool}
749 def __init__(self
, parent
, element
):
750 xxxChildContainer
.__init
__(self
, parent
, element
)
751 # pos and size dont matter for notebookpages
752 if 'pos' in self
.child
.allParams
:
753 self
.child
.allParams
= self
.child
.allParams
[:]
754 self
.child
.allParams
.remove('pos')
755 if 'size' in self
.child
.allParams
:
756 self
.child
.allParams
= self
.child
.allParams
[:]
757 self
.child
.allParams
.remove('size')
759 class xxxSpacer(xxxObject
):
760 hasName
= hasStyle
= False
761 allParams
= ['size', 'option', 'flag', 'border']
762 paramDict
= {'option': ParamInt}
763 default
= {'size': '0,0'}
765 class xxxMenuBar(xxxContainer
):
766 allParams
= ['style']
767 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
768 winStyles
= ['wxMB_DOCKABLE']
770 class xxxMenu(xxxContainer
):
771 allParams
= ['label', 'help', 'style']
772 default
= {'label': ''}
773 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
774 winStyles
= ['wxMENU_TEAROFF']
776 class xxxMenuItem(xxxObject
):
777 allParams
= ['label', 'bitmap', 'accel', 'help',
778 'checkable', 'radio', 'enabled', 'checked']
779 default
= {'label': ''}
782 class xxxSeparator(xxxObject
):
783 hasName
= hasStyle
= False
785 ################################################################################
788 class xxxUnknown(xxxObject
):
789 allParams
= ['pos', 'size', 'style']
790 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
792 ################################################################################
796 'wxDialog': xxxDialog
,
799 'wxToolBar': xxxToolBar
,
800 'wxWizard': xxxWizard
,
801 'wxWizardPage': xxxWizardPage
,
802 'wxWizardPageSimple': xxxWizardPageSimple
,
804 'wxBitmap': xxxBitmap
,
807 'wxButton': xxxButton
,
808 'wxBitmapButton': xxxBitmapButton
,
809 'wxRadioButton': xxxRadioButton
,
810 'wxSpinButton': xxxSpinButton
,
811 'wxToggleButton' : xxxToggleButton
,
813 'wxStaticBox': xxxStaticBox
,
814 'wxStaticBitmap': xxxStaticBitmap
,
815 'wxRadioBox': xxxRadioBox
,
816 'wxComboBox': xxxComboBox
,
817 'wxCheckBox': xxxCheckBox
,
818 'wxListBox': xxxListBox
,
820 'wxStaticText': xxxStaticText
,
821 'wxStaticLine': xxxStaticLine
,
822 'wxTextCtrl': xxxTextCtrl
,
823 'wxChoice': xxxChoice
,
824 'wxSlider': xxxSlider
,
826 'wxScrollBar': xxxScrollBar
,
827 'wxTreeCtrl': xxxTreeCtrl
,
828 'wxListCtrl': xxxListCtrl
,
829 'wxCheckListBox': xxxCheckList
,
830 'wxNotebook': xxxNotebook
,
831 'wxSplitterWindow': xxxSplitterWindow
,
832 'notebookpage': xxxNotebookPage
,
833 'wxHtmlWindow': xxxHtmlWindow
,
834 'wxCalendarCtrl': xxxCalendarCtrl
,
835 'wxGenericDirCtrl': xxxGenericDirCtrl
,
836 'wxSpinCtrl': xxxSpinCtrl
,
837 'wxScrolledWindow': xxxScrolledWindow
,
839 'wxBoxSizer': xxxBoxSizer
,
840 'wxStaticBoxSizer': xxxStaticBoxSizer
,
841 'wxGridSizer': xxxGridSizer
,
842 'wxFlexGridSizer': xxxFlexGridSizer
,
843 'wxGridBagSizer': xxxGridBagSizer
,
844 'wxStdDialogButtonSizer': xxxStdDialogButtonSizer
,
845 'sizeritem': xxxSizerItem
,
848 'wxMenuBar': xxxMenuBar
,
850 'wxMenuItem': xxxMenuItem
,
851 'separator': xxxSeparator
,
853 'unknown': xxxUnknown
,
856 # Create IDs for all parameters of all classes
857 paramIDs
= {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(),
858 'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(),
859 'tooltip': wxNewId(), 'encoding': wxNewId(),
860 'cellpos': wxNewId(), 'cellspan': wxNewId()
862 for cl
in xxxDict
.values():
864 for param
in cl
.allParams
+ cl
.paramDict
.keys():
865 if not paramIDs
.has_key(param
):
866 paramIDs
[param
] = wxNewId()
868 ################################################################################
871 # Test for object elements
873 return node
.nodeType
== minidom
.Node
.ELEMENT_NODE
and node
.tagName
== 'object'
875 # Make XXX object from some DOM object, selecting correct class
876 def MakeXXXFromDOM(parent
, element
):
878 klass
= xxxDict
[element
.getAttribute('class')]
880 # If we encounter a weird class, use unknown template
881 print 'WARNING: unsupported class:', element
.getAttribute('class')
883 return klass(parent
, element
)
885 # Make empty DOM element
886 def MakeEmptyDOM(className
):
887 elem
= g
.tree
.dom
.createElement('object')
888 elem
.setAttribute('class', className
)
889 # Set required and default parameters
890 xxxClass
= xxxDict
[className
]
891 defaultNotRequired
= filter(lambda x
, l
=xxxClass
.required
: x
not in l
,
892 xxxClass
.default
.keys())
893 for param
in xxxClass
.required
+ defaultNotRequired
:
894 textElem
= g
.tree
.dom
.createElement(param
)
896 textNode
= g
.tree
.dom
.createTextNode(xxxClass
.default
[param
])
898 textNode
= g
.tree
.dom
.createTextNode('')
899 textElem
.appendChild(textNode
)
900 elem
.appendChild(textElem
)
903 # Make empty XXX object
904 def MakeEmptyXXX(parent
, className
):
905 # Make corresponding DOM object first
906 elem
= MakeEmptyDOM(className
)
907 # If parent is a sizer, we should create sizeritem object, except for spacers
909 if parent
.isSizer
and className
!= 'spacer':
910 sizerItemElem
= MakeEmptyDOM('sizeritem')
911 sizerItemElem
.appendChild(elem
)
913 elif isinstance(parent
, xxxNotebook
):
914 pageElem
= MakeEmptyDOM('notebookpage')
915 pageElem
.appendChild(elem
)
917 # Now just make object
918 return MakeXXXFromDOM(parent
, elem
)