|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2009 - 2022 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 def __init__(self, parent, helpKeyword, documents): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param parent reference to the parent widget |
|
26 @type QWidget |
|
27 @param helpKeyword keyword for the link set |
|
28 @type str |
|
29 @param documents list of help document link data structures |
|
30 @type list of QHelpLink |
|
31 """ |
|
32 super().__init__(parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 self.label.setText(self.tr("Choose a &topic for <b>{0}</b>:") |
|
36 .format(helpKeyword)) |
|
37 |
|
38 for document in documents: |
|
39 itm = QListWidgetItem(document.title, self.topicsList) |
|
40 itm.setData(Qt.ItemDataRole.UserRole, document.url) |
|
41 if self.topicsList.count() > 0: |
|
42 self.topicsList.setCurrentRow(0) |
|
43 self.topicsList.setFocus() |
|
44 |
|
45 self.topicsList.itemActivated.connect(self.accept) |
|
46 |
|
47 def document(self): |
|
48 """ |
|
49 Public method to retrieve the selected help topic. |
|
50 |
|
51 @return help document link for the selected help topic |
|
52 @rtype QHelpLink |
|
53 """ |
|
54 document = QHelpLink() |
|
55 |
|
56 itm = self.topicsList.currentItem() |
|
57 if itm is not None: |
|
58 document.title = itm.text() |
|
59 document.url = itm.data(Qt.ItemDataRole.UserRole) |
|
60 |
|
61 return document |