Update XRCed to 0.0.7-5

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17372 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2002-09-24 18:34:21 +00:00
parent 4b6cc55fd6
commit 74f4b82837
4 changed files with 102 additions and 72 deletions

View File

@@ -26,6 +26,7 @@ contrib/src/xrc/xmlrsall.cpp
> AddHandler(new wxListCtrlXmlHandler); > AddHandler(new wxListCtrlXmlHandler);
> #if wxUSE_CHECKLISTBOX > #if wxUSE_CHECKLISTBOX
This is fixed in CVS.
0.0.6 0.0.6
----- -----

View File

@@ -109,7 +109,7 @@ class ParamBinaryOr(PPanel):
class ParamFlag(ParamBinaryOr): class ParamFlag(ParamBinaryOr):
values = ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL', values = ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL',
'wxEXPAND', 'wxSHAPED', 'wxALIGN_CENTRE', 'wxALIGN_RIGHT', 'wxEXPAND', 'wxGROW', 'wxSHAPED', 'wxALIGN_CENTRE', 'wxALIGN_RIGHT',
'wxALIGN_BOTTOM', 'wxALIGN_CENTRE_VERTICAL', 'wxALIGN_BOTTOM', 'wxALIGN_CENTRE_VERTICAL',
'wxALIGN_CENTRE_HORIZONTAL'] 'wxALIGN_CENTRE_HORIZONTAL']
equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE', equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE',

View File

