From 4d7340ff11a3f49029815cb8ebfd6a57275b21f9 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 28 Apr 2024 21:22:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E5=86=85=E5=AE=B9=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/Ui_tool_panel.py | 6 +- 工具v4/tool_panel.py | 8 ++- 工具v4/tool_panel.ui | 7 ++- 工具v4/修改目标内容.py | 118 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 工具v4/修改目标内容.py diff --git a/工具v4/Ui_tool_panel.py b/工具v4/Ui_tool_panel.py index aeffc5d7..18f74dbf 100644 --- a/工具v4/Ui_tool_panel.py +++ b/工具v4/Ui_tool_panel.py @@ -154,6 +154,9 @@ class Ui_MainWindow(object): self.tab_bjjc = QWidget() self.tab_bjjc.setObjectName(u"tab_bjjc") self.tabWidget_mubiaojichu.addTab(self.tab_bjjc, "") + self.tab_xgmb = QWidget() + self.tab_xgmb.setObjectName(u"tab_xgmb") + self.tabWidget_mubiaojichu.addTab(self.tab_xgmb, "") self.tabWidget_main.addTab(self.tab_mubiaojichu, "") self.horizontalLayoutWidget = QWidget(self.centralwidget) self.horizontalLayoutWidget.setObjectName(u"horizontalLayoutWidget") @@ -188,7 +191,7 @@ class Ui_MainWindow(object): self.tabWidget_shiyong.setCurrentIndex(2) self.tabWidget_beikezu.setCurrentIndex(1) self.tabWidget.setCurrentIndex(1) - self.tabWidget_mubiaojichu.setCurrentIndex(1) + self.tabWidget_mubiaojichu.setCurrentIndex(2) QMetaObject.connectSlotsByName(MainWindow) @@ -225,6 +228,7 @@ class Ui_MainWindow(object): self.tabWidget_main.setTabText(self.tabWidget_main.indexOf(self.tab_latex), QCoreApplication.translate("MainWindow", u"LaTeX\u4ee3\u7801\u76f8\u5173", None)) self.tabWidget_mubiaojichu.setTabText(self.tabWidget_mubiaojichu.indexOf(self.tab_tjjc), QCoreApplication.translate("MainWindow", u"\u65b0\u589e\u57fa\u7840\u77e5\u8bc6\u68b3\u7406", None)) self.tabWidget_mubiaojichu.setTabText(self.tabWidget_mubiaojichu.indexOf(self.tab_bjjc), QCoreApplication.translate("MainWindow", u"\u57fa\u7840\u77e5\u8bc6\u7f16\u8f91", None)) + self.tabWidget_mubiaojichu.setTabText(self.tabWidget_mubiaojichu.indexOf(self.tab_xgmb), QCoreApplication.translate("MainWindow", u"\u4fee\u6539\u76ee\u6807\u6587\u672c", None)) self.tabWidget_main.setTabText(self.tabWidget_main.indexOf(self.tab_mubiaojichu), QCoreApplication.translate("MainWindow", u"\u76ee\u6807\u4e0e\u57fa\u7840\u77e5\u8bc6", None)) self.pushButton_tiku.setText(QCoreApplication.translate("MainWindow", u"\u6b63\u5f0f\u6570\u636e\u5e93", None)) self.pushButton_tikutest.setText(QCoreApplication.translate("MainWindow", u"\u6d4b\u8bd5\u6570\u636e\u5e93", None)) diff --git a/工具v4/tool_panel.py b/工具v4/tool_panel.py index 2c96d509..5cc5768e 100644 --- a/工具v4/tool_panel.py +++ b/工具v4/tool_panel.py @@ -25,6 +25,7 @@ from 获取小闲平台使用数据 import MyWindow_xxdr from 题目内容直接编辑 import MyWindow_bjtm from 修改metadata import MyWindow_tjzd from 基础知识编辑 import MyWindow_bjjc +from 修改目标内容 import MyWindow_xgmb from database_tools_2 import * class MyWindow(QMainWindow,Ui_MainWindow): @@ -137,6 +138,10 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.bjjc = MyWindow_bjjc(self.database) self.layout_bjjc.addWidget(self.bjjc) #以上三行为初始化“编辑知识梳理”tab + self.layout_xgmb = QVBoxLayout(self.tab_xgmb) + self.xgmb = MyWindow_xgmb(self.database) + self.layout_xgmb.addWidget(self.xgmb) #以上三行为初始化"修改目标文本"tab + for func in [ @@ -154,7 +159,8 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.bjtm.setdbname, self.tjzd.setdbname, self.bjjc.setdbname, - self.wbzh.setdbname + self.wbzh.setdbname, + self.xgmb.setdbname ]: #在列表中的tab里传送数据库名的连接 self.sendDBname.connect(func) def sendValue(self): diff --git a/工具v4/tool_panel.ui b/工具v4/tool_panel.ui index 80615860..6542b36c 100644 --- a/工具v4/tool_panel.ui +++ b/工具v4/tool_panel.ui @@ -285,7 +285,7 @@ QTabWidget::Triangular - 1 + 2 @@ -297,6 +297,11 @@ 基础知识编辑 + + + 修改目标文本 + + diff --git a/工具v4/修改目标内容.py b/工具v4/修改目标内容.py new file mode 100644 index 00000000..acea48ce --- /dev/null +++ b/工具v4/修改目标内容.py @@ -0,0 +1,118 @@ +from PySide6.QtWidgets import QWidget, QApplication, QFileDialog, QTableWidgetItem +from Ui_修改目标内容 import Ui_Form +from database_tools_2 import * + +class MyWindow_xgmb(QWidget,Ui_Form): + def __init__(self,database_name): + super().__init__() + self.database_name = database_name + self.setupUi(self) + self.bind() + + def setdbname(self,string): + self.database_name = string + # print(self.database_name) + + def bind(self): + self.pushButton_getcontent.clicked.connect(self.getcontent) + self.pushButton_modify.clicked.connect(self.modify) + self.pushButton_commit.clicked.connect(self.tocommit) + self.pushButton_commit.setDisabled(True) + self.pushButton_modify.setDisabled(True) + self.plainTextEdit_objcontent.textChanged.connect(lambda: self.pushButton_modify.setEnabled(True)) + errorflag = True + + def getcontent(self): + self.db = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name) + self.cursor = self.db.cursor() + self.id = self.lineEdit_id.text().upper() + if self.id[0] == "K": + self.obj_type = "lesson" + elif self.id[0] == "D": + self.obj_type = "unit" + else: + self.obj_type = "error" + if self.obj_type == "lesson": + sql = "SELECT * FROM lessonobj WHERE objid = %s;" + val = (self.id,) + self.cursor.execute(sql,val) + ret_list = self.cursor.fetchall() + if not len(ret_list) == 1: + print("课时目标代码有误, 请重试.") + self.plainTextEdit_objcontent.setPlainText("课时目标代码有误, 请重试.") + else: + self.objcontent_raw = ret_list[0][1] + self.plainTextEdit_objcontent.setPlainText(self.objcontent_raw) + elif self.obj_type == "unit": + sql = "SELECT * FROM unitobj WHERE unit_obj_id = %s;" + val = (self.id,) + self.cursor.execute(sql,val) + ret_list = self.cursor.fetchall() + if not len(ret_list) == 1: + print("单元目标代码有误, 请重试.") + self.plainTextEdit_objcontent.setPlainText("单元目标代码有误, 请重试.") + else: + self.objcontent_raw = ret_list[0][1] + self.plainTextEdit_objcontent.setPlainText(self.objcontent_raw) + else: + print("目标代码类型有误, 请重试.") + self.plainTextEdit_objcontent.setPlainText("目标代码类型有误, 请重试.") + self.pushButton_modify.setDisabled(True) + + + + + def modify(self): + pass + self.objcontent_new = self.plainTextEdit_objcontent.toPlainText() + self.cursor = self.db.cursor() + if self.obj_type == "lesson": + sql = "UPDATE lessonobj SET obj_content = %s where objid = %s;" + val = (self.objcontent_new,self.id) + self.cursor.execute(sql,val) + sql = "INSERT INTO logs (DATE,TIME,username,action,db_content) VALUE (%s,%s,%s,%s,%s);" + val = (GetDate(),GetTime(),get_git_username(),"修改课时目标",f"{self.id}: {self.objcontent_raw} -> {self.objcontent_new}") + self.cursor.execute(sql,val) + self.pushButton_modify.setDisabled(True) + self.pushButton_commit.setEnabled(True) + elif self.obj_type == "unit": + sql = "UPDATE unitobj SET unit_obj_content = %s where unit_obj_id = %s;" + val = (self.objcontent_new,self.id) + self.cursor.execute(sql,val) + sql = "INSERT INTO logs (DATE,TIME,username,action,db_content) VALUE (%s,%s,%s,%s,%s);" + val = (GetDate(),GetTime(),get_git_username(),"修改单元目标",f"{self.id}: {self.objcontent_raw} -> {self.objcontent_new}") + self.cursor.execute(sql,val) + self.pushButton_modify.setDisabled(True) + self.pushButton_commit.setEnabled(True) + + + def tocommit(self): + self.pushButton_commit.setDisabled(True) + latex_raw = ReadTextFile("模板文件/讲义模板.txt") + if sys.platform != "win32": #非win系统用默认字体 + latex_raw = re.sub(r"fontset[\s]*=[\s]*none","fontset = fandol",latex_raw) + latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw) + latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,("试编译",self.objcontent_new)) #替换标题和bodystring + outputdir = os.path.join(os.getcwd(),"临时文件") + outputfilepath = os.path.join(outputdir,"试编译.tex") + SaveTextFile(latex_data,outputfilepath) + if XeLaTeXCompile(outputdir,"试编译.tex",times=1): + print("修改后检验成功, 已导入数据库.") + self.db.commit() + else: + print("修改后检验失败, 已回滚.") + self.db.rollback() + self.db.close() + + + + + + + +if __name__ == '__main__': + app = QApplication([]) + windows = MyWindow_xgmb("tikutest") + windows.show() + app.exec() +