WebBrowser/QtHelp/HelpTopicDialog.py

branch
QtWebEngine
changeset 4875
4ee26909ac0d
parent 4631
5c1a96925da4
child 5389
9b1c800daff3
equal deleted inserted replaced
4870:72901685681d 4875:4ee26909ac0d
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 2016 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 __future__ import unicode_literals
11
12 from PyQt5.QtWidgets import QDialog
13 from PyQt5.QtCore import QUrl
14
15 from .Ui_HelpTopicDialog import Ui_HelpTopicDialog
16
17
18 class HelpTopicDialog(QDialog, Ui_HelpTopicDialog):
19 """
20 Class implementing a dialog to select a help topic to display.
21 """
22 def __init__(self, parent, keyword, links):
23 """
24 Constructor
25
26 @param parent reference to the parent widget (QWidget)
27 @param keyword keyword for the link set (string)
28 @param links dictionary with help topic as key (string) and
29 URL as value (QUrl)
30 """
31 super(HelpTopicDialog, self).__init__(parent)
32 self.setupUi(self)
33
34 self.label.setText(self.tr("Choose a &topic for <b>{0}</b>:")
35 .format(keyword))
36
37 self.__links = links
38 for topic in sorted(self.__links):
39 self.topicsList.addItem(topic)
40 if self.topicsList.count() > 0:
41 self.topicsList.setCurrentRow(0)
42 self.topicsList.setFocus()
43
44 self.topicsList.itemActivated.connect(self.accept)
45
46 def link(self):
47 """
48 Public method to the link of the selected topic.
49
50 @return URL of the selected topic (QUrl)
51 """
52 itm = self.topicsList.currentItem()
53 if itm is None:
54 return QUrl()
55
56 topic = itm.text()
57 if topic == "" or topic not in self.__links:
58 return QUrl()
59
60 return self.__links[topic]

eric ide

mercurial