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', 'family', 'style', 'weight', '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
):
340 # Simulate normal parameter for encoding
343 return g
.currentEncoding
344 def update(self
, val
):
345 g
.currentEncoding
= val
347 # Special class for root node
348 class xxxMainNode(xxxContainer
):
349 allParams
= ['encoding']
350 hasStyle
= hasName
= False
351 def __init__(self
, dom
):
352 xxxContainer
.__init
__(self
, None, dom
.documentElement
)
353 self
.className
= 'XML tree'
354 # Reset required parameters after processing XML, because encoding is
356 self
.required
= ['encoding']
357 self
.params
['encoding'] = xxxEncoding()
359 ################################################################################
362 class xxxPanel(xxxContainer
):
363 allParams
= ['pos', 'size', 'style']
364 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
367 class xxxDialog(xxxContainer
):
368 allParams
= ['title', 'centered', 'pos', 'size', 'style']
369 paramDict
= {'centered': ParamBool}
371 default
= {'title': ''}
372 winStyles
= ['wxDEFAULT_DIALOG_STYLE',
373 'wxCAPTION', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX', 'wxCLOSE_BOX',
376 'wxNO_3D', 'wxDIALOG_NO_PARENT']
377 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
380 class xxxFrame(xxxContainer
):
381 allParams
= ['title', 'centered', 'pos', 'size', 'style']
382 paramDict
= {'centered': ParamBool}
384 default
= {'title': ''}
385 winStyles
= ['wxDEFAULT_FRAME_STYLE',
386 'wxCAPTION', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX', 'wxCLOSE_BOX',
388 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
389 'wxFRAME_TOOL_WINDOW', 'wxFRAME_NO_TASKBAR',
390 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_SHAPED'
392 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
395 class xxxTool(xxxObject
):
396 allParams
= ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp', 'label']
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', 'wxTB_TEXT']
410 class xxxWizard(xxxContainer
):
411 allParams
= ['title', 'bitmap', 'pos']
413 default
= {'title': ''}
415 exStyles
= ['wxWIZARD_EX_HELPBUTTON']
417 class xxxWizardPage(xxxContainer
):
418 allParams
= ['bitmap']
422 class xxxWizardPageSimple(xxxContainer
):
423 allParams
= ['bitmap']
427 ################################################################################
430 class xxxBitmap(xxxObject
):
431 allParams
= ['bitmap']
432 required
= ['bitmap']
435 class xxxIcon(xxxObject
):
438 ################################################################################
441 class xxxStaticText(xxxObject
):
442 allParams
= ['label', 'pos', 'size', 'style']
444 default
= {'label': ''}
445 winStyles
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
447 class xxxStaticLine(xxxObject
):
448 allParams
= ['pos', 'size', 'style']
449 winStyles
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
451 class xxxStaticBitmap(xxxObject
):
452 allParams
= ['bitmap', 'pos', 'size', 'style']
453 required
= ['bitmap']
455 class xxxTextCtrl(xxxObject
):
456 allParams
= ['value', 'pos', 'size', 'style']
457 winStyles
= ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
458 'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
459 paramDict
= {'value': ParamMultilineText}
461 class xxxChoice(xxxObject
):
462 allParams
= ['content', 'selection', 'pos', 'size', 'style']
463 required
= ['content']
464 default
= {'content': '[]'}
465 winStyles
= ['wxCB_SORT']
467 class xxxSlider(xxxObject
):
468 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style',
469 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
471 paramDict
= {'value': ParamInt
, 'tickfreq': ParamInt
, 'pagesize': ParamInt
,
472 'linesize': ParamInt
, 'thumb': ParamInt
, 'thumb': ParamInt
,
473 'tick': ParamInt
, 'selmin': ParamInt
, 'selmax': ParamInt
}
474 required
= ['value', 'min', 'max']
475 winStyles
= ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
476 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
477 'wxSL_BOTH', 'wxSL_SELRANGE']
479 class xxxGauge(xxxObject
):
480 allParams
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
481 paramDict
= {'range': ParamInt
, 'value': ParamInt
,
482 'shadow': ParamInt
, 'bezel': ParamInt
}
483 winStyles
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
485 class xxxScrollBar(xxxObject
):
486 allParams
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
487 paramDict
= {'value': ParamInt
, 'range': ParamInt
, 'thumbsize': ParamInt
,
488 'pagesize': ParamInt
}
489 winStyles
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
491 class xxxListCtrl(xxxObject
):
492 allParams
= ['pos', 'size', 'style']
493 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
494 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
495 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
496 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
498 class xxxTreeCtrl(xxxObject
):
499 allParams
= ['pos', 'size', 'style']
500 winStyles
= ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT',
501 'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE']
503 class xxxHtmlWindow(xxxObject
):
504 allParams
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
505 paramDict
= {'borders': ParamInt, 'htmlcode':ParamMultilineText}
506 winStyles
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
508 class xxxCalendarCtrl(xxxObject
):
509 allParams
= ['pos', 'size', 'style']
511 class xxxNotebook(xxxContainer
):
512 allParams
= ['usenotebooksizer', 'pos', 'size', 'style']
513 paramDict
= {'usenotebooksizer': ParamBool}
514 winStyles
= ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM']
516 class xxxSplitterWindow(xxxContainer
):
517 allParams
= ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style']
518 paramDict
= {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit }
519 winStyles
= ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER', 'wxSP_BORDER',
520 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE',
523 class xxxGenericDirCtrl(xxxObject
):
524 allParams
= ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style']
525 paramDict
= {'defaultfilter': ParamInt}
526 winStyles
= ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
527 'wxDIRCTRL_SHOW_FILTERS', 'wxDIRCTRL_EDIT_LABELS']
529 class xxxScrolledWindow(xxxContainer
):
530 allParams
= ['pos', 'size', 'style']
531 winStyles
= ['wxHSCROLL', 'wxVSCROLL']
533 ################################################################################
536 class xxxButton(xxxObject
):
537 allParams
= ['label', 'default', 'pos', 'size', 'style']
538 paramDict
= {'default': ParamBool}
540 winStyles
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
542 class xxxBitmapButton(xxxObject
):
543 allParams
= ['bitmap', 'selected', 'focus', 'disabled', 'default',
544 'pos', 'size', 'style']
545 required
= ['bitmap']
546 winStyles
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP',
547 'wxBU_RIGHT', 'wxBU_BOTTOM']
549 class xxxRadioButton(xxxObject
):
550 allParams
= ['label', 'value', 'pos', 'size', 'style']
551 paramDict
= {'value': ParamBool}
553 winStyles
= ['wxRB_GROUP']
555 class xxxSpinButton(xxxObject
):
556 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
557 paramDict
= {'value': ParamInt}
558 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
560 class xxxSpinCtrl(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 xxxToggleButton(xxxObject
):
566 allParams
= ['label', 'checked', 'pos', 'size', 'style']
567 paramDict
= {'checked': ParamBool}
570 ################################################################################
573 class xxxStaticBox(xxxObject
):
574 allParams
= ['label', 'pos', 'size', 'style']
577 class xxxRadioBox(xxxObject
):
578 allParams
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
579 paramDict
= {'dimension': ParamInt}
580 required
= ['label', 'content']
581 default
= {'content': '[]'}
582 winStyles
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS']
584 class xxxCheckBox(xxxObject
):
585 allParams
= ['label', 'checked', 'pos', 'size', 'style']
586 paramDict
= {'checked': ParamBool}
587 winStyles
= ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER',
591 class xxxComboBox(xxxObject
):
592 allParams
= ['content', 'selection', 'value', 'pos', 'size', 'style']
593 required
= ['content']
594 default
= {'content': '[]'}
595 winStyles
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
597 class xxxListBox(xxxObject
):
598 allParams
= ['content', 'selection', 'pos', 'size', 'style']
599 required
= ['content']
600 default
= {'content': '[]'}
601 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
602 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
604 class xxxCheckList(xxxObject
):
605 allParams
= ['content', 'pos', 'size', 'style']
606 required
= ['content']
607 default
= {'content': '[]'}
608 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
609 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
610 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
611 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
612 paramDict
= {'content': ParamContentCheckList}
614 ################################################################################
617 class xxxSizer(xxxContainer
):
618 hasName
= hasStyle
= False
619 paramDict
= {'orient': ParamOrient}
622 class xxxBoxSizer(xxxSizer
):
623 allParams
= ['orient']
624 required
= ['orient']
625 default
= {'orient': 'wxVERTICAL'}
626 # Tree icon depends on orientation
628 if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
629 else: return self
.imageV
631 class xxxStaticBoxSizer(xxxBoxSizer
):
632 allParams
= ['label', 'orient']
633 required
= ['label', 'orient']
635 class xxxGridSizer(xxxSizer
):
636 allParams
= ['cols', 'rows', 'vgap', 'hgap']
638 default
= {'cols': '2', 'rows': '2'}
640 class xxxStdDialogButtonSizer(xxxSizer
):
643 # For repeated parameters
645 def __init__(self
, node
):
647 self
.l
, self
.data
= [], []
648 def append(self
, param
):
650 self
.data
.append(param
.value())
656 self
.l
, self
.data
= [], []
658 class xxxFlexGridSizer(xxxGridSizer
):
659 specials
= ['growablecols', 'growablerows']
660 allParams
= ['cols', 'rows', 'vgap', 'hgap'] + specials
661 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
662 # Special processing for growable* parameters
663 # (they are represented by several nodes)
664 def special(self
, tag
, node
):
665 if not self
.params
.has_key(tag
):
666 # Create new multi-group
667 self
.params
[tag
] = xxxParamMulti(node
)
668 self
.params
[tag
].append(xxxParamInt(node
))
669 def setSpecial(self
, param
, value
):
670 # Straightforward implementation: remove, add again
671 self
.params
[param
].remove()
672 del self
.params
[param
]
674 node
= g
.tree
.dom
.createElement(param
)
675 text
= g
.tree
.dom
.createTextNode(str(i
))
676 node
.appendChild(text
)
677 self
.element
.appendChild(node
)
678 self
.special(param
, node
)
680 class xxxGridBagSizer(xxxSizer
):
681 specials
= ['growablecols', 'growablerows']
682 allParams
= ['vgap', 'hgap'] + specials
683 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
684 # Special processing for growable* parameters
685 # (they are represented by several nodes)
686 def special(self
, tag
, node
):
687 if not self
.params
.has_key(tag
):
688 # Create new multi-group
689 self
.params
[tag
] = xxxParamMulti(node
)
690 self
.params
[tag
].append(xxxParamInt(node
))
691 def setSpecial(self
, param
, value
):
692 # Straightforward implementation: remove, add again
693 self
.params
[param
].remove()
694 del self
.params
[param
]
696 node
= g
.tree
.dom
.createElement(param
)
697 text
= g
.tree
.dom
.createTextNode(str(i
))
698 node
.appendChild(text
)
699 self
.element
.appendChild(node
)
700 self
.special(param
, node
)
702 # Container with only one child.
704 class xxxChildContainer(xxxObject
):
705 hasName
= hasStyle
= False
707 def __init__(self
, parent
, element
):
708 xxxObject
.__init
__(self
, parent
, element
)
709 # Must have one child with 'object' tag, but we don't check it
710 nodes
= element
.childNodes
[:] # create copy
712 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
713 if node
.tagName
== 'object':
714 # Create new xxx object for child node
715 self
.child
= MakeXXXFromDOM(self
, node
)
716 self
.child
.parent
= parent
717 # Copy hasChildren and isSizer attributes
718 self
.hasChildren
= self
.child
.hasChildren
719 self
.isSizer
= self
.child
.isSizer
722 element
.removeChild(node
)
724 assert 0, 'no child found'
726 class xxxSizerItem(xxxChildContainer
):
727 allParams
= ['option', 'flag', 'border', 'minsize', 'ratio']
728 paramDict
= {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
729 #default = {'cellspan': '1,1'}
730 def __init__(self
, parent
, element
):
731 # For GridBag sizer items, extra parameters added
732 if isinstance(parent
, xxxGridBagSizer
):
733 self
.allParams
= self
.allParams
+ ['cellpos', 'cellspan']
734 xxxChildContainer
.__init
__(self
, parent
, element
)
735 # Remove pos parameter - not needed for sizeritems
736 if 'pos' in self
.child
.allParams
:
737 self
.child
.allParams
= self
.child
.allParams
[:]
738 self
.child
.allParams
.remove('pos')
740 class xxxNotebookPage(xxxChildContainer
):
741 allParams
= ['label', 'selected']
742 paramDict
= {'selected': ParamBool}
744 def __init__(self
, parent
, element
):
745 xxxChildContainer
.__init
__(self
, parent
, element
)
746 # pos and size dont matter for notebookpages
747 if 'pos' in self
.child
.allParams
:
748 self
.child
.allParams
= self
.child
.allParams
[:]
749 self
.child
.allParams
.remove('pos')
750 if 'size' in self
.child
.allParams
:
751 self
.child
.allParams
= self
.child
.allParams
[:]
752 self
.child
.allParams
.remove('size')
754 class xxxSpacer(xxxObject
):
755 hasName
= hasStyle
= False
756 allParams
= ['size', 'option', 'flag', 'border']
757 paramDict
= {'option': ParamInt}
758 default
= {'size': '0,0'}
760 class xxxMenuBar(xxxContainer
):
761 allParams
= ['style']
762 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
763 winStyles
= ['wxMB_DOCKABLE']
765 class xxxMenu(xxxContainer
):
766 allParams
= ['label', 'help', 'style']
767 default
= {'label': ''}
768 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
769 winStyles
= ['wxMENU_TEAROFF']
771 class xxxMenuItem(xxxObject
):
772 allParams
= ['label', 'bitmap', 'accel', 'help',
773 'checkable', 'radio', 'enabled', 'checked']
774 default
= {'label': ''}
777 class xxxSeparator(xxxObject
):
778 hasName
= hasStyle
= False
780 ################################################################################
783 class xxxUnknown(xxxObject
):
784 allParams
= ['pos', 'size', 'style']
785 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
787 ################################################################################
791 'wxDialog': xxxDialog
,
794 'wxToolBar': xxxToolBar
,
795 'wxWizard': xxxWizard
,
796 'wxWizardPage': xxxWizardPage
,
797 'wxWizardPageSimple': xxxWizardPageSimple
,
799 'wxBitmap': xxxBitmap
,
802 'wxButton': xxxButton
,
803 'wxBitmapButton': xxxBitmapButton
,
804 'wxRadioButton': xxxRadioButton
,
805 'wxSpinButton': xxxSpinButton
,
806 'wxToggleButton' : xxxToggleButton
,
808 'wxStaticBox': xxxStaticBox
,
809 'wxStaticBitmap': xxxStaticBitmap
,
810 'wxRadioBox': xxxRadioBox
,
811 'wxComboBox': xxxComboBox
,
812 'wxCheckBox': xxxCheckBox
,
813 'wxListBox': xxxListBox
,
815 'wxStaticText': xxxStaticText
,
816 'wxStaticLine': xxxStaticLine
,
817 'wxTextCtrl': xxxTextCtrl
,
818 'wxChoice': xxxChoice
,
819 'wxSlider': xxxSlider
,
821 'wxScrollBar': xxxScrollBar
,
822 'wxTreeCtrl': xxxTreeCtrl
,
823 'wxListCtrl': xxxListCtrl
,
824 'wxCheckListBox': xxxCheckList
,
825 'wxNotebook': xxxNotebook
,
826 'wxSplitterWindow': xxxSplitterWindow
,
827 'notebookpage': xxxNotebookPage
,
828 'wxHtmlWindow': xxxHtmlWindow
,
829 'wxCalendarCtrl': xxxCalendarCtrl
,
830 'wxGenericDirCtrl': xxxGenericDirCtrl
,
831 'wxSpinCtrl': xxxSpinCtrl
,
832 'wxScrolledWindow': xxxScrolledWindow
,
834 'wxBoxSizer': xxxBoxSizer
,
835 'wxStaticBoxSizer': xxxStaticBoxSizer
,
836 'wxGridSizer': xxxGridSizer
,
837 'wxFlexGridSizer': xxxFlexGridSizer
,
838 'wxGridBagSizer': xxxGridBagSizer
,
839 'wxStdDialogButtonSizer': xxxStdDialogButtonSizer
,
840 'sizeritem': xxxSizerItem
,
843 'wxMenuBar': xxxMenuBar
,
845 'wxMenuItem': xxxMenuItem
,
846 'separator': xxxSeparator
,
848 'unknown': xxxUnknown
,
851 # Create IDs for all parameters of all classes
852 paramIDs
= {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(),
853 'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(),
854 'tooltip': wxNewId(), 'encoding': wxNewId(),
855 'cellpos': wxNewId(), 'cellspan': wxNewId()
857 for cl
in xxxDict
.values():
859 for param
in cl
.allParams
+ cl
.paramDict
.keys():
860 if not paramIDs
.has_key(param
):
861 paramIDs
[param
] = wxNewId()
863 ################################################################################
866 # Test for object elements
868 return node
.nodeType
== minidom
.Node
.ELEMENT_NODE
and node
.tagName
== 'object'
870 # Make XXX object from some DOM object, selecting correct class
871 def MakeXXXFromDOM(parent
, element
):
873 klass
= xxxDict
[element
.getAttribute('class')]
875 # If we encounter a weird class, use unknown template
876 print 'WARNING: unsupported class:', element
.getAttribute('class')
878 return klass(parent
, element
)
880 # Make empty DOM element
881 def MakeEmptyDOM(className
):
882 elem
= g
.tree
.dom
.createElement('object')
883 elem
.setAttribute('class', className
)
884 # Set required and default parameters
885 xxxClass
= xxxDict
[className
]
886 defaultNotRequired
= filter(lambda x
, l
=xxxClass
.required
: x
not in l
,
887 xxxClass
.default
.keys())
888 for param
in xxxClass
.required
+ defaultNotRequired
:
889 textElem
= g
.tree
.dom
.createElement(param
)
891 textNode
= g
.tree
.dom
.createTextNode(xxxClass
.default
[param
])
893 textNode
= g
.tree
.dom
.createTextNode('')
894 textElem
.appendChild(textNode
)
895 elem
.appendChild(textElem
)
898 # Make empty XXX object
899 def MakeEmptyXXX(parent
, className
):
900 # Make corresponding DOM object first
901 elem
= MakeEmptyDOM(className
)
902 # If parent is a sizer, we should create sizeritem object, except for spacers
904 if parent
.isSizer
and className
!= 'spacer':
905 sizerItemElem
= MakeEmptyDOM('sizeritem')
906 sizerItemElem
.appendChild(elem
)
908 elif isinstance(parent
, xxxNotebook
):
909 pageElem
= MakeEmptyDOM('notebookpage')
910 pageElem
.appendChild(elem
)
912 # Now just make object
913 return MakeXXXFromDOM(parent
, elem
)