Add progress dialog and threading for signature updates
This commit is contained in:
91
src/ui/dialogs/progress.py
Normal file
91
src/ui/dialogs/progress.py
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
from typing import List, Optional, Set, Union
|
||||||
|
import re
|
||||||
|
|
||||||
|
from PySide6 import QtCore
|
||||||
|
from PySide6.QtWidgets import QDialog, QPushButton, QVBoxLayout
|
||||||
|
from qtqdm import Qtqdm, QtqdmProgressBar
|
||||||
|
|
||||||
|
from src.logic import BookData
|
||||||
|
from src.logic.lehmannsapi import LehmannsClient
|
||||||
|
from src.logic.swb import SWB
|
||||||
|
|
||||||
|
|
||||||
|
class CheckThread(QtCore.QThread):
|
||||||
|
updateSignal = QtCore.Signal()
|
||||||
|
total_entries_signal = QtCore.Signal(int)
|
||||||
|
resultSignal = QtCore.Signal(str)
|
||||||
|
etaSignal = QtCore.Signal(dict)
|
||||||
|
startSignal = QtCore.Signal()
|
||||||
|
progress = QtCore.Signal(dict)
|
||||||
|
|
||||||
|
def __init__(self, items: list[BookData]):
|
||||||
|
super().__init__()
|
||||||
|
self.items: List[BookData] = items
|
||||||
|
self.results: List[tuple[BookData, List[BookData]]] = []
|
||||||
|
self.total_entries_signal.emit(len(items))
|
||||||
|
|
||||||
|
def _update_callback(self, status):
|
||||||
|
self.progress.emit(status)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
tqdm_object = Qtqdm(
|
||||||
|
range(len(self.items)),
|
||||||
|
unit_scale=True,
|
||||||
|
)
|
||||||
|
for i in tqdm_object:
|
||||||
|
book: BookData = self.items[i]
|
||||||
|
author = (
|
||||||
|
book.author.split(";")[0].replace(" ", "")
|
||||||
|
if ";" in book.author
|
||||||
|
else book.author.replace(" ", "")
|
||||||
|
)
|
||||||
|
# title = book.title.split(":")[0].strip()
|
||||||
|
# remove trailing punctuation from title
|
||||||
|
title = book.title.rstrip(" .:,;!?")
|
||||||
|
response: list[BookData] = []
|
||||||
|
response = SWB().getBooks(
|
||||||
|
[
|
||||||
|
"pica.bib=20735",
|
||||||
|
f"pica.tit={title.split(':')[0].strip()}",
|
||||||
|
# f"pica.per={author}",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# in the response, remove the entry with the same ppn
|
||||||
|
response = [entry for entry in response if entry.ppn != book.ppn]
|
||||||
|
for respo in response:
|
||||||
|
respo.link = "SWB"
|
||||||
|
with LehmannsClient() as client:
|
||||||
|
results = client.search_by_title(title, strict=True)
|
||||||
|
client.enrich_pages(results)
|
||||||
|
if not results:
|
||||||
|
continue
|
||||||
|
for res in results:
|
||||||
|
response.append(BookData().from_LehmannsSearchResult(res))
|
||||||
|
if response == []:
|
||||||
|
continue
|
||||||
|
# check results if lehmanns has a result with the same isbn from the results of swb. if so, if we have a signature, remove, else keep
|
||||||
|
response = filter_prefer_swb(response)
|
||||||
|
|
||||||
|
result = (book, response)
|
||||||
|
|
||||||
|
self.results.append(result)
|
||||||
|
|
||||||
|
|
||||||
|
class ProgressDialog(QDialog):
|
||||||
|
def __init__(self, items: list):
|
||||||
|
super().__init__()
|
||||||
|
self.setWindowTitle("Progress")
|
||||||
|
self.setModal(True)
|
||||||
|
layout = QVBoxLayout(self)
|
||||||
|
self.progress_bar = QtqdmProgressBar(self)
|
||||||
|
self.items: List[BookData] = items
|
||||||
|
layout.addWidget(self.progress_bar)
|
||||||
|
self.results: List[tuple[BookData, List[BookData]]] = []
|
||||||
|
self.start_button = QPushButton("Start Progress", self)
|
||||||
|
self.start_button.hide()
|
||||||
|
self.start_button.clicked.connect(self.start)
|
||||||
|
layout.addWidget(self.start_button)
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
|
||||||
35
src/ui/widgets/widget_sources/admin_update_signatures.ui
Normal file
35
src/ui/widgets/widget_sources/admin_update_signatures.ui
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Signaturen aktualisieren</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QProgressBar" name="progressBar">
|
||||||
|
<property name="value">
|
||||||
|
<number>24</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user