forked from PyQt5/PyQtClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyQtClient.py
70 lines (59 loc) · 1.83 KB
/
PyQtClient.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
65
66
67
68
69
70
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019年1月1日
@author: Irony
@site: https://pyqt5.com https://github.com/892768447
@email: 892768447@qq.com
@file: PyQtClient
@description:
"""
import os
import sys
import traceback
__Author__ = """By: Irony
QQ: 892768447
Email: 892768447@qq.com"""
__Copyright__ = 'Copyright (c) 2019 Irony'
__Version__ = 1.0
sys.path.append(os.path.abspath('Library.zip'))
from PyQt5.QtWidgets import QApplication
libpath = os.path.abspath('Lib/site-packages/PyQt5/Qt/plugins')
if os.path.exists(libpath):
QApplication.addLibraryPath(libpath)
def escape(s):
s = s.replace("&", "&")
s = s.replace("<", "<")
s = s.replace(">", ">")
s = s.replace('"', """)
s = s.replace('\'', "'")
s = s.replace('\n', '<br/>')
s = s.replace(' ', ' ')
return s
def showError(message):
from PyQt5.QtWidgets import QErrorMessage, QCheckBox, \
QPushButton, QLabel, QStyle
from PyQt5.QtCore import Qt
app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(True)
# 设置内置错误图标
app.setWindowIcon(app.style().standardIcon(QStyle.SP_MessageBoxCritical))
w = QErrorMessage()
w.finished.connect(lambda _: app.quit)
w.resize(600, 400)
# 去掉右上角?
w.setWindowFlags(w.windowFlags() & ~Qt.WindowContextHelpButtonHint)
w.setWindowTitle(w.tr('Error'))
# 隐藏图标、勾选框、按钮
w.findChild(QLabel, '').setVisible(False)
w.findChild(QCheckBox, '').setVisible(False)
w.findChild(QPushButton, '').setVisible(False)
w.showMessage(escape(message))
sys.exit(app.exec_())
try:
from Widgets import MainWindow
MainWindow.main()
except SystemExit:
pass
except:
showError(traceback.format_exc())