Mon, 10 Oct 2016 19:23:38 +0200
Corrected a bug using a class variable, harmonized the code and moved the QtHelp stuff to a separate directory so the files can be used from both variants.
--- a/Helpviewer/HelpWindow.py Mon Oct 10 19:21:22 2016 +0200 +++ b/Helpviewer/HelpWindow.py Mon Oct 10 19:23:38 2016 +0200 @@ -72,7 +72,7 @@ helpwindows = [] _fromEric = False - useQtHelp = QTHELP_AVAILABLE + _useQtHelp = QTHELP_AVAILABLE _networkAccessManager = None _cookieJar = None @@ -146,10 +146,10 @@ from E5Network.E5SslUtilities import initSSL initSSL() - if self.useQtHelp: - self.__helpEngine = \ - QHelpEngine(os.path.join(Utilities.getConfigDir(), - "browser", "eric6help.qhc"), self) + if HelpWindow._useQtHelp: + self.__helpEngine = QHelpEngine( + HelpWindow.getQtHelpCollectionFileName(), + self) self.__removeOldDocumentation() self.__helpEngine.warning.connect(self.__warning) else: @@ -184,7 +184,7 @@ self.setCentralWidget(centralWidget) self.findDlg.hide() - if self.useQtHelp: + if HelpWindow._useQtHelp: # setup the TOC widget self.__tocWindow = HelpTocWidget(self.__helpEngine, self) self.__tocDock = QDockWidget(self.tr("Contents"), self) @@ -260,7 +260,7 @@ # setup connections self.__activating = False - if self.useQtHelp: + if HelpWindow._useQtHelp: # TOC window self.__tocWindow.linkActivated.connect(self.__linkActivated) self.__tocWindow.escapePressed.connect( @@ -294,7 +294,7 @@ self.flashCookieManager() - if self.useQtHelp: + if HelpWindow._useQtHelp: QTimer.singleShot(0, self.__lookForNewDocumentation) if self.__searchWord is not None: QTimer.singleShot(0, self.__searchForWord) @@ -1240,7 +1240,7 @@ self.__showFeaturePermissionDialog) self.__actions.append(self.featurePermissionAct) - if self.useQtHelp or self.initShortcutsOnly: + if HelpWindow._useQtHelp or self.initShortcutsOnly: self.syncTocAct = E5Action( self.tr('Sync with Table of Contents'), UI.PixmapCache.getIcon("syncToc.png"), @@ -1657,7 +1657,7 @@ menu.addSeparator() menu.addAction(self.stopAct) menu.addAction(self.reloadAct) - if self.useQtHelp: + if HelpWindow._useQtHelp: menu.addSeparator() menu.addAction(self.syncTocAct) @@ -1721,7 +1721,7 @@ menu.addAction(self.userAgentManagerAct) menu.addSeparator() - if self.useQtHelp: + if HelpWindow._useQtHelp: menu.addAction(self.manageQtHelpDocsAct) menu.addAction(self.manageQtHelpFiltersAct) menu.addAction(self.reindexDocumentationAct) @@ -1741,7 +1741,7 @@ menu = mb.addMenu(self.tr("&Window")) menu.setTearOffEnabled(True) menu.addAction(self.showDownloadManagerAct) - if self.useQtHelp: + if HelpWindow._useQtHelp: menu.addSeparator() menu.addAction(self.showTocAct) menu.addAction(self.showIndexAct) @@ -1807,7 +1807,7 @@ findtb.addAction(self.findNextAct) findtb.addAction(self.findPrevAct) - if self.useQtHelp: + if HelpWindow._useQtHelp: filtertb = self.addToolBar(self.tr("Filter")) filtertb.setObjectName("FilterToolBar") self.filterCombo = QComboBox() @@ -2262,7 +2262,7 @@ self.searchEdit.openSearchManager().close() - if self.useQtHelp: + if HelpWindow._useQtHelp: self.__searchEngine.cancelIndexing() self.__searchEngine.cancelSearching() @@ -2587,9 +2587,9 @@ @param use flag indicating usage (boolean) """ if use: - cls.useQtHelp = use and QTHELP_AVAILABLE + cls._useQtHelp = use and QTHELP_AVAILABLE else: - cls.useQtHelp = False + cls._useQtHelp = False @classmethod def helpEngine(cls): @@ -2600,13 +2600,25 @@ """ if cls.useQtHelp: if cls._helpEngine is None: - cls._helpEngine = \ - QHelpEngine(os.path.join(Utilities.getConfigDir(), - "browser", "eric6help.qhc")) + cls._helpEngine = QHelpEngine( + HelpWindow.getQtHelpCollectionFileName()) return cls._helpEngine else: return None - + + @classmethod + def getQtHelpCollectionFileName(cls): + """ + Class method to determine the name of the QtHelp collection file. + + @return path of the QtHelp collection file + @rtype str + """ + qthelpDir = os.path.join(Utilities.getConfigDir(), "qthelp") + if not os.path.exists(qthelpDir): + os.makedirs(qthelpDir) + return os.path.join(qthelpDir, "eric6help.qhc") + @classmethod def networkAccessManager(cls): """ @@ -2680,7 +2692,7 @@ """ Private slot to synchronize the TOC with the currently shown page. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: QApplication.setOverrideCursor(Qt.WaitCursor) url = self.currentBrowser().source() self.__showTocWindow() @@ -2693,42 +2705,42 @@ """ Private method to show the table of contents window. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: self.__activateDock(self.__tocWindow) def __hideTocWindow(self): """ Private method to hide the table of contents window. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: self.__tocDock.hide() def __showIndexWindow(self): """ Private method to show the index window. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: self.__activateDock(self.__indexWindow) def __hideIndexWindow(self): """ Private method to hide the index window. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: self.__indexDock.hide() def __showSearchWindow(self): """ Private method to show the search window. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: self.__activateDock(self.__searchWindow) def __hideSearchWindow(self): """ Private method to hide the search window. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: self.__searchDock.hide() def __activateDock(self, widget): @@ -2745,7 +2757,7 @@ """ Private slot to setup the filter combo box. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: curFilter = self.filterCombo.currentText() if not curFilter: curFilter = self.__helpEngine.currentFilter() @@ -2769,7 +2781,7 @@ """ Private slot to manage the QtHelp documentation database. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: from .QtHelpDocumentationDialog import QtHelpDocumentationDialog dlg = QtHelpDocumentationDialog(self.__helpEngine, self) dlg.exec_() @@ -2790,7 +2802,7 @@ """ Private slot to manage the QtHelp filters. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: from .QtHelpFiltersDialog import QtHelpFiltersDialog dlg = QtHelpFiltersDialog(self.__helpEngine, self) dlg.exec_() @@ -2799,7 +2811,7 @@ """ Private slot to handle the start of the indexing process. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: self.__indexing = True if self.__indexingProgress is None: self.__indexingProgress = QWidget() @@ -2826,7 +2838,7 @@ """ Private slot to handle the start of the indexing process. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: self.statusBar().removeWidget(self.__indexingProgress) self.__indexingProgress = None self.__indexing = False @@ -2837,7 +2849,7 @@ """ Private slot to search for a word. """ - if self.useQtHelp and not self.__indexing and \ + if HelpWindow._useQtHelp and not self.__indexing and \ self.__searchWord is not None: self.__searchDock.show() self.__searchDock.raise_() @@ -2852,7 +2864,7 @@ @param word word to search for (string) """ - if self.useQtHelp: + if HelpWindow._useQtHelp: self.__searchWord = word self.__searchForWord() @@ -2870,7 +2882,7 @@ Private slot to look for new documentation to be loaded into the help database. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: from .HelpDocsInstaller import HelpDocsInstaller self.__helpInstaller = HelpDocsInstaller( self.__helpEngine.collectionFile()) @@ -2900,7 +2912,7 @@ @param installed flag indicating that documents were installed (boolean) """ - if self.useQtHelp: + if HelpWindow._useQtHelp: if installed: self.__helpEngine.setupData() self.statusBar().clearMessage() @@ -2909,7 +2921,7 @@ """ Private slot to initialize the documentation database. """ - if self.useQtHelp: + if HelpWindow._useQtHelp: if not self.__helpEngine.setupData(): return
--- a/Helpviewer/QtHelpDocumentationDialog.py Mon Oct 10 19:21:22 2016 +0200 +++ b/Helpviewer/QtHelpDocumentationDialog.py Mon Oct 10 19:23:38 2016 +0200 @@ -14,6 +14,7 @@ from PyQt5.QtHelp import QHelpEngineCore from E5Gui import E5MessageBox, E5FileDialog +from E5Gui.E5Application import e5App from .Ui_QtHelpDocumentationDialog import Ui_QtHelpDocumentationDialog @@ -43,6 +44,15 @@ self.__registeredDocs = [] self.__unregisteredDocs = [] self.__tabsToClose = [] + + try: + self.__pluginHelpDocuments = \ + e5App().getObject("PluginManager").getPluginQtHelpFiles() + except KeyError: + from PluginManager.PluginManager import PluginManager + self.__pluginHelpDocuments = \ + PluginManager(self).getPluginQtHelpFiles() + self.addPluginButton.setEnabled(bool(self.__pluginHelpDocuments)) @pyqtSlot() def on_documentsList_itemSelectionChanged(self): @@ -137,6 +147,14 @@ self.documentsList.setCurrentRow( 0, QItemSelectionModel.ClearAndSelect) + @pyqtSlot() + def on_addPluginButton_clicked(self): + """ + Private slot to add QtHelp documents provided by plug-ins. + """ + # TODO: not implemented yet + raise NotImplementedError + def hasChanges(self): """ Public slot to test the dialog for changes.
--- a/Helpviewer/QtHelpDocumentationDialog.ui Mon Oct 10 19:21:22 2016 +0200 +++ b/Helpviewer/QtHelpDocumentationDialog.ui Mon Oct 10 19:23:38 2016 +0200 @@ -26,7 +26,20 @@ </item> <item> <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0" rowspan="3"> + <item row="3" column="1"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>98</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="0" rowspan="4"> <widget class="QListWidget" name="documentsList"> <property name="alternatingRowColors"> <bool>true</bool> @@ -49,7 +62,7 @@ </property> </widget> </item> - <item row="1" column="1"> + <item row="2" column="1"> <widget class="QPushButton" name="removeButton"> <property name="toolTip"> <string>Press to remove the selected documents from the database</string> @@ -59,18 +72,15 @@ </property> </widget> </item> - <item row="2" column="1"> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> + <item row="1" column="1"> + <widget class="QPushButton" name="addPluginButton"> + <property name="toolTip"> + <string>Press to select QtHelp documents provided by a plug-in to add to the database</string> </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>98</height> - </size> + <property name="text"> + <string>Add from Plug-ins...</string> </property> - </spacer> + </widget> </item> </layout> </item> @@ -89,8 +99,8 @@ <tabstops> <tabstop>documentsList</tabstop> <tabstop>addButton</tabstop> + <tabstop>addPluginButton</tabstop> <tabstop>removeButton</tabstop> - <tabstop>buttonBox</tabstop> </tabstops> <resources/> <connections>
--- a/WebBrowser/QtHelp/QtHelpDocumentationDialog.py Mon Oct 10 19:21:22 2016 +0200 +++ b/WebBrowser/QtHelp/QtHelpDocumentationDialog.py Mon Oct 10 19:23:38 2016 +0200 @@ -14,6 +14,7 @@ from PyQt5.QtHelp import QHelpEngineCore from E5Gui import E5MessageBox, E5FileDialog +from E5Gui.E5Application import e5App from .Ui_QtHelpDocumentationDialog import Ui_QtHelpDocumentationDialog @@ -43,6 +44,15 @@ self.__registeredDocs = [] self.__unregisteredDocs = [] self.__tabsToClose = [] + + try: + self.__pluginHelpDocuments = \ + e5App().getObject("PluginManager").getPluginQtHelpFiles() + except KeyError: + from PluginManager.PluginManager import PluginManager + self.__pluginHelpDocuments = \ + PluginManager(self).getPluginQtHelpFiles() + self.addPluginButton.setEnabled(bool(self.__pluginHelpDocuments)) @pyqtSlot() def on_documentsList_itemSelectionChanged(self): @@ -137,6 +147,14 @@ self.documentsList.setCurrentRow( 0, QItemSelectionModel.ClearAndSelect) + @pyqtSlot() + def on_addPluginButton_clicked(self): + """ + Private slot to add QtHelp documents provided by plug-ins. + """ + # TODO: not implemented yet + raise NotImplementedError + def hasChanges(self): """ Public slot to test the dialog for changes.
--- a/WebBrowser/QtHelp/QtHelpDocumentationDialog.ui Mon Oct 10 19:21:22 2016 +0200 +++ b/WebBrowser/QtHelp/QtHelpDocumentationDialog.ui Mon Oct 10 19:23:38 2016 +0200 @@ -26,7 +26,7 @@ </item> <item> <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0" rowspan="3"> + <item row="0" column="0" rowspan="4"> <widget class="QListWidget" name="documentsList"> <property name="alternatingRowColors"> <bool>true</bool> @@ -49,7 +49,7 @@ </property> </widget> </item> - <item row="1" column="1"> + <item row="2" column="1"> <widget class="QPushButton" name="removeButton"> <property name="toolTip"> <string>Press to remove the selected documents from the database</string> @@ -59,7 +59,7 @@ </property> </widget> </item> - <item row="2" column="1"> + <item row="3" column="1"> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum> @@ -72,6 +72,16 @@ </property> </spacer> </item> + <item row="1" column="1"> + <widget class="QPushButton" name="addPluginButton"> + <property name="toolTip"> + <string>Press to select QtHelp documents provided by a plug-in to add to the database</string> + </property> + <property name="text"> + <string>Add from Plug-ins...</string> + </property> + </widget> + </item> </layout> </item> <item> @@ -89,8 +99,8 @@ <tabstops> <tabstop>documentsList</tabstop> <tabstop>addButton</tabstop> + <tabstop>addPluginButton</tabstop> <tabstop>removeButton</tabstop> - <tabstop>buttonBox</tabstop> </tabstops> <resources/> <connections>
--- a/WebBrowser/WebBrowserWindow.py Mon Oct 10 19:21:22 2016 +0200 +++ b/WebBrowser/WebBrowserWindow.py Mon Oct 10 19:23:38 2016 +0200 @@ -83,7 +83,7 @@ BrowserWindows = [] _fromEric = False - UseQtHelp = QTHELP_AVAILABLE + _useQtHelp = QTHELP_AVAILABLE _isPrivate = False _webProfile = None @@ -187,10 +187,9 @@ from E5Network.E5SslUtilities import initSSL initSSL() - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: self.__helpEngine = QHelpEngine( - os.path.join(Utilities.getConfigDir(), - "web_browser", "eric6help.qhc"), + WebBrowserWindow.getQtHelpCollectionFileName(), self) self.__removeOldDocumentation() self.__helpEngine.warning.connect(self.__warning) @@ -228,7 +227,7 @@ self.setCentralWidget(centralWidget) self.__searchWidget.hide() - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: # setup the TOC widget self.__tocWindow = HelpTocWidget(self.__helpEngine) self.__tocDock = QDockWidget(self.tr("Contents"), self) @@ -327,7 +326,7 @@ # setup connections self.__activating = False - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: # TOC window self.__tocWindow.escapePressed.connect( self.__activateCurrentBrowser) @@ -372,7 +371,7 @@ self.flashCookieManager() - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: QTimer.singleShot(0, self.__lookForNewDocumentation) if self.__searchWord is not None: QTimer.singleShot(0, self.__searchForWord) @@ -1392,7 +1391,7 @@ self.__showFeaturePermissionDialog) self.__actions.append(self.featurePermissionAct) - if WebBrowserWindow.useQtHelp or self.__initShortcutsOnly: + if WebBrowserWindow._useQtHelp or self.__initShortcutsOnly: self.syncTocAct = E5Action( self.tr('Sync with Table of Contents'), UI.PixmapCache.getIcon("syncToc.png"), @@ -1828,7 +1827,7 @@ menu.addSeparator() menu.addAction(self.stopAct) menu.addAction(self.reloadAct) - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: menu.addSeparator() menu.addAction(self.syncTocAct) @@ -1894,7 +1893,7 @@ menu.addAction(self.userAgentManagerAct) menu.addSeparator() - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: menu.addAction(self.manageQtHelpDocsAct) menu.addAction(self.manageQtHelpFiltersAct) menu.addAction(self.reindexDocumentationAct) @@ -1914,7 +1913,7 @@ menu.addAction(self.showDownloadManagerAct) menu.addAction(self.showJavaScriptConsoleAct) menu.addAction(self.showTabManagerAct) - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: menu.addSeparator() menu.addAction(self.showTocAct) menu.addAction(self.showIndexAct) @@ -1992,7 +1991,7 @@ findtb.addAction(self.findNextAct) findtb.addAction(self.findPrevAct) - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: filtertb = self.addToolBar(self.tr("Filter")) filtertb.setObjectName("FilterToolBar") self.filterCombo = QComboBox() @@ -2553,7 +2552,7 @@ # it is the last window self.tabManager().close() - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: self.__searchEngine.cancelIndexing() self.__searchEngine.cancelSearching() @@ -2886,9 +2885,9 @@ @param use flag indicating usage (boolean) """ if use: - cls.useQtHelp = use and QTHELP_AVAILABLE + cls._useQtHelp = use and QTHELP_AVAILABLE else: - cls.useQtHelp = False + cls._useQtHelp = False @classmethod def helpEngine(cls): @@ -2897,15 +2896,27 @@ @return reference to the help engine (QHelpEngine) """ - if cls.useQtHelp: + if cls._useQtHelp: if cls._helpEngine is None: - cls._helpEngine = \ - QHelpEngine(os.path.join(Utilities.getConfigDir(), - "web_browser", "eric6help.qhc")) + cls._helpEngine = QHelpEngine( + WebBrowserWindow.getQtHelpCollectionFileName()) return cls._helpEngine else: return None - + + @classmethod + def getQtHelpCollectionFileName(cls): + """ + Class method to determine the name of the QtHelp collection file. + + @return path of the QtHelp collection file + @rtype str + """ + qthelpDir = os.path.join(Utilities.getConfigDir(), "qthelp") + if not os.path.exists(qthelpDir): + os.makedirs(qthelpDir) + return os.path.join(qthelpDir, "eric6help.qhc") + @classmethod def networkManager(cls): """ @@ -2966,7 +2977,7 @@ """ Private slot to synchronize the TOC with the currently shown page. """ - if WebBrowserWindow.UseQtHelp: + if WebBrowserWindow._useQtHelp: QApplication.setOverrideCursor(Qt.WaitCursor) url = self.currentBrowser().source() self.__showTocWindow() @@ -2979,21 +2990,21 @@ """ Private method to show the table of contents window. """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: self.__activateDock(self.__tocWindow) def __showIndexWindow(self): """ Private method to show the index window. """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: self.__activateDock(self.__indexWindow) def __showSearchWindow(self): """ Private method to show the search window. """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: self.__activateDock(self.__searchWindow) def __activateDock(self, widget): @@ -3010,7 +3021,7 @@ """ Private slot to setup the filter combo box. """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: curFilter = self.filterCombo.currentText() if not curFilter: curFilter = self.__helpEngine.currentFilter() @@ -3034,7 +3045,7 @@ """ Private slot to manage the QtHelp documentation database. """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: from .QtHelp.QtHelpDocumentationDialog import \ QtHelpDocumentationDialog dlg = QtHelpDocumentationDialog(self.__helpEngine, self) @@ -3056,7 +3067,7 @@ """ Private slot to manage the QtHelp filters. """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: from .QtHelp.QtHelpFiltersDialog import QtHelpFiltersDialog dlg = QtHelpFiltersDialog(self.__helpEngine, self) dlg.exec_() @@ -3065,7 +3076,7 @@ """ Private slot to handle the start of the indexing process. """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: self.__indexing = True if self.__indexingProgress is None: self.__indexingProgress = QWidget() @@ -3092,7 +3103,7 @@ """ Private slot to handle the start of the indexing process. """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: self.statusBar().removeWidget(self.__indexingProgress) self.__indexingProgress = None self.__indexing = False @@ -3103,7 +3114,7 @@ """ Private slot to search for a word. """ - if WebBrowserWindow.useQtHelp and not self.__indexing and \ + if WebBrowserWindow._useQtHelp and not self.__indexing and \ self.__searchWord is not None: self.__searchDock.show() self.__searchDock.raise_() @@ -3118,7 +3129,7 @@ @param word word to search for (string) """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: self.__searchWord = word self.__searchForWord() @@ -3136,7 +3147,7 @@ Private slot to look for new documentation to be loaded into the help database. """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: from .QtHelp.HelpDocsInstaller import HelpDocsInstaller self.__helpInstaller = HelpDocsInstaller( self.__helpEngine.collectionFile()) @@ -3166,7 +3177,7 @@ @param installed flag indicating that documents were installed (boolean) """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: if installed: self.__helpEngine.setupData() self.statusBar().clearMessage() @@ -3175,7 +3186,7 @@ """ Private slot to initialize the documentation database. """ - if WebBrowserWindow.useQtHelp: + if WebBrowserWindow._useQtHelp: if not self.__helpEngine.setupData(): return