-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.py
241 lines (218 loc) · 11.6 KB
/
GUI.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# -*- coding: utf-8 -*-
import sys
import time
# Form implementation generated from reading ui file 'MainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt6.QtCore import QThread, pyqtSignal, QSettings
from StatusFetcher import returnStatus
from MachineURL import *
from GlobalVar import global_result
import icon_rc
class getStatusThread(QThread):
finished = pyqtSignal()
def __init__(self, building, side, parent=None):
super().__init__(parent)
self.parent = parent
self.building = building
self.side = side
def run(self):
result = self.msgGenerator()
# 赋值给全局变量global_result
global global_result
global_result = result
self.finished.emit()
def msgGenerator(self):
result='抱歉,暂时不支持该楼的洗衣机查询'
if self.building == "东十九":
if self.side == "兆基":
urlList = D19[0]
result = self.building + '楼' + self.side + '侧洗衣机状态:\n\n'
result = result + returnStatus(urlList)
elif self.side == "常工":
urlList = D19[1]
result = self.building + '楼' + self.side + '侧洗衣机状态:\n\n'
result = result + returnStatus(urlList)
elif self.building == "西一":
if self.side=='混合':
urlList = X1_Machine_1
result='每层第一台洗衣机状态:\n\n'
result=result+returnStatus(urlList)
urlList = X1_Machine_2
result = result + '每层第二台洗衣机状态:\n\n'
result = result + returnStatus(urlList)
return result
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(907, 699)
self.centralwidget = QtWidgets.QWidget(parent=MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.label_4 = QtWidgets.QLabel(parent=self.centralwidget)
font = QtGui.QFont()
font.setFamily("华文新魏")
font.setPointSize(16)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 1, 2, 1, 1, QtCore.Qt.AlignmentFlag.AlignHCenter)
self.pushButton_ExitProgram = QtWidgets.QPushButton(parent=self.centralwidget)
font = QtGui.QFont()
font.setFamily("华文新魏")
font.setPointSize(18)
self.pushButton_ExitProgram.setFont(font)
self.pushButton_ExitProgram.setObjectName("pushButton_ExitProgram")
self.gridLayout.addWidget(self.pushButton_ExitProgram, 11, 2, 1, 1)
self.label_2 = QtWidgets.QLabel(parent=self.centralwidget)
font = QtGui.QFont()
font.setFamily("华文新魏")
font.setPointSize(18)
self.label_2.setFont(font)
self.label_2.setAutoFillBackground(False)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 5, 1, 1, 1, QtCore.Qt.AlignmentFlag.AlignHCenter)
self.label_3 = QtWidgets.QLabel(parent=self.centralwidget)
font = QtGui.QFont()
font.setFamily("华文新魏")
font.setPointSize(18)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 6, 1, 1, 1, QtCore.Qt.AlignmentFlag.AlignHCenter|QtCore.Qt.AlignmentFlag.AlignVCenter)
self.pushButton_About = QtWidgets.QPushButton(parent=self.centralwidget)
font = QtGui.QFont()
font.setFamily("华文新魏")
font.setPointSize(18)
self.pushButton_About.setFont(font)
self.pushButton_About.setObjectName("pushButton_About")
self.gridLayout.addWidget(self.pushButton_About, 11, 1, 1, 1)
self.pushButton_UploadData = QtWidgets.QPushButton(parent=self.centralwidget)
font = QtGui.QFont()
font.setFamily("华文新魏")
font.setPointSize(18)
self.pushButton_UploadData.setFont(font)
self.pushButton_UploadData.setObjectName("pushButton_UploadData")
self.gridLayout.addWidget(self.pushButton_UploadData, 8, 2, 1, 1)
self.comboBox_SideSelect = QtWidgets.QComboBox(parent=self.centralwidget)
font = QtGui.QFont()
font.setFamily("华文新魏")
font.setPointSize(18)
self.comboBox_SideSelect.setFont(font)
self.comboBox_SideSelect.setObjectName("comboBox_SideSelect")
self.gridLayout.addWidget(self.comboBox_SideSelect, 6, 2, 1, 1)
self.pushButton_StartCheck = QtWidgets.QPushButton(parent=self.centralwidget)
font = QtGui.QFont()
font.setFamily("华文新魏")
font.setPointSize(18)
self.pushButton_StartCheck.setFont(font)
self.pushButton_StartCheck.setObjectName("pushButton_StartCheck")
self.gridLayout.addWidget(self.pushButton_StartCheck, 8, 1, 1, 1)
self.comboBox_BuildingSelect = QtWidgets.QComboBox(parent=self.centralwidget)
font = QtGui.QFont()
font.setFamily("华文新魏")
font.setPointSize(18)
self.comboBox_BuildingSelect.setFont(font)
self.comboBox_BuildingSelect.setObjectName("comboBox_BuildingSelect")
self.comboBox_BuildingSelect.addItem("")
self.comboBox_BuildingSelect.addItem("")
self.comboBox_BuildingSelect.addItem("")
self.gridLayout.addWidget(self.comboBox_BuildingSelect, 5, 2, 1, 1)
self.textBrowser_ShowResult = QtWidgets.QTextBrowser(parent=self.centralwidget)
self.textBrowser_ShowResult.setObjectName("textBrowser_ShowResult")
self.gridLayout.addWidget(self.textBrowser_ShowResult, 12, 1, 1, 2)
self.label = QtWidgets.QLabel(parent=self.centralwidget)
font = QtGui.QFont()
font.setFamily("华文新魏")
font.setPointSize(20)
self.label.setFont(font)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 1, 1, 1, 1, QtCore.Qt.AlignmentFlag.AlignHCenter)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
self.pushButton_StartCheck.clicked.connect(self.StartCheck) # type: ignore
self.pushButton_ExitProgram.clicked.connect(self.ExitProgram) # type: ignore
self.pushButton_UploadData.clicked.connect(self.UploadData) # type: ignore
self.pushButton_About.clicked.connect(self.AboutProgram) # type: ignore
self.comboBox_BuildingSelect.currentTextChanged['QString'].connect(self.UpdateSideSelect) # type: ignore
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label_4.setText(_translate("MainWindow", "For SCNU"))
self.pushButton_ExitProgram.setText(_translate("MainWindow", "退出程序"))
self.label_2.setText(_translate("MainWindow", "选择宿舍楼:"))
self.label_3.setText(_translate("MainWindow", "选择水控端:"))
self.pushButton_About.setText(_translate("MainWindow", "关于程序"))
self.pushButton_UploadData.setText(_translate("MainWindow", "协助开发"))
self.pushButton_StartCheck.setText(_translate("MainWindow", "开始查询"))
self.comboBox_BuildingSelect.setItemText(0, _translate("MainWindow", "东十九"))
self.comboBox_BuildingSelect.setItemText(1, _translate("MainWindow", "西一"))
self.comboBox_BuildingSelect.setItemText(2, _translate("MainWindow", "西二"))
self.label.setText(_translate("MainWindow", "U净洗衣机状态查询器"))
# 设置字体为18,华文新魏
font = QtGui.QFont()
font.setFamily("华文新魏")
font.setPointSize(16)
self.textBrowser_ShowResult.setFont(font)
# 设置窗口图标,利用icon_rc.py文件
MainWindow.setWindowIcon(QtGui.QIcon(':/icon.ico'))
# 设置窗口标题
MainWindow.setWindowTitle("U Clean Status Checker")
self.textBrowser_ShowResult.clear()
self.textBrowser_ShowResult.setText(
'本项目GitHub地址: https://github.com/AnInsomniacy\n\n如需支持更多宿舍楼的洗衣机,请点击"协助开发"按钮,帮助作者获得必要信息\n\n本程序仅供学习交流使用,请勿用于非法用途')
# 加载上一次选择的值BuildingSelect
settings = QSettings("HIDAYAT-Lee", "U Clean Status Checker")
index = settings.value('index', type=int)
self.comboBox_BuildingSelect.setCurrentIndex(index)
self.comboBox_BuildingSelect.currentIndexChanged.connect(self.saveIndex)
self.UpdateSideSelect()
def StartCheck(self):
# 按钮变灰
self.pushButton_StartCheck.setEnabled(False)
# 改变按钮文字
self.pushButton_StartCheck.setText("查询中...")
# 创建线程
self.thread = getStatusThread(self.comboBox_BuildingSelect.currentText(),
self.comboBox_SideSelect.currentText())
# 连接信号
self.thread.finished.connect(self.doneThread)
self.thread.start()
def doneThread(self):
self.pushButton_StartCheck.setEnabled(True)
self.thread.quit()
self.thread.wait()
self.thread.deleteLater()
self.thread = None
self.pushButton_StartCheck.setText("开始查询")
self.textBrowser_ShowResult.setText(global_result)
def ExitProgram(self):
sys.exit()
def UploadData(self):
# 输出文字到文本框,先清空
self.textBrowser_ShowResult.clear()
self.textBrowser_ShowResult.setText(
"如需支持更多宿舍楼的洗衣机,请协助作者获取对应宿舍楼的洗衣机URL\n\n洗衣机的二维码扫描之后,会得到一串指向这台机器的链接\n\n请前往GitHub提交issue,并附加洗衣机二维码扫描后得到的链接。\n\n请按照以下格式提交: xx楼xx侧xx层洗衣机:扫码得到的url\n\n如: 东十九楼兆基侧一层洗衣机:http://app.littleswan.com/u_download.html?type=Ujing& uuid=0000000000000A0007555201809040059546\n\n作者将及时更新并提供支持服务")
def AboutProgram(self):
# 输出文字到文本框,先清空
self.textBrowser_ShowResult.clear()
self.textBrowser_ShowResult.setText(
'本项目GitHub地址: https://github.com/AnInsomniacy\n\n如需支持更多宿舍楼的洗衣机,请点击"协助开发"按钮,帮助作者获得必要信息\n\n本程序仅供学习交流使用,请勿用于非法用途\n\n代码已开源,欢迎各位提出建议')
def UpdateSideSelect(self):
# 清空下拉框
self.comboBox_SideSelect.clear()
# 选择宿舍楼后,更新下拉框
if self.comboBox_BuildingSelect.currentText() == "东十九":
self.comboBox_SideSelect.addItem("兆基")
self.comboBox_SideSelect.addItem("常工")
elif self.comboBox_BuildingSelect.currentText() == "西一":
self.comboBox_SideSelect.addItem("混合")
elif self.comboBox_BuildingSelect.currentText() == "西二":
self.comboBox_SideSelect.addItem("混合")
def saveIndex(self, index):
settings = QSettings("AnInsomniacy", "U Clean Status Checker")
settings.setValue('index', index)