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) # 设置布局 - -