5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog to select a help topic to display. |
7 Module implementing a dialog to select a help topic to display. |
8 """ |
8 """ |
9 |
9 |
|
10 from PyQt6.QtCore import Qt |
|
11 from PyQt6.QtHelp import QHelpLink |
10 from PyQt6.QtWidgets import QDialog |
12 from PyQt6.QtWidgets import QDialog |
11 from PyQt6.QtCore import QUrl |
|
12 |
13 |
13 from .Ui_HelpTopicDialog import Ui_HelpTopicDialog |
14 from .Ui_HelpTopicDialog import Ui_HelpTopicDialog |
14 |
15 |
15 |
16 |
16 class HelpTopicDialog(QDialog, Ui_HelpTopicDialog): |
17 class HelpTopicDialog(QDialog, Ui_HelpTopicDialog): |
17 """ |
18 """ |
18 Class implementing a dialog to select a help topic to display. |
19 Class implementing a dialog to select a help topic to display. |
19 """ |
20 """ |
20 def __init__(self, parent, keyword, links): |
21 def __init__(self, parent, keyword, documents): |
21 """ |
22 """ |
22 Constructor |
23 Constructor |
23 |
24 |
24 @param parent reference to the parent widget (QWidget) |
25 @param parent reference to the parent widget |
25 @param keyword keyword for the link set (string) |
26 @type QWidget |
26 @param links dictionary with help topic as key (string) and |
27 @param keyword keyword for the link set |
27 URL as value (QUrl) |
28 @type str |
|
29 @param documents list of help document link data structures |
|
30 @type list of QHelpLink |
28 """ |
31 """ |
29 super().__init__(parent) |
32 super().__init__(parent) |
30 self.setupUi(self) |
33 self.setupUi(self) |
31 |
34 |
32 self.label.setText(self.tr("Choose a &topic for <b>{0}</b>:") |
35 self.label.setText(self.tr("Choose a &topic for <b>{0}</b>:") |
33 .format(keyword)) |
36 .format(keyword)) |
34 |
37 |
35 self.__links = links |
38 for document in documents: |
36 for topic in sorted(self.__links): |
39 itm = self.topicsList.addItem(document.title) |
37 self.topicsList.addItem(topic) |
40 itm.setData(Qt.ItemDataRole.UserRole, document.url) |
38 if self.topicsList.count() > 0: |
41 if self.topicsList.count() > 0: |
39 self.topicsList.setCurrentRow(0) |
42 self.topicsList.setCurrentRow(0) |
40 self.topicsList.setFocus() |
43 self.topicsList.setFocus() |
41 |
44 |
42 self.topicsList.itemActivated.connect(self.accept) |
45 self.topicsList.itemActivated.connect(self.accept) |
43 |
46 |
44 def link(self): |
47 def document(self): |
45 """ |
48 """ |
46 Public method to the link of the selected topic. |
49 Public method to retrieve the selected help topic. |
47 |
50 |
48 @return URL of the selected topic (QUrl) |
51 @return help document link for the selected help topic |
|
52 @rtype QHelpLink |
49 """ |
53 """ |
|
54 document = QHelpLink() |
|
55 |
50 itm = self.topicsList.currentItem() |
56 itm = self.topicsList.currentItem() |
51 if itm is None: |
57 if itm is not None: |
52 return QUrl() |
58 document.title = itm.text() |
|
59 document.url = itm.data(Qt.ItemDataRole.UserRole) |
53 |
60 |
54 topic = itm.text() |
61 return document |
55 if topic == "" or topic not in self.__links: |
|
56 return QUrl() |
|
57 |
|
58 return self.__links[topic] |
|