完善json编辑器

This commit is contained in:
moyanj 2024-09-08 21:14:02 +08:00
parent 47ee71d7e2
commit 0fbac536dd
3 changed files with 12 additions and 6 deletions

3
config.json Normal file
View File

@ -0,0 +1,3 @@
{
"1":"13"
}

View File

@ -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()

View File

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