forked from Class-Widgets/Class-Widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
1892 lines (1637 loc) · 88.3 KB
/
menu.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
import datetime as dt
import importlib
import json
import os
import subprocess
import sys
from copy import deepcopy
from pathlib import Path
from shutil import rmtree
from PyQt5 import uic, QtCore
from PyQt5.QtCore import Qt, QTime, QUrl, QDate, pyqtSignal
from PyQt5.QtGui import QIcon, QDesktopServices, QColor
from PyQt5.QtWidgets import QApplication, QHeaderView, QTableWidgetItem, QLabel, QHBoxLayout, QSizePolicy, \
QSpacerItem, QFileDialog, QVBoxLayout, QScroller
from loguru import logger
from qfluentwidgets import (
Theme, setTheme, FluentWindow, FluentIcon as fIcon, ToolButton, ListWidget, ComboBox, CaptionLabel,
SpinBox, LineEdit, PrimaryPushButton, TableWidget, Flyout, InfoBarIcon,
FlyoutAnimationType, NavigationItemPosition, MessageBox, SubtitleLabel, PushButton, SwitchButton,
CalendarPicker, BodyLabel, ColorDialog, isDarkTheme, TimeEdit, EditableComboBox, MessageBoxBase,
SearchLineEdit, Slider, PlainTextEdit, ToolTipFilter, ToolTipPosition, RadioButton, HyperlinkLabel,
PrimaryDropDownPushButton, Action, RoundMenu, CardWidget, ImageLabel, StrongBodyLabel,
TransparentDropDownToolButton, Dialog, SmoothScrollArea, TransparentToolButton, HyperlinkButton
)
import conf
import list
import tip_toast
import utils
import weather_db
import weather_db as wd
from conf import base_directory
from cses_mgr import CSES_Converter
from network_thread import VersionThread
from plugin import p_loader
from plugin_plaza import PluginPlaza
from utils import restart
# 适配高DPI缩放
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
today = dt.date.today()
plugin_plaza = None
plugin_dict = {} # 插件字典
enabled_plugins = {} # 启用的插件列表
morning_st = 0
afternoon_st = 0
current_week = 0
filename = conf.read_conf('General', 'schedule')
loaded_data = conf.load_from_json(filename)
schedule_dict = {} # 对应时间线的课程表
schedule_even_dict = {} # 对应时间线的课程表(双周)
timeline_dict = {} # 时间线字典
def open_plaza():
global plugin_plaza
if plugin_plaza is None or not plugin_plaza.isVisible():
plugin_plaza = PluginPlaza()
plugin_plaza.show()
plugin_plaza.closed.connect(cleanup_plaza)
logger.info('打开“插件广场”')
else:
plugin_plaza.raise_()
plugin_plaza.activateWindow()
def cleanup_plaza():
global plugin_plaza
logger.info('关闭“插件广场”')
del plugin_plaza
plugin_plaza = None
def get_timeline():
global loaded_data
loaded_data = conf.load_from_json(filename)
return loaded_data['timeline']
def open_dir(path: str):
if sys.platform.startswith('win32'):
os.startfile(path)
elif sys.platform.startswith('linux'):
subprocess.run(['xdg-open', path])
else:
msg_box = Dialog(
'无法打开文件夹', f'Class Widgets 在您的系统下不支持自动打开文件夹,请手动打开以下地址:\n{path}'
)
msg_box.yesButton.setText('好')
msg_box.cancelButton.hide()
msg_box.buttonLayout.insertStretch(0, 1)
msg_box.setFixedWidth(550)
msg_box.exec()
def switch_checked(section, key, checked):
if checked:
conf.write_conf(section, key, '1')
else:
conf.write_conf(section, key, '0')
def get_theme_name():
theme = conf.read_conf('General', 'theme')
if os.path.exists(f'{base_directory}/ui/{theme}/theme.json'):
return theme
else:
return 'default'
def load_schedule_dict(schedule, part, part_name):
"""
加载课表字典
"""
schedule_dict_ = {}
for week, item in schedule.items():
all_class = []
count = [] # 初始化计数器
for i in range(len(part)):
count.append(0)
if str(week) in loaded_data['timeline'] and loaded_data['timeline'][str(week)]:
timeline = get_timeline()[str(week)]
else:
timeline = get_timeline()['default']
for item_name, item_time in timeline.items():
if item_name.startswith('a'):
try:
if int(item_name[1]) == 0:
count_num = 0
else:
count_num = sum(count[:int(item_name[1])])
prefix = item[int(item_name[-1]) - 1 + count_num]
period = part_name[str(item_name[1])]
all_class.append(f'{prefix}-{period}')
except IndexError or ValueError: # 未设置值
prefix = '未添加'
period = part_name[str(item_name[1])]
all_class.append(f'{prefix}-{period}')
count[int(item_name[1])] += 1
schedule_dict_[week] = all_class
return schedule_dict_
def convert_to_dict(data_dict_):
data_dict = {}
for week, item in data_dict_.items():
cache_list = item
replace_list = []
for activity_num in range(len(cache_list)):
item_info = cache_list[int(activity_num)].split('-')
replace_list.append(item_info[0])
data_dict[str(week)] = replace_list
return data_dict
def se_load_item():
global schedule_dict
global schedule_even_dict
global loaded_data
loaded_data = conf.load_from_json(filename)
part_name = loaded_data.get('part_name')
part = loaded_data.get('part')
schedule = loaded_data.get('schedule')
schedule_even = loaded_data.get('schedule_even')
schedule_dict = load_schedule_dict(schedule, part, part_name)
schedule_even_dict = load_schedule_dict(schedule_even, part, part_name)
class selectCity(MessageBoxBase): # 选择城市
def __init__(self, parent=None):
super().__init__(parent)
title_label = SubtitleLabel()
subtitle_label = BodyLabel()
self.search_edit = SearchLineEdit()
title_label.setText('搜索城市')
subtitle_label.setText('请输入当地城市名进行搜索')
self.yesButton.setText('选择此城市') # 按钮组件汉化
self.cancelButton.setText('取消')
self.search_edit.setPlaceholderText('输入城市名')
self.search_edit.setClearButtonEnabled(True)
self.search_edit.textChanged.connect(self.search_city)
self.city_list = ListWidget()
self.city_list.addItems(wd.search_by_name(''))
self.get_selected_city()
# 将组件添加到布局中
self.viewLayout.addWidget(title_label)
self.viewLayout.addWidget(subtitle_label)
self.viewLayout.addWidget(self.search_edit)
self.viewLayout.addWidget(self.city_list)
self.widget.setMinimumWidth(500)
self.widget.setMinimumHeight(600)
def search_city(self):
self.city_list.clear()
self.city_list.addItems(wd.search_by_name(self.search_edit.text()))
self.city_list.clearSelection() # 清除选中项
def get_selected_city(self):
selected_city = self.city_list.findItems(
wd.search_by_num(str(conf.read_conf('Weather', 'city'))), QtCore.Qt.MatchFlag.MatchExactly
)
if selected_city: # 若找到该城市
item = selected_city[0]
# 选中该项
self.city_list.setCurrentItem(item)
# 聚焦该项
self.city_list.scrollToItem(item)
class licenseDialog(MessageBoxBase): # 显示软件许可协议
def __init__(self, parent=None):
super().__init__(parent)
title_label = SubtitleLabel()
subtitle_label = BodyLabel()
self.license_text = PlainTextEdit()
title_label.setText('软件许可协议')
subtitle_label.setText('此项目 (Class Widgets) 基于 GPL-3.0 许可证授权发布,详情请参阅:')
self.yesButton.setText('好') # 按钮组件汉化
self.cancelButton.hide()
self.buttonLayout.insertStretch(0, 1)
self.license_text.setPlainText(open('LICENSE', 'r', encoding='utf-8').read())
self.license_text.setReadOnly(True)
# 将组件添加到布局中
self.viewLayout.addWidget(title_label)
self.viewLayout.addWidget(subtitle_label)
self.viewLayout.addWidget(self.license_text)
self.widget.setMinimumWidth(600)
self.widget.setMinimumHeight(500)
class PluginSettingsDialog(MessageBoxBase): # 插件设置对话框
def __init__(self, plugin_dir=None, parent=None):
super().__init__(parent)
self.plugin_widget = None
self.plugin_dir = plugin_dir
self.parent = parent
self.init_ui()
def init_ui(self):
# 加载已定义的UI
self.plugin_widget = p_loader.plugins_settings[self.plugin_dir]
self.viewLayout.addWidget(self.plugin_widget)
self.viewLayout.setContentsMargins(0, 0, 0, 0)
self.cancelButton.hide()
self.buttonLayout.insertStretch(0, 1)
self.widget.setMinimumWidth(875)
self.widget.setMinimumHeight(625)
class PluginCard(CardWidget): # 插件卡片
def __init__(
self, icon, title='Unknown', content='Unknown', version='1.0.0', plugin_dir='', author=None, parent=None,
enable_settings=None
):
super().__init__(parent)
icon_radius = 5
self.plugin_dir = plugin_dir
self.title = title
self.parent = parent
self.iconWidget = ImageLabel(icon) # 插件图标
self.titleLabel = StrongBodyLabel(title, self) # 插件名
self.versionLabel = BodyLabel(version, self) # 插件版本
self.authorLabel = BodyLabel(author, self) # 插件作者
self.contentLabel = CaptionLabel(content, self) # 插件描述
self.enableButton = SwitchButton()
self.moreButton = TransparentDropDownToolButton()
self.moreMenu = RoundMenu(parent=self.moreButton)
self.settingsBtn = TransparentToolButton() # 设置按钮
self.hBoxLayout = QHBoxLayout(self)
self.hBoxLayout_Title = QHBoxLayout(self)
self.vBoxLayout = QVBoxLayout(self)
self.moreMenu.addActions([
Action(
fIcon.FOLDER, f'打开“{title}”插件文件夹',
triggered=lambda: open_dir(os.path.join(os.getcwd(), conf.PLUGINS_DIR, self.plugin_dir))
),
Action(
fIcon.DELETE, f'卸载“{title}”插件',
triggered=self.remove_plugin
)
])
if enable_settings:
self.moreMenu.addSeparator()
self.moreMenu.addAction(Action(fIcon.SETTING, f'“{title}”插件设置', triggered=self.show_settings))
else:
self.settingsBtn.hide()
if plugin_dir in enabled_plugins['enabled_plugins']: # 插件是否启用
self.enableButton.setChecked(True)
self.setFixedHeight(73)
self.iconWidget.setFixedSize(48, 48)
self.moreButton.setFixedSize(34, 34)
self.iconWidget.setBorderRadius(icon_radius, icon_radius, icon_radius, icon_radius) # 圆角
self.contentLabel.setTextColor("#606060", "#d2d2d2")
self.contentLabel.setMaximumWidth(500)
self.contentLabel.setWordWrap(True) # 自动换行
self.versionLabel.setTextColor("#999999", "#999999")
self.authorLabel.setTextColor("#606060", "#d2d2d2")
self.enableButton.checkedChanged.connect(self.set_enable)
self.enableButton.setOffText('禁用')
self.enableButton.setOnText('启用')
self.moreButton.setMenu(self.moreMenu)
self.settingsBtn.setIcon(fIcon.SETTING)
self.settingsBtn.clicked.connect(self.show_settings)
self.hBoxLayout.setContentsMargins(20, 11, 11, 11)
self.hBoxLayout.setSpacing(15)
self.hBoxLayout.addWidget(self.iconWidget)
# 内容
self.vBoxLayout.setContentsMargins(0, 0, 0, 0)
self.vBoxLayout.setSpacing(0)
self.vBoxLayout.addLayout(self.hBoxLayout_Title)
self.vBoxLayout.addWidget(self.contentLabel, 0, Qt.AlignmentFlag.AlignVCenter)
self.vBoxLayout.setAlignment(Qt.AlignmentFlag.AlignVCenter)
self.hBoxLayout.addLayout(self.vBoxLayout, 1) # !!!
# 标题栏
self.hBoxLayout_Title.setSpacing(12)
self.hBoxLayout_Title.setAlignment(Qt.AlignmentFlag.AlignLeft)
self.hBoxLayout_Title.addWidget(self.titleLabel, 0, Qt.AlignmentFlag.AlignVCenter)
self.hBoxLayout_Title.addWidget(self.authorLabel, 0, Qt.AlignmentFlag.AlignVCenter)
self.hBoxLayout_Title.addWidget(self.versionLabel, 0, Qt.AlignmentFlag.AlignVCenter)
self.hBoxLayout.addStretch(1)
self.hBoxLayout.addWidget(self.settingsBtn, 0, Qt.AlignmentFlag.AlignRight)
self.hBoxLayout.addWidget(self.enableButton, 0, Qt.AlignmentFlag.AlignRight)
self.hBoxLayout.addWidget(self.moreButton, 0, Qt.AlignmentFlag.AlignRight)
def set_enable(self):
global enabled_plugins
if self.enableButton.isChecked():
enabled_plugins['enabled_plugins'].append(self.plugin_dir)
conf.save_plugin_config(enabled_plugins)
else:
enabled_plugins['enabled_plugins'].remove(self.plugin_dir)
conf.save_plugin_config(enabled_plugins)
def show_settings(self):
w = PluginSettingsDialog(self.plugin_dir, self.parent)
w.exec()
def remove_plugin(self):
alert = MessageBox(f"您确定要删除插件“{self.title}”吗?", "删除此插件后,将无法恢复。", self.parent)
alert.yesButton.setText('永久删除')
alert.yesButton.setStyleSheet("""
PushButton{
border-radius: 5px;
padding: 5px 12px 6px 12px;
outline: none;
}
PrimaryPushButton{
color: white;
background-color: #FF6167;
border: 1px solid #FF8585;
border-bottom: 1px solid #943333;
}
PrimaryPushButton:hover{
background-color: #FF7E83;
border: 1px solid #FF8084;
border-bottom: 1px solid #B13939;
}
PrimaryPushButton:pressed{
color: rgba(255, 255, 255, 0.63);
background-color: #DB5359;
border: 1px solid #DB5359;
}
""")
alert.cancelButton.setText('我再想想……')
if alert.exec():
global enabled_plugins
if self.plugin_dir in enabled_plugins: # 移除启动项
enabled_plugins['enabled_plugins'].remove(self.plugin_dir)
conf.save_plugin_config(enabled_plugins)
try:
with open(f"{base_directory}/plugins/plugins_from_pp.json", 'r', encoding='utf-8') as f: # 移除插件广场安装记录
installed_plugins = json.load(f).get('plugins')
installed_plugins.remove(self.plugin_dir)
with open(f"{base_directory}/plugins/plugins_from_pp.json", 'w', encoding='utf-8') as f2: # 移除插件广场安装记录
json.dump({"plugins": installed_plugins}, f2, ensure_ascii=False, indent=4)
except Exception as e:
logger.error(f"保存已安装插件失败:{e}")
try:
rmtree(os.path.join(os.getcwd(), conf.PLUGINS_DIR, self.plugin_dir)) # 删除插件
self.setParent(None)
self.deleteLater() # 删除卡片
except Exception as e:
logger.error(f'删除插件“{self.title}”时发生错误:{e}')
class SettingsMenu(FluentWindow):
closed = pyqtSignal()
def __init__(self):
super().__init__()
self.button_clear_log = None
self.version_thread = None
# 创建子页面
self.spInterface = uic.loadUi(f'{base_directory}/view/menu/preview.ui') # 预览
self.spInterface.setObjectName("spInterface")
self.teInterface = uic.loadUi(f'{base_directory}/view/menu/timeline_edit.ui') # 时间线编辑
self.teInterface.setObjectName("teInterface")
self.seInterface = uic.loadUi(f'{base_directory}/view/menu/schedule_edit.ui') # 课程表编辑
self.seInterface.setObjectName("seInterface")
self.adInterface = uic.loadUi(f'{base_directory}/view/menu/advance.ui') # 高级选项
self.adInterface.setObjectName("adInterface")
self.ifInterface = uic.loadUi(f'{base_directory}/view/menu/about.ui') # 关于
self.ifInterface.setObjectName("ifInterface")
self.ctInterface = uic.loadUi(f'{base_directory}/view/menu/custom.ui') # 自定义
self.ctInterface.setObjectName("ctInterface")
self.cfInterface = uic.loadUi(f'{base_directory}/view/menu/configs.ui') # 配置文件
self.cfInterface.setObjectName("cfInterface")
self.sdInterface = uic.loadUi(f'{base_directory}/view/menu/sound.ui') # 通知
self.sdInterface.setObjectName("sdInterface")
self.hdInterface = uic.loadUi(f'{base_directory}/view/menu/help.ui') # 帮助
self.hdInterface.setObjectName("hdInterface")
self.plInterface = uic.loadUi(f'{base_directory}/view/menu/plugin_mgr.ui') # 插件
self.plInterface.setObjectName("plInterface")
self.init_nav()
self.init_window()
def init_font(self): # 设置字体
self.setStyleSheet("""QLabel {
font-family: 'Microsoft YaHei';
}""")
def load_all_item(self):
self.setup_timeline_edit()
self.setup_schedule_edit()
self.setup_schedule_preview()
self.setup_advance_interface()
self.setup_about_interface()
self.setup_customization_interface()
self.setup_configs_interface()
self.setup_sound_interface()
self.setup_help_interface()
self.setup_plugin_mgr_interface()
# 初始化界面
def setup_plugin_mgr_interface(self):
pm_scroll = self.findChild(SmoothScrollArea, 'pm_scroll')
QScroller.grabGesture(pm_scroll.viewport(), QScroller.LeftMouseButtonGesture) # 触摸屏适配
global plugin_dict, enabled_plugins
enabled_plugins = conf.load_plugin_config() # 加载启用的插件
plugin_dict = (conf.load_plugins()) # 加载插件信息
open_pp = self.findChild(PushButton, 'open_plugin_plaza')
open_pp.clicked.connect(open_plaza) # 打开插件广场
open_pp2 = self.findChild(PushButton, 'open_plugin_plaza_2')
open_pp2.clicked.connect(open_plaza) # 打开插件广场
auto_delay = self.findChild(SpinBox, 'auto_delay')
auto_delay.setValue(int(conf.read_conf('Plugin', 'auto_delay')))
auto_delay.valueChanged.connect(lambda: conf.write_conf('Plugin', 'auto_delay', str(auto_delay.value())))
# 设置自动化延迟
plugin_card_layout = self.findChild(QVBoxLayout, 'plugin_card_layout')
open_plugin_folder = self.findChild(PushButton, 'open_plugin_folder')
open_plugin_folder.clicked.connect(lambda: open_dir(os.path.join(os.getcwd(), conf.PLUGINS_DIR))) # 打开插件目录
if not p_loader.plugins_settings: # 若插件设置为空
p_loader.load_plugins() # 加载插件设置
for plugin in plugin_dict:
if (Path(conf.PLUGINS_DIR) / plugin / 'icon.png').exists(): # 若插件目录存在icon.png
icon_path = f'{base_directory}/plugins/{plugin}/icon.png'
else:
icon_path = f'{base_directory}/img/settings/plugin-icon.png'
card = PluginCard(
icon=icon_path,
title=plugin_dict[plugin]['name'],
version=plugin_dict[plugin]['version'],
author=plugin_dict[plugin]['author'],
plugin_dir=plugin,
content=plugin_dict[plugin]['description'],
enable_settings=plugin_dict[plugin]['settings'],
parent=self
)
plugin_card_layout.addWidget(card)
tips_plugin_empty = self.findChild(QLabel, 'tips_plugin_empty')
if plugin_dict:
tips_plugin_empty.hide()
def setup_help_interface(self):
open_by_browser = self.findChild(PushButton, 'open_by_browser')
open_by_browser.setIcon(fIcon.LINK)
open_by_browser.clicked.connect(lambda: QDesktopServices.openUrl(QUrl(
'https://classwidgets.rinlit.cn/docs-user/'
)))
def setup_sound_interface(self):
sd_scroll = self.findChild(SmoothScrollArea, 'sd_scroll') # 触摸屏适配
QScroller.grabGesture(sd_scroll.viewport(), QScroller.LeftMouseButtonGesture)
switch_enable_toast = self.findChild(SwitchButton, 'switch_enable_attend')
switch_enable_toast.setChecked(int(conf.read_conf('Toast', 'attend_class')))
switch_enable_toast.checkedChanged.connect(lambda checked: switch_checked('Toast', 'attend_class', checked))
# 上课提醒开关
switch_enable_finish = self.findChild(SwitchButton, 'switch_enable_finish')
switch_enable_finish.setChecked(int(conf.read_conf('Toast', 'finish_class')))
switch_enable_finish.checkedChanged.connect(lambda checked: switch_checked('Toast', 'finish_class', checked))
# 下课提醒开关
switch_enable_prepare = self.findChild(SwitchButton, 'switch_enable_prepare')
switch_enable_prepare.setChecked(int(conf.read_conf('Toast', 'prepare_class')))
switch_enable_prepare.checkedChanged.connect(lambda checked: switch_checked('Toast', 'prepare_class', checked))
# 预备铃开关
switch_enable_pin_toast = self.findChild(SwitchButton, 'switch_enable_pin_toast')
switch_enable_pin_toast.setChecked(int(conf.read_conf('Toast', 'pin_on_top')))
switch_enable_pin_toast.checkedChanged.connect(lambda checked: switch_checked('Toast', 'pin_on_top', checked))
# 置顶开关
slider_volume = self.findChild(Slider, 'slider_volume')
slider_volume.setValue(int(conf.read_conf('Audio', 'volume')))
slider_volume.valueChanged.connect(self.save_volume) # 音量滑块
preview_toast_button = self.findChild(PrimaryDropDownPushButton, 'preview')
pre_toast_menu = RoundMenu(parent=preview_toast_button)
pre_toast_menu.addActions([
Action(fIcon.EDUCATION, '上课提醒',
triggered=lambda: tip_toast.push_notification(1, lesson_name='信息技术')),
Action(fIcon.CAFE, '下课提醒',
triggered=lambda: tip_toast.push_notification(0, lesson_name='信息技术')),
Action(fIcon.BOOK_SHELF, '预备提醒',
triggered=lambda: tip_toast.push_notification(3, lesson_name='信息技术')),
Action(fIcon.CODE, '其他提醒',
triggered=lambda: tip_toast.push_notification(4, title='通知', subtitle='测试通知示例',
content='这是一条测试通知ヾ(≧▽≦*)o'))
])
preview_toast_button.setMenu(pre_toast_menu) # 预览通知栏
switch_wave_effect = self.findChild(SwitchButton, 'switch_enable_wave')
switch_wave_effect.setChecked(int(conf.read_conf('Toast', 'wave')))
switch_wave_effect.checkedChanged.connect(lambda checked: switch_checked('Toast', 'wave', checked)) # 波纹开关
spin_prepare_time = self.findChild(SpinBox, 'spin_prepare_class')
spin_prepare_time.setValue(int(conf.read_conf('Toast', 'prepare_minutes')))
spin_prepare_time.valueChanged.connect(self.save_prepare_time) # 准备时间
def setup_configs_interface(self): # 配置界面
cf_import_schedule = self.findChild(PushButton, 'im_schedule')
cf_import_schedule.clicked.connect(self.cf_import_schedule) # 导入课程表
cf_export_schedule = self.findChild(PushButton, 'ex_schedule')
cf_export_schedule.clicked.connect(self.cf_export_schedule) # 导出课程表
cf_open_schedule_folder = self.findChild(PushButton, 'open_schedule_folder') # 打开课程表文件夹
cf_open_schedule_folder.clicked.connect(lambda: open_dir(os.path.join(os.path.abspath('.'), 'config/schedule')))
cf_import_schedule_cses = self.findChild(PushButton, 'im_schedule_cses')
cf_import_schedule_cses.clicked.connect(self.cf_import_schedule_cses) # 导入课程表(CSES)
cf_export_schedule_cses = self.findChild(PushButton, 'ex_schedule_cses')
cf_export_schedule_cses.clicked.connect(self.cf_export_schedule_cses) # 导出课程表(CSES)
cf_what_is_cses = self.findChild(HyperlinkButton, 'what_is')
cf_what_is_cses.setUrl(QUrl('https://github.com/CSES-org/CSES'))
def setup_customization_interface(self):
ct_scroll = self.findChild(SmoothScrollArea, 'ct_scroll') # 触摸屏适配
QScroller.grabGesture(ct_scroll.viewport(), QScroller.LeftMouseButtonGesture)
self.ct_update_preview()
widgets_list_widgets = self.findChild(ListWidget, 'widgets_list')
widgets_list = []
for key in list.get_widget_config():
try:
widgets_list.append(list.widget_name[key])
except KeyError:
logger.warning(f'未知的组件:{key}')
except Exception as e:
logger.error(f'获取组件名称时发生错误:{sys.exc_info()[0]}/{e}')
widgets_list_widgets.addItems(widgets_list)
widgets_list_widgets.sizePolicy().setVerticalPolicy(QSizePolicy.Policy.MinimumExpanding)
save_config_button = self.findChild(PrimaryPushButton, 'save_config')
save_config_button.clicked.connect(self.ct_save_widget_config)
set_wcc_title = self.findChild(LineEdit, 'set_wcc_title') # 倒计时标题
set_wcc_title.setText(conf.read_conf('Date', 'cd_text_custom'))
set_wcc_title.textChanged.connect(lambda: conf.write_conf('Date', 'cd_text_custom', set_wcc_title.text()))
set_countdown_date = self.findChild(CalendarPicker, 'set_countdown_date') # 倒计时日期
if conf.read_conf('Date', 'countdown_date') != '':
set_countdown_date.setDate(QDate.fromString(conf.read_conf('Date', 'countdown_date'), 'yyyy-M-d'))
set_countdown_date.dateChanged.connect(
lambda: conf.write_conf(
'Date', 'countdown_date', set_countdown_date.date.toString('yyyy-M-d'))
)
set_ac_color = self.findChild(PushButton, 'set_ac_color') # 主题色
set_ac_color.clicked.connect(self.ct_set_ac_color)
set_fc_color = self.findChild(PushButton, 'set_fc_color')
set_fc_color.clicked.connect(self.ct_set_fc_color)
open_theme_folder = self.findChild(HyperlinkLabel, 'open_theme_folder') # 打开主题文件夹
open_theme_folder.clicked.connect(lambda: open_dir(os.path.join(os.getcwd(), 'ui')))
select_theme_combo = self.findChild(ComboBox, 'combo_theme_select') # 主题选择
select_theme_combo.addItems(list.theme_names)
print(list.theme_folder, list.theme_names, get_theme_name())
select_theme_combo.setCurrentIndex(list.theme_folder.index(get_theme_name()))
select_theme_combo.currentIndexChanged.connect(
lambda: conf.write_conf('General', 'theme', list.get_theme_ui_path(select_theme_combo.currentText())))
color_mode_combo = self.findChild(ComboBox, 'combo_color_mode') # 颜色模式选择
color_mode_combo.addItems(list.color_mode)
color_mode_combo.setCurrentIndex(int(conf.read_conf('General', 'color_mode')))
color_mode_combo.currentIndexChanged.connect(self.ct_change_color_mode)
widgets_combo = self.findChild(ComboBox, 'widgets_combo') # 组件选择
widgets_combo.addItems(list.get_widget_names())
search_city_button = self.findChild(PushButton, 'select_city') # 查找城市
search_city_button.clicked.connect(self.show_search_city)
add_widget_button = self.findChild(PrimaryPushButton, 'add_widget')
add_widget_button.clicked.connect(self.ct_add_widget)
remove_widget_button = self.findChild(PushButton, 'remove_widget')
remove_widget_button.clicked.connect(self.ct_remove_widget)
slider_opacity = self.findChild(Slider, 'slider_opacity')
slider_opacity.setValue(int(conf.read_conf('General', 'opacity')))
slider_opacity.valueChanged.connect(
lambda: conf.write_conf('General', 'opacity', str(slider_opacity.value()))
) # 透明度
blur_countdown = self.findChild(SwitchButton, 'switch_blur_countdown')
blur_countdown.setChecked(int(conf.read_conf('General', 'blur_countdown')))
blur_countdown.checkedChanged.connect(lambda checked: switch_checked('General', 'blur_countdown', checked))
# 模糊倒计时
select_weather_api = self.findChild(ComboBox, 'select_weather_api') # 天气API选择
select_weather_api.addItems(weather_db.api_config['weather_api_list_zhCN'])
select_weather_api.setCurrentIndex(weather_db.api_config['weather_api_list'].index(
conf.read_conf('Weather', 'api')
))
select_weather_api.currentIndexChanged.connect(
lambda: conf.write_conf('Weather', 'api',
weather_db.api_config['weather_api_list'][select_weather_api.currentIndex()])
)
api_key_edit = self.findChild(LineEdit, 'api_key_edit') # API密钥
api_key_edit.setText(conf.read_conf('Weather', 'api_key'))
api_key_edit.textChanged.connect(lambda: conf.write_conf('Weather', 'api_key', api_key_edit.text()))
def setup_about_interface(self):
ab_scroll = self.findChild(SmoothScrollArea, 'ab_scroll') # 触摸屏适配
QScroller.grabGesture(ab_scroll.viewport(), QScroller.LeftMouseButtonGesture)
self.version = self.findChild(BodyLabel, 'version')
check_update_btn = self.findChild(PrimaryPushButton, 'check_update')
check_update_btn.setIcon(fIcon.SYNC)
check_update_btn.clicked.connect(self.check_update)
self.auto_check_update = self.ifInterface.findChild(SwitchButton, 'auto_check_update')
self.auto_check_update.setChecked(int(conf.read_conf("Other", "auto_check_update")))
self.auto_check_update.checkedChanged.connect(
lambda checked: switch_checked("Other", "auto_check_update", checked)
) # 自动检查更新
self.version_channel = self.findChild(ComboBox, 'version_channel')
self.version_channel.addItems(list.version_channel)
self.version_channel.setCurrentIndex(int(conf.read_conf("Other", "version_channel")))
self.version_channel.currentIndexChanged.connect(
lambda: conf.write_conf("Other", "version_channel", self.version_channel.currentIndex())
) # 版本更新通道
github_page = self.findChild(PushButton, "button_github")
github_page.clicked.connect(lambda: QDesktopServices.openUrl(QUrl(
'https://github.com/RinLit-233-shiroko/Class-Widgets')))
bilibili_page = self.findChild(PushButton, 'button_bilibili')
bilibili_page.clicked.connect(lambda: QDesktopServices.openUrl(QUrl(
'https://space.bilibili.com/569522843')))
license_button = self.findChild(PushButton, 'button_show_license')
license_button.clicked.connect(self.show_license)
thanks_button = self.findChild(PushButton, 'button_thanks')
thanks_button.clicked.connect(lambda: QDesktopServices.openUrl(QUrl(
'https://github.com/RinLit-233-shiroko/Class-Widgets?tab=readme-ov-file#致谢')))
self.check_update()
def setup_advance_interface(self):
adv_scroll = self.adInterface.findChild(SmoothScrollArea, 'adv_scroll') # 触摸屏适配
QScroller.grabGesture(adv_scroll.viewport(), QScroller.LeftMouseButtonGesture)
margin_spin = self.adInterface.findChild(SpinBox, 'margin_spin')
margin_spin.setValue(int(conf.read_conf('General', 'margin')))
margin_spin.valueChanged.connect(
lambda: conf.write_conf('General', 'margin', str(margin_spin.value()))
) # 保存边距设定
self.conf_combo = self.adInterface.findChild(ComboBox, 'conf_combo')
self.conf_combo.clear()
self.conf_combo.addItems(list.get_schedule_config())
self.conf_combo.setCurrentIndex(list.get_schedule_config().index(conf.read_conf('General', 'schedule')))
self.conf_combo.currentIndexChanged.connect(self.ad_change_file) # 切换配置文件
conf_name = self.adInterface.findChild(LineEdit, 'conf_name')
conf_name.setText(filename[:-5])
conf_name.textEdited.connect(self.ad_change_file_name)
window_status_combo = self.adInterface.findChild(ComboBox, 'window_status_combo')
window_status_combo.addItems(list.window_status)
window_status_combo.setCurrentIndex(int(conf.read_conf('General', 'pin_on_top')))
window_status_combo.currentIndexChanged.connect(
lambda: conf.write_conf('General', 'pin_on_top', str(window_status_combo.currentIndex()))
) # 窗口状态
switch_startup = self.adInterface.findChild(SwitchButton, 'switch_startup')
switch_startup.setChecked(int(conf.read_conf('General', 'auto_startup')))
switch_startup.checkedChanged.connect(lambda checked: switch_checked('General', 'auto_startup', checked))
# 开机自启
if os.name != 'nt':
switch_startup.setEnabled(False)
hide_mode_combo = self.adInterface.findChild(ComboBox, 'hide_mode_combo')
hide_mode_combo.addItems(list.hide_mode if os.name == 'nt' else list.non_nt_hide_mode)
hide_mode_combo.setCurrentIndex(int(conf.read_conf('General', 'hide')))
hide_mode_combo.currentIndexChanged.connect(
lambda: conf.write_conf('General', 'hide', str(hide_mode_combo.currentIndex()))
) # 隐藏模式
hide_method_default = self.adInterface.findChild(RadioButton, 'hide_method_default')
hide_method_default.setChecked(conf.read_conf('General', 'hide_method') == '0')
hide_method_default.toggled.connect(lambda: conf.write_conf('General', 'hide_method', '0'))
if os.name != 'nt':
hide_method_default.setEnabled(False)
# 默认隐藏
hide_method_all = self.adInterface.findChild(RadioButton, 'hide_method_all')
hide_method_all.setChecked(conf.read_conf('General', 'hide_method') == '1')
hide_method_all.toggled.connect(lambda: conf.write_conf('General', 'hide_method', '1'))
# 单击全部隐藏
hide_method_floating = self.adInterface.findChild(RadioButton, 'hide_method_floating')
hide_method_floating.setChecked(conf.read_conf('General', 'hide_method') == '2')
hide_method_floating.toggled.connect(lambda: conf.write_conf('General', 'hide_method', '2'))
# 最小化为浮窗
switch_enable_alt_schedule = self.adInterface.findChild(SwitchButton, 'switch_enable_alt_schedule')
switch_enable_alt_schedule.setChecked(int(conf.read_conf('General', 'enable_alt_schedule')))
switch_enable_alt_schedule.checkedChanged.connect(
lambda checked: switch_checked('General', 'enable_alt_schedule', checked)
) # 安全模式
switch_enable_safe_mode = self.adInterface.findChild(SwitchButton, 'switch_safe_mode')
switch_enable_safe_mode.setChecked(int(conf.read_conf('Other', 'safe_mode')))
switch_enable_safe_mode.checkedChanged.connect(
lambda checked: switch_checked('Other', 'safe_mode', checked)
)
# 安全模式开关
switch_enable_multiple_programs = self.adInterface.findChild(SwitchButton, 'switch_multiple_programs')
switch_enable_multiple_programs.setChecked(int(conf.read_conf('Other', 'multiple_programs')))
switch_enable_multiple_programs.checkedChanged.connect(
lambda checked: switch_checked('Other', 'multiple_programs', checked)
) # 多开程序
switch_disable_log = self.adInterface.findChild(SwitchButton, 'switch_disable_log')
switch_disable_log.setChecked(int(conf.read_conf('Other', 'do_not_log')))
switch_disable_log.checkedChanged.connect(
lambda checked: switch_checked('Other', 'do_not_log', checked)
) # 禁用日志
button_clear_log = self.adInterface.findChild(PushButton, 'button_clear_log')
button_clear_log.clicked.connect(self.clear_log) # 清空日志
set_start_date = self.adInterface.findChild(CalendarPicker, 'set_start_date') # 日期
if conf.read_conf('Date', 'start_date') != '':
set_start_date.setDate(QDate.fromString(conf.read_conf('Date', 'start_date'), 'yyyy-M-d'))
set_start_date.dateChanged.connect(
lambda: conf.write_conf('Date', 'start_date', set_start_date.date.toString('yyyy-M-d'))) # 开学日期
offset_spin = self.adInterface.findChild(SpinBox, 'offset_spin')
offset_spin.setValue(int(conf.read_conf('General', 'time_offset')))
offset_spin.valueChanged.connect(
lambda: conf.write_conf('General', 'time_offset', str(offset_spin.value()))
) # 保存时差偏移
text_scale_factor = self.adInterface.findChild(LineEdit, 'text_scale_factor')
text_scale_factor.setText(str(float(conf.read_conf('General', 'scale')) * 100) + '%') # 初始化缩放系数显示
slider_scale_factor = self.adInterface.findChild(Slider, 'slider_scale_factor')
slider_scale_factor.setValue(int(float(conf.read_conf('General', 'scale')) * 100))
slider_scale_factor.valueChanged.connect(
lambda: (conf.write_conf('General', 'scale', str(slider_scale_factor.value() / 100)),
text_scale_factor.setText(str(slider_scale_factor.value()) + '%'))
) # 保存缩放系数
def setup_schedule_edit(self):
se_load_item()
se_set_button = self.findChild(ToolButton, 'set_button')
se_set_button.setIcon(fIcon.EDIT)
se_set_button.setToolTip('编辑课程')
se_set_button.installEventFilter(ToolTipFilter(se_set_button, showDelay=300, position=ToolTipPosition.TOP))
se_set_button.clicked.connect(self.se_edit_item)
se_clear_button = self.findChild(ToolButton, 'clear_button')
se_clear_button.setIcon(fIcon.DELETE)
se_clear_button.setToolTip('清空课程')
se_clear_button.installEventFilter(ToolTipFilter(se_clear_button, showDelay=300, position=ToolTipPosition.TOP))
se_clear_button.clicked.connect(self.se_delete_item)
se_class_kind_combo = self.findChild(ComboBox, 'class_combo') # 课程类型
se_class_kind_combo.addItems(list.class_kind)
se_week_combo = self.findChild(ComboBox, 'week_combo') # 星期
se_week_combo.addItems(list.week)
se_week_combo.currentIndexChanged.connect(self.se_upload_list)
se_schedule_list = self.findChild(ListWidget, 'schedule_list')
se_schedule_list.addItems(schedule_dict[str(current_week)])
se_schedule_list.itemChanged.connect(self.se_upload_item)
QScroller.grabGesture(se_schedule_list.viewport(), QScroller.LeftMouseButtonGesture) # 触摸屏适配
se_save_button = self.findChild(PrimaryPushButton, 'save_schedule')
se_save_button.clicked.connect(self.se_save_item)
se_week_type_combo = self.findChild(ComboBox, 'week_type_combo')
se_week_type_combo.addItems(list.week_type)
se_week_type_combo.currentIndexChanged.connect(self.se_upload_list)
se_copy_schedule_button = self.findChild(PushButton, 'copy_schedule')
se_copy_schedule_button.hide()
se_copy_schedule_button.clicked.connect(self.se_copy_odd_schedule)
quick_set_schedule = self.findChild(ListWidget, 'subject_list')
quick_set_schedule.addItems(list.class_kind[1:])
quick_set_schedule.itemClicked.connect(self.se_quick_set_schedule)
quick_select_week_button = self.findChild(PushButton, 'quick_select_week')
quick_select_week_button.clicked.connect(self.se_quick_select_week)
def setup_timeline_edit(self): # 底层大改
self.te_load_item() # 加载时段
# teInterface
te_add_button = self.findChild(ToolButton, 'add_button') # 添加
te_add_button.setIcon(fIcon.ADD)
te_add_button.setToolTip('添加时间线') # 增加提示
te_add_button.installEventFilter(ToolTipFilter(te_add_button, showDelay=300, position=ToolTipPosition.TOP))
te_add_button.clicked.connect(self.te_add_item)
te_add_button.clicked.connect(self.te_upload_item)
te_add_part_button = self.findChild(ToolButton, 'add_part_button') # 添加节点
te_add_part_button.setIcon(fIcon.ADD)
te_add_part_button.setToolTip('添加节点')
te_add_part_button.installEventFilter(
ToolTipFilter(te_add_part_button, showDelay=300, position=ToolTipPosition.TOP))
te_add_part_button.clicked.connect(self.te_add_part)
te_part_type_combo = self.findChild(ComboBox, 'part_type') # 节次类型
te_part_type_combo.addItems(list.part_type)
te_name_edit = self.findChild(EditableComboBox, 'name_part_combo') # 名称
te_name_edit.addItems(list.time)
te_delete_part_button = self.findChild(ToolButton, 'delete_part_button') # 删除节点
te_delete_part_button.setIcon(fIcon.DELETE)
te_delete_part_button.setToolTip('删除节点')
te_delete_part_button.installEventFilter(
ToolTipFilter(te_delete_part_button, showDelay=300, position=ToolTipPosition.TOP))
te_delete_part_button.clicked.connect(self.te_delete_part)
te_edit_button = self.findChild(ToolButton, 'edit_button') # 编辑
te_edit_button.setIcon(fIcon.EDIT)
te_edit_button.setToolTip('编辑时间线')
te_edit_button.installEventFilter(ToolTipFilter(te_edit_button, showDelay=300, position=ToolTipPosition.TOP))
te_edit_button.clicked.connect(self.te_edit_item)
te_delete_button = self.findChild(ToolButton, 'delete_button') # 删除
te_delete_button.setIcon(fIcon.DELETE)
te_delete_button.setToolTip('删除时间线')
te_delete_button.installEventFilter(
ToolTipFilter(te_delete_button, showDelay=300, position=ToolTipPosition.TOP))
te_delete_button.clicked.connect(self.te_delete_item)
te_delete_button.clicked.connect(self.te_upload_item)
te_class_activity_combo = self.findChild(ComboBox, 'class_activity') # 活动类型
te_class_activity_combo.addItems(list.class_activity)
te_class_activity_combo.setToolTip('选择活动类型(“课程”或“课间”)')
te_class_activity_combo.currentIndexChanged.connect(self.te_sync_time)
te_select_timeline = self.findChild(ComboBox, 'select_timeline') # 选择时间线
te_select_timeline.addItem('默认')
te_select_timeline.addItems(list.week)
te_select_timeline.setToolTip('选择一周内的某一天的时间线')
te_select_timeline.currentIndexChanged.connect(self.te_upload_list)
te_timeline_list = self.findChild(ListWidget, 'timeline_list') # 所选时间线列表
te_timeline_list.addItems(timeline_dict['default'])
te_timeline_list.itemChanged.connect(self.te_upload_item)
te_save_button = self.findChild(PrimaryPushButton, 'save') # 保存
te_save_button.clicked.connect(self.te_save_item)
part_list = self.findChild(ListWidget, 'part_list')
QScroller.grabGesture(te_timeline_list.viewport(), QScroller.LeftMouseButtonGesture) # 触摸屏适配
QScroller.grabGesture(part_list.viewport(), QScroller.LeftMouseButtonGesture) # 触摸屏适配
self.te_detect_item()
self.te_detect_part() # 修复在启动时无法添加时段到下拉框的问题
def setup_schedule_preview(self):
subtitle = self.findChild(SubtitleLabel, 'subtitle_file')
subtitle.setText(f'预览 - {filename[:-5]}')
schedule_view = self.findChild(TableWidget, 'schedule_view')
schedule_view.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) # 使列表自动等宽
sp_week_type_combo = self.findChild(ComboBox, 'pre_week_type_combo')
sp_week_type_combo.addItems(list.week_type)
sp_week_type_combo.currentIndexChanged.connect(self.sp_fill_grid_row)
# 设置表格
schedule_view.setColumnCount(7)
schedule_view.setHorizontalHeaderLabels(list.week[0:7])
schedule_view.setBorderVisible(True)
schedule_view.verticalHeader().hide()
schedule_view.setBorderRadius(8)
QScroller.grabGesture(schedule_view.viewport(), QScroller.LeftMouseButtonGesture) # 触摸屏适配
self.sp_fill_grid_row()
def save_volume(self):
slider_volume = self.findChild(Slider, 'slider_volume')
conf.write_conf('Audio', 'volume', str(slider_volume.value()))
def show_search_city(self):
search_city_dialog = selectCity(self)
if search_city_dialog.exec():
selected_city = search_city_dialog.city_list.selectedItems()
if selected_city:
conf.write_conf('Weather', 'city', wd.search_code_by_name(selected_city[0].text()))
def show_license(self):
license_dialog = licenseDialog(self)
license_dialog.exec()
def save_prepare_time(self):
prepare_time_spin = self.findChild(SpinBox, 'spin_prepare_class')
conf.write_conf('Toast', 'prepare_minutes', str(prepare_time_spin.value()))
def clear_log(self): # 清空日志
def get_directory_size(path): # 计算目录大小
total_size = 0
for dir_path, dir_names, filenames in os.walk(path):
for file_name in filenames:
file_path = os.path.join(dir_path, file_name)
total_size += os.path.getsize(file_path)
total_size /= 1024
return round(total_size, 2)
self.button_clear_log = self.adInterface.findChild(PushButton, 'button_clear_log')
size = get_directory_size('log')
try:
if os.path.exists('log'):
rmtree('log')
Flyout.create(
icon=InfoBarIcon.SUCCESS,
title='已清除日志',
content=f"已清空所有日志文件,约 {size} KB",
target=self.button_clear_log,
parent=self,
isClosable=True,