Qt重写 手动同届结果导入 并加入Qt面板

This commit is contained in:
weiye.wang 2024-03-02 22:28:21 +08:00
parent b2b2ee3639
commit 8adeb9f39c
5 changed files with 203 additions and 24 deletions

View File

@ -9,7 +9,7 @@ def run_command(name,openfilelist):
configjson = load_dict("文本文件/config.json")
for f in openfilelist:
if not f in configjson:
os.system("code -w "+f)
os.system("code "+f)
else:
lineindex = getlineindex(f'"{f}"',"文本文件/config.json")
os.system(f"code -w -g 文本文件/config.json:{lineindex}")

View File

@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file '手动统计结果导入.ui'
##
## Created by: Qt User Interface Compiler version 6.6.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QLabel, QPlainTextEdit, QPushButton,
QSizePolicy, QWidget)
class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(281, 183)
self.plainTextEdit = QPlainTextEdit(Form)
self.plainTextEdit.setObjectName(u"plainTextEdit")
self.plainTextEdit.setEnabled(True)
self.plainTextEdit.setGeometry(QRect(10, 30, 181, 141))
self.plainTextEdit.setReadOnly(True)
self.label = QLabel(Form)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(10, 10, 101, 16))
self.pushButton_exec = QPushButton(Form)
self.pushButton_exec.setObjectName(u"pushButton_exec")
self.pushButton_exec.setGeometry(QRect(200, 10, 75, 161))
font = QFont()
font.setBold(True)
self.pushButton_exec.setFont(font)
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
# setupUi
def retranslateUi(self, Form):
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u624b\u52a8\u7edf\u8ba1\u7ed3\u679c\u5bfc\u5165", None))
self.plainTextEdit.setPlainText(QCoreApplication.translate("Form", u"[BEGIN]\n"
"##20240101\n"
"**2026\u5c4a\u9ad8\u4e0001\u73ed\n"
"1 0.875\n"
"10001 0.825 0.630\n"
"[END]", None))
self.label.setText(QCoreApplication.translate("Form", u"\u624b\u52a8\u7edf\u8ba1\u7ed3\u679c\u6a21\u677f", None))
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u5bfc\u5165\u4e3a\n"
"metadata", None))
# retranslateUi

View File

@ -1,13 +1,20 @@
handmadeusagedatafilepath = r"临时文件/手动统计结果.txt" #手动统计文件的位置
metadatafilepath = r"文本文件/metadata.txt" #输出的metadata文件的位置
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
from Ui_手动统计结果导入 import Ui_Form
from database_tools import *
class MyWindow(QWidget,Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.bind()
def bind(self):
self.pushButton_exec.clicked.connect(self.exec)
def exec(self):
handmadeusagedatafilepath = r"临时文件/手动统计结果.txt" #手动统计文件的位置
metadatafilepath = r"文本文件/metadata.txt" #输出的metadata文件的位置
raw_data = ReadTextFile(handmadeusagedatafilepath)
data_list = [d.strip() for d in re.findall(r"\[BEGIN\]([\s\S]*?)\[END\]",raw_data)]
output = "usages\n\n"
for item in data_list:
lines = item.split("\n")
for line in lines:
@ -21,6 +28,19 @@ for item in data_list:
id = usage.pop(0)
usagestr = "\t".join(usage)
output += "%s\n%s\t%s\t%s\n\n"%(id.zfill(6),date,classname,usagestr)
SaveTextFile(output,metadatafilepath)
os.system(f"code {metadatafilepath}")
self.close()
if __name__ == '__main__':
app = QApplication([])
windows = MyWindow()
windows.show()
app.exec()

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>281</width>
<height>183</height>
</rect>
</property>
<property name="windowTitle">
<string>手动统计结果导入</string>
</property>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>181</width>
<height>141</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText">
<string>[BEGIN]
##20240101
**2026届高一01班
1 0.875
10001 0.825 0.630
[END]</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>101</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>手动统计结果模板</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>200</x>
<y>10</y>
<width>75</width>
<height>161</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>导入为
metadata</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,26 @@
handmadeusagedatafilepath = r"临时文件/手动统计结果.txt" #手动统计文件的位置
metadatafilepath = r"文本文件/metadata.txt" #输出的metadata文件的位置
from database_tools import *
raw_data = ReadTextFile(handmadeusagedatafilepath)
data_list = [d.strip() for d in re.findall(r"\[BEGIN\]([\s\S]*?)\[END\]",raw_data)]
output = "usages\n\n"
for item in data_list:
lines = item.split("\n")
for line in lines:
if line.startswith("##"):
date = line.replace("##","").strip()
elif line.startswith("**"):
classname = line.replace("**","").strip()
else:
linedata = re.sub(r"\s+","\t",line)
usage = linedata.split("\t")
id = usage.pop(0)
usagestr = "\t".join(usage)
output += "%s\n%s\t%s\t%s\n\n"%(id.zfill(6),date,classname,usagestr)
SaveTextFile(output,metadatafilepath)