-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
380 lines (328 loc) · 12.7 KB
/
main.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
"""
单机版程序,界面使用tkinter或pyQt等,数据存入MySql数据库,
数据存入时加密存储,加密算法可以采用Crypto包,利用AES或DES算法。
数据记录的录入界面中,可以包含记录类别(银行账户、校内账户、社交账户、邮箱账户等),
记录包含名称、账户名、密码、网址、注册手机、备注等信息,所有数据都以加密形式存入数据库中。
该系统具有增删改查功能,具有用户登录功能。,
在显示查询内容之前需要输入登录密码进行验证,并且只显示要查询的记录信息。
"""
import sys
from PyQt5.QtGui import QMovie
# PyQt5中使用的基本控件都在PyQt5.QtWidgets模块中
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QAbstractItemView, QTableWidgetItem, QHeaderView
# 导入designer工具生成的login模块f
from UI import Ui_widget
import function as fun
G_user = ""
SaveMode = 'save'
SelectId = 0
class MyMainForm(QMainWindow, Ui_widget):
def __init__(self, parent=None):
super(MyMainForm, self).__init__(parent)
self.setupUi(self)
self.rb_main_another.setChecked(True) # 设置默认选中
self.tabWidget.tabBar().hide()
self.bac = QMovie('img/g1.gif')
self.label_hello_gif.setMovie(self.bac)
self.bac.start()
self.tabWidget.setCurrentIndex(0)
'''
hello
'''
fun.init_project()
saved, auto, user, password = fun.is_login()
self.le_login_account.setText(user)
self.le_login_password.setText(password)
self.cb_login_remember.setChecked(saved)
self.cb_login_auto.setChecked(auto)
if auto:
self.f_btn_login_login()
self.btn_hello_start.clicked.connect(lambda: self.tab_jump(1))
table = self.table_show
table.setEditTriggers(QAbstractItemView.NoEditTriggers)
table.setSelectionBehavior(QAbstractItemView.SelectRows)
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
'''
login
'''
self.cb_login_auto.stateChanged.connect(self.f_cb_login_auto)
self.btn_login_regist.clicked.connect(lambda: self.tab_jump(2))
self.btn_login_login.clicked.connect(self.f_btn_login_login)
'''
regist
'''
self.btn_regist_back.clicked.connect(self.f_btn_regist_back)
self.btn_regist_ok.clicked.connect(self.f_btn_regist_ok)
self.le_regist_password2.editingFinished.connect(self.f_le_regist_ok2)
'''
menu
'''
self.btn_menu_add.clicked.connect(lambda: self.tab_jump(4))
self.btn_menu_show.clicked.connect(self.f_btn_menu_show)
self.btn_menu_exit.clicked.connect(self.f_btn_menu_exit)
'''
main
'''
self.btn_main_back.clicked.connect(lambda: self.tab_jump(3))
self.btn_main_save.clicked.connect(self.f_btn_main_save)
'''
show
'''
self.btn_show_back.clicked.connect(self.f_btn_show_back)
self.btn_show_search.clicked.connect(self.f_btn_show_search)
self.btn_show_delete.clicked.connect(self.f_btn_show_delete)
self.comboBox_show.currentIndexChanged.connect(self.f_comboBox_show_search)
self.le_show_search.setEnabled(False)
self.btn_show_change.clicked.connect(self.f_btn_show_change)
'''
综合
'''
def clear_main(self):
self.rb_main_another.setChecked(True)
self.le_main_name.clear()
self.le_main_account.clear()
self.le_main_password.clear()
self.le_main_address.clear()
self.le_main_phone.clear()
self.le_main_remark.clear()
def table_clear(self):
num = self.table_show.rowCount()
for i in range(0, num):
self.table_show.removeRow(0)
def tab_jump(self, a):
self.tabWidget.setCurrentIndex(a)
def show_info(self, title, text):
reply = QMessageBox.information(self, title, text, QMessageBox.Ok, QMessageBox.Ok)
return reply
def table_data(self, mode='all', key='null'):
global G_user
table = self.table_show
if mode == 'all':
data = fun.show(G_user)
else:
data = fun.search(G_user, mode, key)
x = 0
if not data:
return
for i in data:
y = 0
# print(i) #todo 获取的消息
i = list(i)
i.pop(1)
# print(i) #todo 删除了用户
table.insertRow(table.rowCount())
for j in i:
table.setItem(x, y, QTableWidgetItem(str(j)))
y += 1
x += 1
'''
Login
'''
def f_cb_login_auto(self):
if self.cb_login_auto.isChecked():
self.cb_login_remember.setChecked(True)
def f_btn_login_login(self):
acc = self.le_login_account
pwd = self.le_login_password
if acc.text() == 'admin' and pwd.text() == 'admin':
self.tab_jump(3)
return False
if acc.text() == '':
self.show_info('账号不能为空', '账号不能为空')
return False
elif pwd.text() == '':
self.show_info('密码不能为空', '密码不能为空')
return False
if fun.login(acc.text(), pwd.text()):
global G_user
G_user = acc.text()
fun.save_login(acc.text(), pwd.text(), self.cb_login_remember.isChecked(), self.cb_login_auto.isChecked())
print('登陆成功') # todo 信息框
self.label_menu_user.setText(f'迷糊工具,欢迎用户:{acc.text()}')
self.tab_jump(3)
else:
print('用户名或密码错误,请重新输入')
acc.clear()
pwd.clear()
acc.setFocus()
'''
regist
'''
def f_le_regist_ok2(self):
ok1 = self.le_regist_password
ok2 = self.le_regist_password2
if ok1.text() != ok2.text():
self.show_info('错误', '与第一次密码不符')
def f_btn_regist_back(self):
self.le_regist_account.clear()
self.le_regist_password.clear()
self.le_regist_password2.clear()
self.tab_jump(1)
def f_btn_regist_ok(self):
acc = self.le_regist_account
pwd = self.le_regist_password
if acc.text() == '':
self.show_info('账号不能为空', '账号不能为空')
return False
elif pwd.text() == '':
self.show_info('密码不能为空', '密码不能为空')
return False
if fun.regist(acc.text(), pwd.text()):
self.show_info('注册成功', f"""
注册成功,您的信息如下:
账号:{acc.text()}
密码:{pwd.text()}
""")
self.le_login_account.setText(acc.text())
self.le_login_password.setText(pwd.text())
self.f_btn_regist_back()
self.f_btn_login_login()
else:
print(f'已存在{acc.text()},请重新注册')
acc.clear()
pwd.clear()
self.le_regist_password2.clear()
acc.setFocus()
'''
menu
'''
def f_btn_menu_show(self):
self.tab_jump(5)
self.table_data()
def f_btn_menu_exit(self):
self.tab_jump(1)
self.table_show.clearContents()
self.le_login_account.clear()
self.le_login_password.clear()
self.cb_login_remember.setChecked(False)
self.cb_login_auto.setChecked(False)
self.table_clear()
'''
main
'''
def f_btn_main_save(self):
if self.rb_main_bank.isChecked():
a_type = "bank"
elif self.rb_main_school.isChecked():
a_type = "school"
elif self.rb_main_social.isChecked():
a_type = "social"
elif self.rb_main_mail.isChecked():
a_type = "mail"
else:
a_type = "another"
a_name = self.le_main_name.text()
a_account = self.le_main_account.text()
a_password = self.le_main_password.text()
a_address = self.le_main_address.text()
a_phone = self.le_main_phone.text()
a_remark = self.le_main_remark.toPlainText()
print("获取成功")
global SaveMode
if SaveMode == 'change':
SaveMode = 'save'
fun.update(SelectId, a_type, a_name, a_account, a_password, a_address, a_phone, a_remark)
self.clear_main()
self.table_clear()
self.table_data('id', str(SelectId))
self.tab_jump(5)
return
global G_user
result = fun.save_line(G_user, a_type, a_name, a_account, a_password, a_address, a_phone, a_remark)
se = QMessageBox.information(self, "是否打印保存的信息", "是否打印保存的信息", QMessageBox.Yes | QMessageBox.No,
QMessageBox.Yes)
if result:
if se == QMessageBox.Yes:
self.show_info("保存成功", f"""
当前用户:{G_user}\t\t
保存信息如下:
名称:{a_name}
账户名:{a_account}
密码:{a_password}
网址:{a_address}
注册手机:{a_phone}
备注:{a_remark}
""")
# self.table_show.
self.clear_main()
'''
show
'''
def f_comboBox_show_search(self):
if (self.comboBox_show.currentIndex() == 0) or ("类型" in self.comboBox_show.currentText()):
self.le_show_search.clear()
self.le_show_search.setEnabled(False)
else:
self.le_show_search.setEnabled(True)
def f_btn_show_back(self):
self.tab_jump(3)
self.table_clear()
def f_btn_show_delete(self):
# print(self.table_show.currentRow())
table = self.table_show
global SelectId
SelectId = table.item(table.currentIndex().row(), 0).text()
fun.delete(SelectId)
self.table_clear()
self.table_data()
def f_btn_show_change(self):
global SaveMode
SaveMode = 'change'
select_data = []
table = self.table_show
row = table.currentIndex().row()
for i in range(0, table.columnCount()):
select_data.append(table.item(row, i).text())
# print(select_data)
global SelectId
SelectId = select_data[0]
eval('self.rb_main_' + select_data[1]).setChecked(True)
self.le_main_name.setText(select_data[2])
self.le_main_account.setText(select_data[3])
self.le_main_password.setText(select_data[4])
self.le_main_address.setText(select_data[5])
self.le_main_phone.setText(select_data[6])
self.le_main_remark.setText(select_data[7])
self.tab_jump(4)
def f_btn_show_search(self):
self.table_clear()
key = self.le_show_search.text()
cbox = self.comboBox_show
box_text = cbox.currentText()
get_date = self.table_data
if box_text == "名称":
get_date("name", key)
elif box_text == "账户名":
get_date("account", key)
elif box_text == "密码":
get_date("password", key)
elif box_text == "网址":
get_date("address", key)
elif box_text == "手机":
get_date("phone", key)
elif box_text == "备注":
get_date("remark", key)
elif box_text == "银行账户类型":
get_date("atype", "bank")
elif box_text == "学校账户类型":
get_date("atype", "school")
elif box_text == "社交账户类型":
get_date("atype", "social")
elif box_text == "邮箱账户类型":
get_date("atype", "mail")
elif box_text == "其他账户类型":
get_date("atype", "another")
else:
get_date(key=key)
self.le_show_search.clear()
def main():
# 固定的,PyQt5程序都需要QApplication对象。sys.argv是命令行参数列表,确保程序可以双击运行
app = QApplication(sys.argv)
# 初始化
myWin = MyMainForm()
# 将窗口控件显示在屏幕上
myWin.show()
# 程序运行,sys.exit方法确保程序完整退出。
# myWin.show_info()
sys.exit(app.exec_())
main()