迁移 LaTeX代码相关菜单 功能 至工具v3
This commit is contained in:
parent
6710db3fd1
commit
0af4a28a1c
|
|
@ -0,0 +1,96 @@
|
|||
# -*- 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,
|
||||
QRadioButton, QSizePolicy, QVBoxLayout, QWidget)
|
||||
|
||||
class Ui_Form(object):
|
||||
def setupUi(self, Form):
|
||||
if not Form.objectName():
|
||||
Form.setObjectName(u"Form")
|
||||
Form.resize(720, 401)
|
||||
self.plainTextEdit_origin = QPlainTextEdit(Form)
|
||||
self.plainTextEdit_origin.setObjectName(u"plainTextEdit_origin")
|
||||
self.plainTextEdit_origin.setGeometry(QRect(10, 30, 291, 361))
|
||||
self.label = QLabel(Form)
|
||||
self.label.setObjectName(u"label")
|
||||
self.label.setGeometry(QRect(10, 10, 54, 16))
|
||||
self.label_2 = QLabel(Form)
|
||||
self.label_2.setObjectName(u"label_2")
|
||||
self.label_2.setGeometry(QRect(390, 10, 54, 16))
|
||||
self.plainTextEdit_dest = QPlainTextEdit(Form)
|
||||
self.plainTextEdit_dest.setObjectName(u"plainTextEdit_dest")
|
||||
self.plainTextEdit_dest.setGeometry(QRect(430, 30, 281, 361))
|
||||
self.plainTextEdit_dest.setAutoFillBackground(False)
|
||||
self.plainTextEdit_dest.setReadOnly(True)
|
||||
self.pushButton_convert = QPushButton(Form)
|
||||
self.pushButton_convert.setObjectName(u"pushButton_convert")
|
||||
self.pushButton_convert.setGeometry(QRect(310, 230, 111, 71))
|
||||
font = QFont()
|
||||
font.setBold(True)
|
||||
self.pushButton_convert.setFont(font)
|
||||
self.layoutWidget = QWidget(Form)
|
||||
self.layoutWidget.setObjectName(u"layoutWidget")
|
||||
self.layoutWidget.setGeometry(QRect(320, 80, 97, 126))
|
||||
self.verticalLayout = QVBoxLayout(self.layoutWidget)
|
||||
self.verticalLayout.setObjectName(u"verticalLayout")
|
||||
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
|
||||
self.radioButton_mathpix = QRadioButton(self.layoutWidget)
|
||||
self.radioButton_mathpix.setObjectName(u"radioButton_mathpix")
|
||||
|
||||
self.verticalLayout.addWidget(self.radioButton_mathpix)
|
||||
|
||||
self.radioButton_textcircled = QRadioButton(self.layoutWidget)
|
||||
self.radioButton_textcircled.setObjectName(u"radioButton_textcircled")
|
||||
|
||||
self.verticalLayout.addWidget(self.radioButton_textcircled)
|
||||
|
||||
self.radioButton_multiple = QRadioButton(self.layoutWidget)
|
||||
self.radioButton_multiple.setObjectName(u"radioButton_multiple")
|
||||
|
||||
self.verticalLayout.addWidget(self.radioButton_multiple)
|
||||
|
||||
self.radioButton_puctuations = QRadioButton(self.layoutWidget)
|
||||
self.radioButton_puctuations.setObjectName(u"radioButton_puctuations")
|
||||
|
||||
self.verticalLayout.addWidget(self.radioButton_puctuations)
|
||||
|
||||
self.radioButton_answers = QRadioButton(self.layoutWidget)
|
||||
self.radioButton_answers.setObjectName(u"radioButton_answers")
|
||||
|
||||
self.verticalLayout.addWidget(self.radioButton_answers)
|
||||
|
||||
|
||||
self.retranslateUi(Form)
|
||||
|
||||
QMetaObject.connectSlotsByName(Form)
|
||||
# setupUi
|
||||
|
||||
def retranslateUi(self, Form):
|
||||
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u6587\u672c\u8f6c\u6362\u5904\u7406", None))
|
||||
self.plainTextEdit_origin.setPlaceholderText(QCoreApplication.translate("Form", u"\u5c06\u6e90\u6587\u672c \u7c98\u8d34 \u5728\u8fd9\u4e2a\u6587\u672c\u6846\u5185", None))
|
||||
self.label.setText(QCoreApplication.translate("Form", u"\u6e90\u6587\u672c", None))
|
||||
self.label_2.setText(QCoreApplication.translate("Form", u"\u76ee\u6807\u6587\u672c", None))
|
||||
self.plainTextEdit_dest.setPlaceholderText(QCoreApplication.translate("Form", u"\u6309 \u8f6c\u6362 \u4ee5\u83b7\u5f97\u76ee\u6807\u6587\u672c", None))
|
||||
self.pushButton_convert.setText(QCoreApplication.translate("Form", u"\u8f6c\u6362", None))
|
||||
self.radioButton_mathpix.setText(QCoreApplication.translate("Form", u"Mathpix", None))
|
||||
self.radioButton_textcircled.setText(QCoreApplication.translate("Form", u"\u5706\u5708\u6570\u5b57", None))
|
||||
self.radioButton_multiple.setText(QCoreApplication.translate("Form", u"\u591a\u9009\u8f6c\u586b\u7a7a", None))
|
||||
self.radioButton_puctuations.setText(QCoreApplication.translate("Form", u"\u6807\u70b9\u8f6c\u534a\u89d2", None))
|
||||
self.radioButton_answers.setText(QCoreApplication.translate("Form", u"\u5df2\u6709\u7b54\u6848\u6807\u7ea2", None))
|
||||
# retranslateUi
|
||||
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
# -*- 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, QHBoxLayout, QLabel, QLineEdit,
|
||||
QPlainTextEdit, QPushButton, QSizePolicy, QTextBrowser,
|
||||
QVBoxLayout, QWidget)
|
||||
|
||||
class Ui_Form(object):
|
||||
def setupUi(self, Form):
|
||||
if not Form.objectName():
|
||||
Form.setObjectName(u"Form")
|
||||
Form.resize(400, 381)
|
||||
self.pushButton_generatexlist = QPushButton(Form)
|
||||
self.pushButton_generatexlist.setObjectName(u"pushButton_generatexlist")
|
||||
self.pushButton_generatexlist.setGeometry(QRect(10, 130, 121, 24))
|
||||
self.textBrowser = QTextBrowser(Form)
|
||||
self.textBrowser.setObjectName(u"textBrowser")
|
||||
self.textBrowser.setEnabled(False)
|
||||
self.textBrowser.setGeometry(QRect(10, 160, 121, 211))
|
||||
self.label_6 = QLabel(Form)
|
||||
self.label_6.setObjectName(u"label_6")
|
||||
self.label_6.setGeometry(QRect(140, 10, 121, 16))
|
||||
self.plainTextEdit_yinfo = QPlainTextEdit(Form)
|
||||
self.plainTextEdit_yinfo.setObjectName(u"plainTextEdit_yinfo")
|
||||
self.plainTextEdit_yinfo.setGeometry(QRect(140, 30, 171, 181))
|
||||
self.pushButton_exec = QPushButton(Form)
|
||||
self.pushButton_exec.setObjectName(u"pushButton_exec")
|
||||
self.pushButton_exec.setGeometry(QRect(320, 30, 71, 181))
|
||||
font = QFont()
|
||||
font.setBold(True)
|
||||
self.pushButton_exec.setFont(font)
|
||||
self.label_7 = QLabel(Form)
|
||||
self.label_7.setObjectName(u"label_7")
|
||||
self.label_7.setGeometry(QRect(140, 220, 71, 16))
|
||||
self.plainTextEdit_latexcode = QPlainTextEdit(Form)
|
||||
self.plainTextEdit_latexcode.setObjectName(u"plainTextEdit_latexcode")
|
||||
self.plainTextEdit_latexcode.setGeometry(QRect(140, 240, 251, 131))
|
||||
self.widget = QWidget(Form)
|
||||
self.widget.setObjectName(u"widget")
|
||||
self.widget.setGeometry(QRect(10, 10, 121, 108))
|
||||
self.verticalLayout = QVBoxLayout(self.widget)
|
||||
self.verticalLayout.setObjectName(u"verticalLayout")
|
||||
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
|
||||
self.horizontalLayout = QHBoxLayout()
|
||||
self.horizontalLayout.setObjectName(u"horizontalLayout")
|
||||
self.label = QLabel(self.widget)
|
||||
self.label.setObjectName(u"label")
|
||||
|
||||
self.horizontalLayout.addWidget(self.label)
|
||||
|
||||
self.lineEdit_xmin = QLineEdit(self.widget)
|
||||
self.lineEdit_xmin.setObjectName(u"lineEdit_xmin")
|
||||
|
||||
self.horizontalLayout.addWidget(self.lineEdit_xmin)
|
||||
|
||||
|
||||
self.verticalLayout.addLayout(self.horizontalLayout)
|
||||
|
||||
self.horizontalLayout_2 = QHBoxLayout()
|
||||
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
|
||||
self.label_2 = QLabel(self.widget)
|
||||
self.label_2.setObjectName(u"label_2")
|
||||
|
||||
self.horizontalLayout_2.addWidget(self.label_2)
|
||||
|
||||
self.lineEdit_xmax = QLineEdit(self.widget)
|
||||
self.lineEdit_xmax.setObjectName(u"lineEdit_xmax")
|
||||
|
||||
self.horizontalLayout_2.addWidget(self.lineEdit_xmax)
|
||||
|
||||
|
||||
self.verticalLayout.addLayout(self.horizontalLayout_2)
|
||||
|
||||
self.horizontalLayout_5 = QHBoxLayout()
|
||||
self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
|
||||
self.label_5 = QLabel(self.widget)
|
||||
self.label_5.setObjectName(u"label_5")
|
||||
|
||||
self.horizontalLayout_5.addWidget(self.label_5)
|
||||
|
||||
self.lineEdit_xwidth = QLineEdit(self.widget)
|
||||
self.lineEdit_xwidth.setObjectName(u"lineEdit_xwidth")
|
||||
|
||||
self.horizontalLayout_5.addWidget(self.lineEdit_xwidth)
|
||||
|
||||
|
||||
self.verticalLayout.addLayout(self.horizontalLayout_5)
|
||||
|
||||
self.horizontalLayout_4 = QHBoxLayout()
|
||||
self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
|
||||
self.label_4 = QLabel(self.widget)
|
||||
self.label_4.setObjectName(u"label_4")
|
||||
|
||||
self.horizontalLayout_4.addWidget(self.label_4)
|
||||
|
||||
self.lineEdit_xlabel = QLineEdit(self.widget)
|
||||
self.lineEdit_xlabel.setObjectName(u"lineEdit_xlabel")
|
||||
|
||||
self.horizontalLayout_4.addWidget(self.lineEdit_xlabel)
|
||||
|
||||
|
||||
self.verticalLayout.addLayout(self.horizontalLayout_4)
|
||||
|
||||
|
||||
self.retranslateUi(Form)
|
||||
|
||||
QMetaObject.connectSlotsByName(Form)
|
||||
# setupUi
|
||||
|
||||
def retranslateUi(self, Form):
|
||||
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u751f\u6210\u76f4\u65b9\u56fe\u4ee3\u7801", None))
|
||||
self.pushButton_generatexlist.setText(QCoreApplication.translate("Form", u"\u751f\u6210\u6a2a\u5750\u6807\u5e8f\u5217", None))
|
||||
self.textBrowser.setHtml(QCoreApplication.translate("Form", u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
|
||||
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
|
||||
"p, li { white-space: pre-wrap; }\n"
|
||||
"hr { height: 1px; border-width: 0; }\n"
|
||||
"li.unchecked::marker { content: \"\\2610\"; }\n"
|
||||
"li.checked::marker { content: \"\\2612\"; }\n"
|
||||
"</style></head><body style=\" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">\u4e0d\u6539\u53d8\u6a2a\u5750\u6807\u7684\u503c, \u5728\u9017\u53f7\u540e\u8f93\u5165\u7eb5\u5750\u6807\u7684\u503c</p>\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">\u5982\u679c\u6807\u7b7e\u548c\u7eb5\u5750\u6807\u7684\u503c\u4e0d\u540c, \u5728\u540e\u9762\u7684\u65b9\u62ec\u53f7\u5185\u8f93\u5165\u6807\u7b7e</"
|
||||
"p>\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">\u5982:</p>\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">(10,0.02)[]</p>\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">(20,0.04)[a]</p>\n"
|
||||
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">(30,0.04][]</p>\n"
|
||||
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>", None))
|
||||
self.label_6.setText(QCoreApplication.translate("Form", u"\u8f93\u5165\u7eb5\u5750\u6807\u4fe1\u606f", None))
|
||||
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u751f\u6210\u4ee3\u7801", None))
|
||||
self.label_7.setText(QCoreApplication.translate("Form", u"\u76f4\u65b9\u56fe\u4ee3\u7801", None))
|
||||
self.label.setText(QCoreApplication.translate("Form", u"x\u6700\u5c0f\u503c", None))
|
||||
self.label_2.setText(QCoreApplication.translate("Form", u"x\u6700\u5927\u503c", None))
|
||||
self.label_5.setText(QCoreApplication.translate("Form", u"x\u5bbd\u5ea6", None))
|
||||
self.label_4.setText(QCoreApplication.translate("Form", u"x\u8f74label", None))
|
||||
# retranslateUi
|
||||
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
||||
from Ui_文本转换处理 import Ui_Form
|
||||
from database_tools_2 import *
|
||||
|
||||
class MyWindow(QWidget,Ui_Form):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setupUi(self)
|
||||
self.bind()
|
||||
def bind(self):
|
||||
self.radioButton_mathpix.setChecked(True)
|
||||
self.pushButton_convert.clicked.connect(self.exec)
|
||||
def exec(self):
|
||||
raw_string = self.plainTextEdit_origin.toPlainText()
|
||||
if self.radioButton_mathpix.isChecked():
|
||||
dest_string = RefineMathpix(raw_string)
|
||||
elif self.radioButton_textcircled.isChecked():
|
||||
dest_string = re.sub(r"\((\d)\)",lambda x: "\\textcircled{"+x.group(1)+"}",raw_string) #替换所有的小括号包围的单个数字为圆圈包围的
|
||||
dest_string = re.sub(r"\$\\textcircled\{\\scriptsize\{(\d)\}\}",lambda x: "\\textcircled{"+x.group(1)+"}$",dest_string)
|
||||
dest_string = re.sub(r"\\textcircled\{\\scriptsize\{(\d)\}\}",lambda x: "\\textcircled{"+x.group(1)+"}",dest_string)
|
||||
elif self.radioButton_multiple.isChecked():
|
||||
try:
|
||||
dest_string = MultiplechoicetoBlankFilling(raw_string)
|
||||
except:
|
||||
dest_string = "转换失败"
|
||||
elif self.radioButton_puctuations.isChecked():
|
||||
dest_string = RefinePunctuations(raw_string)
|
||||
elif self.radioButton_answers.isChecked():
|
||||
self.pro_dict = load_dict("../题库0.3/Problems.json")
|
||||
dest_string = PaintRedAnswers(raw_string,self.pro_dict)
|
||||
self.plainTextEdit_dest.setPlainText(dest_string)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication([])
|
||||
windows = MyWindow()
|
||||
windows.show()
|
||||
app.exec()
|
||||
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
<?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>720</width>
|
||||
<height>401</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>文本转换处理</string>
|
||||
</property>
|
||||
<widget class="QPlainTextEdit" name="plainTextEdit_origin">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>30</y>
|
||||
<width>291</width>
|
||||
<height>361</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>将源文本 粘贴 在这个文本框内</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>54</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>源文本</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>390</x>
|
||||
<y>10</y>
|
||||
<width>54</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>目标文本</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPlainTextEdit" name="plainTextEdit_dest">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>430</x>
|
||||
<y>30</y>
|
||||
<width>281</width>
|
||||
<height>361</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>按 转换 以获得目标文本</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_convert">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>310</x>
|
||||
<y>230</y>
|
||||
<width>111</width>
|
||||
<height>71</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>转换</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>320</x>
|
||||
<y>80</y>
|
||||
<width>97</width>
|
||||
<height>126</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_mathpix">
|
||||
<property name="text">
|
||||
<string>Mathpix</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_textcircled">
|
||||
<property name="text">
|
||||
<string>圆圈数字</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_multiple">
|
||||
<property name="text">
|
||||
<string>多选转填空</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_puctuations">
|
||||
<property name="text">
|
||||
<string>标点转半角</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_answers">
|
||||
<property name="text">
|
||||
<string>已有答案标红</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
||||
from Ui_生成直方图代码 import Ui_Form
|
||||
import re
|
||||
|
||||
|
||||
class MyWindow(QWidget,Ui_Form):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setupUi(self)
|
||||
self.bind()
|
||||
def bind(self):
|
||||
self.pushButton_generatexlist.clicked.connect(self.generateXList)
|
||||
self.pushButton_exec.clicked.connect(self.exec)
|
||||
def generateXList(self):
|
||||
self.xmin = int(self.lineEdit_xmin.text())
|
||||
self.xmax = int(self.lineEdit_xmax.text())
|
||||
self.xwidth = int(self.lineEdit_xwidth.text())
|
||||
self.xlist = list(range(self.xmin,self.xmax,self.xwidth))
|
||||
output = ""
|
||||
for x in self.xlist:
|
||||
output += f"({x},)[]\n"
|
||||
self.plainTextEdit_yinfo.setPlainText(output)
|
||||
def folding(self):
|
||||
if self.xmin <= self.xwidth:
|
||||
foldingstr = ""
|
||||
else:
|
||||
midpoint = 1/2 * (self.xstart + self.xmin)
|
||||
dist = (midpoint - self.xstart) / 6
|
||||
foldingstr = ""
|
||||
height = 0.2/self.yscale
|
||||
foldingstr += f" -- ({(self.xstart+dist*4):.2f},0)"
|
||||
foldingstr += f" -- ({(self.xstart+dist*5):.2f},{height:.4f})"
|
||||
foldingstr += f" -- ({(self.xstart+dist*7):.2f},{-height:.4f})"
|
||||
foldingstr += f" -- ({(self.xstart+dist*8):.2f},0)"
|
||||
return foldingstr
|
||||
def exec(self):
|
||||
xlabel = self.lineEdit_xlabel.text()
|
||||
coordinateinfo = self.plainTextEdit_yinfo.toPlainText()
|
||||
if self.xmin < self.xwidth: #计算x轴的起点坐标
|
||||
self.xstart = 0
|
||||
else:
|
||||
self.xstart = self.xmin - self.xwidth
|
||||
self.xmax = self.xlist[-1] + self.xwidth
|
||||
self.xend = self.xmax + self.xwidth #计算x轴的终点坐标
|
||||
self.xscale = 5/(self.xend-self.xstart) #计算x放缩比例
|
||||
# print(self.xscale)
|
||||
self.coordinatelist = re.findall(r"\(([\d\.]+),([\d\.]+)\)\[([\S]*)\]",coordinateinfo) #计算坐标信息
|
||||
for cindex in range(len(self.coordinatelist)):
|
||||
x,y,label = self.coordinatelist[cindex]
|
||||
if label.strip() == "":
|
||||
self.coordinatelist[cindex] = (x,y,y)
|
||||
self.coordinatestr_raw = []
|
||||
for coord in self.coordinatelist:
|
||||
x,y,label = coord
|
||||
self.coordinatestr_raw.append(f"{x}/{y}")
|
||||
self.coordinatestr = ",".join(self.coordinatestr_raw)
|
||||
# print(self.coordinatelist)
|
||||
self.dasheddict = {} #计算以纵坐标为key的虚线信息, 内容为(x,label)
|
||||
for coord in self.coordinatelist:
|
||||
x,y,label = coord
|
||||
if not y in self.dasheddict:
|
||||
self.dasheddict[y] = (x,label)
|
||||
else:
|
||||
if x > self.dasheddict[y][0] and label == y:
|
||||
self.dasheddict[y] = (x,self.dasheddict[y][1])
|
||||
elif x > self.dasheddict[y][0] and label != y:
|
||||
self.dasheddict[y] = (x,label)
|
||||
self.dashedstr_raw = []
|
||||
for y in self.dasheddict:
|
||||
x,label = self.dasheddict[y]
|
||||
self.dashedstr_raw.append(f"{x}/{y}/{label}")
|
||||
self.dashedstr = ",".join(self.dashedstr_raw)
|
||||
# print(self.dasheddict)
|
||||
ymax = max([float(i) for i in self.dasheddict.keys()])
|
||||
self.yscale = 3/ymax #3是y的长度, 计算y放缩比例
|
||||
self.yend = ymax + 1/float(self.yscale)
|
||||
latexcode = f"""\\begin{{center}}
|
||||
\\begin{{tikzpicture}}[>=latex, xscale = {self.xscale:.4f}, yscale = {self.yscale:.4f}]
|
||||
\\draw [->] ({self.xstart},0) {self.folding()}-- ({self.xend},0) node [below right] {{{xlabel}}};
|
||||
\\draw [->] ({self.xstart},0) -- ({self.xstart},{self.yend:.2f}) node [left] {{$\\dfrac{{\\text{{频率}}}}{{\\text{{组距}}}}$}};
|
||||
\\draw ({self.xstart},0) node [below] {{$0$}};
|
||||
\\foreach \\i/\\j in {{{self.coordinatestr}}}
|
||||
{{\\draw (\\i,0) node [below] {{$\\i$}} --++ (0,\\j) --++ ({self.xwidth},0) --++ (0,-\\j);}};
|
||||
\\draw ({self.xmax},0) node [below] {{${self.xmax}$}};
|
||||
\\foreach \i/\j/\k in {{{self.dashedstr}}}
|
||||
{{\\draw [dashed] (\\i,\\j) -- ({self.xstart},\\j) node [left] {{$\\k$}};}};
|
||||
\\end{{tikzpicture}}
|
||||
\\end{{center}}"""
|
||||
latexcode = re.sub(r"\n\s+","\n",latexcode)
|
||||
self.plainTextEdit_latexcode.setPlainText(latexcode)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication([])
|
||||
windows = MyWindow()
|
||||
windows.show()
|
||||
app.exec()
|
||||
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
<?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>400</width>
|
||||
<height>381</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>生成直方图代码</string>
|
||||
</property>
|
||||
<widget class="QPushButton" name="pushButton_generatexlist">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>130</y>
|
||||
<width>121</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>生成横坐标序列</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTextBrowser" name="textBrowser">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>160</y>
|
||||
<width>121</width>
|
||||
<height>211</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
hr { height: 1px; border-width: 0; }
|
||||
li.unchecked::marker { content: "\2610"; }
|
||||
li.checked::marker { content: "\2612"; }
|
||||
</style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">不改变横坐标的值, 在逗号后输入纵坐标的值</p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">如果标签和纵坐标的值不同, 在后面的方括号内输入标签</p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">如:</p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">(10,0.02)[]</p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">(20,0.04)[a]</p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">(30,0.04][]</p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>140</x>
|
||||
<y>10</y>
|
||||
<width>121</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>输入纵坐标信息</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPlainTextEdit" name="plainTextEdit_yinfo">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>140</x>
|
||||
<y>30</y>
|
||||
<width>171</width>
|
||||
<height>181</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_exec">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>320</x>
|
||||
<y>30</y>
|
||||
<width>71</width>
|
||||
<height>181</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>生成代码</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>140</x>
|
||||
<y>220</y>
|
||||
<width>71</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>直方图代码</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPlainTextEdit" name="plainTextEdit_latexcode">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>140</x>
|
||||
<y>240</y>
|
||||
<width>251</width>
|
||||
<height>131</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>121</width>
|
||||
<height>108</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>x最小值</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_xmin"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>x最大值</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_xmax"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>x宽度</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_xwidth"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>x轴label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_xlabel"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue