From 00d153468c7d1be2093de839bcf70b6a45aa388f Mon Sep 17 00:00:00 2001 From: Roman Rolinsky Date: Tue, 13 Mar 2007 23:59:38 +0000 Subject: [PATCH] Support for custom controls, first attempt git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44794 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/wx/tools/XRCed/tree.py | 12 +++++++ wxPython/wx/tools/XRCed/xrced.py | 2 ++ wxPython/wx/tools/XRCed/xxx.py | 60 ++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/wxPython/wx/tools/XRCed/tree.py b/wxPython/wx/tools/XRCed/tree.py index ec093e4055..ad64a5a709 100644 --- a/wxPython/wx/tools/XRCed/tree.py +++ b/wxPython/wx/tools/XRCed/tree.py @@ -902,6 +902,18 @@ class XML_Tree(wx.TreeCtrl): if not g.currentEncoding: xmlFlags != xrc.XRC_USE_LOCALE res = xrc.XmlResource('', xmlFlags) + xrc.XmlResource.Set(res) # set as global + # Register handlers + addHandlers(res) + # Test Test.py + #import Test + #res.InsertHandler(Test.TestXmlHandler()) + # Test test.so + import ctypes + test = ctypes.CDLL('test.so') + addr = int(str(res.this).split('_')[1], 16) + #test._Z17AddTestXmlHandlerP13wxXmlResource(ctypes.c_void_p(addr)) + #test.AddTestXmlHandler(ctypes.c_void_p(addr)) res.Load('memory:xxx.xrc') try: if xxx.__class__ == xxxFrame: diff --git a/wxPython/wx/tools/XRCed/xrced.py b/wxPython/wx/tools/XRCed/xrced.py index 046bb763f4..5e1068f57b 100644 --- a/wxPython/wx/tools/XRCed/xrced.py +++ b/wxPython/wx/tools/XRCed/xrced.py @@ -1365,6 +1365,8 @@ Homepage: http://xrced.sourceforge.net\ xxxMenuBar, xxxMenu, xxxToolBar, xxxWizard, xxxBitmap, xxxIcon]: self.maxIDs[cl] = 0 + # Handlers + clearHandlers() def SetModified(self, state=True): self.modified = state diff --git a/wxPython/wx/tools/XRCed/xxx.py b/wxPython/wx/tools/XRCed/xxx.py index 659ddebfcc..1ee0ffa5a3 100644 --- a/wxPython/wx/tools/XRCed/xxx.py +++ b/wxPython/wx/tools/XRCed/xxx.py @@ -7,6 +7,7 @@ from xml.dom import minidom from globals import * from params import * +import traceback, types # Base class for interface parameter classes class xxxNode: @@ -918,10 +919,69 @@ class xxxUnknown(xxxObject): ################################################################################ # Comment +_handlers = [] +_CFuncPtr = None + +def register(hndlr): + if _CFuncPtr and isinstance(hndlr, _CFuncPtr): + _handlers.append(hndlr) + return + if not isinstance(hndlr, type): + wx.LogError('handler is not a type: %s' % hndlr) + elif not issubclass(hndlr, wx.xrc.XmlResourceHandler): + wx.LogError('handler is not a XmlResourceHandler: %s' % hndlr) + else: + _handlers.append(hndlr) + +def load_dl(path, localname=''): + try: + import ctypes + global _CFuncPtr + _CFuncPtr = ctypes._CFuncPtr + except ImportError: + wx.LogError('ctypes module not found') + return + try: + dl = ctypes.CDLL(path) + if not localname: + localname = os.path.basename(os.path.splitext(dl._name)[0]) + globals()[localname] = dl + except: + wx.LogError('error loading dynamic library: %s', path) + print traceback.print_exc() + +# Called when creating test window +def addHandlers(res): + for h in _handlers: + if _CFuncPtr and isinstance(h, _CFuncPtr): + try: + apply(h, ()) + except: + wx.LogError('error calling DL func: "%s"' % h) + print traceback.print_exc() + else: + try: + res.AddHandler(apply(h, ())) + except: + wx.LogError('error adding XmlHandler: "%s"' % h) + print traceback.print_exc() + +def clearHandlers(): + global _handlers + _handlers = [] + class xxxParamComment(xxxParam): def __init__(self, node): xxxNode.__init__(self, node) self.textNode = node + # Parse "pragma" comments + if node.data and node.data[0] == '%': + try: + code = node.data[1:] + exec code in globals() + except: + wx.LogError('exec error: "%s"' % code) + print traceback.print_exc() class xxxComment(xxxObject): hasStyle = hasName = False