添加提示
This commit is contained in:
parent
a94c87ba3b
commit
c49d38cdd5
|
@ -1,17 +1,19 @@
|
||||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from qfluentwidgets import FluentIcon as FIF
|
from qfluentwidgets import FluentIcon as FIF
|
||||||
from qfluentwidgets import CommandBar, Action
|
from qfluentwidgets import CommandBar, Action, InfoBar, InfoBarPosition, SubtitleLabel
|
||||||
from .json_edit import CodeEditor
|
from .json_edit import CodeEditor
|
||||||
import json
|
|
||||||
|
|
||||||
class SettingWidget(QWidget):
|
class SettingWidget(QWidget):
|
||||||
def __init__(self, title="设置"):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.base = QVBoxLayout(self)
|
self.base = QVBoxLayout(self)
|
||||||
|
|
||||||
# 创建水平布局来放置工具栏
|
# 创建水平布局来放置工具栏
|
||||||
bar_layout = QHBoxLayout()
|
bar_layout = QHBoxLayout()
|
||||||
|
title = SubtitleLabel("设置")
|
||||||
|
bar_layout.addWidget(title, alignment=Qt.AlignmentFlag.AlignLeft) # 设置工具栏右对齐
|
||||||
|
|
||||||
bar = CommandBar()
|
bar = CommandBar()
|
||||||
bar.addAction(Action(FIF.SAVE, "保存", triggered=self.save))
|
bar.addAction(Action(FIF.SAVE, "保存", triggered=self.save))
|
||||||
bar.addAction(Action(FIF.SYNC, "重新加载", triggered=self.reload))
|
bar.addAction(Action(FIF.SYNC, "重新加载", triggered=self.reload))
|
||||||
|
@ -24,7 +26,6 @@ class SettingWidget(QWidget):
|
||||||
with open("config.json", "r") as config_file:
|
with open("config.json", "r") as config_file:
|
||||||
config_data = config_file.read()
|
config_data = config_file.read()
|
||||||
self.c1 = CodeEditor(config_data)
|
self.c1 = CodeEditor(config_data)
|
||||||
|
|
||||||
# 将代码编辑器添加到垂直布局中
|
# 将代码编辑器添加到垂直布局中
|
||||||
self.base.addWidget(self.c1)
|
self.base.addWidget(self.c1)
|
||||||
|
|
||||||
|
@ -35,8 +36,28 @@ class SettingWidget(QWidget):
|
||||||
with open("config.json", "w") as config_file:
|
with open("config.json", "w") as config_file:
|
||||||
config_file.write(self.c1.toPlainText())
|
config_file.write(self.c1.toPlainText())
|
||||||
|
|
||||||
|
InfoBar.success(
|
||||||
|
title='成功',
|
||||||
|
content="配置文件保存成功",
|
||||||
|
orient=Qt.Horizontal,
|
||||||
|
isClosable=True,
|
||||||
|
position=InfoBarPosition.TOP,
|
||||||
|
duration=2000,
|
||||||
|
parent=self
|
||||||
|
)
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
# 重新加载 JSON 配置
|
# 重新加载 JSON 配置
|
||||||
with open("config.json", "r") as config_file:
|
with open("config.json", "r") as config_file:
|
||||||
config_data = config_file.read()
|
config_data = config_file.read()
|
||||||
self.c1.setPlainText(config_data)
|
self.c1.setPlainText(config_data)
|
||||||
|
|
||||||
|
InfoBar.success(
|
||||||
|
title='成功',
|
||||||
|
content="配置文件加载成功",
|
||||||
|
orient=Qt.Horizontal,
|
||||||
|
isClosable=True,
|
||||||
|
position=InfoBarPosition.TOP,
|
||||||
|
duration=2000,
|
||||||
|
parent=self
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user