1
+ import os
2
+ import subprocess
3
+ from PySide6 .QtWidgets import QWidget , QVBoxLayout , QLabel , QStackedWidget
4
+ from PySide6 .QtCore import Qt
5
+ from qfluentwidgets import FluentIcon as FIF
6
+ from qfluentwidgets import (Pivot , qrouter , ScrollArea , SettingCardGroup ,
7
+ PrimaryPushSettingCard , InfoBar , InfoBarPosition )
8
+ from src .component .style_sheet import StyleSheet
9
+
10
+
11
+ class Config (ScrollArea ):
12
+ Nav = Pivot
13
+ def __init__ (self , text : str , parent = None ):
14
+ super ().__init__ (parent = parent )
15
+ self .parent = parent
16
+ self .setObjectName (text .replace (' ' , '-' ))
17
+ self .scrollWidget = QWidget ()
18
+ self .vBoxLayout = QVBoxLayout (self .scrollWidget )
19
+
20
+ # 栏定义
21
+ self .pivot = self .Nav (self )
22
+ self .stackedWidget = QStackedWidget (self )
23
+
24
+ # 添加项 , 名字会隐藏
25
+ self .LauncherInterface = SettingCardGroup ('配置' , self .scrollWidget )
26
+ self .settingConfigCard = PrimaryPushSettingCard (
27
+ '打开文件' ,
28
+ FIF .LABEL ,
29
+ '启动器设置' ,
30
+ '自定义启动器配置'
31
+ )
32
+ self .personalConfigCard = PrimaryPushSettingCard (
33
+ '打开文件' ,
34
+ FIF .LABEL ,
35
+ '个性化' ,
36
+ '自定义个性化配置'
37
+ )
38
+ self .LunarCoreInterface = SettingCardGroup ('LunarCore' , self .scrollWidget )
39
+ self .bannersConfigCard = PrimaryPushSettingCard (
40
+ '打开文件' ,
41
+ FIF .LABEL ,
42
+ 'Banners' ,
43
+ 'LunarCore的跃迁配置'
44
+ )
45
+
46
+ self .__initWidget ()
47
+
48
+ def __initWidget (self ):
49
+ self .setHorizontalScrollBarPolicy (Qt .ScrollBarAlwaysOff ) # 水平滚动条关闭
50
+ self .setViewportMargins (20 , 0 , 20 , 20 )
51
+ self .setWidget (self .scrollWidget )
52
+ self .setWidgetResizable (True ) # 必须设置!!!
53
+
54
+ # 使用qss设置样式
55
+ self .scrollWidget .setObjectName ('scrollWidget' )
56
+ StyleSheet .SETTING_INTERFACE .apply (self )
57
+
58
+ self .__initLayout ()
59
+ self .__connectSignalToSlot ()
60
+
61
+ def __initLayout (self ):
62
+ # 项绑定到栏目
63
+ self .LauncherInterface .addSettingCard (self .settingConfigCard )
64
+ self .LauncherInterface .addSettingCard (self .personalConfigCard )
65
+ self .LunarCoreInterface .addSettingCard (self .bannersConfigCard )
66
+
67
+ # 目前无法做到导航栏各个页面独立分组 , 故隐藏组标题
68
+ self .LauncherInterface .titleLabel .setHidden (True )
69
+ self .LunarCoreInterface .titleLabel .setHidden (True )
70
+
71
+ # 栏绑定界面
72
+ self .addSubInterface (self .LauncherInterface , 'LauncherInterface' ,'启动器' , icon = FIF .PLAY )
73
+ self .addSubInterface (self .LunarCoreInterface , 'LunarCoreInterface' ,'LunarCore' , icon = FIF .TAG )
74
+
75
+ # 初始化配置界面
76
+ self .vBoxLayout .addWidget (self .pivot , 0 , Qt .AlignLeft )
77
+ self .vBoxLayout .addWidget (self .stackedWidget )
78
+ self .vBoxLayout .setSpacing (28 )
79
+ self .vBoxLayout .setContentsMargins (0 , 10 , 10 , 0 )
80
+ self .stackedWidget .currentChanged .connect (self .onCurrentIndexChanged )
81
+ self .stackedWidget .setCurrentWidget (self .LauncherInterface )
82
+ self .pivot .setCurrentItem (self .LauncherInterface .objectName ())
83
+ qrouter .setDefaultRouteKey (self .stackedWidget , self .LauncherInterface .objectName ())
84
+
85
+ def __connectSignalToSlot (self ):
86
+ self .settingConfigCard .clicked .connect (lambda : self .open_file ('config/config.json' ))
87
+ self .personalConfigCard .clicked .connect (lambda : self .open_file ('config/auto.json' ))
88
+ self .bannersConfigCard .clicked .connect (lambda : self .open_file ('server/lunarcore/data/banners.json' ))
89
+
90
+ def addSubInterface (self , widget : QLabel , objectName , text , icon = None ):
91
+ widget .setObjectName (objectName )
92
+ self .stackedWidget .addWidget (widget )
93
+ self .pivot .addItem (
94
+ icon = icon ,
95
+ routeKey = objectName ,
96
+ text = text ,
97
+ onClick = lambda : self .stackedWidget .setCurrentWidget (widget )
98
+ )
99
+
100
+ def onCurrentIndexChanged (self , index ):
101
+ widget = self .stackedWidget .widget (index )
102
+ self .pivot .setCurrentItem (widget .objectName ())
103
+ qrouter .push (self .stackedWidget , widget .objectName ())
104
+
105
+ def open_file (self , file_path ):
106
+ if os .path .exists (file_path ):
107
+ subprocess .run (['start' , file_path ], shell = True )
108
+ else :
109
+ InfoBar .error (
110
+ title = "找不到文件,请重新下载!" ,
111
+ content = "" ,
112
+ orient = Qt .Horizontal ,
113
+ isClosable = True ,
114
+ position = InfoBarPosition .TOP ,
115
+ duration = 3000 ,
116
+ parent = self
117
+ )
0 commit comments