From 0fbac536dd512577d1f2cd7694b96beedf617907 Mon Sep 17 00:00:00 2001 From: moyanj <1561515308@qq.com> Date: Sun, 8 Sep 2024 21:14:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84json=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 3 +++ interface/json_edit.py | 8 ++++++-- interface/setting.py | 7 +++---- 3 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 config.json diff --git a/config.json b/config.json new file mode 100644 index 0000000..c21f73d --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "1":"13" +} \ No newline at end of file diff --git a/interface/json_edit.py b/interface/json_edit.py index 50729ab..261647f 100644 --- a/interface/json_edit.py +++ b/interface/json_edit.py @@ -1,11 +1,15 @@ from PyQt5.QtWidgets import QApplication, QTextEdit -from PyQt5.QtGui import QSyntaxHighlighter, QTextCharFormat, QFont, QColor +from PyQt5.QtGui import QSyntaxHighlighter, QTextCharFormat, QFont, QFontMetrics from PyQt5.QtCore import QRegularExpression, Qt class CodeEditor(QTextEdit): - def __init__(self): + def __init__(self, text:str=""): super().__init__() self.setFont(QFont("Courier New", 12)) + fontMetrics = QFontMetrics(self.font()) + tabWidth = 4 * fontMetrics.width(' ') # Calculate the width of a tab + self.setTabStopWidth(tabWidth) + self.setPlainText(text) self.highlighter = CodeHighlighter(self.document()) self.highlighter.rehighlight() diff --git a/interface/setting.py b/interface/setting.py index a4aacef..b624edc 100644 --- a/interface/setting.py +++ b/interface/setting.py @@ -1,15 +1,14 @@ from PyQt5.QtWidgets import QWidget, QHBoxLayout -from qfluentwidgets import SwitchSettingCard from qfluentwidgets import FluentIcon as FIF from .json_edit import CodeEditor +import json class SettingWidget(QWidget): def __init__(self, title="设置"): super().__init__() self.base = QHBoxLayout(self) - c1 = CodeEditor() + json.load(open("config.json")) + c1 = CodeEditor(open("config.json").read()) self.base.addWidget(c1) self.setLayout(self.base) # 设置布局 - -