-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainUI.py
192 lines (156 loc) · 6.15 KB
/
mainUI.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
import time
from PyQt6 import QtGui, QtCore
from PyQt6.QtCore import QCoreApplication
from PyQt6.QtGui import QAction
from PyQt6.QtWidgets import *
import sys
import os
import re
import loginin
import logindata
import warningbox
def createsis(mainwindow, userid, pas, operator):
# 创建会话类
logina = loginin.Loginof(userid, pas, operator)
rt = logina.on_login()
if rt[0] == 3:
for i in range(4):
time.sleep(2)
rt = logina.on_login()
if rt[0] != 3:
break
wmess = warningbox.Warningbox(rt)
wmess.jugmess(mainwindow)
return rt
def quitwin():
QCoreApplication.exit(0)
def writinpath(situ):
start_path = r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup'
flag = os.path.exists(start_path + r"\login_school.bat")
propath = os.path.abspath('.')
if flag:
if situ == "close":
os.remove(start_path + r"\login_school.bat")
else:
if situ == "open":
print("adminper.exe " + propath + ' ' + os.path.basename(sys.argv[0]))
os.system("adminper.exe " + propath + ' ' + os.path.basename(sys.argv[0]))
class Mainwindow(QWidget):
def __init__(self):
super(Mainwindow, self).__init__()
# 学号输入
self.text_userid = QLabel('Student number:')
self.enter_userid = QLineEdit()
# 密码输入
self.text_pas = QLabel('Password:')
self.enter_pas = QLineEdit()
self.enter_pas.setEchoMode(QLineEdit.EchoMode.Password)
# 运营商选择
self.text_oper = QLabel('Select operator:')
self.op_cbb = QComboBox(self)
self.op_cbb.addItem("中国移动")
self.op_cbb.addItem("中国联通")
# 提交按钮
self.subbutton = QPushButton("submit")
# 开机自启选择框
self.text_sta = QLabel('auto-start:')
self.startCheckbox = QCheckBox()
# 用户历史数据
'''{"id": "templateUser",
"pas": "123456",
"ope": 0}'''
self.database = logindata.usersdata()
self.enter_userid.setText(self.database.rutdefaultuesr()['id'])
self.enter_pas.setText(self.database.rutdefaultuesr()['pas'])
self.op_cbb.setCurrentIndex(self.database.rutdefaultuesr()['ope'])
self.startCheckbox.setChecked(self.database.rutdefaultuesr()['auto_start'])
def initui(self):
# 标签列
vboxl = QVBoxLayout()
vboxl.addWidget(self.text_userid)
vboxl.addWidget(self.text_pas)
vboxl.addWidget(self.text_oper)
# 输入组件列
vboxaction = QVBoxLayout()
vboxaction.addWidget(self.enter_userid)
vboxaction.addWidget(self.enter_pas)
vboxaction.addWidget(self.op_cbb)
# 表单填写组
hbox = QHBoxLayout()
hbox.addLayout(vboxl)
hbox.addLayout(vboxaction)
# 提交按钮,开机自启选项行
ablehbox = QHBoxLayout()
ablehbox.addWidget(self.text_sta)
ablehbox.addWidget(self.startCheckbox)
ablehbox.addStretch(1)
ablehbox.addWidget(self.subbutton)
# 整体布局
vboxall = QVBoxLayout()
vboxall.addLayout(hbox)
vboxall.addLayout(ablehbox)
self.setWindowTitle("LoginSetting")
self.setLayout(vboxall)
# self.setFixedSize(257, 125)
self.show()
class systray(QSystemTrayIcon):
def __init__(self, mainwindow, parent=None):
super(QSystemTrayIcon, self).__init__(parent)
self.menu = None
self.autoflag = 1
self.actionset = QAction("Setting", self)
self.actionquit = QAction("Quit", self)
self.actionlogin = QAction("Login", self)
self.actionset.triggered.connect(self.showui)
self.actionquit.triggered.connect(quitwin)
self.actionlogin.triggered.connect(lambda: self.onclicksub())
self.mainwindow = mainwindow
self.creatMenu()
# 提交按钮
mainwindow.subbutton.clicked.connect(lambda: self.onclicksub())
def onclicksub(self):
if self.mainwindow.enter_userid.text() != 'templateUser':
rt = createsis(self.mainwindow, self.mainwindow.enter_userid.text(),
self.mainwindow.enter_pas.text(),
self.mainwindow.op_cbb.currentText())
if self.mainwindow.startCheckbox.isChecked():
writinpath("open")
self.autoflag = 1
elif not self.mainwindow.startCheckbox.isChecked():
writinpath("close")
self.autoflag = 0
if (rt[0] == 1) or (rt[0] == 0 and rt[1] == 2):
self.mainwindow.database.changefault(self.mainwindow.enter_userid.text(),
self.mainwindow.enter_pas.text(),
self.mainwindow.op_cbb.currentIndex(),
self.autoflag)
self.mainwindow.showMinimized()
self.mainwindow.setWindowFlags(
QtCore.Qt.WindowType.SplashScreen | QtCore.Qt.WindowType.FramelessWindowHint)
self.mainwindow.hide()
def creatMenu(self):
self.menu = QMenu()
self.menu.addAction(self.actionset)
self.menu.addAction(self.actionlogin)
self.menu.addAction(self.actionquit)
self.setContextMenu(self.menu)
self.setIcon(QtGui.QIcon(r".\res\connect.ico"))
self.mainwindow.setWindowFlags(QtCore.Qt.WindowType.SplashScreen | QtCore.Qt.WindowType.FramelessWindowHint)
def showui(self):
self.mainwindow.showNormal()
self.mainwindow.activateWindow()
def check_network():
osOutPut = os.popen("netsh WLAN show interfaces").read()
if len(re.findall(r"SSID", osOutPut)) != 0:
return True
else:
return False
if __name__ == '__main__':
app = QApplication(sys.argv)
mainui = Mainwindow()
mainui.initui()
mainui.setWindowFlags(QtCore.Qt.WindowType.SplashScreen | QtCore.Qt.WindowType.FramelessWindowHint)
tray = systray(mainui)
tray.onclicksub()
tray.show()
sys.exit(app.exec())