This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
1244 lines (1151 loc) · 52.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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import sys
import random
import difflib
import os
import requests
import pygame
import hashlib
import gettext
import glob
import ctypes
import win32com.client
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QCursor, QIcon, QPixmap
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QComboBox, QPushButton, QDesktopWidget, QMessageBox, QListView, QMainWindow, QGridLayout, QInputDialog
from datetime import datetime, timedelta
from Crypto.Cipher import ARC4
import webbrowser as web
try:
with open('language.ini', 'r') as file:
language_value = str(file.read())
localedir1 = os.path.join(os.path.abspath(
os.path.dirname(__file__)), 'locale')
translate = gettext.translation(
domain=f"{language_value}", localedir=localedir1, languages=[f"{language_value}"])
_ = translate.gettext
except:
localedir1 = os.path.join(os.path.abspath(
os.path.dirname(__file__)), 'locale')
translate = gettext.translation(
domain="zh_CN", localedir=localedir1, languages=["zh_CN"])
_ = translate.gettext
dmversion = 5.96
big = False
running = False
seed = False
choud = False
zt = 50
name_list = []
default_name_list = _("默认名单")
file_path = f"name/{default_name_list}.txt"
selected_file = f"{default_name_list}"
is_first_run = "0"
mdcd = 0
pygame.init()
pygame.mixer.init()
def make_name_list():
for i in range(1, 21):
yield str(i).rjust(2, "0")
def init_name(name_list):
global name_path
name_path = os.path.join("name", f"{default_name_list}.txt") # 打开文件并写入内容
with open(name_path, "w", encoding="utf8") as f:
for i in name_list:
f.write(i)
f.write("\n")
def opentext(path):
if sys.platform == "win32":
os.system("start %s" % path)
else:
os.system("vim %s" % path)
def ttsinitialize():
global allownametts
try:
with open('allownametts.ini', 'r') as file:
allownametts = int(file.read())
except FileNotFoundError:
# 语音播报开关
ifvoice = QMessageBox()
ifvoice.setWindowTitle(_("语音播报"))
ifvoice.setText(_(
"需要开启语音播报功能吗?\n单抽后会播报抽取结果。\n"))
allow_button = ifvoice.addButton(_("好的"), QMessageBox.ActionRole)
cancel_button = ifvoice.addButton(_("下次一定"), QMessageBox.ActionRole)
dictation_button = ifvoice.addButton(
_("听写模式(不会读\"恭喜\")"), QMessageBox.ActionRole)
button = ifvoice.addButton(_("取消"), QMessageBox.NoRole)
button.setVisible(False)
ifvoice.exec_()
if ifvoice.clickedButton() == allow_button:
# 同意
allownametts = 1
with open('allownametts.ini', "w", encoding='utf-8') as f:
f.write("1")
QMessageBox.information(
None, _("语音播报"), _("语音播报已经开启,您可以删除目录下的allownametts.ini重新设置此功能。"))
elif ifvoice.clickedButton() == cancel_button:
allownametts = 0
# 不同意
with open('allownametts.ini', "w", encoding='utf-8') as f:
f.write("0")
QMessageBox.information(
None, _("语音播报"), _("语音播报已禁用,您可以删除目录下的allownametts.ini重新设置此功能。"))
elif ifvoice.clickedButton() == dictation_button:
allownametts = 2
# 听写模式
with open('allownametts.ini', "w", encoding='utf-8') as f:
f.write("2")
QMessageBox.information(
None, _("语音播报"), _("语音播报(听写模式)已启用,您可以删除目录下的allownametts.ini重新设置此功能。"))
except ValueError:
QMessageBox.information(
None, _("语音播报"), _("目录下的allownametts.ini中不是一个有效的值"))
if os.path.exists("allownametts.ini"):
os.remove("allownametts.ini")
ttsinitialize()
def ttsread(text):
global allownametts
if allownametts == 1:
print(_("语音播报已开启"))
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak(text)
elif allownametts == 2:
print(_("语音播报(听写模式)已开启"))
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak(text)
else:
allownametts == 0
print(_("语音播报已关闭"))
def first_run():
global is_first_run
init_name(make_name_list())
app = QApplication(sys.argv)
welcom = QMessageBox()
welcom.setWindowTitle(_("欢迎使用"))
welcom.setText(_("欢迎使用沉梦课堂点名器!\n本程序支持单抽,连抽。同时提供单抽时背景音乐、多名单支持、数据导出等功能。\n\n请及时修改目录下的名单文件,请确保格式正确(将原本的1-20的数字删除,一行输入一个名字,像下面这样):\n名字1\n名字2\n名字3\n名字4\n名字5\n名字6\n......\n\n请在名单管理器中处理好名单,下次运行将开启名单校验功能。\n\n如需帮助请点击关于按钮。\n\n沉梦小站"))
# 设置消息框的图标和按钮
welcom.setIconPixmap(QIcon('picker.ico').pixmap(64, 64)) # 64x64 大小的图标
welcom.setStandardButtons(QMessageBox.Ok)
welcom.exec_()
is_first_run = '1'
opentext(name_path)
print(_("这应该是首次启动"))
return
def name_list_selector():
global txtnum, name_list, file_path, namefolder, mdnum, is_first_run
try:
with open('allownameselect.ini', 'r') as file:
allownameselect_value = int(file.read())
if allownameselect_value == 1:
select = 1
print(_("已配置为名单数量大于1时显示选择窗口"))
else:
select = 0
print(_("配置文件仅支持0或1,0或其他数字默认为0"))
except:
allownameselect_value = 0
print(_("名单管理器配置文件错误或不存在,默认名单数量大于0时显示选择窗口"))
select = 0
namefolder = "name"
os.makedirs("name", exist_ok=True)
if not os.path.exists(namefolder) or not os.listdir(namefolder):
first_run()
txtnum = [filename for filename in os.listdir(
namefolder) if filename.endswith(".txt")]
mdnum = len(txtnum)
if mdnum > select:
# 创建窗口和UI元素
app1 = QApplication([])
window = QWidget()
window.setWindowTitle(_('名单管理'))
window.setGeometry(100, 100, 500, 200)
layout = QVBoxLayout()
combo_box = QComboBox(window)
custom_list_view = QListView(combo_box)
combo_box.setFixedHeight(40)
custom_list_view.setStyleSheet("QListView::item { height: 40px; }")
combo_box.setView(custom_list_view)
layout.addWidget(combo_box)
button = QPushButton(_('确定'), window)
button.setFixedHeight(40)
layout.addWidget(button)
window.setLayout(layout)
screen = QDesktopWidget().screenGeometry()
window_width, window_height = window.sizeHint().width(), window.sizeHint().height()
x = int((screen.width() - window_width) // 2.25)
y = int((screen.height() - window_height) // 2.25)
window.setGeometry(x, y, 500, 200)
layout.addStretch()
layout.addSpacing(40)
add_button = QPushButton(_('新增名单'), window)
add_button.setFixedHeight(40)
layout.addWidget(add_button)
delete_button = QPushButton(_('删除名单'), window)
delete_button.setFixedHeight(40)
layout.addWidget(delete_button)
change_button = QPushButton(_('修改名单'), window)
change_button.setFixedHeight(40)
layout.addWidget(change_button)
def add_new_list():
newfilename, ok_pressed = QInputDialog.getText(
window, _("新增名单"), _("请输入名单名称:(文件名即可,无需输入.txt)"))
if ok_pressed and newfilename:
print("新增名单名称是: {newfilename}")
newnamepath = os.path.join(
"name", f"{newfilename}.txt") # 打开文件并写入内容
with open(newnamepath, "w", encoding="utf8") as f:
pass
message = (_("已创建名为 '%s.txt' 的文件,路径为: %s") %
(newfilename, newnamepath))
QMessageBox.information(
window, _("新建成功"), message, QMessageBox.Ok)
opentext(newnamepath)
txtnum = [filename for filename in os.listdir(
"name") if filename.endswith(".txt")]
combo_box.clear() # 清空下拉框的选项
combo_box.addItems(txtnum) # 添加新的文件名到下拉框
add_button.clicked.connect(add_new_list)
def delete_list():
target_filename, ok_pressed = QInputDialog.getText(
window, _("删除名单"), _("请输入要删除的名单名称:(文件名即可,无需输入.txt)"))
if ok_pressed and target_filename:
target_filepath = os.path.join(
"name", f"{target_filename}.txt")
if os.path.exists(target_filepath):
os.remove(target_filepath) # 删除文件
message = (_("已成功删除名为 '%s.txt' 的文件。") % target_filename)
QMessageBox.information(
window, _("删除成功"), message, QMessageBox.Ok)
txtnum = [filename for filename in os.listdir(
"name") if filename.endswith(".txt")]
combo_box.clear() # 清空下拉框的选项
combo_box.addItems(txtnum) # 添加新的文件名到下拉框
else:
QMessageBox.warning(
window, _('警告'), _('名单文件不存在'), QMessageBox.Ok)
delete_button.clicked.connect(delete_list)
def change_name_list():
target_filename = combo_box.currentText()
target_filepath = os.path.join(
"name", f"{target_filename}")
if os.path.exists(target_filepath):
opentext(target_filepath)
else:
QMessageBox.warning(
window, _('警告'), _('名单文件不存在'), QMessageBox.Ok)
change_button.clicked.connect(change_name_list)
combo_box.addItems(txtnum)
def showlist():
global selected_file, file_path
selected_file = combo_box.currentText()
file_path = os.path.join("name", selected_file)
if not os.path.exists(file_path):
QMessageBox.warning(window, _('警告'), _(
'名单文件不存在'), QMessageBox.Ok)
else:
print(f"所选文件的路径为: {file_path}\n")
window.close()
button.clicked.connect(showlist)
# 显示窗口
window.show()
app1.exec_()
else:
pass
def cs_sha256():
delrecordfile = 0
app = QApplication([])
os.makedirs('data', exist_ok=True)
ctypes.windll.kernel32.SetFileAttributesW('data', 2)
os.makedirs('bak', exist_ok=True)
ctypes.windll.kernel32.SetFileAttributesW('bak', 2)
for filename1 in os.listdir('name'):
if filename1.endswith('.txt'):
file_path = os.path.join('name', filename1)
output_file_path = os.path.join('data', filename1 + '.cmxz')
if not os.path.exists(output_file_path):
sha256_value = calculate_sha256(file_path)
with open(output_file_path, 'w') as f:
f.write(sha256_value)
print(f'已保存标识符值:{output_file_path}')
fileoperation('name', filename1, 'encrypt')
else:
sha256_value = calculate_sha256(file_path)
with open(output_file_path, 'r') as f:
saved_sha256_value = f.read().strip()
if sha256_value == saved_sha256_value:
print(f'{filename1} 的标识符值与记录一致。')
fileoperation('name', filename1, 'encrypt')
else:
print(f'警告:{filename1} 的标识符值与记录不一致。')
fileoperation('bak', filename1, 'decrypt')
with open(file_path, 'r', encoding='utf-8', errors='ignore') as original_file, open(processed_file_path, 'r', encoding='utf-8', errors='ignore') as bak_file:
original_content = original_file.read()
bak_content = bak_file.read()
if original_content == bak_content:
print(_('文件内容一致。'))
else:
print(_('文件内容不一致。以下是修改的内容:'))
# 去除内容中的空行
bak_lines = [line for line in bak_content.splitlines() if line.strip()]
original_lines = [line for line in original_content.splitlines() if line.strip()]
diff = difflib.unified_diff(bak_lines, original_lines)
diff_str = '\n'.join(diff)
diff_str = diff_str[11:]
msg_box = QMessageBox()
msg_box.setIcon(QMessageBox.Warning)
msg_box.setWindowTitle(_("警告"))
msg_box.setText(
_('警告:%s 最近被修改,加号是新增的,减号是减少的\n\n此记录会在 2天后 不再展示。\n%s') % (filename1, diff_str))
msg_box.exec_()
# 确保在最后一次循环才执行manage_deadline(filename1)
delrecordfile = delrecordfile + 1
if delrecordfile > 0:
manage_deadline("0")
def calculate_sha256(file_path):
sha256_hash = hashlib.sha256()
with open(file_path, 'rb') as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()
def fileoperation(folder_path, filename, operation):
enfilename = filename + ".cmxz"
file_path = os.path.join(folder_path, filename)
if operation == 'encrypt':
if filename.endswith('.txt'):
process_file(file_path, 'encrypt')
elif operation == 'decrypt':
if enfilename.endswith('.cmxz'):
file_path = os.path.join(folder_path, enfilename)
process_file(file_path, 'decrypt')
return processed_file_path
def process_file(file_path, operation):
global processed_file_path
try:
with open(file_path, 'rb') as f:
data = f.read()
except FileNotFoundError:
# 文件不存在时弹窗提示
bpp = QApplication([])
msg_box = QMessageBox()
msg_box.setIcon(QMessageBox.Warning)
msg_box.setWindowTitle(_("警告"))
msg_box.setText(_('警告:%s 的备份被删除,此名单可能已经被修改!') % file_path)
msg_box.exec_()
cipher = ARC4.new(b'cmxztopktdmq')
if operation == 'encrypt':
try:
processed_data = cipher.encrypt(data)
processed_file_path = os.path.join(
'bak', os.path.basename(file_path) + '.cmxz')
if os.path.exists(processed_file_path):
print(f'加密文件已存在: {processed_file_path}')
return processed_file_path
except:
print(_("加密文件不存在"))
elif operation == 'decrypt':
try:
processed_data = cipher.decrypt(data)
original_filename = os.path.basename(file_path)[:-5]
processed_file_path = os.path.join('bak', original_filename)
except:
print(_("解密文件不存在"))
try:
with open(processed_file_path, 'wb') as f:
f.write(processed_data)
print(f'文件{operation}成功: {processed_file_path}')
return processed_file_path
except:
manage_deadline("1")
def manage_deadline(now):
timefile_path = os.path.join('bak', 'adeadline.txt')
current_date = datetime.now().date()
def write_to_file():
# 获取默认截止日期并写入文件
global result_time
deadline_date = datetime.now() + timedelta(days=2)
result_time = deadline_date
if now != "1":
with open(timefile_path, 'w') as file:
file.write(deadline_date.strftime('%Y-%m-%d'))
fileoperation('bak', 'adeadline.txt', 'encrypt')
os.remove(timefile_path)
else:
print(_("名单校验已重置"))
def read_from_file():
# 从文件中读取截止日期
if os.path.exists(timefile_path + '.cmxz'):
fileoperation('bak', 'adeadline.txt', 'decrypt')
with open(timefile_path, 'r') as file:
date_str = file.read().strip()
if date_str:
return datetime.strptime(date_str, '%Y-%m-%d').date()
return None
def remove_directory(data_folder):
txt_files = glob.glob(os.path.join(data_folder, '*.txt'))
# 获取指定文件夹中所有扩展名为 .cmxz 的文件列表
cmxz_files = glob.glob(os.path.join(data_folder, '*.cmxz'))
all_files = txt_files + cmxz_files
# 循环删除文件
for file_path in all_files:
try:
os.remove(file_path)
print(f"Deleted: {file_path}")
except OSError as e:
print(f"Error: {e.filename} - {e.strerror}")
deadline_date = read_from_file()
if deadline_date:
# 如果截止日期已过,删除数据文件夹
if current_date > deadline_date:
print(f"截止日期({deadline_date})已过。删除数据文件夹。")
try:
# 递归删除目录及其内容
remove_directory("data")
remove_directory("bak")
print(_("数据文件夹已删除。"))
except OSError as e:
print(f"删除数据文件夹时发生错误: {e}")
else:
print(f"截止日期是{deadline_date}。尚未过期。暂不重置校验")
if now == "1":
remove_directory("data") # 异常处理
remove_directory("bak")
try:
os.remove(timefile_path)
except:
pass
else:
# 如果没有截止日期,生成随机日期并写入文件
if now == "1":
remove_directory("data") # 异常处理
remove_directory("bak")
write_to_file()
print(f"生成了一个随机截止日期: {result_time}。写入文件。")
class Ui_MainWindow(QMainWindow):
def init(self):
super().init()
self.RowLength = 0
try:
icon_path = os.path.join(os.path.dirname(
__file__), "./picker.ico") # 任务栏的ico
icon = QIcon()
icon.addPixmap(QPixmap(icon_path))
MainWindow.setWindowIcon(icon)
except:
pass
# self.setupUi(MainWindow())
def setupUi(self, MainWindow):
global mdcd, name_list, file_path
if not os.path.exists(file_path):
sys.exit()
with open(file_path, encoding='utf8') as f:
name_list = [line.strip('\n') for line in f.readlines()]
print("\n", name_list)
mdcd = len(name_list)
print(_("读取到的有效名单长度 :"), mdcd)
# 以下可直接粘贴生成的setupui代码
MainWindow.setObjectName(_("沉梦课堂点名器"))
MainWindow.resize(460, 400)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(30, 45, 700, 150)) # 主体
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(zt) # 主体大小#字体大小
self.label.setFont(font)
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(75, 220, 111, 61)) # 开始按钮
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(20)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(283, 220, 111, 61)) # 结束按钮
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(20)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_9 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_9.setGeometry(QtCore.QRect(20, 15, 50, 30)) # 关于
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(11)
self.pushButton_9.setFont(font)
self.pushButton_9.setObjectName("pushButton_9")
self.listWidget = QtWidgets.QListWidget(self.centralwidget)
self.listWidget.setGeometry(QtCore.QRect(12, 420, 435, 250)) # 统计
self.listWidget.setObjectName("listWidget")
font = QtGui.QFont()
font.setPointSize(15)
font.setFamily("宋体")
self.listWidget.setFont(font)
self.listWidget.setFocusPolicy(QtCore.Qt.WheelFocus)
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 380, 210, 21)) # 文字
self.label_2.setObjectName("label_2")
font = QtGui.QFont()
font.setFamily("宋体")
self.label_2.setFont(font)
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(570, 10, 210, 30)) # 文字
self.label_4.setObjectName("label_4")
font = QtGui.QFont()
font.setFamily("宋体")
self.label_4.setFont(font)
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_5.setGeometry(
QtCore.QRect(20, 320, 111, 35)) # 查看点过的名字
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(9)
self.pushButton_5.setFont(font)
self.pushButton_5.setObjectName("pushButton_5")
self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_6.setGeometry(QtCore.QRect(360, 320, 75, 35)) # 连抽模式
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(10)
self.pushButton_6.setFont(font)
self.pushButton_6.setObjectName("pushButton_6")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(600, 370, 89, 20)) # 连抽输入框
self.lineEdit.setObjectName("lineEdit")
self.lineEdit.setText("2")
self.lineEdit.setStyleSheet(
"""
QListView, QLineEdit {
color: #D2D2D2;
background-color:#29292C;
selection-color: #29292C;
border: 2px groove #29292C;
border-radius: 10px;
padding: 2px 4px;
}
QLineEdit:focus {
color: #D2D2D2;
selection-color: #29292C;
border: 2px groove #29292C;
border-radius: 10px;
padding: 2px 4px;
}
"""
)
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(525, 370, 60, 21)) # 连抽人数
self.label_3.setObjectName("label_3")
self.label_3.setStyleSheet("color:white;background:#323232")
self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_7.setGeometry(QtCore.QRect(710, 360, 111, 40)) # 连抽开始
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(20)
self.pushButton_7.setFont(font)
self.pushButton_7.setObjectName("pushButton_7")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(
QtCore.QRect(550, 240, 100, 25)) # 修改名单按钮
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(
QtCore.QRect(690, 215, 100, 25)) # 历史记录按钮
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_8 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_8.setGeometry(QtCore.QRect(550, 290, 100, 25)) # 统计按钮
self.pushButton_8.setObjectName("pushButton_8")
self.pushButton_10 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_10.setGeometry(
QtCore.QRect(690, 265, 100, 25)) # 背景音乐按钮
self.pushButton_10.setObjectName("pushButton_10")
self.pushButton_11 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_11.setGeometry(QtCore.QRect(550, 190, 100, 25)) # 应用中心
self.pushButton_11.setObjectName("pushButton_11")
self.listWidget_2 = QtWidgets.QListWidget(self.centralwidget)
self.listWidget_2.setGeometry(QtCore.QRect(503, 420, 358, 250)) # 连抽列表
font = QtGui.QFont()
font.setPointSize(20)
self.listWidget_2.setFont(font)
self.listWidget_2.setFocusPolicy(QtCore.Qt.WheelFocus)
self.listWidget_2.setVerticalScrollBarPolicy(
QtCore.Qt.ScrollBarAsNeeded)
self.listWidget_2.setHorizontalScrollBarPolicy(
QtCore.Qt.ScrollBarAsNeeded)
self.listWidget_2.setSizeAdjustPolicy(
QtWidgets.QAbstractScrollArea.AdjustToContents)
self.listWidget_2.setObjectName("listWidget_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 874, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.pushButton.clicked.connect(self.start)
self.pushButton_2.clicked.connect(self.stop)
self.pushButton_5.clicked.connect(self.showHistory)
self.pushButton_7.setStyleSheet(
"""QPushButton{background:#6DDF6D;border-radius:5px;}QPushButton:hover{background:green;}"""
) # 连抽开始
self.pushButton_6.clicked.connect(self.showContinue)
self.pushButton_7.clicked.connect(self.ten)
self.pushButton_6.setStyleSheet(
"""QPushButton{background:#F7D674;border-radius:5px;}QPushButton:hover{background:yellow;}"""
) # 连抽模式
self.pushButton.setStyleSheet(
"""QPushButton{background:#6DDF6D;border-radius:5px;}QPushButton:hover{background:green;}"""
) # 单抽开始
self.pushButton_2.setStyleSheet(
"""QPushButton{background:#F76677;border-radius:5px;}QPushButton:hover{background:red;}"""
) # 单抽停止
self.pushButton_3.setStyleSheet(
"""QPushButton{background:#6DDF6D;border-radius:5px;}QPushButton:hover{background:green;}"""
)
# 查看点过的名字
self.pushButton_4.setStyleSheet(
"""QPushButton{background:#6DDF6D;border-radius:5px;}QPushButton:hover{background:green;}"""
)
# 查看历史记录
self.pushButton_8.setStyleSheet(
"""QPushButton{background:#6DDF6D;border-radius:5px;}QPushButton:hover{background:green;}"""
)
# 统计名单
self.pushButton_9.setStyleSheet(
"""QPushButton{background:#F7D674;border-radius:5px;}QPushButton:hover{background:yellow;}"""
) # 关于
self.pushButton_10.setStyleSheet(
"""QPushButton{background:#6DDF6D;border-radius:5px;}QPushButton:hover{background:green;}"""
)
# 统计名单
self.pushButton_11.setStyleSheet(
"""QPushButton{background:#6DDF6D;border-radius:5px;}QPushButton:hover{background:green;}"""
) # 应用中心
self.pushButton_5.setStyleSheet(
"""QPushButton{background:#F7D674;border-radius:5px;}QPushButton:hover{background:yellow;}"""
) # 查看点过的名字
self.centralwidget.setStyleSheet(
"""
QWidget#centralwidget{
color:#323232;
background:#323232;
border-top:1px solid #323232;
border-bottom:1px solid #323232;
border-right:1px solid #323232;
border-left:1px solid #323232;
border-top-left-radius:10px;
border-top-right-radius:10px;
border-bottom-left-radius:10px;
border-bottom-right-radius:10px;
}
"""
) # 上面是总(背景)
self.close_widget = QtWidgets.QWidget(self.centralwidget)
self.close_widget.setGeometry(QtCore.QRect(365, 5, 90, 30))
self.close_widget.setObjectName("close_widget")
self.close_layout = QGridLayout() # 创建左侧部件的网格布局层
self.close_widget.setLayout(self.close_layout) # 设置左侧部件布局为网格
self.left_close = QPushButton("×") # 关闭按钮
self.left_close.clicked.connect(MainWindow.close)
self.left_visit = QPushButton("□") # 最大化按钮
self.left_visit.clicked.connect(MainWindow.big)
self.left_mini = QPushButton("-") # 最小化按钮
self.left_mini.clicked.connect(MainWindow.mini)
self.close_layout.addWidget(self.left_mini, 0, 0, 1, 1)
self.close_layout.addWidget(self.left_close, 0, 2, 1, 1)
self.close_layout.addWidget(self.left_visit, 0, 1, 1, 1)
self.left_close.setFixedSize(20, 20) # 设置关闭按钮的大小
self.left_visit.setFixedSize(20, 20) # 设置按钮大小
self.left_mini.setFixedSize(20, 20) # 设置最小化按钮大小
self.left_close.setStyleSheet(
"""QPushButton{background:#F76677;border-radius:5px;}QPushButton:hover{background:red;}"""
) # 右上角叉叉
self.left_visit.setStyleSheet(
"""QPushButton{background:#F7D674;border-radius:5px;}QPushButton:hover{background:yellow;}"""
)
self.left_mini.setStyleSheet(
"""QPushButton{background:#6DDF6D;border-radius:5px;}QPushButton:hover{background:green;}"""
)
self.pushButton_9.clicked.connect(self.cmxz)
self.pushButton_3.clicked.connect(self.ren)
self.pushButton_4.clicked.connect(self.dmhistory)
self.pushButton_8.clicked.connect(self.countname)
self.pushButton_10.clicked.connect(self.bgmusic)
self.pushButton_11.clicked.connect(self.moreprogram)
self.label_2.setStyleSheet("color:white")
self.label_4.setStyleSheet("color:white")
self.scc = """
QListWidget{background-color:#2B2B2B;color:white}
/*垂直滚动条*/
QScrollBar:vertical{
width:12px;
border:1px solid #2B2B2B;
margin:0px,0px,0px,0px;
padding-top:0px;
padding-bottom:0px;
}
QScrollBar::handle:vertical{
width:3px;
background:#4B4B4B;
min-height:3;
}
QScrollBar::handle:vertical:hover{
background:#3F3F3F;
border:0px #3F3F3F;
}
QScrollBar::sub-line:vertical{
width:0px;
border-image:url(:/Res/scroll_left.png);
subcontrol-position:left;
}
QScrollBar::sub-line:vertical:hover{
height:0px;
background:#323232;
subcontrol-position:top;
}
QScrollBar::add-line:vertical{
height:0px;
border-image:url(:/Res/scroll_down.png);
subcontrol-position:bottom;
}
QScrollBar::add-line:vertical:hover{
height:0px;
background:#3F3F3F;
subcontrol-position:bottom;
}
QScrollBar::add-page:vertical{
background:#2B2B2B;
}
QScrollBar::sub-page:vertical{
background:#2B2B2B;
}
QScrollBar::up-arrow:vertical{
border-style:outset;
border-width:0px;
}
QScrollBar::down-arrow:vertical{
border-style:outset;
border-width:0px;
}
QScrollBar:horizontal{
height:12px;
border:1px #2B2B2B;
margin:0px,0px,0px,0px;
padding-left:0px;
padding-right:0px;
}
QScrollBar::handle:horizontal{
height:16px;
background:#4B4B4B;
min-width:20;
}
QScrollBar::handle:horizontal:hover{
background:#3F3F3F;
border:0px #3F3F3F;
}
QScrollBar::sub-line:horizontal{
width:0px;
border-image:url(:/Res/scroll_left.png);
subcontrol-position:left;
}
QScrollBar::sub-line:horizontal:hover{
width:0px;
background:#2B2B2B;
subcontrol-position:left;
}
QScrollBar::add-line:horizontal{
width:0px;
border-image:url(:/Res/scroll_right.png);
subcontrol-position:right;
}
QScrollBar::add-line:horizontal:hover{
width:0px;
background::#2B2B2B;
subcontrol-position:right;
}
QScrollBar::add-page:horizontal{
background:#2B2B2B;
}
QScrollBar::sub-page:horizontal{
background:#2B2B2B;
}
"""
self.listWidget.setStyleSheet(self.scc)
self.listWidget_2.setStyleSheet(self.scc)
MainWindow.setWindowOpacity(0.98) # 设置窗口透明度
MainWindow.setAttribute(Qt.WA_TranslucentBackground)
MainWindow.setWindowFlag(Qt.FramelessWindowHint) # 隐藏边框
def retranslateUi(self, MainWindow):
self.wide = 420
self.high = 360
_translate = QtCore.QCoreApplication.translate
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate(
"MainWindow", _("沉梦课堂点名器%s")) % dmversion) # 任务栏名称
self.label.setText(_translate("MainWindow", _("幸运儿是 {}")))
self.label.setStyleSheet("color:white")
self.pushButton.setText(_translate("MainWindow", _("开始")))
self.pushButton_9.setText(_translate("MainWindow", _("关于")))
self.pushButton_2.setText(_translate("MainWindow", _("结束")))
self.pushButton_3.setText(_translate("MainWindow", _("修改名单文件")))
self.pushButton_4.setText(_translate("MainWindow", _("查看历史记录")))
self.pushButton_8.setText(_translate("MainWindow", _("统计中奖人员")))
self.pushButton_10.setText(_translate("MainWindow", _("背景音乐目录")))
self.pushButton_11.setText(_translate("MainWindow", _("获取更多应用")))
self.label_2.setText(_translate("MainWindow", _("点过的姓名:")))
self.label_4.setText(_translate(
"MainWindow", "制作:Yish_,QQB,limuy2022 v%s") % dmversion)
self.pushButton_5.setText(_translate("MainWindow", _("查看点过的名字")))
self.pushButton_6.setText(_translate("MainWindow", _("连抽模式")))
self.label_3.setText(_translate("MainWindow", _("连抽人数")))
self.pushButton_7.setText(_translate("MainWindow", _("开始")))
self.listWidget.addItem(_("选择了%s,共有:%s人") % (selected_file, mdcd))
try:
with open('allowcheck.ini', 'r') as file:
allowcheck_value = int(file.read())
if allowcheck_value == 1:
try:
updatecheck = "https://cdn.cmxz.top/programs/dm/api/check.html"
page = requests.get(updatecheck, timeout=1.5)
newversion = float(page.text)
print("云端版本号为:", newversion)
findnewversion = _("检测到新版本!请点击左上角“更新”下载新版")
if newversion > dmversion:
print(_("检测到新版本:"), newversion,
_("当前版本为:"), dmversion)
self.pushButton_9.setText(
_translate("MainWindow", _("更新")))
updatabutton = QMessageBox.question(self, _("检测到新版本"), _("云端最新版本为%s,要现在下载新版本吗?<br>您也可以稍后点击点名器左上角'更新'按钮升级新版本") % newversion,
QMessageBox.Ok | QMessageBox.No, QMessageBox.Ok,)
if updatabutton == QMessageBox.Ok:
web.open_new("https://cmxz.top/ktdmq")
else:
pass
self.listWidget.addItem(findnewversion)
else:
print(_("当前已经是最新版本:"))
except:
print(_("网络异常,无法检测更新"))
noconnect = _("网络连接异常,检查更新失败")
self.listWidget.addItem(noconnect)
elif allowcheck_value == 0:
print(_("检查更新已关闭"))
except FileNotFoundError:
# 检查更新开关
ifupdate = QMessageBox()
ifupdate.setWindowTitle(_("检查更新"))
ifupdate.setText(
_("需要开启检查更新功能吗?\n新版本会带来新功能、优化以及修复错误。\n在服务器发布新版本后,会在您打开点名器时收到更新的提示"))
allow_button = ifupdate.addButton(
_("好的,谢谢你"), QMessageBox.ActionRole)
cancel_button = ifupdate.addButton(
_("下次一定"), QMessageBox.ActionRole)
button = ifupdate.addButton(_("取消"), QMessageBox.NoRole)
button.setVisible(False)
ifupdate.exec_()
if ifupdate.clickedButton() == allow_button:
# 同意
print(_("检查更新已开启"))
with open('allowcheck.ini', "w", encoding='utf-8') as f:
f.write("1")
QMessageBox.information(
self, _("检查更新"), _("检查更新功能已经开启,您可以删除目录下的allowcheck.ini重新设置此功能。"))
elif ifupdate.clickedButton() == cancel_button:
# 不同意
with open('allowcheck.ini', "w", encoding='utf-8') as f:
f.write("0")
ifupdate1 = QMessageBox()
ifupdate1.setWindowTitle(_("真的不需要吗(π一π)"))
ifupdate1.setText(
_("我们的每一次的更新都是很有意义的,能给您带来更好的体验,真的不开启检查更新功能吗?\no(╥﹏╥)o\no(╥﹏╥)o\no(╥﹏╥)o"))
allow_button1 = ifupdate1.addButton(
_("行吧,我准许了"), QMessageBox.ActionRole)
allow_button2 = ifupdate1.addButton(
_("算了,我同意了"), QMessageBox.ActionRole)
cancel_button1 = ifupdate1.addButton(
_("不要,我不要啊"), QMessageBox.ActionRole)
allow_button3 = ifupdate1.addButton(
_("行了,快开启吧"), QMessageBox.ActionRole)
button1 = ifupdate1.addButton(_("取消"), QMessageBox.NoRole)
button1.setVisible(False)
ifupdate1.exec_()
if ifupdate1.clickedButton() == allow_button1 or ifupdate1.clickedButton() == allow_button2 or ifupdate1.clickedButton() == allow_button3:
# 梅开二度
print(_("检查更新已开启"))
with open('allowcheck.ini', "w", encoding='utf-8') as f:
f.write("1")
QMessageBox.information(
self, _("检查更新"), _("检查更新功能已经开启,您可以删除目录下的allowcheck.ini重新设置此功能。"))
else:
pass
except ValueError:
QMessageBox.information(
self, _("检查更新"), _("目录下的allowcheck.ini中不是一个有效的值"))
if os.path.exists("allowcheck.ini"):
os.remove("allowcheck.ini")
def ten(self):
lenth = len(name_list)
num = self.lineEdit.text()
print(num)
try:
num = int(num)
except ValueError:
reply = QtWidgets.QMessageBox.warning(
self, _("警告"), _("啥玩意呀?请输入数字!!!"), QtWidgets.QMessageBox.Yes
)
return
if not num <= 0 and not num > lenth:
self.listWidget_2.clear()
name_set = set()
while len(name_set) != num:
name_set.add(random.choice(name_list))
name_set = list(name_set)
random.shuffle(name_set)
today = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
try:
print(
today,
_("沉梦课堂点名器%s") % dmversion,
"幸运儿是: %s " % name_set,
file=open(_("点名器中奖名单.txt"), "a"),
)
except:
print(_("无法写入历史记录"))
print(today, "幸运儿是: %s " % name_set)
for name in name_set:
self.listWidget_2.addItem(name)
self.listWidget.addItem(name)
elif num < 0:
reply = QtWidgets.QMessageBox.warning(
self, _("警告"), _("你见过负数个人么???????"), QtWidgets.QMessageBox.Yes
)
self.listWidget_2.clear()
elif num == 0: