From 02c06475f505340487f388e58771dd920aada040 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 3 Jan 2019 21:57:06 -0800 Subject: [PATCH] Generate optional stubs for the wxFileSystemWatcher* classes --- CHANGES.rst | 2 +- docs/sphinx/itemToModuleMap.json | 1 + etg/fswatcher.py | 13 ++++++++++++- etgtools/tweaker_tools.py | 9 ++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9f77ba71..396f2222 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -113,7 +113,7 @@ Changes in this release include the following: * Added the ability to generate stub classes for use when optional wxWidgets features are not part of the build. So far, stubs are available for - wx.Accessible, wx.glcanvas, wx.media and wx.html2. + wx.Accessible, wx.FileSystemWatcher, wx.glcanvas, wx.media and wx.html2. * Moved the wxpy_api.h file into the wx package at wx/include/wxPython so it will be included in the wheel file. (#961) diff --git a/docs/sphinx/itemToModuleMap.json b/docs/sphinx/itemToModuleMap.json index ffbcc23d..83326459 100644 --- a/docs/sphinx/itemToModuleMap.json +++ b/docs/sphinx/itemToModuleMap.json @@ -6108,6 +6108,7 @@ "USER_ATTENTION_ERROR":"wx.", "USER_ATTENTION_INFO":"wx.", "USE_ACCESSIBILITY":"wx.", +"USE_FSWATCHER":"wx.", "USE_GLCANVAS":"wx.glcanvas.", "USE_JOYSTICK":"wx.adv.", "USE_MEDIACTRL":"wx.media.", diff --git a/etg/fswatcher.py b/etg/fswatcher.py index 863559b5..e3731174 100644 --- a/etg/fswatcher.py +++ b/etg/fswatcher.py @@ -32,11 +32,22 @@ def run(): # Tweak the parsed meta objects in the module object as needed for # customizing the generated code and docstrings. + c = module.find('wxFileSystemWatcherEvent') + assert isinstance(c, etgtools.ClassDef) + c.addItem(etgtools.MethodDef(name='Clone', type='wxEvent*', argsString='() const', + isConst=True, isVirtual=True)) + + tools.generateStubs('wxUSE_FSWATCHER', module, + extraHdrCode='static wxFileName _NullFileName;\n', + typeValMap={'const wxFileName &': '_NullFileName', + 'wxFSWWarningType': 'wxFSW_WARNING_NONE'} + ) + # In the C++ code the wxFSW_EVENT_UNMOUNT item is only part of the enum # for platforms that have INOTIFY so we need to fake it elsewhere. module.addHeaderCode(""" #include - #ifndef wxHAS_INOTIFY + #if wxUSE_FSWATCHER && !defined(wxHAS_INOTIFY) const int wxFSW_EVENT_UNMOUNT = 0x2000; #endif """) diff --git a/etgtools/tweaker_tools.py b/etgtools/tweaker_tools.py index c8a9e17a..5938312f 100644 --- a/etgtools/tweaker_tools.py +++ b/etgtools/tweaker_tools.py @@ -1270,7 +1270,8 @@ def guessTypeStr(v): # generating stubs then we can still provide the wrapper classes but simply # have them raise NotImplemented errors or whatnot. -def generateStubs(cppFlag, module, excludes=[], typeValMap={}): +def generateStubs(cppFlag, module, excludes=[], typeValMap={}, + extraHdrCode=None, extraCppCode=None): """ Generate C++ stubs for all items in the module, except those that are in the optional excludes list. @@ -1306,6 +1307,12 @@ def generateStubs(cppFlag, module, excludes=[], typeValMap={}): if isinstance(item, extractors.ClassDef): code.hdr.append('class {};'.format(item.name)) + if extraHdrCode: + code.hdr.append(extraHdrCode) + + if extraCppCode: + code.cpp.append(extraCppCode) + # Now write code for all the items in the module. for item in module: if item.name in excludes: