--- a/eric7/HelpViewer/HelpViewerWidget.py Tue Oct 12 21:55:56 2021 +0200 +++ b/eric7/HelpViewer/HelpViewerWidget.py Wed Oct 13 18:15:30 2021 +0200 @@ -9,7 +9,7 @@ import os -from PyQt6.QtCore import pyqtSlot, QUrl +from PyQt6.QtCore import pyqtSlot, Qt, QUrl from PyQt6.QtGui import QAction from PyQt6.QtHelp import QHelpEngine from PyQt6.QtWidgets import ( @@ -25,6 +25,8 @@ from .OpenPagesWidget import OpenPagesWidget +from WebBrowser.QtHelp.HelpTocWidget import HelpTocWidget + class HelpViewerWidget(QWidget): """ @@ -42,6 +44,8 @@ self.__ui = parent + self.__initHelpEngine() + self.__layout = QVBoxLayout() self.__layout.setObjectName("MainLayout") self.__layout.setContentsMargins(0, 3, 0, 0) @@ -109,7 +113,6 @@ self.__buttonLine1.setFrameShadow(QFrame.Shadow.Sunken) self.__navButtonsLayout.addWidget(self.__buttonLine1) - # TODO: add zoom in button self.__zoomInButton = QToolButton(self) self.__zoomInButton.setIcon(UI.PixmapCache.getIcon("zoomIn")) self.__zoomInButton.setToolTip( @@ -117,7 +120,6 @@ self.__zoomInButton.clicked.connect(self.__zoomIn) self.__navButtonsLayout.addWidget(self.__zoomInButton) - # TODO: add zoom out button self.__zoomOutButton = QToolButton(self) self.__zoomOutButton.setIcon(UI.PixmapCache.getIcon("zoomOut")) self.__zoomOutButton.setToolTip( @@ -125,7 +127,6 @@ self.__zoomOutButton.clicked.connect(self.__zoomOut) self.__navButtonsLayout.addWidget(self.__zoomOutButton) - # TODO: add zoom reset button self.__zoomResetButton = QToolButton(self) self.__zoomResetButton.setIcon(UI.PixmapCache.getIcon("zoomReset")) self.__zoomResetButton.setToolTip( @@ -177,6 +178,9 @@ self.__openPagesButton = self.__addNavigationButton( "fileMisc", self.tr("Show list of open pages")) + self.__helpTocButton = self.__addNavigationButton( + "tableOfContents", self.tr("Show table of contents")) + self.__openPagesButton.setChecked(True) # TODO: add buttons for the QHelp related widgets @@ -223,10 +227,20 @@ """ Private method to populate the stack of navigation widgets. """ + # Open Pages self.__openPagesList = OpenPagesWidget(self.__helpStack, self) self.__openPagesList.currentChanged.connect(self.__checkActionButtons) self.__helpNavigationStack.addWidget(self.__openPagesList) + # QtHelp TOC + self.__tocWidget = HelpTocWidget(self.__helpEngine, internal=True) + self.__tocWidget.escapePressed.connect(self.__activateCurrentPage) + self.__tocWidget.openUrl.connect(self.openUrl) + self.__tocWidget.newTab.connect(self.openUrlNewPage) + self.__tocWidget.newBackgroundTab.connect( + self.openUrlNewBackgroundPage) + self.__helpNavigationStack.addWidget(self.__tocWidget) + # TODO: not yet implemented @pyqtSlot(QAbstractButton) @@ -239,6 +253,8 @@ """ if button == self.__openPagesButton: self.__helpNavigationStack.setCurrentWidget(self.__openPagesList) + elif button == self.__helpTocButton: + self.__helpNavigationStack.setCurrentWidget(self.__tocWidget) # TODO: not yet implemented @@ -290,7 +306,9 @@ @param searchWord word to search for (defaults to None) @type str (optional) """ - # TODO: not yet implemented + cv = self.currentViewer() + if cv: + cv.setFocus(Qt.FocusReason.OtherFocusReason) if searchWord: self.searchQtHelp(searchWord) @@ -309,18 +327,71 @@ if htmlFile: self.currentViewer().setUrl(QUrl.fromLocalFile(htmlFile)) - def addPage(self, url=QUrl("about:blank")): + def addPage(self, url=QUrl("about:blank"), background=False): """ Public method to add a new help page with the given URL. @param url requested URL (defaults to QUrl("about:blank")) @type QUrl (optional) + @param background flag indicating to open the page in the background + (defaults to False) + @type bool (optional) """ viewer = self.__newViewer() viewer.setUrl(url) + if background: + cv = self.currentViewer() + if cv: + index = self.__helpStack.indexOf(cv) + 1 + self.__helpStack.insertWidget(index, viewer) + self.__openPagesList.insertPage( + index, viewer, background=background) + return + self.__helpStack.addWidget(viewer) - self.__openPagesList.addPage(viewer) + self.__openPagesList.addPage(viewer, background=background) + + @pyqtSlot(QUrl) + def openUrl(self, url): + """ + Public slot to load a URL in the current page. + + @param url URL to be opened + @type QUrl + """ + cv = self.currentViewer() + if cv: + cv.setUrl(url) + + @pyqtSlot(QUrl) + def openUrlNewPage(self, url): + """ + Public slot to load a URL in a new page. + + @param url URL to be opened + @type QUrl + """ + self.addPage(url=url) + + @pyqtSlot(QUrl) + def openUrlNewBackgroundPage(self, url): + """ + Public slot to load a URL in a new background page. + + @param url URL to be opened + @type QUrl + """ + self.addPage(url=url, background=True) + + @pyqtSlot() + def __activateCurrentPage(self): + """ + Private slot to activate the current page. + """ + cv = self.currentViewer() + if cv: + cv.setFocus() def __newViewer(self): """ @@ -474,10 +545,16 @@ Private slot to set the enabled state of the action buttons. """ cv = self.currentViewer() - self.__backwardButton.setEnabled(cv and cv.isBackwardAvailable()) - self.__forwardButton.setEnabled(cv and cv.isForwardAvailable()) - self.__zoomInButton.setEnabled(cv and cv.isScaleUpAvailable()) - self.__zoomOutButton.setEnabled(cv and cv.isScaleDownAvailable()) + if cv: + self.__backwardButton.setEnabled(cv.isBackwardAvailable()) + self.__forwardButton.setEnabled(cv.isForwardAvailable()) + self.__zoomInButton.setEnabled(cv.isScaleUpAvailable()) + self.__zoomOutButton.setEnabled(cv.isScaleDownAvailable()) + else: + self.__backwardButton.setEnabled(False) + self.__forwardButton.setEnabled(False) + self.__zoomInButton.setEnabled(False) + self.__zoomOutButton.setEnabled(False) def __showBackMenu(self): """ @@ -529,7 +606,8 @@ cv = self.currentViewer() if cv: index = act.data() - cv.gotoHistory(index) + if index is not None: + cv.gotoHistory(index) def __clearHistory(self): """