From a94c87ba3bcf8f7c424ed22897e0403bc907f430 Mon Sep 17 00:00:00 2001 From: moyanj <1561515308@qq.com> Date: Mon, 9 Sep 2024 10:50:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BF=9D=E5=AD=98=E4=B8=8E?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interface/setting.py | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/interface/setting.py b/interface/setting.py index b624edc..16d21f6 100644 --- a/interface/setting.py +++ b/interface/setting.py @@ -1,14 +1,42 @@ -from PyQt5.QtWidgets import QWidget, QHBoxLayout +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout +from PyQt5.QtCore import Qt from qfluentwidgets import FluentIcon as FIF +from qfluentwidgets import CommandBar, Action from .json_edit import CodeEditor import json class SettingWidget(QWidget): def __init__(self, title="设置"): super().__init__() - self.base = QHBoxLayout(self) - json.load(open("config.json")) - c1 = CodeEditor(open("config.json").read()) - self.base.addWidget(c1) + self.base = QVBoxLayout(self) + + # 创建水平布局来放置工具栏 + bar_layout = QHBoxLayout() + bar = CommandBar() + bar.addAction(Action(FIF.SAVE, "保存", triggered=self.save)) + bar.addAction(Action(FIF.SYNC, "重新加载", triggered=self.reload)) + bar_layout.addWidget(bar, alignment=Qt.AlignmentFlag.AlignRight) # 设置工具栏右对齐 + + # 将水平布局添加到垂直布局中 + self.base.addLayout(bar_layout) + + # 加载 JSON 配置 + with open("config.json", "r") as config_file: + config_data = config_file.read() + self.c1 = CodeEditor(config_data) + + # 将代码编辑器添加到垂直布局中 + self.base.addWidget(self.c1) self.setLayout(self.base) # 设置布局 + + def save(self): + # 保存配置到 JSON 文件 + with open("config.json", "w") as config_file: + config_file.write(self.c1.toPlainText()) + + def reload(self): + # 重新加载 JSON 配置 + with open("config.json", "r") as config_file: + config_data = config_file.read() + self.c1.setPlainText(config_data) \ No newline at end of file