-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
269 lines (212 loc) · 10.1 KB
/
main.py
File metadata and controls
269 lines (212 loc) · 10.1 KB
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
import sys
import os
from PyQt5.QtCore import Qt, QSize, QUrl
from PyQt5.QtGui import QIcon, QDesktopServices, QColor
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QFrame, QLabel, QStackedWidget
from qfluentwidgets import (
FluentWindow, SubtitleLabel, TitleLabel, BodyLabel, PrimaryPushButton,
StrongBodyLabel, CardWidget, SwitchButton, FluentIcon,
InfoBar, InfoBarPosition, Theme, setTheme, setThemeColor,
NavigationItemPosition, ScrollArea, PushButton, ToolButton,
ComboBox, qconfig, QConfig, ConfigItem, OptionsConfigItem, OptionsValidator,
ConfigSerializer
)
# Custom Config for storing theme settings
class Config(QConfig):
themeMode = OptionsConfigItem(
"Theme", "ThemeMode", Theme.AUTO, OptionsValidator(Theme),
serializer=lambda x: x.value
)
# Instantiate the config
cfg = Config()
qconfig.load('config.json', cfg)
from qfluentwidgets import FluentIcon as FIF
# Import the core logic
from core import HackerCore
class HomeInterface(QWidget):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.core = HackerCore()
# Main Layout
self.vBoxLayout = QVBoxLayout(self)
self.vBoxLayout.setContentsMargins(30, 30, 30, 30)
self.vBoxLayout.setSpacing(20)
# Title
self.titleLabel = TitleLabel('仪表盘', self)
self.vBoxLayout.addWidget(self.titleLabel)
self.vBoxLayout.addStretch(1)
# Status Card
self.statusCard = CardWidget(self)
self.statusCard.setFixedSize(600, 120)
self.statusLayout = QHBoxLayout(self.statusCard)
self.statusLayout.setContentsMargins(24, 0, 24, 0)
self.statusLayout.setSpacing(20)
self.statusIcon = QLabel(self.statusCard)
self.statusIcon.setFixedSize(48, 48)
self.statusLayout.addWidget(self.statusIcon)
self.statusInfoLayout = QVBoxLayout()
self.statusInfoLayout.setSpacing(4)
self.statusInfoLayout.setAlignment(Qt.AlignVCenter)
self.statusTitle = SubtitleLabel('状态未知', self.statusCard)
self.statusDetail = BodyLabel('正在检查系统配置...', self.statusCard)
self.statusInfoLayout.addWidget(self.statusTitle)
self.statusInfoLayout.addWidget(self.statusDetail)
self.statusLayout.addLayout(self.statusInfoLayout)
self.statusLayout.addStretch(1)
self.vBoxLayout.addWidget(self.statusCard, 0, Qt.AlignHCenter)
# Action Area
self.actionCard = CardWidget(self)
self.actionCard.setFixedSize(600, 200)
self.actionLayout = QVBoxLayout(self.actionCard)
self.actionLayout.setContentsMargins(30, 30, 30, 30)
self.actionLayout.setAlignment(Qt.AlignCenter)
self.actionLabel = StrongBodyLabel("一键模式切换", self.actionCard)
self.actionLayout.addWidget(self.actionLabel, 0, Qt.AlignTop | Qt.AlignHCenter)
self.toggleBtn = PrimaryPushButton(self.actionCard)
self.toggleBtn.setFixedSize(240, 60)
self.toggleBtn.setIconSize(QSize(24, 24))
self.toggleBtn.clicked.connect(self.toggle_mode)
self.actionLayout.addWidget(self.toggleBtn)
self.vBoxLayout.addWidget(self.actionCard, 0, Qt.AlignHCenter)
# Config Info
self.configLabel = BodyLabel(self)
self.configLabel.setTextColor(QColor(120, 120, 120), QColor(150, 150, 150))
self.vBoxLayout.addWidget(self.configLabel, 0, Qt.AlignHCenter)
self.vBoxLayout.addStretch(1)
# Initialize UI state
self.refresh_status()
def refresh_status(self):
is_iwb, msg = self.core.check_status()
self.configLabel.setText(f"配置文件路径: {self.core.get_config_path()}")
if is_iwb:
self.statusTitle.setText("一体机模式已激活")
self.statusDetail.setText("您的设备正在模拟希沃一体机环境。")
# Set icon to checkmark or similar (using built-in if possible, else text)
# Assuming FluentIcon.ACCEPT or similar exists, using generic check
self.statusIcon.setPixmap(FIF.ACCEPT.icon(color=QColor(0, 200, 0)).pixmap(48, 48))
self.toggleBtn.setText("切换到普通模式")
self.toggleBtn.setIcon(FIF.SYNC)
self.toggleBtn.setProperty('is_iwb', True)
else:
self.statusTitle.setText("普通模式已激活")
self.statusDetail.setText("您的设备正在运行标准 PC 模式。")
self.statusIcon.setPixmap(FIF.APPLICATION.icon(color=QColor(0, 120, 215)).pixmap(48, 48))
self.toggleBtn.setText("切换到一体机模式")
self.toggleBtn.setIcon(FIF.PENCIL_INK)
self.toggleBtn.setProperty('is_iwb', False)
def toggle_mode(self):
current_is_iwb = self.toggleBtn.property('is_iwb')
target_enable = not current_is_iwb
success, msg = self.core.toggle_mode(target_enable)
if success:
title = "成功"
content = msg
icon = FIF.ACCEPT
else:
title = "错误"
content = msg
icon = FIF.CANCEL
InfoBar.info(
title=title,
content=content,
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP_RIGHT,
duration=3000,
parent=self.window()
)
self.refresh_status()
class SettingsInterface(ScrollArea):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.scrollWidget = QWidget()
self.vBoxLayout = QVBoxLayout(self.scrollWidget)
self.vBoxLayout.setContentsMargins(30, 30, 30, 30)
self.vBoxLayout.setSpacing(20)
self.titleLabel = TitleLabel('设置', self.scrollWidget)
self.vBoxLayout.addWidget(self.titleLabel)
# Personalization
self.personalGroup = CardWidget(self.scrollWidget)
self.personalLayout = QVBoxLayout(self.personalGroup)
self.themeLabel = SubtitleLabel("个性化", self.personalGroup)
self.personalLayout.addWidget(self.themeLabel)
# Theme Switcher
self.themeRow = QWidget()
self.themeRowLayout = QHBoxLayout(self.themeRow)
self.themeRowLayout.setContentsMargins(0, 0, 0, 0)
self.themeText = BodyLabel("应用主题", self.themeRow)
self.themeComboBox = ComboBox(self.themeRow)
self.themeComboBox.addItems(['浅色', '深色', '跟随系统'])
# Set initial index based on config
initial_theme = cfg.get(cfg.themeMode)
self.themeComboBox.setCurrentIndex(0 if initial_theme == Theme.LIGHT else 1 if initial_theme == Theme.DARK else 2)
self.themeComboBox.currentIndexChanged.connect(self.set_theme)
self.themeRowLayout.addWidget(self.themeText)
self.themeRowLayout.addStretch(1)
self.themeRowLayout.addWidget(self.themeComboBox)
self.personalLayout.addWidget(self.themeRow)
self.vBoxLayout.addWidget(self.personalGroup)
# About
self.aboutGroup = CardWidget(self.scrollWidget)
self.aboutLayout = QVBoxLayout(self.aboutGroup)
self.aboutTitle = SubtitleLabel("关于", self.aboutGroup)
self.aboutContent = BodyLabel("希沃一体机模式伪装工具\n版本 2.0 (Fluent GUI)\n\n仅供学习交流使用。", self.aboutGroup)
self.aboutLayout.addWidget(self.aboutTitle)
self.aboutLayout.addWidget(self.aboutContent)
self.vBoxLayout.addWidget(self.aboutGroup)
self.vBoxLayout.addStretch(1)
self.setWidget(self.scrollWidget)
self.setWidgetResizable(True)
self.scrollWidget.setObjectName('scrollWidget')
# Ensure transparency for the entire hierarchy
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setViewportMargins(0, 0, 0, 0)
# Attribute-based transparency
self.setAttribute(Qt.WA_TranslucentBackground)
self.viewport().setAttribute(Qt.WA_TranslucentBackground)
self.scrollWidget.setAttribute(Qt.WA_TranslucentBackground)
# Robust stylesheet to force transparency on ScrollArea and its container
self.setStyleSheet("""
SettingsInterface, #scrollWidget {
background-color: transparent;
border: none;
}
QScrollArea {
background-color: transparent;
border: none;
}
""")
def set_theme(self, index):
theme = Theme.LIGHT if index == 0 else Theme.DARK if index == 1 else Theme.AUTO
# Manually set the config value as serialized string to bypass serialization issues
cfg.set(cfg.themeMode, theme.value)
setTheme(theme)
class MainWindow(FluentWindow):
def __init__(self):
super().__init__()
self.initWindow()
# Create sub interfaces
self.homeInterface = HomeInterface(self)
self.homeInterface.setObjectName('homeInterface')
self.settingsInterface = SettingsInterface(self)
self.settingsInterface.setObjectName('settingsInterface')
# Add sub interfaces to navigation
self.addSubInterface(self.homeInterface, FIF.HOME, '主页')
self.addSubInterface(self.settingsInterface, FIF.SETTING, '设置', NavigationItemPosition.BOTTOM)
def initWindow(self):
self.resize(900, 700)
self.setWindowIcon(QIcon('icon.png'))
self.setWindowTitle('希沃一体机模式伪装工具')
# Center window
desktop = QApplication.desktop().availableGeometry()
w, h = desktop.width(), desktop.height()
self.move(w//2 - self.width()//2, h//2 - self.height()//2)
if __name__ == '__main__':
# Enable High DPI scaling
QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())