单一题号转为图片功能迁移至工具v3

This commit is contained in:
weiye.wang 2024-04-15 20:49:26 +08:00
parent 43f526f643
commit 2368511e22
4 changed files with 248 additions and 0 deletions

View File

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

View File

@ -530,6 +530,7 @@ def CreateRelatedProblems(links): # 根据links关联生成待编辑的新题目
ret = mycursor.fetchone()[0] ret = mycursor.fetchone()[0]
output += f"\\item ({id}->{rid}) {ret}\n\n" output += f"\\item ({id}->{rid}) {ret}\n\n"
output = f"{output}\n\\end{{enumerate}}\n" output = f"{output}\n\\end{{enumerate}}\n"
mydb.close()
return output #正常返回0 return output #正常返回0
def ImportRelatedProblems(new_json,main_json): # 导入编辑过的关联题目json文件到主数据库 def ImportRelatedProblems(new_json,main_json): # 导入编辑过的关联题目json文件到主数据库

View File

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

View File

@ -0,0 +1,117 @@
<?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>278</width>
<height>97</height>
</rect>
</property>
<property name="windowTitle">
<string>单一题号转为图片</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>题号</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_ID">
<property name="geometry">
<rect>
<x>40</x>
<y>10</y>
<width>71</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>DPI</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_dpi">
<property name="geometry">
<rect>
<x>40</x>
<y>40</y>
<width>71</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_convert">
<property name="geometry">
<rect>
<x>120</x>
<y>10</y>
<width>75</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>转换</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_open">
<property name="geometry">
<rect>
<x>200</x>
<y>10</y>
<width>75</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>打开</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>51</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>附加文字</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_message">
<property name="geometry">
<rect>
<x>70</x>
<y>70</y>
<width>201</width>
<height>20</height>
</rect>
</property>
<property name="placeholderText">
<string>输入附加文字, 留空表示无附加文字</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>