From 434365ec00792df9e977d283a5496891e96d045d Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 2 Mar 2020 15:11:14 -0800 Subject: [PATCH] Add CHMHelpController, and a wx.HelpController factory function --- docs/sphinx/itemToModuleMap.json | 1 + etg/_msw.py | 1 + etg/help.py | 37 ++++++++++++++++------------ src/helpchm.sip | 42 ++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 src/helpchm.sip diff --git a/docs/sphinx/itemToModuleMap.json b/docs/sphinx/itemToModuleMap.json index c53aaeef..fba9c104 100644 --- a/docs/sphinx/itemToModuleMap.json +++ b/docs/sphinx/itemToModuleMap.json @@ -1572,6 +1572,7 @@ "HeaderCtrlSimple":"wx.", "HeaderSortIconType":"wx.", "Height":"wx.", +"HelpController":"wx.", "HelpControllerBase":"wx.", "HelpControllerHelpProvider":"wx.", "HelpEvent":"wx.", diff --git a/etg/_msw.py b/etg/_msw.py index 900cd17b..efe6799d 100644 --- a/etg/_msw.py +++ b/etg/_msw.py @@ -31,6 +31,7 @@ ITEMS = [] INCLUDES = [ 'axbase', + 'helpchm', ] # Separate the list into those that are generated from ETG scripts and the diff --git a/etg/help.py b/etg/help.py index ec5bfacb..764a05b0 100644 --- a/etg/help.py +++ b/etg/help.py @@ -44,24 +44,29 @@ def run(): # NOTE: Since wxHelpController is an alias for wxHtmlHelpController on # Mac and GTK, and since we don't want to force the wx.core extension # 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 - # or factory of our own in Python code. + # for the wxHelpController 'class' here. + # + # Instead we'll add a Python factory function that accomplishes the same + # thing. Basically it just provides a help controller instance that is the + # best for the platform. + module.addPyFunction('HelpController', '(parentWindow=None)', + doc="""\ + Rather than being an alias for some class, the Python version of + ``HelpController`` is a factory function that creates and returns an + instance of the best Help Controller is returned to the caller. + """, + body="""\ + try: + if 'wxMSW' in wx.PlatformInfo: + import wx.msw.wxCHMHelpController as ControllerClass + else: + import wx.html.HtmlHelpController as ControllerClass + except ImportError: + ControllerClass = wx.ExtHelpController - #c = module.find('wxHelpController') - #c.mustHaveApp() - #c.addPrivateCopyCtor() - ## Add pure virtuals with implemenations here - #c.addItem(etgtools.WigCode("""\ - #virtual bool DisplayBlock(long blockNo); - #virtual bool DisplayContents(); - #virtual bool DisplaySection(int sectionNo); - #virtual bool KeywordSearch(const wxString& keyWord, - # wxHelpSearchMode mode = wxHELP_SEARCH_ALL); - #virtual bool LoadFile(const wxString& file = wxEmptyString); - #virtual bool Quit(); - #""")) + return ControllerClass(parentWindow) + """) diff --git a/src/helpchm.sip b/src/helpchm.sip new file mode 100644 index 00000000..13a71d6d --- /dev/null +++ b/src/helpchm.sip @@ -0,0 +1,42 @@ +//-------------------------------------------------------------------------- +// Name: helpchm.sip +// Purpose: SIP wrapper details for wxCHMHelpController +// +// Author: Robin Dunn +// +// Created: 02-March-2020 +// Copyright: (c) 2020 by Total Control Software +// Licence: wxWindows license +//-------------------------------------------------------------------------- + + + +class wxCHMHelpController : public wxHelpControllerBase +{ + %TypeHeaderCode + #include + %End + +public: + wxCHMHelpController(wxWindow* parentWindow = NULL); + + virtual bool Initialize(const wxString& file); + + virtual bool LoadFile(const wxString& file = wxEmptyString); + virtual bool DisplayContents(); + virtual bool DisplaySection(int sectionNo); + virtual bool DisplaySection(const wxString& section); + virtual bool DisplayBlock(long blockNo); + virtual bool DisplayContextPopup(int contextId); + virtual bool DisplayTextPopup(const wxString& text, const wxPoint& pos); + virtual bool KeywordSearch(const wxString& k, + wxHelpSearchMode mode = wxHELP_SEARCH_ALL); + virtual bool Quit(); + + wxString GetHelpFile() const; + + static bool ShowContextHelpPopup(const wxString& text, + const wxPoint& pos, + wxWindow *window); + +};