/
helpform.py
65 lines (50 loc) · 2.3 KB
/
helpform.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
# Copyright (c) 2008-10 Qtrac Ltd. All rights reserved.
# This program or module is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 2 of the License, or
# version 3 of the License, or (at your option) any later version. It is
# provided for educational purposes and is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QIcon, QKeySequence
from PyQt5.QtWidgets import QDialog, QLabel, QToolBar, QTextBrowser, QVBoxLayout, QApplication, QAction
import qrc_resource
class HelpForm(QDialog):
def __init__(self, page, parent=None):
super(HelpForm, self).__init__(parent)
self.setAttribute(Qt.WA_DeleteOnClose)
self.setAttribute(Qt.WA_GroupLeader)
backAction = QAction(QIcon(":/back.png"), "&Back", self)
backAction.setShortcut(QKeySequence.Back)
homeAction = QAction(QIcon(":/home.png"), "&Home", self)
homeAction.setShortcut("Home")
self.pageLabel = QLabel()
toolBar = QToolBar()
toolBar.addAction(backAction)
toolBar.addAction(homeAction)
toolBar.addWidget(self.pageLabel)
self.textBrowser = QTextBrowser()
layout = QVBoxLayout()
layout.addWidget(toolBar)
layout.addWidget(self.textBrowser, 1)
self.setLayout(layout)
backAction.triggered.connect(self.textBrowser.backward)
homeAction.triggered.connect(self.textBrowser.home)
self.textBrowser.sourceChanged[(QUrl)].connect(self.updatePageTitle)
self.textBrowser.setSearchPaths([":/help"])
#print(self.textBrowser.searchPaths())
self.textBrowser.setSource(QUrl(page))
self.resize(400, 600)
self.setWindowTitle("{} Help".format(
QApplication.applicationName()))
def updatePageTitle(self):
self.pageLabel.setText(self.textBrowser.documentTitle())
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
form = HelpForm("index.html")
form.show()
app.exec_()