From 2368511e22d1d35b91bfe3a1226570d80fa1e26a Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Mon, 15 Apr 2024 20:49:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E4=B8=80=E9=A2=98=E5=8F=B7=E8=BD=AC?= =?UTF-8?q?=E4=B8=BA=E5=9B=BE=E7=89=87=E5=8A=9F=E8=83=BD=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E8=87=B3=E5=B7=A5=E5=85=B7v3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v3/Ui_单一题号转为图片.py | 65 +++++++++++++++++++ 工具v3/database_tools_2.py | 1 + 工具v3/单一题号转为图片.py | 65 +++++++++++++++++++ 工具v3/单一题号转为图片.ui | 117 ++++++++++++++++++++++++++++++++++ 4 files changed, 248 insertions(+) create mode 100644 工具v3/Ui_单一题号转为图片.py create mode 100644 工具v3/单一题号转为图片.py create mode 100644 工具v3/单一题号转为图片.ui diff --git a/工具v3/Ui_单一题号转为图片.py b/工具v3/Ui_单一题号转为图片.py new file mode 100644 index 00000000..63297f4f --- /dev/null +++ b/工具v3/Ui_单一题号转为图片.py @@ -0,0 +1,65 @@ +# -*- 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, QLineEdit, QPushButton, + QSizePolicy, QWidget) + +class Ui_Form(object): + def setupUi(self, Form): + if not Form.objectName(): + Form.setObjectName(u"Form") + Form.resize(278, 97) + self.label = QLabel(Form) + self.label.setObjectName(u"label") + self.label.setGeometry(QRect(10, 10, 31, 16)) + self.lineEdit_ID = QLineEdit(Form) + self.lineEdit_ID.setObjectName(u"lineEdit_ID") + self.lineEdit_ID.setGeometry(QRect(40, 10, 71, 20)) + self.label_2 = QLabel(Form) + self.label_2.setObjectName(u"label_2") + self.label_2.setGeometry(QRect(10, 40, 31, 16)) + self.lineEdit_dpi = QLineEdit(Form) + self.lineEdit_dpi.setObjectName(u"lineEdit_dpi") + self.lineEdit_dpi.setGeometry(QRect(40, 40, 71, 20)) + self.pushButton_convert = QPushButton(Form) + self.pushButton_convert.setObjectName(u"pushButton_convert") + self.pushButton_convert.setGeometry(QRect(120, 10, 75, 51)) + self.pushButton_open = QPushButton(Form) + self.pushButton_open.setObjectName(u"pushButton_open") + self.pushButton_open.setGeometry(QRect(200, 10, 75, 51)) + self.label_3 = QLabel(Form) + self.label_3.setObjectName(u"label_3") + self.label_3.setGeometry(QRect(10, 70, 51, 16)) + self.lineEdit_message = QLineEdit(Form) + self.lineEdit_message.setObjectName(u"lineEdit_message") + self.lineEdit_message.setGeometry(QRect(70, 70, 201, 20)) + + self.retranslateUi(Form) + + QMetaObject.connectSlotsByName(Form) + # setupUi + + def retranslateUi(self, Form): + Form.setWindowTitle(QCoreApplication.translate("Form", u"\u5355\u4e00\u9898\u53f7\u8f6c\u4e3a\u56fe\u7247", None)) + self.label.setText(QCoreApplication.translate("Form", u"\u9898\u53f7", None)) + self.label_2.setText(QCoreApplication.translate("Form", u"DPI", None)) + self.pushButton_convert.setText(QCoreApplication.translate("Form", u"\u8f6c\u6362", None)) + self.pushButton_open.setText(QCoreApplication.translate("Form", u"\u6253\u5f00", None)) + self.label_3.setText(QCoreApplication.translate("Form", u"\u9644\u52a0\u6587\u5b57", None)) + self.lineEdit_message.setPlaceholderText(QCoreApplication.translate("Form", u"\u8f93\u5165\u9644\u52a0\u6587\u5b57, \u7559\u7a7a\u8868\u793a\u65e0\u9644\u52a0\u6587\u5b57", None)) + # retranslateUi + diff --git a/工具v3/database_tools_2.py b/工具v3/database_tools_2.py index 1d840e2c..a2930cc8 100644 --- a/工具v3/database_tools_2.py +++ b/工具v3/database_tools_2.py @@ -530,6 +530,7 @@ def CreateRelatedProblems(links): # 根据links关联生成待编辑的新题目 ret = mycursor.fetchone()[0] output += f"\\item ({id}->{rid}) {ret}\n\n" output = f"{output}\n\\end{{enumerate}}\n" + mydb.close() return output #正常返回0 def ImportRelatedProblems(new_json,main_json): # 导入编辑过的关联题目json文件到主数据库 diff --git a/工具v3/单一题号转为图片.py b/工具v3/单一题号转为图片.py new file mode 100644 index 00000000..8599760f --- /dev/null +++ b/工具v3/单一题号转为图片.py @@ -0,0 +1,65 @@ +from PySide6.QtWidgets import QWidget, QApplication, QFileDialog +from Ui_单一题号转为图片 import Ui_Form +from database_tools_2 import * +import os +from datetime import datetime + +class MyWindow(QWidget,Ui_Form): + def __init__(self): + super().__init__() + self.setupUi(self) + self.bind() + + def bind(self): + self.pushButton_open.setDisabled(True) + self.pushButton_convert.clicked.connect(self.convert) + self.pushButton_open.clicked.connect(self.open) + self.lineEdit_ID.textChanged.connect(self.toggleopen) + self.lineEdit_dpi.textChanged.connect(self.toggleopen) + def convert(self): + self.time = datetime.now().strftime("%Y%m%d%H%M%S") + self.id = self.lineEdit_ID.text() + self.dpi = self.lineEdit_dpi.text() + mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest") + mycursor = mydb.cursor() + sql = "SELECT content FROM problems WHERE ID = %s;" + val = (self.id.strip().zfill(6),) + mycursor.execute(sql,val) + content = mycursor.fetchall()[0][0] + mydb.close() + prefix = self.lineEdit_message.text().strip() + latexcontent = f"{prefix} {content}" + latex_raw = ReadTextFile("模板文件/独立文件模板.txt") + #识别操作系统 + if sys.platform != "win32": + latex_raw = re.sub(r"fontset[\s]*=[\s]*none","fontset = fandol",latex_raw) + latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw) + latexdata = StringSubstitute(r"<<待替换\d*>>",latex_raw,[latexcontent]) + makedir("临时文件/pics") + SaveTextFile(latexdata,f"临时文件/pics/ID{self.id}-{self.dpi}-{self.time}.tex") + os.system(f"xelatex -interaction=batchmode -output-directory=临时文件/pics ID{self.id}-{self.dpi}-{self.time}.tex") + os.chdir("临时文件/pics") + os.system(f"pdftocairo -png -r {self.dpi} ID{self.id}-{self.dpi}-{self.time}.pdf") + os.chdir("../..") + self.pushButton_open.setEnabled(True) + def open(self): + startfile(os.path.join("临时文件/pics", f"ID{self.id}-{self.dpi}-{self.time}-1.png")) + def toggleopen(self): + self.pushButton_open.setDisabled(True) + + + + + + + + + + + +if __name__ == '__main__': + app = QApplication([]) + windows = MyWindow() + windows.show() + app.exec() + diff --git a/工具v3/单一题号转为图片.ui b/工具v3/单一题号转为图片.ui new file mode 100644 index 00000000..fbc411ec --- /dev/null +++ b/工具v3/单一题号转为图片.ui @@ -0,0 +1,117 @@ + + + Form + + + + 0 + 0 + 278 + 97 + + + + 单一题号转为图片 + + + + + 10 + 10 + 31 + 16 + + + + 题号 + + + + + + 40 + 10 + 71 + 20 + + + + + + + 10 + 40 + 31 + 16 + + + + DPI + + + + + + 40 + 40 + 71 + 20 + + + + + + + 120 + 10 + 75 + 51 + + + + 转换 + + + + + + 200 + 10 + 75 + 51 + + + + 打开 + + + + + + 10 + 70 + 51 + 16 + + + + 附加文字 + + + + + + 70 + 70 + 201 + 20 + + + + 输入附加文字, 留空表示无附加文字 + + + + + +