@@ -8,8 +8,7 @@ from wxPython.wx import *
from wxPython.xrc import * from wxPython.xrc import *
from wxPython.html import wxHtmlWindow from wxPython.html import wxHtmlWindow
from xml.dom import minidom from xml.dom import minidom
import os import os, sys, getopt, traceback
import getopt
# Icons # Icons
import images import images
@@ -27,7 +26,7 @@ else:
modernFont = wxFont(10, wxMODERN, wxNORMAL, wxNORMAL) modernFont = wxFont(10, wxMODERN, wxNORMAL, wxNORMAL)
progname = 'XRCed' progname = 'XRCed'
version = '0.0.7-3' version = '0.0.7-5'
# Local modules # Local modules
from xxx import * from xxx import *
@@ -294,7 +293,7 @@ class PropPage(ParamPage):
(control, 0, wxALIGN_CENTER_VERTICAL) ]) (control, 0, wxALIGN_CENTER_VERTICAL) ])
self.controlName = control self.controlName = control
for param in xxx.allParams: for param in xxx.allParams:
present = param in xxx.params present = xxx.params.has_key(param)
if param in xxx.required: if param in xxx.required:
label = wxStaticText(self, paramIDs[param], param + ':', label = wxStaticText(self, paramIDs[param], param + ':',
size = (100,-1), name = param) size = (100,-1), name = param)
@@ -354,7 +353,7 @@ class StylePage(ParamPage):
topSizer = wxStaticBoxSizer(box, wxVERTICAL) topSizer = wxStaticBoxSizer(box, wxVERTICAL)
sizer = wxFlexGridSizer(len(xxx.styles), 2, 1, 1) sizer = wxFlexGridSizer(len(xxx.styles), 2, 1, 1)
for param in xxx.styles: for param in xxx.styles:
present = param in xxx.params.keys() present = xxx.params.has_key(param)
check = wxCheckBox(self, paramIDs[param], check = wxCheckBox(self, paramIDs[param],
param + ':', size = (100,-1), name = param) param + ':', size = (100,-1), name = param)
check.SetValue(present) check.SetValue(present)
@@ -372,7 +371,7 @@ class StylePage(ParamPage):
def SetValues(self, xxx): def SetValues(self, xxx):
self.xxx = xxx self.xxx = xxx
for param in xxx.styles: for param in xxx.styles:
present = param in xxx.params.keys() present = xxx.params.has_key(param)
check = self.checks[param] check = self.checks[param]
check.SetValue(present) check.SetValue(present)
w = self.controls[param] w = self.controls[param]
@@ -388,6 +387,8 @@ class StylePage(ParamPage):
class HightLightBox: class HightLightBox:
def __init__(self, pos, size): def __init__(self, pos, size):
if size.x == -1: size.x = 0
if size.y == -1: size.y = 0
w = testWin.panel w = testWin.panel
l1 = wxWindow(w, -1, pos, wxSize(size.x, 2)) l1 = wxWindow(w, -1, pos, wxSize(size.x, 2))
l1.SetBackgroundColour(wxRED) l1.SetBackgroundColour(wxRED)
@@ -400,12 +401,12 @@ class HightLightBox:
self.lines = [l1, l2, l3, l4] self.lines = [l1, l2, l3, l4]
# Move highlight to a new position # Move highlight to a new position
def Replace(self, pos, size): def Replace(self, pos, size):
self.lines[0].SetDimensions(pos.x, pos.y, size.x, 2, wxSIZE_ALLOW_MINUS_ONE) if size.x == -1: size.x = 0
self.lines[1].SetDimensions(pos.x, pos.y, 2, size.y, wxSIZE_ALLOW_MINUS_ONE) if size.y == -1: size.y = 0
self.lines[2].SetDimensions(pos.x + size.x - 2, pos.y, 2, size.y, self.lines[0].SetDimensions(pos.x, pos.y, size.x, 2)
wxSIZE_ALLOW_MINUS_ONE) self.lines[1].SetDimensions(pos.x, pos.y, 2, size.y)
self.lines[3].SetDimensions(pos.x, pos.y + size.y - 2, size.x, 2, self.lines[2].SetDimensions(pos.x + size.x - 2, pos.y, 2, size.y)
wxSIZE_ALLOW_MINUS_ONE) self.lines[3].SetDimensions(pos.x, pos.y + size.y - 2, size.x, 2)
# Remove it # Remove it
def Remove(self): def Remove(self):
map(wxWindow.Destroy, self.lines) map(wxWindow.Destroy, self.lines)
@@ -578,21 +579,16 @@ class XML_Tree(wxTreeCtrl):
return parentPos + pos return parentPos + pos
# Find window (or sizer) corresponding to a tree item. # Find window (or sizer) corresponding to a tree item.
def FindNodeObject(self, item): def FindNodeObject(self, item):
# If top-level, return testWin (or panel its panel)
if item == testWin.item: return testWin.panel if item == testWin.item: return testWin.panel
itemParent = self.GetItemParent(item) itemParent = self.GetItemParent(item)
# If top-level, return testWin (or panel if wxFrame)
xxx = self.GetPyData(item).treeObject() xxx = self.GetPyData(item).treeObject()
parentWin = self.FindNodeObject(itemParent) parentWin = self.FindNodeObject(itemParent)
# Top-level sizer? return window's sizer # Top-level sizer? return window's sizer
if xxx.isSizer and isinstance(parentWin, wxWindowPtr): if xxx.isSizer and isinstance(parentWin, wxWindowPtr):
return parentWin.GetSizer() return parentWin.GetSizer()
# Otherwise get parent's object and it's child # Otherwise get parent's object and it's child
n = 0 # index of sibling child = parentWin.GetChildren()[self.ItemIndex(item)]
prev = self.GetPrevSibling(item)
while prev.IsOk():
prev = self.GetPrevSibling(prev)
n += 1
child = parentWin.GetChildren()[n]
# Return window or sizer for sizer items # Return window or sizer for sizer items
if child.GetClassName() == 'wxSizerItem': if child.GetClassName() == 'wxSizerItem':
if child.IsWindow(): child = child.GetWindow() if child.IsWindow(): child = child.GetWindow()
@@ -615,7 +611,7 @@ class XML_Tree(wxTreeCtrl):
self.Apply(xxx, oldItem) self.Apply(xxx, oldItem)
#if conf.autoRefresh: #if conf.autoRefresh:
if testWin: if testWin:
if testWin.highLight and not tree.IsHighlatable(oldItem): if testWin.highLight:
testWin.highLight.Remove() testWin.highLight.Remove()
self.needUpdate = true self.needUpdate = true
status = 'Changes were applied' status = 'Changes were applied'
@@ -642,12 +638,9 @@ class XML_Tree(wxTreeCtrl):
# Highlight selected item # Highlight selected item
def HighLight(self, item): def HighLight(self, item):
self.pendingHighLight = None self.pendingHighLight = None
if not testWin or self.GetPyData(testWin.item).className \ # Can highlight only with some top-level windows
not in ['wxDialog', 'wxPanel', 'wxFrame']: if not testWin or self.GetPyData(testWin.item).__class__ \
return not in [xxxDialog, xxxPanel, xxxFrame]:
# Top-level does not have highlight
if item == testWin.item or item == tree.root:
if testWin.highLight: testWin.highLight.Remove()
return return
# If a control from another window is selected, remove highlight # If a control from another window is selected, remove highlight
if not self.IsHighlatable(item): if not self.IsHighlatable(item):
@@ -673,14 +666,12 @@ class XML_Tree(wxTreeCtrl):
'wxMenuBar', 'wxToolBar']: 'wxMenuBar', 'wxToolBar']:
wxLogMessage('No view for this element (yet)') wxLogMessage('No view for this element (yet)')
return return
if not treeObj.name:
wxLogError("Can't display a noname element!")
return
# Show item in bold # Show item in bold
if testWin: if testWin: # Reset old
self.SetItemBold(testWin.item, false) self.SetItemBold(testWin.item, false)
self.SetItemBold(item)
self.CreateTestWin(item) self.CreateTestWin(item)
# Maybe an error occured, so we need to test
if testWin: self.SetItemBold(testWin.item)
# Double-click on Linux # Double-click on Linux
def OnItemActivated(self, evt): def OnItemActivated(self, evt):
if evt.GetItem() != self.root: if evt.GetItem() != self.root:
@@ -731,6 +722,12 @@ class XML_Tree(wxTreeCtrl):
# Remove temporarily from old parent # Remove temporarily from old parent
elem = xxx.element elem = xxx.element
# Give temporary name if not exist
if not xxx.name:
name = 'noname'
elem.setAttribute('name', name)
else:
name = xxx.name
parent = elem.parentNode parent = elem.parentNode
next = elem.nextSibling next = elem.nextSibling
parent.replaceChild(self.dummyNode, elem) parent.replaceChild(self.dummyNode, elem)
@@ -741,46 +738,57 @@ class XML_Tree(wxTreeCtrl):
mainNode.removeChild(elem) mainNode.removeChild(elem)
dom.unlink() dom.unlink()
parent.replaceChild(elem, self.dummyNode) parent.replaceChild(elem, self.dummyNode)
if not xxx.name:
name = 'noname'
elem.removeAttribute('name')
memFile.close() # write to wxMemoryFS memFile.close() # write to wxMemoryFS
res = wxXmlResource('') res = wxXmlResource('')
res.Load('memory:xxx.xrc') res.Load('memory:xxx.xrc')
if xxx.className == 'wxFrame': if xxx.__class__ == xxxFrame:
# Create new frame # Frame can't have many children,
# but it's first child possibly can...
child = tree.GetFirstChild(item, 0)[0]
if child.IsOk() and tree.GetPyData(child).__class__ == xxxPanel:
# Clean-up before recurcive call or error
wxMemoryFSHandler_RemoveFile('xxx.xrc')
wxEndBusyCursor()
self.CreateTestWin(child)
return
# This currently works under GTK, but not under MSW
testWin = wxPreFrame() testWin = wxPreFrame()
res.LoadOnFrame(testWin, frame, xxx.name) res.LoadOnFrame(testWin, frame, name)
# Create status bar # Create status bar
testWin.CreateStatusBar() testWin.CreateStatusBar()
testWin.panel = testWin testWin.panel = testWin
testWin.SetPosition(pos) testWin.SetPosition(pos)
testWin.Show(true) testWin.Show(true)
elif xxx.className == 'wxPanel': elif xxx.__class__ == xxxPanel:
# Create new frame # Create new frame
if not testWin: if not testWin:
testWin = wxFrame(frame, -1, 'Panel: ' + xxx.name, pos=pos) testWin = wxFrame(frame, -1, 'Panel: ' + name, pos=pos)
testWin.panel = res.LoadPanel(testWin, xxx.name) testWin.panel = res.LoadPanel(testWin, name)
testWin.SetClientSize(testWin.panel.GetSize()) testWin.SetClientSize(testWin.panel.GetSize())
testWin.Show(true) testWin.Show(true)
elif xxx.className == 'wxDialog': elif xxx.__class__ == xxxDialog:
# Create new frame testWin = res.LoadDialog(None, name)
testWin = res.LoadDialog(None, xxx.name)
testWin.panel = testWin testWin.panel = testWin
testWin.Layout() testWin.Layout()
testWin.SetPosition(pos) testWin.SetPosition(pos)
testWin.Show(true) testWin.Show(true)
elif xxx.className == 'wxMenuBar': elif xxx.__class__ == xxxMenuBar:
testWin = wxFrame(frame, -1, 'MenuBar: ' + xxx.name, pos=pos) testWin = wxFrame(frame, -1, 'MenuBar: ' + name, pos=pos)
testWin.panel = None testWin.panel = None
# Set status bar to display help # Set status bar to display help
testWin.CreateStatusBar() testWin.CreateStatusBar()
testWin.menuBar = res.LoadMenuBar(xxx.name) testWin.menuBar = res.LoadMenuBar(name)
testWin.SetMenuBar(testWin.menuBar) testWin.SetMenuBar(testWin.menuBar)
testWin.Show(true) testWin.Show(true)
elif xxx.className == 'wxToolBar': elif xxx.__class__ == xxxToolBar:
testWin = wxFrame(frame, -1, 'ToolBar: ' + xxx.name, pos=pos) testWin = wxFrame(frame, -1, 'ToolBar: ' + name, pos=pos)
testWin.panel = None testWin.panel = None
# Set status bar to display help # Set status bar to display help
testWin.CreateStatusBar() testWin.CreateStatusBar()
testWin.toolBar = res.LoadToolBar(testWin, xxx.name) testWin.toolBar = res.LoadToolBar(testWin, name)
testWin.SetToolBar(testWin.toolBar) testWin.SetToolBar(testWin.toolBar)
testWin.Show(true) testWin.Show(true)
wxMemoryFSHandler_RemoveFile('xxx.xrc') wxMemoryFSHandler_RemoveFile('xxx.xrc')
@@ -801,13 +809,13 @@ class XML_Tree(wxTreeCtrl):
testWin = None testWin = None
# Return item index in parent # Return item index in parent
def ItemIndex(self, parent, item): def ItemIndex(self, item):
i = 0 n = 0 # index of sibling
it, cookie = self.GetFirstChild(parent, 0) prev = self.GetPrevSibling(item)
while it != item: while prev.IsOk():
i += 1 prev = self.GetPrevSibling(prev)
it, cookie = self.GetNextChild(parent, cookie) n += 1
return i return n
# True if next item should be inserted after current (vs. appended to it) # True if next item should be inserted after current (vs. appended to it)
def NeedInsert(self, item): def NeedInsert(self, item):
@@ -1028,6 +1036,9 @@ class Frame(wxFrame):
menu.Append(wxID_PASTE, '&Paste\tCtrl-V', 'Paste from the clipboard') menu.Append(wxID_PASTE, '&Paste\tCtrl-V', 'Paste from the clipboard')
self.ID_DELETE = wxNewId() self.ID_DELETE = wxNewId()
menu.Append(self.ID_DELETE, '&Delete\tCtrl-D', 'Delete object') menu.Append(self.ID_DELETE, '&Delete\tCtrl-D', 'Delete object')
# menu.AppendSeparator()
ID_SELECT = wxNewId()
# menu.Append(ID_SELECT, '&Select', 'Select object')
menuBar.Append(menu, '&Edit') menuBar.Append(menu, '&Edit')
menu = wxMenu() menu = wxMenu()
@@ -1095,6 +1106,7 @@ class Frame(wxFrame):
EVT_MENU(self, wxID_COPY, self.OnCopy) EVT_MENU(self, wxID_COPY, self.OnCopy)
EVT_MENU(self, wxID_PASTE, self.OnPaste) EVT_MENU(self, wxID_PASTE, self.OnPaste)
EVT_MENU(self, self.ID_DELETE, self.OnDelete) EVT_MENU(self, self.ID_DELETE, self.OnDelete)
EVT_MENU(self, ID_SELECT, self.OnSelect)
# View # View
EVT_MENU(self, self.ID_EMBED_PANEL, self.OnEmbedPanel) EVT_MENU(self, self.ID_EMBED_PANEL, self.OnEmbedPanel)
EVT_MENU(self, self.ID_TEST, self.OnTest) EVT_MENU(self, self.ID_TEST, self.OnTest)
@@ -1118,7 +1130,6 @@ class Frame(wxFrame):
splitter = wxSplitterWindow(self, -1, style=wxSP_3DSASH) splitter = wxSplitterWindow(self, -1, style=wxSP_3DSASH)
self.splitter = splitter self.splitter = splitter
splitter.SetMinimumPaneSize(100) splitter.SetMinimumPaneSize(100)
# Create tree # Create tree
global tree global tree
tree = XML_Tree(splitter, -1) tree = XML_Tree(splitter, -1)
@@ -1281,6 +1292,7 @@ class Frame(wxFrame):
# Other events # Other events
EVT_IDLE(self, self.OnIdle) EVT_IDLE(self, self.OnIdle)
EVT_CLOSE(self, self.OnCloseWindow) EVT_CLOSE(self, self.OnCloseWindow)
EVT_LEFT_DOWN(self, self.OnLeftDown)
def OnNew(self, evt): def OnNew(self, evt):
self.Clear() self.Clear()
@@ -1294,12 +1306,10 @@ class Frame(wxFrame):
self.SetStatusText('Loading...') self.SetStatusText('Loading...')
wxYield() wxYield()
wxBeginBusyCursor() wxBeginBusyCursor()
try: if self.Open(path):
self.Open(path)
self.SetStatusText('Data loaded') self.SetStatusText('Data loaded')
except: else:
self.SetStatusText('Failed') self.SetStatusText('Failed')
raise
wxEndBusyCursor() wxEndBusyCursor()
dlg.Destroy() dlg.Destroy()
@@ -1472,7 +1482,7 @@ class Frame(wxFrame):
node = tree.GetPyData(nextItem).element node = tree.GetPyData(nextItem).element
parent.element.insertBefore(elem, node) parent.element.insertBefore(elem, node)
# Inserting before is difficult, se we insert after or first child # Inserting before is difficult, se we insert after or first child
index = tree.ItemIndex(parentLeaf, nextItem) index = tree.ItemIndex(nextItem)
newItem = tree.InsertItemBefore(parentLeaf, index, newItem = tree.InsertItemBefore(parentLeaf, index,
xxx.treeName(), image=xxx.treeImage()) xxx.treeName(), image=xxx.treeImage())
tree.SetPyData(newItem, xxx) tree.SetPyData(newItem, xxx)
@@ -1515,9 +1525,9 @@ class Frame(wxFrame):
testWin = None testWin = None
else: else:
# Remove highlight, update testWin # Remove highlight, update testWin
if not tree.IsHighlatable(selected): if testWin.highLight:
if testWin.highLight: testWin.highLight.Remove() testWin.highLight.Remove()
tree.needUpdate = true tree.needUpdate = true
xnode = tree.RemoveLeaf(selected) xnode = tree.RemoveLeaf(selected)
# !!! cloneNode is broken, or something is wrong # !!! cloneNode is broken, or something is wrong
# self.undo.append(xnode.cloneNode(true)) # self.undo.append(xnode.cloneNode(true))
@@ -1528,6 +1538,17 @@ class Frame(wxFrame):
self.modified = true self.modified = true
self.SetStatusText('Deleted') self.SetStatusText('Deleted')
def OnSelect(self, evt):
print >> sys.stderr, 'Xperimental function!'
wxYield()
self.SetCursor(wxCROSS_CURSOR)
self.CaptureMouse()
def OnLeftDown(self, evt):
pos = evt.GetPosition()
self.SetCursor(wxNullCursor)
self.ReleaseMouse()
def OnEmbedPanel(self, evt): def OnEmbedPanel(self, evt):
conf.embedPanel = evt.IsChecked() conf.embedPanel = evt.IsChecked()
if conf.embedPanel: if conf.embedPanel:
@@ -1669,7 +1690,7 @@ class Frame(wxFrame):
parent.element.insertBefore(elem, node) parent.element.insertBefore(elem, node)
# !!! There is a different behavious on Win and GTK # !!! There is a different behavious on Win and GTK
# !!! On Win InsertItem(parent, parent, ...) inserts at the end. # !!! On Win InsertItem(parent, parent, ...) inserts at the end.
index = tree.ItemIndex(parentLeaf, nextItem) index = tree.ItemIndex(nextItem)
newItem = tree.InsertItemBefore(parentLeaf, index, newItem = tree.InsertItemBefore(parentLeaf, index,
xxx.treeName(), image=xxx.treeImage()) xxx.treeName(), image=xxx.treeImage())
# data=wxTreeItemData(xxx)) # does not work # data=wxTreeItemData(xxx)) # does not work
@@ -1771,6 +1792,9 @@ class Frame(wxFrame):
self.maxIDs[xxxMenuBar] = self.maxIDs[xxxMenu] = self.maxIDs[xxxToolBar] = 0 self.maxIDs[xxxMenuBar] = self.maxIDs[xxxMenu] = self.maxIDs[xxxToolBar] = 0
def Open(self, path): def Open(self, path):
if not os.path.exists(path):
wxLogError('File does not exists: %s' % path)
return false
# Try to read the file # Try to read the file
try: try:
open(path) open(path)
@@ -1781,8 +1805,12 @@ class Frame(wxFrame):
self.dataFile = path self.dataFile = path
self.SetTitle(progname + ': ' + os.path.basename(path)) self.SetTitle(progname + ': ' + os.path.basename(path))
except: except:
# Nice exception printing
inf = sys.exc_info()
wxLogError(traceback.format_exception(inf[0], inf[1], None)[-1])
wxLogError('Error reading file: %s' % path) wxLogError('Error reading file: %s' % path)
raise return false
return true
def Indent(self, node, indent = 0): def Indent(self, node, indent = 0):
# Copy child list because it will change soon # Copy child list because it will change soon
@@ -1804,7 +1832,8 @@ class Frame(wxFrame):
def Save(self, path): def Save(self, path):
try: try:
# Apply changes # Apply changes
self.OnRefresh(wxCommandEvent()) if tree.selection and panel.IsModified():
self.OnRefresh(wxCommandEvent())
f = open(path, 'w') f = open(path, 'w')
# Make temporary copy # Make temporary copy
# !!! We can't clone dom node, it works only once # !!! We can't clone dom node, it works only once

View File

@@ -129,7 +129,7 @@ class xxxParamContentCheckList(xxxNode):
for n in childNodes: for n in childNodes:
self.node.removeChild(n) self.node.removeChild(n)
l = [] l = []
for (s,ch) in value: for s,ch in value:
itemElem = tree.dom.createElement('item') itemElem = tree.dom.createElement('item')
itemElem.setAttribute('checked', str(ch)) itemElem.setAttribute('checked', str(ch))
itemText = tree.dom.createTextNode(s) itemText = tree.dom.createTextNode(s)
@@ -184,7 +184,7 @@ class xxxObject:
tag = node.tagName tag = node.tagName
if tag == 'object': if tag == 'object':
continue # do nothing for object children here continue # do nothing for object children here
if not tag in self.allParams and not tag in self.styles: if tag not in self.allParams and tag not in self.styles:
print 'WARNING: unknown parameter for %s: %s' % \ print 'WARNING: unknown parameter for %s: %s' % \
(self.className, tag) (self.className, tag)
elif tag in self.specials: elif tag in self.specials:
@@ -511,7 +511,7 @@ class xxxFlexGridSizer(xxxGridSizer):
# Special processing for growable* parameters # Special processing for growable* parameters
# (they are represented by several nodes) # (they are represented by several nodes)
def special(self, tag, node): def special(self, tag, node):
if tag not in self.params: if not self.params.has_key(tag):
self.params[tag] = xxxParamMulti() self.params[tag] = xxxParamMulti()
self.params[tag].append(xxxParamInt(node)) self.params[tag].append(xxxParamInt(node))
def setSpecial(self, param, value): def setSpecial(self, param, value):
@@ -668,12 +668,12 @@ def IsObject(node):
# Make XXX object from some DOM object, selecting correct class # Make XXX object from some DOM object, selecting correct class
def MakeXXXFromDOM(parent, element): def MakeXXXFromDOM(parent, element):
try: try:
return xxxDict[element.getAttribute('class')](parent, element) klass = xxxDict[element.getAttribute('class')]
except KeyError: except KeyError:
# Verify that it's not recursive exception # Verify that it's not recursive exception
if element.getAttribute('class') not in xxxDict: print 'ERROR: unknown class:', element.getAttribute('class')
print 'ERROR: unknown class:', element.getAttribute('class')
raise raise
return klass(parent, element)
# Make empty DOM element # Make empty DOM element
def MakeEmptyDOM(className): def MakeEmptyDOM(className):