寻找空闲题号功能基本完成, 还有一个动态读取database_name的功能尚未完成
This commit is contained in:
parent
2db6b47f06
commit
001f02cecc
|
|
@ -150,15 +150,15 @@ class Ui_MainWindow(object):
|
||||||
self.horizontalLayout = QHBoxLayout(self.horizontalLayoutWidget)
|
self.horizontalLayout = QHBoxLayout(self.horizontalLayoutWidget)
|
||||||
self.horizontalLayout.setObjectName(u"horizontalLayout")
|
self.horizontalLayout.setObjectName(u"horizontalLayout")
|
||||||
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
|
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
|
||||||
self.pushButton = QPushButton(self.horizontalLayoutWidget)
|
self.pushButton_tiku = QPushButton(self.horizontalLayoutWidget)
|
||||||
self.pushButton.setObjectName(u"pushButton")
|
self.pushButton_tiku.setObjectName(u"pushButton_tiku")
|
||||||
|
|
||||||
self.horizontalLayout.addWidget(self.pushButton)
|
self.horizontalLayout.addWidget(self.pushButton_tiku)
|
||||||
|
|
||||||
self.pushButton_2 = QPushButton(self.horizontalLayoutWidget)
|
self.pushButton_tikutest = QPushButton(self.horizontalLayoutWidget)
|
||||||
self.pushButton_2.setObjectName(u"pushButton_2")
|
self.pushButton_tikutest.setObjectName(u"pushButton_tikutest")
|
||||||
|
|
||||||
self.horizontalLayout.addWidget(self.pushButton_2)
|
self.horizontalLayout.addWidget(self.pushButton_tikutest)
|
||||||
|
|
||||||
MainWindow.setCentralWidget(self.centralwidget)
|
MainWindow.setCentralWidget(self.centralwidget)
|
||||||
self.menubar = QMenuBar(MainWindow)
|
self.menubar = QMenuBar(MainWindow)
|
||||||
|
|
@ -171,11 +171,11 @@ class Ui_MainWindow(object):
|
||||||
|
|
||||||
self.retranslateUi(MainWindow)
|
self.retranslateUi(MainWindow)
|
||||||
|
|
||||||
self.tabWidget_main.setCurrentIndex(4)
|
self.tabWidget_main.setCurrentIndex(3)
|
||||||
self.tabWidget_luru.setCurrentIndex(2)
|
self.tabWidget_luru.setCurrentIndex(2)
|
||||||
self.tabWidget_weihu.setCurrentIndex(5)
|
self.tabWidget_weihu.setCurrentIndex(5)
|
||||||
self.tabWidget_shiyong.setCurrentIndex(4)
|
self.tabWidget_shiyong.setCurrentIndex(4)
|
||||||
self.tabWidget_beikezu.setCurrentIndex(2)
|
self.tabWidget_beikezu.setCurrentIndex(1)
|
||||||
self.tabWidget.setCurrentIndex(1)
|
self.tabWidget.setCurrentIndex(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -212,7 +212,7 @@ class Ui_MainWindow(object):
|
||||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_wbzh), QCoreApplication.translate("MainWindow", u"\u6587\u672c\u8f6c\u6362\u5904\u7406", None))
|
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_wbzh), QCoreApplication.translate("MainWindow", u"\u6587\u672c\u8f6c\u6362\u5904\u7406", None))
|
||||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_hist), QCoreApplication.translate("MainWindow", u"\u76f4\u65b9\u56fe\u4ee3\u7801\u751f\u6210", None))
|
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_hist), QCoreApplication.translate("MainWindow", u"\u76f4\u65b9\u56fe\u4ee3\u7801\u751f\u6210", None))
|
||||||
self.tabWidget_main.setTabText(self.tabWidget_main.indexOf(self.tab_latex), QCoreApplication.translate("MainWindow", u"LaTeX\u4ee3\u7801\u76f8\u5173", None))
|
self.tabWidget_main.setTabText(self.tabWidget_main.indexOf(self.tab_latex), QCoreApplication.translate("MainWindow", u"LaTeX\u4ee3\u7801\u76f8\u5173", None))
|
||||||
self.pushButton.setText(QCoreApplication.translate("MainWindow", u"\u6b63\u5f0f\u6570\u636e\u5e93", None))
|
self.pushButton_tiku.setText(QCoreApplication.translate("MainWindow", u"\u6b63\u5f0f\u6570\u636e\u5e93", None))
|
||||||
self.pushButton_2.setText(QCoreApplication.translate("MainWindow", u"\u6d4b\u8bd5\u6570\u636e\u5e93", None))
|
self.pushButton_tikutest.setText(QCoreApplication.translate("MainWindow", u"\u6d4b\u8bd5\u6570\u636e\u5e93", None))
|
||||||
# retranslateUi
|
# retranslateUi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
# -*- 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, QFrame, QLabel, QPushButton,
|
||||||
|
QSizePolicy, QWidget)
|
||||||
|
|
||||||
|
class Ui_Form(object):
|
||||||
|
def setupUi(self, Form):
|
||||||
|
if not Form.objectName():
|
||||||
|
Form.setObjectName(u"Form")
|
||||||
|
Form.resize(800, 490)
|
||||||
|
self.label_used = QLabel(Form)
|
||||||
|
self.label_used.setObjectName(u"label_used")
|
||||||
|
self.label_used.setGeometry(QRect(20, 50, 291, 401))
|
||||||
|
self.label_used.setFrameShape(QFrame.StyledPanel)
|
||||||
|
self.label_used.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop)
|
||||||
|
self.label_available = QLabel(Form)
|
||||||
|
self.label_available.setObjectName(u"label_available")
|
||||||
|
self.label_available.setGeometry(QRect(330, 50, 291, 401))
|
||||||
|
self.label_available.setFrameShape(QFrame.StyledPanel)
|
||||||
|
self.label_available.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop)
|
||||||
|
self.label = QLabel(Form)
|
||||||
|
self.label.setObjectName(u"label")
|
||||||
|
self.label.setGeometry(QRect(30, 20, 71, 16))
|
||||||
|
self.label_2 = QLabel(Form)
|
||||||
|
self.label_2.setObjectName(u"label_2")
|
||||||
|
self.label_2.setGeometry(QRect(340, 20, 71, 16))
|
||||||
|
self.pushButton_exec = QPushButton(Form)
|
||||||
|
self.pushButton_exec.setObjectName(u"pushButton_exec")
|
||||||
|
self.pushButton_exec.setGeometry(QRect(640, 50, 141, 401))
|
||||||
|
font = QFont()
|
||||||
|
font.setBold(True)
|
||||||
|
self.pushButton_exec.setFont(font)
|
||||||
|
|
||||||
|
self.retranslateUi(Form)
|
||||||
|
|
||||||
|
QMetaObject.connectSlotsByName(Form)
|
||||||
|
# setupUi
|
||||||
|
|
||||||
|
def retranslateUi(self, Form):
|
||||||
|
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u5bfb\u627e\u7a7a\u95f2\u9898\u53f7", None))
|
||||||
|
self.label_used.setText(QCoreApplication.translate("Form", u"TextLabel", None))
|
||||||
|
self.label_available.setText(QCoreApplication.translate("Form", u"TextLabel", None))
|
||||||
|
self.label.setText(QCoreApplication.translate("Form", u"\u5df2\u4f7f\u7528\u9898\u53f7", None))
|
||||||
|
self.label_2.setText(QCoreApplication.translate("Form", u"\u7a7a\u95f2\u9898\u53f7", None))
|
||||||
|
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u751f\u6210\u5df2\u4f7f\u7528\u9898\u53f7\u5217\u8868\n"
|
||||||
|
"\u53ca\u7a7a\u95f2\u9898\u53f7\u5217\u8868", None))
|
||||||
|
# retranslateUi
|
||||||
|
|
||||||
|
|
@ -350,8 +350,25 @@ def extractIDs(filePath): #提取.txt,.tex或.pdf文件中的题号, 返回含
|
||||||
return generate_exp(ids)
|
return generate_exp(ids)
|
||||||
|
|
||||||
|
|
||||||
def spareIDs(): #返回空闲题号, 已更新为适合mariadb的版本
|
def usedIDs(database_name): #返回已使用题号, 已更新为适合mariadb的版本
|
||||||
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = db_database)
|
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = database_name)
|
||||||
|
mycursor = mydb.cursor()
|
||||||
|
mycursor.execute("SELECT ID FROM problems;")
|
||||||
|
idlist = [ret[0] for ret in mycursor.fetchall()]
|
||||||
|
used_str = generate_exp(idlist)
|
||||||
|
used_list = used_str.split(",")
|
||||||
|
output = ""
|
||||||
|
for group in used_list:
|
||||||
|
interval = group.split(":")
|
||||||
|
start = interval[0]
|
||||||
|
end = interval[-1]
|
||||||
|
output += "首个已使用id: %s, 直至: %s"%(str(start).zfill(6),str(end).zfill(6)) + "\n"
|
||||||
|
output = output.strip()
|
||||||
|
mydb.close()
|
||||||
|
return output #返回的是一个多行的字符串, 每一行中含有一个已使用题号的闭区间
|
||||||
|
|
||||||
|
def spareIDs(database_name): #返回空闲题号, 已更新为适合mariadb的版本
|
||||||
|
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = database_name)
|
||||||
mycursor = mydb.cursor()
|
mycursor = mydb.cursor()
|
||||||
mycursor.execute("SELECT ID FROM problems;")
|
mycursor.execute("SELECT ID FROM problems;")
|
||||||
idlist = [ret[0] for ret in mycursor.fetchall()]
|
idlist = [ret[0] for ret in mycursor.fetchall()]
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,30 @@
|
||||||
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog, QMainWindow
|
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog, QMainWindow
|
||||||
from Ui_tool_panel import Ui_MainWindow
|
from Ui_tool_panel import Ui_MainWindow
|
||||||
|
from 寻找空闲题号 import MyWindow_kxth
|
||||||
from database_tools_2 import *
|
from database_tools_2 import *
|
||||||
|
|
||||||
class MyWindow(QMainWindow,Ui_MainWindow):
|
class MyWindow(QMainWindow,Ui_MainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
self.bind()
|
||||||
|
def bind(self):
|
||||||
|
self.SelectTIKUTEST()
|
||||||
|
self.pushButton_tiku.clicked.connect(self.SelectTIKU)
|
||||||
|
self.pushButton_tikutest.clicked.connect(self.SelectTIKUTEST) #以上为设置当前数据库的两个按钮
|
||||||
|
tab_kxth = MyWindow_kxth(self.database) #传递参数时有问题, 未能动态更新
|
||||||
|
for i in range(3):
|
||||||
|
self.tabWidget_luru.removeTab(0)
|
||||||
|
self.tabWidget_luru.addTab(tab_kxth,"寻找空闲题号")
|
||||||
|
def SelectTIKU(self):
|
||||||
|
self.pushButton_tiku.setStyleSheet("background-color: green; font-weight: bold;") #绿色背景粗体
|
||||||
|
self.pushButton_tikutest.setStyleSheet("") #恢复原有背景, 取消粗体
|
||||||
|
self.database = "tiku"
|
||||||
|
def SelectTIKUTEST(self):
|
||||||
|
self.pushButton_tikutest.setStyleSheet("background-color: green; font-weight: bold;") #绿色背景粗体
|
||||||
|
self.pushButton_tiku.setStyleSheet("") #恢复原有背景, 取消粗体
|
||||||
|
self.database = "tikutest"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
<enum>QTabWidget::Triangular</enum>
|
<enum>QTabWidget::Triangular</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>4</number>
|
<number>3</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab_luru">
|
<widget class="QWidget" name="tab_luru">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
|
|
@ -217,7 +217,7 @@
|
||||||
<enum>QTabWidget::Triangular</enum>
|
<enum>QTabWidget::Triangular</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>2</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab_jglr">
|
<widget class="QWidget" name="tab_jglr">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
|
|
@ -282,14 +282,14 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="QPushButton" name="pushButton_tiku">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>正式数据库</string>
|
<string>正式数据库</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_2">
|
<widget class="QPushButton" name="pushButton_tikutest">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>测试数据库</string>
|
<string>测试数据库</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
||||||
|
from Ui_寻找空闲题号 import Ui_Form
|
||||||
|
from database_tools_2 import *
|
||||||
|
|
||||||
|
|
||||||
|
class MyWindow_kxth(QWidget,Ui_Form):
|
||||||
|
def __init__(self,database_name):
|
||||||
|
super().__init__()
|
||||||
|
self.databaes_name = database_name
|
||||||
|
self.setupUi(self)
|
||||||
|
self.bind()
|
||||||
|
def bind(self):
|
||||||
|
self.label_used.setText("")
|
||||||
|
self.label_available.setText("")
|
||||||
|
self.pushButton_exec.clicked.connect(self.exec)
|
||||||
|
|
||||||
|
|
||||||
|
def exec(self):
|
||||||
|
self.label_used.setText(usedIDs(self.databaes_name))
|
||||||
|
self.label_available.setText(spareIDs(self.databaes_name))
|
||||||
|
print(self.databaes_name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication([])
|
||||||
|
windows = MyWindow()
|
||||||
|
windows.show()
|
||||||
|
app.exec()
|
||||||
|
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?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>800</width>
|
||||||
|
<height>490</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>寻找空闲题号</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QLabel" name="label_used">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>50</y>
|
||||||
|
<width>291</width>
|
||||||
|
<height>401</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_available">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>330</x>
|
||||||
|
<y>50</y>
|
||||||
|
<width>291</width>
|
||||||
|
<height>401</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>30</x>
|
||||||
|
<y>20</y>
|
||||||
|
<width>71</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>已使用题号</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>340</x>
|
||||||
|
<y>20</y>
|
||||||
|
<width>71</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>空闲题号</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPushButton" name="pushButton_exec">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>640</x>
|
||||||
|
<y>50</y>
|
||||||
|
<width>141</width>
|
||||||
|
<height>401</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>生成已使用题号列表
|
||||||
|
及空闲题号列表</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue