--- a/eric7/WebBrowser/QtHelp/HelpIndexWidget.py Thu Jun 10 17:10:57 2021 +0200 +++ b/eric7/WebBrowser/QtHelp/HelpIndexWidget.py Thu Jun 10 19:32:22 2021 +0200 @@ -8,6 +8,7 @@ """ from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl, QEvent +from PyQt6.QtHelp import QHelpLink from PyQt6.QtWidgets import ( QWidget, QVBoxLayout, QLabel, QLineEdit, QMenu, QDialog, QApplication ) @@ -34,8 +35,10 @@ """ Constructor - @param engine reference to the help engine (QHelpEngine) - @param parent reference to the parent widget (QWidget) + @param engine reference to the help engine + @type QHelpEngine + @param parent reference to the parent widget + @type QWidget """ super().__init__(parent) @@ -62,9 +65,8 @@ self.__disableSearchEdit) self.__engine.indexModel().indexCreated.connect( self.__enableSearchEdit) - # TODO: change code to use documentActivated and documentsActivated - self.__index.linkActivated.connect(self.__linkActivated) - self.__index.linksActivated.connect(self.__linksActivated) + self.__index.documentActivated.connect(self.__documentActivated) + self.__index.documentsActivated.connect(self.__documentsActivated) self.__index.customContextMenuRequested.connect( self.__showContextMenu) self.__searchEdit.returnPressed.connect( @@ -72,12 +74,13 @@ self.__layout.addWidget(self.__index) @pyqtSlot(QUrl, str) - def __linkActivated(self, url, keyword, modifiers=None): + def __documentActivated(self, document, keyword, modifiers=None): """ Private slot to handle the activation of a keyword entry. - @param url URL of the selected entry - @type QUrl + @param document reference to a data structure containing the + document info + @type QHelpLink @param keyword keyword for the URL @type str @param modifiers keyboard modifiers @@ -85,65 +88,62 @@ """ if modifiers is None: modifiers = QApplication.keyboardModifiers() - if not url.isEmpty() and url.isValid(): - if ( - modifiers & ( - Qt.KeyboardModifier.ControlModifier | - Qt.KeyboardModifier.ShiftModifier - ) == ( - Qt.KeyboardModifier.ControlModifier | - Qt.KeyboardModifier.ShiftModifier - ) + if not document.url.isEmpty() and document.url.isValid(): + if modifiers & ( + Qt.KeyboardModifier.ControlModifier | + Qt.KeyboardModifier.ControlModifier ): - self.newBackgroundTab.emit(url) + self.newBackgroundTab.emit(document.url) elif modifiers & Qt.KeyboardModifier.ControlModifier: - self.newTab.emit(url) + self.newTab.emit(document.url) elif modifiers & Qt.KeyboardModifier.ShiftModifier: - self.newWindow.emit(url) + self.newWindow.emit(document.url) else: - self.openUrl.emit(url) + self.openUrl.emit(document.url) - def __linksActivated(self, links, keyword): + def __documentsActivated(self, documents, keyword): """ - Private slot to handle the activation of an entry with multiple links. + Private slot to handle the activation of an entry with multiple help + documents. - @param links dictionary containing the links - @type dict of key:str and value:QUrl + @param documents list of help document link data structures + @type list of QHelpLink @param keyword keyword for the entry @type str """ modifiers = QApplication.keyboardModifiers() - url = ( - QUrl(links[list(links.keys())[0]]) - if len(links) == 1 else - self.__selectLink(links, keyword) + document = ( + documents[0] + if len(documents) == 1 else + self.__selectDocument(documents, keyword) ) - self.__linkActivated(url, keyword, modifiers) + self.__documentActivated(document, keyword, modifiers) - def __selectLink(self, links, keyword): + def __selectDocument(self, documents, keyword): """ Private method to give the user a chance to select among the - returned links. + given documents. - @param links dictionary of document title and URL to select from - @type dictionary of str (key) and QUrl (value) - @param keyword keyword for the link set + @param documents list of help document link data structures + @type list of QHelpLink + @param keyword keyword for the documents @type str - @return selected link - @rtype QUrl + @return selected document + @rtype QHelpLink """ - link = QUrl() + document = QHelpLink() from .HelpTopicDialog import HelpTopicDialog - dlg = HelpTopicDialog(self, keyword, links) + dlg = HelpTopicDialog(self, keyword, documents) if dlg.exec() == QDialog.DialogCode.Accepted: - link = dlg.link() - return link + document = dlg.document() + return document def __filterIndices(self, indexFilter): """ Private slot to filter the indexes according to the given filter. - @param indexFilter filter to be used (string) + @param indexFilter filter to be used + @type str """ if '*' in indexFilter: self.__index.filterIndices(indexFilter, indexFilter) @@ -167,7 +167,8 @@ """ Protected method handling focus in events. - @param evt reference to the focus event object (QFocusEvent) + @param evt reference to the focus event object + @type QFocusEvent """ if evt.reason() != Qt.FocusReason.MouseFocusReason: self.__searchEdit.selectAll() @@ -177,9 +178,12 @@ """ Public method called to filter the event queue. - @param watched the QObject being watched (QObject) - @param event the event that occurred (QEvent) - @return flag indicating whether the event was handled (boolean) + @param watched the QObject being watched + @type QObject + @param event the event that occurred + @type QEvent + @return flag indicating whether the event was handled + @rtype bool """ if ( self.__searchEdit and watched == self.__searchEdit and @@ -205,7 +209,8 @@ """ Private slot showing the context menu. - @param pos position to show the menu at (QPoint) + @param pos position to show the menu at + @type QPoint """ idx = self.__index.indexAt(pos) if idx.isValid():