文本转换处理 中 增加 将已有的答案标红的功能

This commit is contained in:
weiye.wang 2024-03-18 21:09:44 +08:00
parent c985116866
commit f31c1f9aa2
4 changed files with 38 additions and 6 deletions

View File

@ -39,13 +39,13 @@ class Ui_Form(object):
self.plainTextEdit_dest.setReadOnly(True)
self.pushButton_convert = QPushButton(Form)
self.pushButton_convert.setObjectName(u"pushButton_convert")
self.pushButton_convert.setGeometry(QRect(310, 210, 111, 71))
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, 91, 100))
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)
@ -69,6 +69,11 @@ class Ui_Form(object):
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)
@ -86,5 +91,6 @@ class Ui_Form(object):
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

View File

@ -2145,7 +2145,23 @@ def startfile(filepath): #跨平台打开文件或文件夹
return ret
def PaintRedAnswers(string,prodict): #将prodict中已有的答案标红色
output = string
IDandContentList = generateListOfIDandContent(output)
for id,content in IDandContentList:
raw_string = id+")"+content
# u = output.index(raw_string)
if "textcolor{blue}" in raw_string:
new_ans = generateAnswerTex(content,anspreamble="\\textcolor{blue}{")
raw_ans = prodict[id]["ans"]
if new_ans == raw_ans:
sub_string = raw_string.replace("textcolor{blue}","textcolor{red}")
output = output.replace(raw_string,sub_string)
elif raw_ans == "":
print(f"{id} 已有答案, 请运行提取答案控件以获取新录入的答案")
elif new_ans != "暂无答案":
print(f"{id} 新答案 {new_ans} 和原答案 {raw_ans} 有所不同, 请仔细检查")
return output
if __name__ == "__main__":

View File

@ -25,6 +25,9 @@ class MyWindow(QWidget,Ui_Form):
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)

View File

@ -75,7 +75,7 @@
<property name="geometry">
<rect>
<x>310</x>
<y>210</y>
<y>230</y>
<width>111</width>
<height>71</height>
</rect>
@ -94,8 +94,8 @@
<rect>
<x>320</x>
<y>80</y>
<width>91</width>
<height>100</height>
<width>97</width>
<height>126</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -127,6 +127,13 @@
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_answers">
<property name="text">
<string>已有答案标红</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>