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 currentEncoding
= wxLocale_GetSystemEncodingName()
12 if not currentEncoding
:
13 currentEncoding
= 'ascii'
15 # Base class for interface parameter classes
17 def __init__(self
, node
):
20 self
.node
.parentNode
.removeChild(self
.node
)
23 # Generic (text) parameter class
24 class xxxParam(xxxNode
):
25 # Standard use: for text nodes
26 def __init__(self
, node
):
27 xxxNode
.__init
__(self
, node
)
28 if not node
.hasChildNodes():
29 # If does not have child nodes, create empty text node
30 text
= g
.tree
.dom
.createTextNode('')
31 node
.appendChild(text
)
33 text
= node
.childNodes
[0] # first child must be text node
34 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
35 # Use convertion from unicode to current encoding
37 # Value returns string
38 if wxUSE_UNICODE
: # no conversion is needed
40 return self
.textNode
.data
41 def update(self
, value
):
42 self
.textNode
.data
= value
45 return self
.textNode
.data
.encode(currentEncoding
)
46 def update(self
, value
):
47 self
.textNode
.data
= unicode(value
, currentEncoding
)
50 class xxxParamInt(xxxParam
):
51 # Standard use: for text nodes
52 def __init__(self
, node
):
53 xxxParam
.__init
__(self
, node
)
54 # Value returns string
57 return int(self
.textNode
.data
)
59 return -1 # invalid value
60 def update(self
, value
):
61 self
.textNode
.data
= str(value
)
64 class xxxParamContent(xxxNode
):
65 def __init__(self
, node
):
66 xxxNode
.__init
__(self
, node
)
67 data
, l
= [], [] # data is needed to quicker value retrieval
68 nodes
= node
.childNodes
[:] # make a copy of the child list
70 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
71 assert n
.tagName
== 'item', 'bad content content'
72 if not n
.hasChildNodes():
73 # If does not have child nodes, create empty text node
74 text
= g
.tree
.dom
.createTextNode('')
75 node
.appendChild(text
)
78 text
= n
.childNodes
[0] # first child must be text node
79 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
81 data
.append(str(text
.data
))
85 self
.l
, self
.data
= l
, data
88 def update(self
, value
):
89 # If number if items is not the same, recreate children
90 if len(value
) != len(self
.l
): # remove first if number of items has changed
91 childNodes
= self
.node
.childNodes
[:]
93 self
.node
.removeChild(n
)
96 itemElem
= g
.tree
.dom
.createElement('item')
97 itemText
= g
.tree
.dom
.createTextNode(str)
98 itemElem
.appendChild(itemText
)
99 self
.node
.appendChild(itemElem
)
103 for i
in range(len(value
)):
104 self
.l
[i
].data
= value
[i
]
107 # Content parameter for checklist
108 class xxxParamContentCheckList(xxxNode
):
109 def __init__(self
, node
):
110 xxxNode
.__init
__(self
, node
)
111 data
, l
= [], [] # data is needed to quicker value retrieval
112 nodes
= node
.childNodes
[:] # make a copy of the child list
114 if n
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
115 assert n
.tagName
== 'item', 'bad content content'
116 checked
= n
.getAttribute('checked')
117 if not checked
: checked
= 0
118 if not n
.hasChildNodes():
119 # If does not have child nodes, create empty text node
120 text
= g
.tree
.dom
.createTextNode('')
121 node
.appendChild(text
)
124 text
= n
.childNodes
[0] # first child must be text node
125 assert text
.nodeType
== minidom
.Node
.TEXT_NODE
127 data
.append((str(text
.data
), int(checked
)))
131 self
.l
, self
.data
= l
, data
134 def update(self
, value
):
135 # If number if items is not the same, recreate children
136 if len(value
) != len(self
.l
): # remove first if number of items has changed
137 childNodes
= self
.node
.childNodes
[:]
139 self
.node
.removeChild(n
)
142 itemElem
= g
.tree
.dom
.createElement('item')
143 # Add checked only if True
144 if ch
: itemElem
.setAttribute('checked', '1')
145 itemText
= g
.tree
.dom
.createTextNode(s
)
146 itemElem
.appendChild(itemText
)
147 self
.node
.appendChild(itemElem
)
148 l
.append((itemText
, itemElem
))
151 for i
in range(len(value
)):
152 self
.l
[i
][0].data
= value
[i
][0]
153 self
.l
[i
][1].setAttribute('checked', str(value
[i
][1]))
157 class xxxParamBitmap(xxxParam
):
158 def __init__(self
, node
):
159 xxxParam
.__init
__(self
, node
)
160 self
.stock_id
= node
.getAttribute('stock_id')
162 return [self
.stock_id
, xxxParam
.value(self
)]
163 def update(self
, value
):
164 self
.stock_id
= value
[0]
166 self
.node
.setAttribute('stock_id', self
.stock_id
)
168 self
.node
.removeAttribute('stock_id')
169 xxxParam
.update(self
, value
[1])
171 ################################################################################
173 # Classes to interface DOM objects
176 hasChildren
= False # has children elements?
177 hasStyle
= True # almost everyone
178 hasName
= True # has name attribute?
179 isSizer
= hasChild
= False
180 allParams
= None # Some nodes have no parameters
181 # Style parameters (all optional)
182 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'tooltip']
186 bitmapTags
= ['bitmap', 'bitmap2', 'icon']
187 # Required paremeters: none by default
189 # Default parameters with default values
193 # Window styles and extended styles
197 # Construct a new xxx object from DOM element
198 # parent is parent xxx object (or None if none), element is DOM element object
199 def __init__(self
, parent
, element
):
201 self
.element
= element
204 self
.className
= element
.getAttribute('class')
205 if self
.hasName
: self
.name
= element
.getAttribute('name')
206 # Set parameters (text element children)
208 nodes
= element
.childNodes
[:]
210 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
213 continue # do nothing for object children here
214 if tag
not in self
.allParams
and tag
not in self
.styles
:
215 print 'WARNING: unknown parameter for %s: %s' % \
216 (self
.className
, tag
)
217 elif tag
in self
.specials
:
218 self
.special(tag
, node
)
219 elif tag
== 'content':
220 if self
.className
== 'wxCheckList':
221 self
.params
[tag
] = xxxParamContentCheckList(node
)
223 self
.params
[tag
] = xxxParamContent(node
)
224 elif tag
== 'font': # has children
225 self
.params
[tag
] = xxxParamFont(element
, node
)
226 elif tag
in self
.bitmapTags
:
227 # Can have attributes
228 self
.params
[tag
] = xxxParamBitmap(node
)
229 else: # simple parameter
230 self
.params
[tag
] = xxxParam(node
)
232 # Remove all other nodes
233 element
.removeChild(node
)
235 # Check that all required params are set
236 for param
in self
.required
:
237 if not self
.params
.has_key(param
):
238 # If default is specified, set it
239 if self
.default
.has_key(param
):
240 elem
= g
.tree
.dom
.createElement(param
)
241 self
.params
[param
] = xxxParam(elem
)
242 # Find place to put new element: first present element after param
244 paramStyles
= self
.allParams
+ self
.styles
245 for p
in paramStyles
[paramStyles
.index(param
) + 1:]:
246 # Content params don't have same type
247 if self
.params
.has_key(p
) and p
!= 'content':
251 nextTextElem
= self
.params
[p
].node
252 self
.element
.insertBefore(elem
, nextTextElem
)
254 self
.element
.appendChild(elem
)
256 wxLogWarning('Required parameter %s of %s missing' %
257 (param
, self
.className
))
258 # Returns real tree object
259 def treeObject(self
):
260 if self
.hasChild
: return self
.child
262 # Returns tree image index
264 if self
.hasChild
: return self
.child
.treeImage()
266 # Class name plus wx name
268 if self
.hasChild
: return self
.child
.treeName()
269 if self
.hasName
and self
.name
: return self
.className
+ ' "' + self
.name
+ '"'
270 return self
.className
272 ################################################################################
274 # This is a little special: it is both xxxObject and xxxNode
275 class xxxParamFont(xxxObject
, xxxNode
):
276 allParams
= ['size', 'style', 'weight', 'family', 'underlined',
278 def __init__(self
, parent
, element
):
279 xxxObject
.__init
__(self
, parent
, element
)
280 xxxNode
.__init
__(self
, element
)
281 self
.parentNode
= parent
# required to behave similar to DOM node
283 for p
in self
.allParams
:
285 v
.append(str(self
.params
[p
].value()))
289 def update(self
, value
):
290 # `value' is a list of strings corresponding to all parameters
292 # Remove old elements first
293 childNodes
= elem
.childNodes
[:]
294 for node
in childNodes
: elem
.removeChild(node
)
298 for param
in self
.allParams
:
300 fontElem
= g
.tree
.dom
.createElement(param
)
301 textNode
= g
.tree
.dom
.createTextNode(value
[i
])
302 self
.params
[param
] = textNode
303 fontElem
.appendChild(textNode
)
304 elem
.appendChild(fontElem
)
311 ################################################################################
313 class xxxContainer(xxxObject
):
316 # Simulate normal parameter for encoding
318 def __init__(self
, val
):
322 def update(self
, val
):
325 # Special class for root node
326 class xxxMainNode(xxxContainer
):
327 allParams
= ['encoding']
328 required
= ['encoding']
329 default
= {'encoding': ''}
330 hasStyle
= hasName
= False
331 def __init__(self
, dom
):
332 xxxContainer
.__init
__(self
, None, dom
.documentElement
)
333 self
.className
= 'XML tree'
334 self
.params
['encoding'] = xxxEncoding(dom
.encoding
)
336 ################################################################################
339 class xxxPanel(xxxContainer
):
340 allParams
= ['pos', 'size', 'style']
341 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
343 winStyles
= ['wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
344 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
346 class xxxDialog(xxxContainer
):
347 allParams
= ['title', 'centered', 'pos', 'size', 'style']
348 paramDict
= {'centered': ParamBool}
350 winStyles
= ['wxDEFAULT_DIALOG_STYLE', 'wxSTAY_ON_TOP',
351 'wxDIALOG_MODAL', 'wxDIALOG_MODELESS',
352 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER', 'wxRESIZE_BOX',
354 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
355 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
357 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
359 class xxxFrame(xxxContainer
):
360 allParams
= ['title', 'centered', 'pos', 'size', 'style']
361 paramDict
= {'centered': ParamBool}
363 winStyles
= ['wxDEFAULT_FRAME_STYLE', 'wxDEFAULT_DIALOG_STYLE',
365 'wxCAPTION', 'wxSYSTEM_MENU', 'wxRESIZE_BORDER',
366 'wxRESIZE_BOX', 'wxMINIMIZE_BOX', 'wxMAXIMIZE_BOX',
367 'wxFRAME_FLOAT_ON_PARENT', 'wxFRAME_TOOL_WINDOW',
368 'wxNO_3D', 'wxTAB_TRAVERSAL', 'wxCLIP_CHILDREN']
369 styles
= ['fg', 'bg', 'font', 'enabled', 'focused', 'hidden', 'exstyle',
371 exStyles
= ['wxWS_EX_VALIDATE_RECURSIVELY']
373 class xxxTool(xxxObject
):
374 allParams
= ['bitmap', 'bitmap2', 'toggle', 'tooltip', 'longhelp']
375 required
= ['bitmap']
376 paramDict
= {'bitmap2': ParamBitmap, 'toggle': ParamBool}
379 class xxxToolBar(xxxContainer
):
380 allParams
= ['bitmapsize', 'margins', 'packing', 'separation',
381 'pos', 'size', 'style']
383 paramDict
= {'bitmapsize': ParamPosSize
, 'margins': ParamPosSize
,
384 'packing': ParamInt
, 'separation': ParamInt
,
385 'style': ParamNonGenericStyle
}
386 winStyles
= ['wxTB_FLAT', 'wxTB_DOCKABLE', 'wxTB_VERTICAL', 'wxTB_HORIZONTAL']
388 ################################################################################
391 class xxxBitmap(xxxObject
):
392 allParams
= ['bitmap']
393 required
= ['bitmap']
396 class xxxIcon(xxxObject
):
400 ################################################################################
403 class xxxStaticText(xxxObject
):
404 allParams
= ['label', 'pos', 'size', 'style']
406 default
= {'label': ''}
407 winStyles
= ['wxALIGN_LEFT', 'wxALIGN_RIGHT', 'wxALIGN_CENTRE', 'wxST_NO_AUTORESIZE']
409 class xxxStaticLine(xxxObject
):
410 allParams
= ['pos', 'size', 'style']
411 winStyles
= ['wxLI_HORIZONTAL', 'wxLI_VERTICAL']
413 class xxxStaticBitmap(xxxObject
):
414 allParams
= ['bitmap', 'pos', 'size', 'style']
415 required
= ['bitmap']
417 class xxxTextCtrl(xxxObject
):
418 allParams
= ['value', 'pos', 'size', 'style']
419 winStyles
= ['wxTE_PROCESS_ENTER', 'wxTE_PROCESS_TAB', 'wxTE_MULTILINE',
420 'wxTE_PASSWORD', 'wxTE_READONLY', 'wxHSCROLL']
422 class xxxChoice(xxxObject
):
423 allParams
= ['content', 'selection', 'pos', 'size', 'style']
424 required
= ['content']
425 winStyles
= ['wxCB_SORT']
427 class xxxSlider(xxxObject
):
428 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style',
429 'tickfreq', 'pagesize', 'linesize', 'thumb', 'tick',
431 paramDict
= {'value': ParamInt
, 'tickfreq': ParamInt
, 'pagesize': ParamInt
,
432 'linesize': ParamInt
, 'thumb': ParamInt
, 'thumb': ParamInt
,
433 'tick': ParamInt
, 'selmin': ParamInt
, 'selmax': ParamInt
}
434 required
= ['value', 'min', 'max']
435 winStyles
= ['wxSL_HORIZONTAL', 'wxSL_VERTICAL', 'wxSL_AUTOTICKS', 'wxSL_LABELS',
436 'wxSL_LEFT', 'wxSL_RIGHT', 'wxSL_TOP', 'wxSL_BOTTOM',
437 'wxSL_BOTH', 'wxSL_SELRANGE']
439 class xxxGauge(xxxObject
):
440 allParams
= ['range', 'pos', 'size', 'style', 'value', 'shadow', 'bezel']
441 paramDict
= {'range': ParamInt
, 'value': ParamInt
,
442 'shadow': ParamInt
, 'bezel': ParamInt
}
443 winStyles
= ['wxGA_HORIZONTAL', 'wxGA_VERTICAL', 'wxGA_PROGRESSBAR', 'wxGA_SMOOTH']
445 class xxxScrollBar(xxxObject
):
446 allParams
= ['pos', 'size', 'style', 'value', 'thumbsize', 'range', 'pagesize']
447 paramDict
= {'value': ParamInt
, 'range': ParamInt
, 'thumbsize': ParamInt
,
448 'pagesize': ParamInt
}
449 winStyles
= ['wxSB_HORIZONTAL', 'wxSB_VERTICAL']
451 class xxxListCtrl(xxxObject
):
452 allParams
= ['pos', 'size', 'style']
453 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
454 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
455 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
456 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
458 class xxxTreeCtrl(xxxObject
):
459 allParams
= ['pos', 'size', 'style']
460 winStyles
= ['wxTR_HAS_BUTTONS', 'wxTR_NO_LINES', 'wxTR_LINES_AT_ROOT',
461 'wxTR_EDIT_LABELS', 'wxTR_MULTIPLE']
463 class xxxHtmlWindow(xxxObject
):
464 allParams
= ['pos', 'size', 'style', 'borders', 'url', 'htmlcode']
465 paramDict
= {'borders': ParamInt}
466 winStyles
= ['wxHW_SCROLLBAR_NEVER', 'wxHW_SCROLLBAR_AUTO']
468 class xxxCalendarCtrl(xxxObject
):
469 allParams
= ['pos', 'size', 'style']
471 class xxxNotebook(xxxContainer
):
472 allParams
= ['usenotebooksizer', 'pos', 'size', 'style']
473 paramDict
= {'usenotebooksizer': ParamBool}
474 winStyles
= ['wxNB_FIXEDWIDTH', 'wxNB_LEFT', 'wxNB_RIGHT', 'wxNB_BOTTOM']
476 class xxxGenericDirCtrl(xxxObject
):
477 allParams
= ['defaultfolder', 'filter', 'defaultfilter', 'pos', 'size', 'style']
478 paramDict
= {'defaultfilter': ParamInt}
479 winStyles
= ['wxDIRCTRL_DIR_ONLY', 'wxDIRCTRL_3D_INTERNAL', 'wxDIRCTRL_SELECT_FIRST',
480 'wxDIRCTRL_SHOW_FILTERS', 'wxDIRCTRL_EDIT_LABELS']
482 ################################################################################
485 class xxxButton(xxxObject
):
486 allParams
= ['label', 'default', 'pos', 'size', 'style']
487 paramDict
= {'default': ParamBool}
489 winStyles
= ['wxBU_LEFT', 'wxBU_TOP', 'wxBU_RIGHT', 'wxBU_BOTTOM']
491 class xxxBitmapButton(xxxObject
):
492 allParams
= ['bitmap', 'selected', 'focus', 'disabled', 'default',
493 'pos', 'size', 'style']
494 required
= ['bitmap']
495 winStyles
= ['wxBU_AUTODRAW', 'wxBU_LEFT', 'wxBU_TOP',
496 'wxBU_RIGHT', 'wxBU_BOTTOM']
498 class xxxRadioButton(xxxObject
):
499 allParams
= ['label', 'value', 'pos', 'size', 'style']
500 paramDict
= {'value': ParamBool}
502 winStyles
= ['wxRB_GROUP']
504 class xxxSpinButton(xxxObject
):
505 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
506 paramDict
= {'value': ParamInt}
507 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
509 class xxxSpinCtrl(xxxObject
):
510 allParams
= ['value', 'min', 'max', 'pos', 'size', 'style']
511 paramDict
= {'value': ParamInt}
512 winStyles
= ['wxSP_HORIZONTAL', 'wxSP_VERTICAL', 'wxSP_ARROW_KEYS', 'wxSP_WRAP']
514 ################################################################################
517 class xxxStaticBox(xxxObject
):
518 allParams
= ['label', 'pos', 'size', 'style']
521 class xxxRadioBox(xxxObject
):
522 allParams
= ['label', 'content', 'selection', 'dimension', 'pos', 'size', 'style']
523 paramDict
= {'dimension': ParamInt}
524 required
= ['label', 'content']
525 winStyles
= ['wxRA_SPECIFY_ROWS', 'wxRA_SPECIFY_COLS']
527 class xxxCheckBox(xxxObject
):
528 allParams
= ['label', 'checked', 'pos', 'size', 'style']
529 paramDict
= {'checked': ParamBool}
532 class xxxComboBox(xxxObject
):
533 allParams
= ['content', 'selection', 'value', 'pos', 'size', 'style']
534 required
= ['content']
535 winStyles
= ['wxCB_SIMPLE', 'wxCB_SORT', 'wxCB_READONLY', 'wxCB_DROPDOWN']
537 class xxxListBox(xxxObject
):
538 allParams
= ['content', 'selection', 'pos', 'size', 'style']
539 required
= ['content']
540 winStyles
= ['wxLB_SINGLE', 'wxLB_MULTIPLE', 'wxLB_EXTENDED', 'wxLB_HSCROLL',
541 'wxLB_ALWAYS_SB', 'wxLB_NEEDED_SB', 'wxLB_SORT']
543 class xxxCheckList(xxxObject
):
544 allParams
= ['content', 'pos', 'size', 'style']
545 required
= ['content']
546 winStyles
= ['wxLC_LIST', 'wxLC_REPORT', 'wxLC_ICON', 'wxLC_SMALL_ICON',
547 'wxLC_ALIGN_TOP', 'wxLC_ALIGN_LEFT', 'wxLC_AUTOARRANGE',
548 'wxLC_USER_TEXT', 'wxLC_EDIT_LABELS', 'wxLC_NO_HEADER',
549 'wxLC_SINGLE_SEL', 'wxLC_SORT_ASCENDING', 'wxLC_SORT_DESCENDING']
550 paramDict
= {'content': ParamContentCheckList}
552 ################################################################################
555 class xxxSizer(xxxContainer
):
556 hasName
= hasStyle
= False
557 paramDict
= {'orient': ParamOrient}
560 class xxxBoxSizer(xxxSizer
):
561 allParams
= ['orient']
562 required
= ['orient']
563 default
= {'orient': 'wxVERTICAL'}
564 # Tree icon depends on orientation
566 if self
.params
['orient'].value() == 'wxHORIZONTAL': return self
.imageH
567 else: return self
.imageV
569 class xxxStaticBoxSizer(xxxBoxSizer
):
570 allParams
= ['label', 'orient']
571 required
= ['label', 'orient']
573 class xxxGridSizer(xxxSizer
):
574 allParams
= ['cols', 'rows', 'vgap', 'hgap']
576 default
= {'cols': '2', 'rows': '2'}
578 # For repeated parameters
580 def __init__(self
, node
):
582 self
.l
, self
.data
= [], []
583 def append(self
, param
):
585 self
.data
.append(param
.value())
591 self
.l
, self
.data
= [], []
593 class xxxFlexGridSizer(xxxGridSizer
):
594 specials
= ['growablecols', 'growablerows']
595 allParams
= ['cols', 'rows', 'vgap', 'hgap'] + specials
596 paramDict
= {'growablecols':ParamIntList, 'growablerows':ParamIntList}
597 # Special processing for growable* parameters
598 # (they are represented by several nodes)
599 def special(self
, tag
, node
):
600 if not self
.params
.has_key(tag
):
601 # Create new multi-group
602 self
.params
[tag
] = xxxParamMulti(node
)
603 self
.params
[tag
].append(xxxParamInt(node
))
604 def setSpecial(self
, param
, value
):
605 # Straightforward implementation: remove, add again
606 self
.params
[param
].remove()
607 del self
.params
[param
]
609 node
= g
.tree
.dom
.createElement(param
)
610 text
= g
.tree
.dom
.createTextNode(str(i
))
611 node
.appendChild(text
)
612 self
.element
.appendChild(node
)
613 self
.special(param
, node
)
615 # Container with only one child.
617 class xxxChildContainer(xxxObject
):
618 hasName
= hasStyle
= False
620 def __init__(self
, parent
, element
):
621 xxxObject
.__init
__(self
, parent
, element
)
622 # Must have one child with 'object' tag, but we don't check it
623 nodes
= element
.childNodes
[:] # create copy
625 if node
.nodeType
== minidom
.Node
.ELEMENT_NODE
:
626 if node
.tagName
== 'object':
627 # Create new xxx object for child node
628 self
.child
= MakeXXXFromDOM(self
, node
)
629 self
.child
.parent
= parent
630 # Copy hasChildren and isSizer attributes
631 self
.hasChildren
= self
.child
.hasChildren
632 self
.isSizer
= self
.child
.isSizer
635 element
.removeChild(node
)
637 assert 0, 'no child found'
639 class xxxSizerItem(xxxChildContainer
):
640 allParams
= ['option', 'flag', 'border', 'minsize']
641 paramDict
= {'option': ParamInt, 'minsize': ParamPosSize}
642 def __init__(self
, parent
, element
):
643 xxxChildContainer
.__init
__(self
, parent
, element
)
644 # Remove pos parameter - not needed for sizeritems
645 if 'pos' in self
.child
.allParams
:
646 self
.child
.allParams
= self
.child
.allParams
[:]
647 self
.child
.allParams
.remove('pos')
649 class xxxNotebookPage(xxxChildContainer
):
650 allParams
= ['label', 'selected']
651 paramDict
= {'selected': ParamBool}
653 def __init__(self
, parent
, element
):
654 xxxChildContainer
.__init
__(self
, parent
, element
)
655 # pos and size dont matter for notebookpages
656 if 'pos' in self
.child
.allParams
:
657 self
.child
.allParams
= self
.child
.allParams
[:]
658 self
.child
.allParams
.remove('pos')
659 if 'size' in self
.child
.allParams
:
660 self
.child
.allParams
= self
.child
.allParams
[:]
661 self
.child
.allParams
.remove('size')
663 class xxxSpacer(xxxObject
):
664 hasName
= hasStyle
= False
665 allParams
= ['size', 'option', 'flag', 'border']
666 paramDict
= {'option': ParamInt}
667 default
= {'size': '0,0'}
669 class xxxMenuBar(xxxContainer
):
670 allParams
= ['style']
671 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
672 winStyles
= ['wxMB_DOCKABLE']
674 class xxxMenu(xxxContainer
):
675 allParams
= ['label', 'help', 'style']
676 default
= {'label': ''}
677 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
678 winStyles
= ['wxMENU_TEAROFF']
680 class xxxMenuItem(xxxObject
):
681 allParams
= ['label', 'bitmap', 'accel', 'help',
682 'checkable', 'radio', 'enabled', 'checked']
683 default
= {'label': ''}
686 class xxxSeparator(xxxObject
):
687 hasName
= hasStyle
= False
689 ################################################################################
692 class xxxUnknown(xxxObject
):
693 allParams
= ['pos', 'size', 'style']
694 paramDict
= {'style': ParamNonGenericStyle}
# no generic styles
696 ################################################################################
700 'wxDialog': xxxDialog
,
703 'wxToolBar': xxxToolBar
,
705 'wxBitmap': xxxBitmap
,
708 'wxButton': xxxButton
,
709 'wxBitmapButton': xxxBitmapButton
,
710 'wxRadioButton': xxxRadioButton
,
711 'wxSpinButton': xxxSpinButton
,
713 'wxStaticBox': xxxStaticBox
,
714 'wxStaticBitmap': xxxStaticBitmap
,
715 'wxRadioBox': xxxRadioBox
,
716 'wxComboBox': xxxComboBox
,
717 'wxCheckBox': xxxCheckBox
,
718 'wxListBox': xxxListBox
,
720 'wxStaticText': xxxStaticText
,
721 'wxStaticLine': xxxStaticLine
,
722 'wxTextCtrl': xxxTextCtrl
,
723 'wxChoice': xxxChoice
,
724 'wxSlider': xxxSlider
,
726 'wxScrollBar': xxxScrollBar
,
727 'wxTreeCtrl': xxxTreeCtrl
,
728 'wxListCtrl': xxxListCtrl
,
729 'wxCheckList': xxxCheckList
,
730 'wxNotebook': xxxNotebook
,
731 'notebookpage': xxxNotebookPage
,
732 'wxHtmlWindow': xxxHtmlWindow
,
733 'wxCalendarCtrl': xxxCalendarCtrl
,
734 'wxGenericDirCtrl': xxxGenericDirCtrl
,
735 'wxSpinCtrl': xxxSpinCtrl
,
737 'wxBoxSizer': xxxBoxSizer
,
738 'wxStaticBoxSizer': xxxStaticBoxSizer
,
739 'wxGridSizer': xxxGridSizer
,
740 'wxFlexGridSizer': xxxFlexGridSizer
,
741 'sizeritem': xxxSizerItem
,
744 'wxMenuBar': xxxMenuBar
,
746 'wxMenuItem': xxxMenuItem
,
747 'separator': xxxSeparator
,
749 'unknown': xxxUnknown
,
752 # Create IDs for all parameters of all classes
753 paramIDs
= {'fg': wxNewId(), 'bg': wxNewId(), 'exstyle': wxNewId(), 'font': wxNewId(),
754 'enabled': wxNewId(), 'focused': wxNewId(), 'hidden': wxNewId(),
755 'tooltip': wxNewId(), 'encoding': wxNewId()
757 for cl
in xxxDict
.values():
759 for param
in cl
.allParams
+ cl
.paramDict
.keys():
760 if not paramIDs
.has_key(param
):
761 paramIDs
[param
] = wxNewId()
763 ################################################################################
766 # Test for object elements
768 return node
.nodeType
== minidom
.Node
.ELEMENT_NODE
and node
.tagName
== 'object'
770 # Make XXX object from some DOM object, selecting correct class
771 def MakeXXXFromDOM(parent
, element
):
773 klass
= xxxDict
[element
.getAttribute('class')]
775 # Verify that it's not recursive exception
776 print 'ERROR: unknown class:', element
.getAttribute('class')
778 return klass(parent
, element
)
780 # Make empty DOM element
781 def MakeEmptyDOM(className
):
782 elem
= g
.tree
.dom
.createElement('object')
783 elem
.setAttribute('class', className
)
784 # Set required and default parameters
785 xxxClass
= xxxDict
[className
]
786 defaultNotRequired
= filter(lambda x
, l
=xxxClass
.required
: x
not in l
,
787 xxxClass
.default
.keys())
788 for param
in xxxClass
.required
+ defaultNotRequired
:
789 textElem
= g
.tree
.dom
.createElement(param
)
791 textNode
= g
.tree
.dom
.createTextNode(xxxClass
.default
[param
])
793 textNode
= g
.tree
.dom
.createTextNode('')
794 textElem
.appendChild(textNode
)
795 elem
.appendChild(textElem
)
798 # Make empty XXX object
799 def MakeEmptyXXX(parent
, className
):
800 # Make corresponding DOM object first
801 elem
= MakeEmptyDOM(className
)
802 # If parent is a sizer, we should create sizeritem object, except for spacers
804 if parent
.isSizer
and className
!= 'spacer':
805 sizerItemElem
= MakeEmptyDOM('sizeritem')
806 sizerItemElem
.appendChild(elem
)
808 elif isinstance(parent
, xxxNotebook
):
809 pageElem
= MakeEmptyDOM('notebookpage')
810 pageElem
.appendChild(elem
)
812 # Now just make object
813 return MakeXXXFromDOM(parent
, elem
)