forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
textread.py
48 lines (39 loc) · 1.34 KB
/
textread.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt5.QtCore import QFile, QIODevice, QTextStream, QTextCodec
from PyQt5.QtWidgets import QTextBrowser
import res_rc # @UnresolvedImport @UnusedImport
# Created on 2018年5月1日
# author: Irony
# site: https://github.com/892768447
# email: [email protected]
# file: QRC资源文件使用.textread
# description:
__Author__ = """By: Irony
QQ: 892768447
Email: [email protected]"""
__Copyright__ = 'Copyright (c) 2018 Irony'
__Version__ = 1.0
class TextBrowser(QTextBrowser):
def __init__(self, *args, **kwargs):
super(TextBrowser, self).__init__(*args, **kwargs)
self.setText(self.readText(':/README.md'))
def readText(self, path):
file = QFile(path)
if not file.open(QIODevice.ReadOnly):
return ''
stream = QTextStream(file)
# 下面这句设置编码根据文件的编码自行确定
stream.setCodec(QTextCodec.codecForName('UTF-8'))
data = stream.readAll()
file.close()
del stream
return data
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
app.aboutToQuit.connect(res_rc.qCleanupResources) # 退出时要清理资源
w = TextBrowser()
w.show()
sys.exit(app.exec_())