src/eric7/QtHelpInterface/HelpTopicDialog.py

branch
eric7
changeset 9686
2eee7a645cba
parent 9653
e67609152c5e
child 10439
21c28b0f9e41
equal deleted inserted replaced
9685:b43e04854aba 9686:2eee7a645cba
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to select a help topic to display.
8 """
9
10 from PyQt6.QtCore import Qt
11 from PyQt6.QtHelp import QHelpLink
12 from PyQt6.QtWidgets import QDialog, QListWidgetItem
13
14 from .Ui_HelpTopicDialog import Ui_HelpTopicDialog
15
16
17 class HelpTopicDialog(QDialog, Ui_HelpTopicDialog):
18 """
19 Class implementing a dialog to select a help topic to display.
20 """
21
22 def __init__(self, parent, helpKeyword, documents):
23 """
24 Constructor
25
26 @param parent reference to the parent widget
27 @type QWidget
28 @param helpKeyword keyword for the link set
29 @type str
30 @param documents list of help document link data structures
31 @type list of QHelpLink
32 """
33 super().__init__(parent)
34 self.setupUi(self)
35
36 self.label.setText(
37 self.tr("Choose a &topic for <b>{0}</b>:").format(helpKeyword)
38 )
39
40 for document in documents:
41 itm = QListWidgetItem(document.title, self.topicsList)
42 itm.setData(Qt.ItemDataRole.UserRole, document.url)
43 if self.topicsList.count() > 0:
44 self.topicsList.setCurrentRow(0)
45 self.topicsList.setFocus()
46
47 self.topicsList.itemActivated.connect(self.accept)
48
49 def document(self):
50 """
51 Public method to retrieve the selected help topic.
52
53 @return help document link for the selected help topic
54 @rtype QHelpLink
55 """
56 document = QHelpLink()
57
58 itm = self.topicsList.currentItem()
59 if itm is not None:
60 document.title = itm.text()
61 document.url = itm.data(Qt.ItemDataRole.UserRole)
62
63 return document

eric ide

mercurial