UI-Signatures: implement signature update functionality with progress tracking
This commit is contained in:
59
src/ui/widgets/signature_update.py
Normal file
59
src/ui/widgets/signature_update.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from PySide6 import QtCore, QtWidgets
|
||||
|
||||
from src.backend.catalogue import Catalogue
|
||||
from src.backend.database import Database
|
||||
|
||||
from .widget_sources.admin_update_signatures_ui import Ui_Dialog
|
||||
|
||||
|
||||
class UpdaterThread(QtCore.QThread):
|
||||
progress = QtCore.Signal(int)
|
||||
currtot = QtCore.Signal(int, int)
|
||||
|
||||
def __init__(self, books=None):
|
||||
super().__init__()
|
||||
self.books = books
|
||||
self.db = Database()
|
||||
self.catalogue = Catalogue()
|
||||
|
||||
def run(self):
|
||||
total_books = len(self.books)
|
||||
for index, book in enumerate(self.books):
|
||||
id = book["id"]
|
||||
bookdata = book["bookdata"]
|
||||
ppn = bookdata.link.split("kid=")[-1]
|
||||
result = self.catalogue.get_book(ppn)
|
||||
if result:
|
||||
bookdata.signature = result.signature
|
||||
print(bookdata)
|
||||
self.db.updateBookdata(id, bookdata)
|
||||
else:
|
||||
print(f"No result for {ppn}")
|
||||
self.db.deleteBook(id)
|
||||
self.progress.emit(index + 1)
|
||||
self.currtot.emit(index + 1, total_books)
|
||||
|
||||
|
||||
class UpdateSignatures(QtWidgets.QDialog, Ui_Dialog):
|
||||
def __init__(self, parent=None):
|
||||
super(UpdateSignatures, self).__init__(parent)
|
||||
self.setupUi(self)
|
||||
self.setWindowTitle("Updating signatures...")
|
||||
self.progressBar.setValue(0)
|
||||
self.pushButton.clicked.connect(self.start)
|
||||
self.db = Database()
|
||||
self.catalogue = Catalogue()
|
||||
|
||||
def start(self):
|
||||
books = self.db.getAllBooks()
|
||||
total_books = len(books)
|
||||
self.progressBar.setMaximum(total_books)
|
||||
self.updater = UpdaterThread(books)
|
||||
self.updater.progress.connect(self.update_progress)
|
||||
self.updater.start()
|
||||
|
||||
def update_progress(self, value):
|
||||
self.progressBar.setValue(value)
|
||||
if value >= self.progressBar.maximum():
|
||||
self.pushButton.setText("Done")
|
||||
self.pushButton.setEnabled(False)
|
||||
49
src/ui/widgets/widget_sources/admin_update_signatures_ui.py
Normal file
49
src/ui/widgets/widget_sources/admin_update_signatures_ui.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
################################################################################
|
||||
## Form generated from reading UI file 'admin_update_signatures.ui'
|
||||
##
|
||||
## Created by: Qt User Interface Compiler version 6.9.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, QDialog, QProgressBar, QPushButton,
|
||||
QSizePolicy, QVBoxLayout, QWidget)
|
||||
|
||||
class Ui_Dialog(object):
|
||||
def setupUi(self, Dialog):
|
||||
if not Dialog.objectName():
|
||||
Dialog.setObjectName(u"Dialog")
|
||||
Dialog.resize(400, 300)
|
||||
self.verticalLayout = QVBoxLayout(Dialog)
|
||||
self.verticalLayout.setObjectName(u"verticalLayout")
|
||||
self.pushButton = QPushButton(Dialog)
|
||||
self.pushButton.setObjectName(u"pushButton")
|
||||
|
||||
self.verticalLayout.addWidget(self.pushButton)
|
||||
|
||||
self.progressBar = QProgressBar(Dialog)
|
||||
self.progressBar.setObjectName(u"progressBar")
|
||||
self.progressBar.setValue(24)
|
||||
|
||||
self.verticalLayout.addWidget(self.progressBar)
|
||||
|
||||
|
||||
self.retranslateUi(Dialog)
|
||||
|
||||
QMetaObject.connectSlotsByName(Dialog)
|
||||
# setupUi
|
||||
|
||||
def retranslateUi(self, Dialog):
|
||||
Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"Dialog", None))
|
||||
self.pushButton.setText(QCoreApplication.translate("Dialog", u"Signaturen aktualisieren", None))
|
||||
# retranslateUi
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
################################################################################
|
||||
## Form generated from reading UI file 'new_edition_check_selector.ui'
|
||||
##
|
||||
## Created by: Qt User Interface Compiler version 6.9.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, QDialog, QHBoxLayout, QLabel,
|
||||
QPushButton, QSizePolicy, QVBoxLayout, QWidget)
|
||||
|
||||
class Ui_Dialog(object):
|
||||
def setupUi(self, Dialog):
|
||||
if not Dialog.objectName():
|
||||
Dialog.setObjectName(u"Dialog")
|
||||
Dialog.resize(475, 66)
|
||||
self.verticalLayout = QVBoxLayout(Dialog)
|
||||
self.verticalLayout.setObjectName(u"verticalLayout")
|
||||
self.label = QLabel(Dialog)
|
||||
self.label.setObjectName(u"label")
|
||||
|
||||
self.verticalLayout.addWidget(self.label)
|
||||
|
||||
self.horizontalLayout = QHBoxLayout()
|
||||
self.horizontalLayout.setObjectName(u"horizontalLayout")
|
||||
self.btn_apparat = QPushButton(Dialog)
|
||||
self.btn_apparat.setObjectName(u"btn_apparat")
|
||||
|
||||
self.horizontalLayout.addWidget(self.btn_apparat)
|
||||
|
||||
self.btn_prof = QPushButton(Dialog)
|
||||
self.btn_prof.setObjectName(u"btn_prof")
|
||||
|
||||
self.horizontalLayout.addWidget(self.btn_prof)
|
||||
|
||||
|
||||
self.verticalLayout.addLayout(self.horizontalLayout)
|
||||
|
||||
|
||||
self.retranslateUi(Dialog)
|
||||
|
||||
QMetaObject.connectSlotsByName(Dialog)
|
||||
# setupUi
|
||||
|
||||
def retranslateUi(self, Dialog):
|
||||
Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"Dialog", None))
|
||||
self.label.setText(QCoreApplication.translate("Dialog", u"Soll nur der Apparat gepr\u00fcft werden, oder sollen alle Medien des Profs gepr\u00fcft werden?", None))
|
||||
self.btn_apparat.setText(QCoreApplication.translate("Dialog", u"Apparat", None))
|
||||
self.btn_prof.setText(QCoreApplication.translate("Dialog", u"Prof", None))
|
||||
# retranslateUi
|
||||
|
||||
Reference in New Issue
Block a user