From 8829d26ddebc7122a1fe906f11423a70abc3919f Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 1 Nov 2012 22:51:13 +0000 Subject: [PATCH] Add tweaks for things like output args, ownership transfers, etc. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72854 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- etg/_html.py | 15 ++++++-- etg/help.py | 2 +- etg/helpdlg.py | 1 + etg/helpfrm.py | 1 + etg/helpwnd.py | 2 + etg/htmlcell.py | 3 ++ etg/htmldefs.py | 47 +++++++++++++++++++++++ etg/htmlprint.py | 1 + etg/htmltag.py | 5 +++ etg/htmlwin.py | 2 + etg/htmlwinpars.py | 79 +++++++++++++++++++++++++++++++++++++-- etgtools/tweaker_tools.py | 15 ++++++++ 12 files changed, 166 insertions(+), 7 deletions(-) create mode 100644 etg/htmldefs.py diff --git a/etg/_html.py b/etg/_html.py index cf1fdd98..53cfd1ff 100644 --- a/etg/_html.py +++ b/etg/_html.py @@ -23,21 +23,22 @@ ITEMS = [ ] # The list of other ETG scripts and back-end generator modules that are # included as part of this module. These should all be items that are put in -# the wxWidgets "adv" library in a multi-lib build. +# the wxWidgets "html" library in a multi-lib build. INCLUDES = [ + 'htmldefs', 'htmlcell', 'htmlfilt', 'htmltag', 'htmlpars', 'htmlwin', 'htmlprint', - #'htmlwinpars', + 'htmlwinpars', - 'helpctrl', 'helpdata', 'helpdlg', 'helpfrm', 'helpwnd', + 'helpctrl', ] @@ -66,6 +67,14 @@ def run(): module.addPyCode("import wx", order=10) module.addInclude(INCLUDES) + module.addCppCode("""\ + #include + #include + #include + #include + #include + #include + """) #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/help.py b/etg/help.py index 5bff8e27..68d4d7ca 100644 --- a/etg/help.py +++ b/etg/help.py @@ -46,7 +46,7 @@ def run(): # module to link to the wxHTML library, then we won't provide a wrapper # for the wxHelpController 'class'. Later on when we've got all the help # controller classes that we'll want then we can add a wxHelpController - # alias of our own in Python code. + # or factory of our own in Python code. #c = module.find('wxHelpController') diff --git a/etg/helpdlg.py b/etg/helpdlg.py index 21ea1f82..6a8ba5b5 100644 --- a/etg/helpdlg.py +++ b/etg/helpdlg.py @@ -35,6 +35,7 @@ def run(): assert isinstance(c, etgtools.ClassDef) tools.fixTopLevelWindowClass(c) + c.find('SetController.controller').transfer = True #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/helpfrm.py b/etg/helpfrm.py index 71624efd..74cf1fa2 100644 --- a/etg/helpfrm.py +++ b/etg/helpfrm.py @@ -36,6 +36,7 @@ def run(): assert isinstance(c, etgtools.ClassDef) tools.fixTopLevelWindowClass(c) + c.find('SetController.controller').transfer = True #----------------------------------------------------------------- diff --git a/etg/helpwnd.py b/etg/helpwnd.py index dbedaf75..ae6a22a9 100644 --- a/etg/helpwnd.py +++ b/etg/helpwnd.py @@ -36,6 +36,8 @@ def run(): assert isinstance(c, etgtools.ClassDef) tools.fixWindowClass(c) + c.find('SetController.controller').transfer = True + #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/htmlcell.py b/etg/htmlcell.py index 73dbaedd..5f4049b1 100644 --- a/etg/htmlcell.py +++ b/etg/htmlcell.py @@ -45,6 +45,9 @@ def run(): assert isinstance(c, etgtools.ClassDef) c.addPrivateCopyCtor() + c.find('SetNext.cell').transfer = True + c.find('AdjustPagebreak.pagebreak').inOut = True + #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/htmldefs.py b/etg/htmldefs.py new file mode 100644 index 00000000..d978daa7 --- /dev/null +++ b/etg/htmldefs.py @@ -0,0 +1,47 @@ +#--------------------------------------------------------------------------- +# Name: etg/htmldefs.py +# Author: Robin Dunn +# +# Created: 30-Oct-2012 +# Copyright: (c) 2012 by Total Control Software +# License: wxWindows License +#--------------------------------------------------------------------------- + +import etgtools +import etgtools.tweaker_tools as tools + +PACKAGE = "wx" +MODULE = "_html" +NAME = "htmldefs" # Base name of the file to generate to for this script +DOCSTRING = "" + +# The classes and/or the basename of the Doxygen XML files to be processed by +# this script. +ITEMS = [ "htmldefs_8h.xml", + + ] + +#--------------------------------------------------------------------------- + +def run(): + # Parse the XML file(s) building a collection of Extractor objects + module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING, check4unittest=False) + etgtools.parseDoxyXML(module, ITEMS) + + #----------------------------------------------------------------- + # Tweak the parsed meta objects in the module object as needed for + # customizing the generated code and docstrings. + + #c = module.find('') + #assert isinstance(c, etgtools.ClassDef) + + + #----------------------------------------------------------------- + tools.doCommonTweaks(module) + tools.runGenerators(module) + + +#--------------------------------------------------------------------------- +if __name__ == '__main__': + run() + diff --git a/etg/htmlprint.py b/etg/htmlprint.py index 3a1df144..4f48de36 100644 --- a/etg/htmlprint.py +++ b/etg/htmlprint.py @@ -36,6 +36,7 @@ def run(): c = module.find('wxHtmlDCRenderer') assert isinstance(c, etgtools.ClassDef) c.addPrivateCopyCtor() + tools.fixHtmlSetFonts(c) c = module.find('wxHtmlEasyPrinting') c.addPrivateCopyCtor() diff --git a/etg/htmltag.py b/etg/htmltag.py index 29e8e946..6a615b7d 100644 --- a/etg/htmltag.py +++ b/etg/htmltag.py @@ -36,7 +36,12 @@ def run(): assert isinstance(c, etgtools.ClassDef) c.addPrivateCopyCtor() + c.find('GetParamAsColour.clr').out = True + c.find('GetParamAsInt.value').out = True + c.find('ParseAsColour.clr').out = True + for m in c.findAll('ScanParam'): + m.ignore() #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/htmlwin.py b/etg/htmlwin.py index 3964ec8c..a10de3d5 100644 --- a/etg/htmlwin.py +++ b/etg/htmlwin.py @@ -41,6 +41,8 @@ def run(): c.find('OnCellClicked').ignore(False) c.find('OnCellMouseHover').ignore(False) + + tools.fixHtmlSetFonts(c) # Pure virtuals inherited from wxHtmlWindowInterface c.addItem(etgtools.WigCode("""\ diff --git a/etg/htmlwinpars.py b/etg/htmlwinpars.py index 11bfd702..b6c6aee0 100644 --- a/etg/htmlwinpars.py +++ b/etg/htmlwinpars.py @@ -17,10 +17,12 @@ DOCSTRING = "" # The classes and/or the basename of the Doxygen XML files to be processed by # this script. -ITEMS = [ "wxHtmlWinParser", - "wxHtmlTagsModule", +ITEMS = [ #"wxHtmlTagsModule", + "wxHtmlWinTagHandler", + "wxHtmlWinParser", ] + #--------------------------------------------------------------------------- def run(): @@ -32,10 +34,81 @@ def run(): # Tweak the parsed meta objects in the module object as needed for # customizing the generated code and docstrings. - c = module.find('wxHtmlWinParser') + c = module.find('wxHtmlWinTagHandler') assert isinstance(c, etgtools.ClassDef) + #c.addCppMethod('wxHtmlWinParser*', 'GetParser', '()', + # body="""return self->m_WParser;""") + + c = module.find('wxHtmlWinParser') c.find('GetEncodingConverter').ignore() + c.find('GetInputEncoding').ignore() + c.find('GetOutputEncoding').ignore() + c.find('SetInputEncoding').ignore() + + tools.fixHtmlSetFonts(c) + + c.find('AddModule').ignore() + + + module.addCppCode("""\ + class wxPyHtmlTagsModule : public wxHtmlTagsModule { + public: + wxPyHtmlTagsModule(PyObject* thc) : wxHtmlTagsModule() { + m_tagHandlerClass = thc; + wxPyThreadBlocker blocker; + Py_INCREF(m_tagHandlerClass); + RegisterModule(this); + wxHtmlWinParser::AddModule(this); + } + + void OnExit() { + wxPyThreadBlocker blocker; + Py_DECREF(m_tagHandlerClass); + m_tagHandlerClass = NULL; + for (size_t x=0; x < m_objArray.GetCount(); x++) { + PyObject* obj = (PyObject*)m_objArray.Item(x); + Py_DECREF(obj); + } + }; + + void FillHandlersTable(wxHtmlWinParser *parser) { + // Wave our magic wand... (if it works it's a miracle! ;-) + + wxPyThreadBlocker blocker; + wxHtmlWinTagHandler* thPtr = 0; + // First, make a new instance of the tag handler + PyObject* arg = PyTuple_New(0); + PyObject* obj = PyObject_CallObject(m_tagHandlerClass, arg); + Py_DECREF(arg); + + // now figure out where it's C++ object is... + if (! wxPyConvertWrappedPtr(obj, (void **)&thPtr, wxT("wxHtmlWinTagHandler"))) { + return; + } + + // add it, + parser->AddTagHandler(thPtr); + + // and track it. + m_objArray.Add(obj); + } + + private: + PyObject* m_tagHandlerClass; + wxArrayPtrVoid m_objArray; + + }; + """) + + + module.addCppFunction('void', 'HtmlWinParser_AddTagHandler', '(PyObject* tagHandlerClass)', + body="""\ + // Dynamically create a new wxModule. Refcounts tagHandlerClass + // and adds itself to the wxModules list and to the wxHtmlWinParser. + new wxPyHtmlTagsModule(tagHandlerClass); + """) + #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etgtools/tweaker_tools.py b/etgtools/tweaker_tools.py index 8a43fb8b..76b39462 100644 --- a/etgtools/tweaker_tools.py +++ b/etgtools/tweaker_tools.py @@ -206,6 +206,21 @@ def fixBookctrlClass(klass, treeBook=False): virtual bool InsertPage(size_t index, wxWindow * page, const wxString & text, bool select = false, int imageId = NO_IMAGE); """)) + + +def fixHtmlSetFonts(klass): + # Use wxArrayInt instead of a C array of ints. + m = klass.find('SetFonts') + m.find('sizes').type = 'const wxArrayInt&' + m.find('sizes').default = '' + m.argsString = '(const wxString & normal_face, const wxString & fixed_face, const wxArrayInt& sizes)' + m.setCppCode("""\ + if (sizes->GetCount() != 7) { + wxPyErr_SetString(PyExc_ValueError, "Sequence of 7 integers expected."); + return; + } + self->SetFonts(*normal_face, *fixed_face, &sizes->Item(0)); + """) def removeVirtuals(klass):