eric7/WebBrowser/QtHelp/HelpTopicDialog.py

branch
eric7
changeset 8421
cd4eee7f1d28
parent 8318
962bce857696
child 8565
207b47c2eed9
--- a/eric7/WebBrowser/QtHelp/HelpTopicDialog.py	Thu Jun 10 17:10:57 2021 +0200
+++ b/eric7/WebBrowser/QtHelp/HelpTopicDialog.py	Thu Jun 10 19:32:22 2021 +0200
@@ -7,8 +7,9 @@
 Module implementing a dialog to select a help topic to display.
 """
 
+from PyQt6.QtCore import Qt
+from PyQt6.QtHelp import QHelpLink
 from PyQt6.QtWidgets import QDialog
-from PyQt6.QtCore import QUrl
 
 from .Ui_HelpTopicDialog import Ui_HelpTopicDialog
 
@@ -17,14 +18,16 @@
     """
     Class implementing a dialog to select a help topic to display.
     """
-    def __init__(self, parent, keyword, links):
+    def __init__(self, parent, keyword, documents):
         """
         Constructor
         
-        @param parent reference to the parent widget (QWidget)
-        @param keyword keyword for the link set (string)
-        @param links dictionary with help topic as key (string) and
-            URL as value (QUrl)
+        @param parent reference to the parent widget
+        @type QWidget
+        @param keyword keyword for the link set
+        @type str
+        @param documents list of help document link data structures
+        @type list of QHelpLink
         """
         super().__init__(parent)
         self.setupUi(self)
@@ -32,27 +35,27 @@
         self.label.setText(self.tr("Choose a &topic for <b>{0}</b>:")
                            .format(keyword))
         
-        self.__links = links
-        for topic in sorted(self.__links):
-            self.topicsList.addItem(topic)
+        for document in documents:
+            itm = self.topicsList.addItem(document.title)
+            itm.setData(Qt.ItemDataRole.UserRole, document.url)
         if self.topicsList.count() > 0:
             self.topicsList.setCurrentRow(0)
         self.topicsList.setFocus()
         
         self.topicsList.itemActivated.connect(self.accept)
     
-    def link(self):
+    def document(self):
         """
-        Public method to the link of the selected topic.
+        Public method to retrieve the selected help topic.
         
-        @return URL of the selected topic (QUrl)
+        @return help document link for the selected help topic
+        @rtype QHelpLink
         """
+        document = QHelpLink()
+        
         itm = self.topicsList.currentItem()
-        if itm is None:
-            return QUrl()
+        if itm is not None:
+            document.title = itm.text()
+            document.url = itm.data(Qt.ItemDataRole.UserRole)
         
-        topic = itm.text()
-        if topic == "" or topic not in self.__links:
-            return QUrl()
-        
-        return self.__links[topic]
+        return document

eric ide

mercurial