Qt重写 单一题号转为图片 并加入两个面板
This commit is contained in:
parent
856cd563ed
commit
f742f4f273
|
|
@ -40,7 +40,7 @@ class MyWindow(QMainWindow,Ui_MainWindow):
|
||||||
self.action_tjjc.triggered.connect(lambda: run_command("添加基础知识梳理",["添加基础知识梳理.py"]))
|
self.action_tjjc.triggered.connect(lambda: run_command("添加基础知识梳理",["添加基础知识梳理.py"]))
|
||||||
self.action_sxth.triggered.connect(lambda: run_command("关键字筛选题号",[]))#已完成
|
self.action_sxth.triggered.connect(lambda: run_command("关键字筛选题号",[]))#已完成
|
||||||
self.action_xtby.triggered.connect(lambda: run_command("指定题号编译pdf",[]))#已完成
|
self.action_xtby.triggered.connect(lambda: run_command("指定题号编译pdf",[]))#已完成
|
||||||
self.action_sctp.triggered.connect(lambda: run_command("单一题目转成图片文件",["单一题目转成图片文件.py"]))
|
self.action_sctp.triggered.connect(lambda: run_command("单一题号转为图片",[]))#已完成
|
||||||
self.action_hqth.triggered.connect(lambda: run_command("在.tex或.pdf文件中获取题号",["在.tex或.pdf文件中获取题号.py"]))
|
self.action_hqth.triggered.connect(lambda: run_command("在.tex或.pdf文件中获取题号",["在.tex或.pdf文件中获取题号.py"]))
|
||||||
self.action_jglr.triggered.connect(lambda: run_command("讲义结构编号录入",["讲义结构编号录入.py"]))
|
self.action_jglr.triggered.connect(lambda: run_command("讲义结构编号录入",["讲义结构编号录入.py"]))
|
||||||
self.action_dtdy.triggered.connect(lambda: run_command("录入答题纸对应信息",["录入答题纸对应信息.py"]))
|
self.action_dtdy.triggered.connect(lambda: run_command("录入答题纸对应信息",["录入答题纸对应信息.py"]))
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
# -*- 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, 69)
|
||||||
|
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.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))
|
||||||
|
# retranslateUi
|
||||||
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
||||||
|
from Ui_单一题号转为图片 import Ui_Form
|
||||||
|
from database_tools 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()
|
||||||
|
pro_dict = load_dict("../题库0.3/Problems.json")
|
||||||
|
content = pro_dict[self.id.zfill(6)]["content"]
|
||||||
|
latex_raw = ReadTextFile("模板文件/独立文件模板.txt")
|
||||||
|
latexdata = StringSubstitute(r"<<待替换\d*>>",latex_raw,[content])
|
||||||
|
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):
|
||||||
|
os.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()
|
||||||
|
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
<?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>69</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>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
|
|
@ -116,7 +116,7 @@ UseMenu.add_command(label = "参考答案生成", command = lambda: SetButton("
|
||||||
UseMenu.add_separator()
|
UseMenu.add_separator()
|
||||||
UseMenu.add_command(label = "文件题号提取", command = lambda: SetButton("文件题号提取",["文件题号提取.py"]))
|
UseMenu.add_command(label = "文件题号提取", command = lambda: SetButton("文件题号提取",["文件题号提取.py"]))
|
||||||
UseMenu.add_separator()
|
UseMenu.add_separator()
|
||||||
UseMenu.add_command(label = "单一题目转成图片文件", command = lambda: SetButton("单一题目转成图片文件",["单一题目转成图片文件.py"]))
|
UseMenu.add_command(label = "单一题目转成图片文件", command = lambda: SetButton("单一题号转为图片",[]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Reference in New Issue