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
)
246 # Remove all other nodes
247 # element.removeChild(node)
250 # Check that all required params are set
251 for param
in self
.required
:
252 if not self
.params
.has_key(param
):
253 # If default is specified, set it
254 if self
.default
.has_key(param
):
255 elem
= g
.tree
.dom
.createElement(param
)
256 if param
== 'content':
257 if self
.className
== 'wxCheckListBox':
258 self
.params
[param
] = xxxParamContentCheckList(elem
)
260 self
.params
[param
] = xxxParamContent(elem
)
262 self
.params
[param
] = xxxParam(elem
)
263 # Find place to put new element: first present element after param
265 paramStyles
= self
.allParams
+ self
.styles
266 for p
in paramStyles
[paramStyles
.index(param
) + 1:]:
267 # Content params don't have same type
268 if self
.params
.has_key(p
) and p
!= 'content':
272 nextTextElem
= self
.params
[p
].node
273 self
.element
.insertBefore(elem
, nextTextElem
)
275 self
.element
.appendChild(elem
)
277 wxLogWarning('Required parameter %s of %s missing' %
278 (param
, self
.className
))
279 # Returns real tree object
280 def treeObject(self
):
281 if self
.hasChild
: return self
.child
283 # Returns tree image index
285 if self
.hasChild
: return self
.child
.treeImage()
287 # Class name plus wx name
289 if self
.hasChild
: return self
.child
.treeName()
290 if self
.subclass
: className
= self
.subclass
291 else: className
= self
.className
292 if self
.hasName
and self
.name
: return className
+ ' "' + self
.name
+ '"'
294 # Class name or subclass
296 if self
.subclass
: return self
.subclass
+ '(' + self
.className
+ ')'
297 else: return self
.className
299 ################################################################################
301 # This is a little special: it is both xxxObject and xxxNode
302 class xxxParamFont(xxxObject
, xxxNode
):
303 allParams
= ['size', 'family', 'style', 'weight', 'underlined',
305 def __init__(self
, parent
, element
):
306 xxxObject
.__init
__(self
, parent
, element
)
307 xxxNode
.__init
__(self
, element
)
308 self
.parentNode
= parent
# required to behave similar to DOM node
310 for p
in self
.allParams
:
312 v
.append(str(self
.params
[p
].value()))
316 def update(self
, value
):
317 # `value' is a list of strings corresponding to all parameters
319 # Remove old elements first
320 childNodes
= elem
.childNodes
[:]
321 for node
in childNodes
: elem
.removeChild(node
)
325 for param
in self
.allParams
:
327 fontElem
= g
.tree
.dom
.createElement(param
)
328 textNode
= g
.tree
.dom
.createTextNode(value
[i
])
329 self
.params
[param
] = textNode
330 fontElem
.appendChild(textNode
)
331 elem
.appendChild(fontElem
)
338 ################################################################################
340 class xxxContainer(xxxObject
):
344 # Simulate normal parameter for encoding
347 return g
.currentEncoding
348 def update(self
, val
):
349 g
.currentEncoding
= val
351 # Special class for root node
352 class xxxMainNode(xxxContainer
):
353 allParams
= ['encoding']
354 hasStyle
= hasName
= False
355 def __init__(self
, dom
):
356 xxxContainer
.__init
__(self
, None, dom
.documentElement
)
357 self
.className
= 'XML tree'
358 # Reset required parameters after processing XML, because encoding is
360 self
.required
= ['encoding']
361 self
.params
['encoding'] = xxxEncoding()
363 ################################################################################
366 class xxxPanel(xxxContainer
):
367 allParams
= ['pos', 'size', 'style']
368 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
371 class xxxDialog(xxxContainer
):
372 allParams
= ['title', 'centered', 'pos', 'size', 'style']
373 paramDict
= {'centered': ParamBool}
375 default
= {'title': ''}
376 winStyles
= ['wxDEFAULT_DIALOG_STYLE',
377 'wxCAPTION', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX', 'wxCLOSE_BOX',
380 'wxNO_3D', 'wxDIALOG_NO_PARENT']
381 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
384 class xxxFrame(xxxContainer
):
385 allParams
= ['title', 'centered', 'pos', 'size', 'style']
386 paramDict
= {'centered': ParamBool}
388 default
= {'title': ''}
389 winStyles
= ['wxDEFAULT_FRAME_STYLE',
390 'wxCAPTION', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX', 'wxCLOSE_BOX',
392 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
393 'wxFRAME_TOOL_WINDOW', 'wxFRAME_NO_TASKBAR',
394 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_SHAPED'
396 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
399 class xxxTool(xxxObject
):
400 allParams
= ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp', 'label']
401 required
= ['bitmap']
402 paramDict
= {'bitmap2': ParamBitmap, 'toggle': ParamBool}
405 class xxxToolBar(xxxContainer
):
406 allParams
= ['bitmapsize', 'margins', 'packing', 'separation',
407 'pos', 'size', 'style']
409 paramDict
= {'bitmapsize': ParamPosSize
, 'margins': ParamPosSize
,
410 'packing': ParamInt
, 'separation': ParamInt
,
411 'style': ParamNonGenericStyle
}
412 winStyles
= ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL', 'wxTB_TEXT']
414 class xxxWizard(xxxContainer
):
415 allParams
= ['title', 'bitmap', 'pos']
417 default
= {'title': ''}
419 exStyles
= ['wxWIZARD_EX_HELPBUTTON']
421 class xxxWizardPage(xxxContainer
):
422 allParams
= ['bitmap']
426 class xxxWizardPageSimple(xxxContainer
):
427 allParams
= ['bitmap']
431 ################################################################################
434 class xxxBitmap(xxxObject
):
435 allParams
= ['bitmap']
436 required
= ['bitmap']
439 class xxxIcon(xxxObject
):
442 ################################################################################
445 class xxxStaticText(xxxObject
):
446 allParams
= ['label', 'pos', 'size', 'style']
448 default
= {'label': ''}
449 winStyles
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
451 class xxxStaticLine(xxxObject
):
452 allParams
= ['pos', 'size', 'style']
453 winStyles
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
455 class xxxStaticBitmap(xxxObject
):
456 allParams
= ['bitmap', 'pos', 'size', 'style']
457 required
= ['bitmap']
459 class xxxTextCtrl(xxxObject
):
460 allParams
= ['value', 'pos', 'size', 'style']
461 winStyles
= ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
462 'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
463 paramDict
= {'value': ParamMultilineText}
465 class xxxChoice(xxxObject
):
466 allParams
= ['content', 'selection', 'pos', 'size', 'style']
467 required
= ['content']
468 default
= {'content': '[]'}
469 winStyles
= ['wxCB_SORT']
471 class xxxSlider(xxxObject
):
472 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style',
473 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
475 paramDict
= {'value': ParamInt
, 'tickfreq': ParamInt
, 'pagesize': ParamInt
,
476 'linesize': ParamInt
, 'thumb': ParamInt
, 'thumb': ParamInt
,
477 'tick': ParamInt
, 'selmin': ParamInt
, 'selmax': ParamInt
}
478 required
= ['value', 'min', 'max']
479 winStyles
= ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
480 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
481 'wxSL_BOTH', 'wxSL_SELRANGE', 'wxSL_INVERSE']
483 class xxxGauge(xxxObject
):
484 allParams
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
485 paramDict
= {'range': ParamInt
, 'value': ParamInt
,
486 'shadow': ParamInt
, 'bezel': ParamInt
}
487 winStyles
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
489 class xxxScrollBar(xxxObject
):
490 allParams
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
491 paramDict
= {'value': ParamInt
, 'range': ParamInt
, 'thumbsize': ParamInt
,
492 'pagesize': ParamInt
}
493 winStyles
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
495 class xxxListCtrl(xxxObject
):
496 allParams
= ['pos', 'size', 'style']
497 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
498 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
499 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
500 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
502 class xxxTreeCtrl(xxxObject
):
503 allParams
= ['pos', 'size', 'style']
504 winStyles
= ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT',
505 'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE']
507 class xxxHtmlWindow(xxxObject
):
508 allParams
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
509 paramDict
= {'borders': ParamInt, 'htmlcode':ParamMultilineText}
510 winStyles
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
512 class xxxCalendarCtrl(xxxObject
):
513 allParams
= ['pos', 'size', 'style']
515 class xxxNotebook(xxxContainer
):
516 allParams
= ['usenotebooksizer', 'pos', 'size', 'style']
517 paramDict
= {'usenotebooksizer': ParamBool}
518 winStyles
= ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM']
520 class xxxSplitterWindow(xxxContainer
):
521 allParams
= ['orientation', 'sashpos', 'minsize', 'pos', 'size', 'style']
522 paramDict
= {'orientation': ParamOrientation, 'sashpos': ParamUnit, 'minsize': ParamUnit }
523 winStyles
= ['wxSP_3D', 'wxSP_3DSASH', 'wxSP_3DBORDER', 'wxSP_BORDER',
524 'wxSP_NOBORDER', 'wxSP_PERMIT_UNSPLIT', 'wxSP_LIVE_UPDATE',
527 class xxxGenericDirCtrl(xxxObject
):
528 allParams
= ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style']
529 paramDict
= {'defaultfilter': ParamInt}
530 winStyles
= ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
531 'wxDIRCTRL_SHOW_FILTERS', 'wxDIRCTRL_EDIT_LABELS']
533 class xxxScrolledWindow(xxxContainer
):
534 allParams
= ['pos', 'size', 'style']
535 winStyles
= ['wxHSCROLL', 'wxVSCROLL']
537 ################################################################################
540 class xxxButton(xxxObject
):
541 allParams
= ['label', 'default', 'pos', 'size', 'style']
542 paramDict
= {'default': ParamBool}
544 winStyles
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
546 class xxxBitmapButton(xxxObject
):
547 allParams
= ['bitmap', 'selected', 'focus', 'disabled', 'default',
548 'pos', 'size', 'style']
549 required
= ['bitmap']
550 winStyles
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP',
551 'wxBU_RIGHT', 'wxBU_BOTTOM']
553 class xxxRadioButton(xxxObject
):
554 allParams
= ['label', 'value', 'pos', 'size', 'style']
555 paramDict
= {'value': ParamBool}
557 winStyles
= ['wxRB_GROUP']
559 class xxxSpinButton(xxxObject
):
560 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
561 paramDict
= {'value': ParamInt}
562 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
564 class xxxSpinCtrl(xxxObject
):
565 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
566 paramDict
= {'value': ParamInt}
567 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
569 class xxxToggleButton(xxxObject
):
570 allParams
= ['label', 'checked', 'pos', 'size', 'style']
571 paramDict
= {'checked': ParamBool}
574 ################################################################################
577 class xxxStaticBox(xxxObject
):
578 allParams
= ['label', 'pos', 'size', 'style']
581 class xxxRadioBox(xxxObject
):
582 allParams
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
583 paramDict
= {'dimension': ParamInt}
584 required
= ['label', 'content']
585 default
= {'content': '[]'}
586 winStyles
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS']
588 class xxxCheckBox(xxxObject
):
589 allParams
= ['label', 'checked', 'pos', 'size', 'style']
590 paramDict
= {'checked': ParamBool}
591 winStyles
= ['wxCHK_2STATE', 'wxCHK_3STATE', 'wxCHK_ALLOW_3RD_STATE_FOR_USER',
595 class xxxComboBox(xxxObject
):
596 allParams
= ['content', 'selection', 'value', 'pos', 'size', 'style']
597 required
= ['content']
598 default
= {'content': '[]'}
599 winStyles
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
601 class xxxListBox(xxxObject
):
602 allParams
= ['content', 'selection', 'pos', 'size', 'style']
603 required
= ['content']
604 default
= {'content': '[]'}
605 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
606 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
608 class xxxCheckList(xxxObject
):
609 allParams
= ['content', 'pos', 'size', 'style']
610 required
= ['content']
611 default
= {'content': '[]'}
612 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
613 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
614 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
615 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
616 paramDict
= {'content': ParamContentCheckList}
618 ################################################################################
621 class xxxSizer(xxxContainer
):
622 hasName
= hasStyle
= False
623 paramDict
= {'orient': ParamOrient}
626 class xxxBoxSizer(xxxSizer
):
627 allParams
= ['orient']
628 required
= ['orient']
629 default
= {'orient': 'wxVERTICAL'}
630 # Tree icon depends on orientation
632 if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
633 else: return self
.imageV
635 class xxxStaticBoxSizer(xxxBoxSizer
):
636 allParams
= ['label', 'orient']
637 required
= ['label', 'orient']
639 class xxxGridSizer(xxxSizer
):
640 allParams
= ['cols', 'rows', 'vgap', 'hgap']
642 default
= {'cols': '2', 'rows': '2'}
644 class xxxStdDialogButtonSizer(xxxSizer
):
647 # For repeated parameters
649 def __init__(self
, node
):
651 self
.l
, self
.data
= [], []
652 def append(self
, param
):
654 self
.data
.append(param
.value())
660 self
.l
, self
.data
= [], []
662 class xxxFlexGridSizer(xxxGridSizer
):
663 specials
= ['growablecols', 'growablerows']
664 allParams
= ['cols', 'rows', '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 class xxxGridBagSizer(xxxSizer
):
685 specials
= ['growablecols', 'growablerows']
686 allParams
= ['vgap', 'hgap'] + specials
687 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
688 # Special processing for growable* parameters
689 # (they are represented by several nodes)
690 def special(self
, tag
, node
):
691 if not self
.params
.has_key(tag
):
692 # Create new multi-group
693 self
.params
[tag
] = xxxParamMulti(node
)
694 self
.params
[tag
].append(xxxParamInt(node
))
695 def setSpecial(self
, param
, value
):
696 # Straightforward implementation: remove, add again
697 self
.params
[param
].remove()
698 del self
.params
[param
]
700 node
= g
.tree
.dom
.createElement(param
)
701 text
= g
.tree
.dom
.createTextNode(str(i
))
702 node
.appendChild(text
)
703 self
.element
.appendChild(node
)
704 self
.special(param
, node
)
706 # Container with only one child.
708 class xxxChildContainer(xxxObject
):
709 hasName
= hasStyle
= False
711 def __init__(self
, parent
, element
):
712 xxxObject
.__init
__(self
, parent
, element
)
713 # Must have one child with 'object' tag, but we don't check it
714 nodes
= element
.childNodes
[:] # create copy
716 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
717 if node
.tagName
== 'object':
718 # Create new xxx object for child node
719 self
.child
= MakeXXXFromDOM(self
, node
)
720 self
.child
.parent
= parent
721 # Copy hasChildren and isSizer attributes
722 self
.hasChildren
= self
.child
.hasChildren
723 self
.isSizer
= self
.child
.isSizer
726 element
.removeChild(node
)
728 assert 0, 'no child found'
730 class xxxSizerItem(xxxChildContainer
):
731 allParams
= ['option', 'flag', 'border', 'minsize', 'ratio']
732 paramDict
= {'option': ParamInt, 'minsize': ParamPosSize, 'ratio': ParamPosSize}
733 #default = {'cellspan': '1,1'}
734 def __init__(self
, parent
, element
):
735 # For GridBag sizer items, extra parameters added
736 if isinstance(parent
, xxxGridBagSizer
):
737 self
.allParams
= self
.allParams
+ ['cellpos', 'cellspan']
738 xxxChildContainer
.__init
__(self
, parent
, element
)
739 # Remove pos parameter - not needed for sizeritems
740 if 'pos' in self
.child
.allParams
:
741 self
.child
.allParams
= self
.child
.allParams
[:]
742 self
.child
.allParams
.remove('pos')
744 class xxxNotebookPage(xxxChildContainer
):
745 allParams
= ['label', 'selected']
746 paramDict
= {'selected': ParamBool}
748 def __init__(self
, parent
, element
):
749 xxxChildContainer
.__init
__(self
, parent
, element
)
750 # pos and size dont matter for notebookpages
751 if 'pos' in self
.child
.allParams
:
752 self
.child
.allParams
= self
.child
.allParams
[:]
753 self
.child
.allParams
.remove('pos')
754 if 'size' in self
.child
.allParams
:
755 self
.child
.allParams
= self
.child
.allParams
[:]
756 self
.child
.allParams
.remove('size')
758 class xxxSpacer(xxxObject
):
759 hasName
= hasStyle
= False
760 allParams
= ['size', 'option', 'flag', 'border']
761 paramDict
= {'option': ParamInt}
762 default
= {'size': '0,0'}
764 class xxxMenuBar(xxxContainer
):
765 allParams
= ['style']
766 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
767 winStyles
= ['wxMB_DOCKABLE']
769 class xxxMenu(xxxContainer
):
770 allParams
= ['label', 'help', 'style']
771 default
= {'label': ''}
772 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
773 winStyles
= ['wxMENU_TEAROFF']
775 class xxxMenuItem(xxxObject
):
776 allParams
= ['label', 'bitmap', 'accel', 'help',
777 'checkable', 'radio', 'enabled', 'checked']
778 default
= {'label': ''}
781 class xxxSeparator(xxxObject
):
782 hasName
= hasStyle
= False
784 ################################################################################
787 class xxxUnknown(xxxObject
):
788 allParams
= ['pos', 'size', 'style']
789 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
791 ################################################################################
795 'wxDialog': xxxDialog
,
798 'wxToolBar': xxxToolBar
,
799 'wxWizard': xxxWizard
,
800 'wxWizardPage': xxxWizardPage
,
801 'wxWizardPageSimple': xxxWizardPageSimple
,
803 'wxBitmap': xxxBitmap
,
806 'wxButton': xxxButton
,
807 'wxBitmapButton': xxxBitmapButton
,
808 'wxRadioButton': xxxRadioButton
,
809 'wxSpinButton': xxxSpinButton
,
810 'wxToggleButton' : xxxToggleButton
,
812 'wxStaticBox': xxxStaticBox
,
813 'wxStaticBitmap': xxxStaticBitmap
,
814 'wxRadioBox': xxxRadioBox
,
815 'wxComboBox': xxxComboBox
,
816 'wxCheckBox': xxxCheckBox
,
817 'wxListBox': xxxListBox
,
819 'wxStaticText': xxxStaticText
,
820 'wxStaticLine': xxxStaticLine
,
821 'wxTextCtrl': xxxTextCtrl
,
822 'wxChoice': xxxChoice
,
823 'wxSlider': xxxSlider
,
825 'wxScrollBar': xxxScrollBar
,
826 'wxTreeCtrl': xxxTreeCtrl
,
827 'wxListCtrl': xxxListCtrl
,
828 'wxCheckListBox': xxxCheckList
,
829 'wxNotebook': xxxNotebook
,
830 'wxSplitterWindow': xxxSplitterWindow
,
831 'notebookpage': xxxNotebookPage
,
832 'wxHtmlWindow': xxxHtmlWindow
,
833 'wxCalendarCtrl': xxxCalendarCtrl
,
834 'wxGenericDirCtrl': xxxGenericDirCtrl
,
835 'wxSpinCtrl': xxxSpinCtrl
,
836 'wxScrolledWindow': xxxScrolledWindow
,
838 'wxBoxSizer': xxxBoxSizer
,
839 'wxStaticBoxSizer': xxxStaticBoxSizer
,
840 'wxGridSizer': xxxGridSizer
,
841 'wxFlexGridSizer': xxxFlexGridSizer
,
842 'wxGridBagSizer': xxxGridBagSizer
,
843 'wxStdDialogButtonSizer': xxxStdDialogButtonSizer
,
844 'sizeritem': xxxSizerItem
,
847 'wxMenuBar': xxxMenuBar
,
849 'wxMenuItem': xxxMenuItem
,
850 'separator': xxxSeparator
,
852 'unknown': xxxUnknown
,
855 # Create IDs for all parameters of all classes
856 paramIDs
= {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(),
857 'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(),
858 'tooltip': wxNewId(), 'encoding': wxNewId(),
859 'cellpos': wxNewId(), 'cellspan': wxNewId()
861 for cl
in xxxDict
.values():
863 for param
in cl
.allParams
+ cl
.paramDict
.keys():
864 if not paramIDs
.has_key(param
):
865 paramIDs
[param
] = wxNewId()
867 ################################################################################
870 # Test for object elements
872 return node
.nodeType
== minidom
.Node
.ELEMENT_NODE
and node
.tagName
== 'object'
874 # Make XXX object from some DOM object, selecting correct class
875 def MakeXXXFromDOM(parent
, element
):
877 klass
= xxxDict
[element
.getAttribute('class')]
879 # If we encounter a weird class, use unknown template
880 print 'WARNING: unsupported class:', element
.getAttribute('class')
882 return klass(parent
, element
)
884 # Make empty DOM element
885 def MakeEmptyDOM(className
):
886 elem
= g
.tree
.dom
.createElement('object')
887 elem
.setAttribute('class', className
)
888 # Set required and default parameters
889 xxxClass
= xxxDict
[className
]
890 defaultNotRequired
= filter(lambda x
, l
=xxxClass
.required
: x
not in l
,
891 xxxClass
.default
.keys())
892 for param
in xxxClass
.required
+ defaultNotRequired
:
893 textElem
= g
.tree
.dom
.createElement(param
)
895 textNode
= g
.tree
.dom
.createTextNode(xxxClass
.default
[param
])
897 textNode
= g
.tree
.dom
.createTextNode('')
898 textElem
.appendChild(textNode
)
899 elem
.appendChild(textElem
)
902 # Make empty XXX object
903 def MakeEmptyXXX(parent
, className
):
904 # Make corresponding DOM object first
905 elem
= MakeEmptyDOM(className
)
906 # If parent is a sizer, we should create sizeritem object, except for spacers
908 if parent
.isSizer
and className
!= 'spacer':
909 sizerItemElem
= MakeEmptyDOM('sizeritem')
910 sizerItemElem
.appendChild(elem
)
912 elif isinstance(parent
, xxxNotebook
):
913 pageElem
= MakeEmptyDOM('notebookpage')
914 pageElem
.appendChild(elem
)
916 # Now just make object
917 return MakeXXXFromDOM(parent
, elem
)