rebase codebase, delete trunk, move threads to backend

This commit is contained in:
2025-01-14 16:20:08 +01:00
parent fba652006f
commit 08cd18f3f1
106 changed files with 1604 additions and 1057 deletions

View File

@@ -12,43 +12,41 @@ from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtCore import QThread
from PyQt6.QtGui import QRegularExpressionValidator
from src import Icon, settings, logger
from src.backend import (
Database,
Semester,
recreateFile,
tempdelete,
)
from src import Icon, logger
from src.backend import Database, BookGrabber, AvailChecker
from src.backend.semester import Semester
from src.backend.create_file import recreateFile
from src.backend.delete_temp_contents import delete_temp_contents as tempdelete
from src.ui import Ui_Semesterapparat
from src.logic import (
APP_NRS,
# PROF_TITLES,
ApparatData,
AvailChecker,
BookData,
BookGrabber,
csv_to_list,
word_docx_to_csv,
Prof,
Apparat,
)
from src.ui import (
from src.ui.dialogs import (
popus_confirm,
medienadder_ui,
About,
ApparatExtendDialog,
CalendarEntry,
FilePicker,
Mail_Dialog,
MessageCalendar,
Settings,
Ui_Semesterapparat,
edit_bookdata_ui,
login_ui,
medienadder_ui,
parsed_titles_ui,
popus_confirm,
reminder_ui,
SearchStatisticPage,
)
from src.ui.widgets import (
ElsaDialog,
MessageCalendar,
FilePicker,
CalendarEntry,
UserCreate,
SearchStatisticPage,
EditUser,
EditProf,
)
@@ -122,7 +120,7 @@ class Ui(Ui_Semesterapparat):
self.prof_tel_nr.setValidator(
QtGui.QRegularExpressionValidator(QtCore.QRegularExpression(r"^\d{3,14}"))
)
# print(self.prof_tel_nr.maxLength())
# #print(self.prof_tel_nr.maxLength())
self.app_fach.setValidator( # validator to allow typing in the app_fach field
QtGui.QRegularExpressionValidator(
QtCore.QRegularExpression(r"[a-zA-Z0-9\s\W]+")
@@ -140,7 +138,7 @@ class Ui(Ui_Semesterapparat):
)
self.tableWidget_apparate.doubleClicked.connect(self.load_app_data)
# print(f"user:{self.active_user}")
# #print(f"user:{self.active_user}")
userrole = self.db.getRole(self.active_user)
# hide admin interface when non-admin is logged in
if userrole == "admin":
@@ -236,14 +234,14 @@ class Ui(Ui_Semesterapparat):
"Dokument erstellen?",
)
if result == QtWidgets.QDialog.DialogCode.Accepted:
print("Creating document")
# print("Creating document")
apparats = self.apparats
apps = []
for apparat in apparats:
prof = self.db.getProf(apparat[2])
data = (apparat[4], f"{prof.lastname} ({apparat[1]})")
apps.append(data)
print(apps)
# print(apps)
doc = SemesterDocument(
semester=Semester(),
filename="Semesterapparate",
@@ -345,7 +343,7 @@ class Ui(Ui_Semesterapparat):
stats_layout.addWidget(statistics)
# print("searchpage")
# #print("searchpage")
if self.tabWidget.currentIndex() == 0: # Apparate
# clear all entries from the table
self.tableWidget_apparate.setRowCount(0)
@@ -363,7 +361,7 @@ class Ui(Ui_Semesterapparat):
widget.deleteLater()
elsa_layout.addWidget(ElsaDialog())
print("added")
# print("added")
pass
def generateSemester(self, today=False):
@@ -406,9 +404,9 @@ class Ui(Ui_Semesterapparat):
self.prof_mail.setText(appdata.prof.mail)
self.prof_tel_nr.setText(appdata.prof.telnr)
self.app_name.setText(appdata.apparat.name)
# print("changing dropdown app_fach from '' to ", appdata.app_fach)
# #print("changing dropdown app_fach from '' to ", appdata.app_fach)
self.app_fach.setCurrentText(appdata.apparat.subject)
# print("changed dropdown app_fach to ", self.app_fach.currentText())
# #print("changed dropdown app_fach to ", self.app_fach.currentText())
self.sem_year.setText(appdata.apparat.get_semester.split(" ")[1])
match appdata.apparat.get_semester.split(" ")[0]:
case "SoSe":
@@ -473,7 +471,7 @@ class Ui(Ui_Semesterapparat):
return popup.result()
def thread_check(self):
# print("Thread started")
# #print("Thread started")
self.prof_mail.textChanged.connect(self.validate_prof_mail)
self.drpdwn_prof_name.editTextChanged.connect(self.validate_prof_name)
self.prof_tel_nr.textChanged.connect(self.validate_prof_tel)
@@ -742,7 +740,7 @@ class Ui(Ui_Semesterapparat):
bookGrabber.start()
while bookGrabber.isRunning():
# print("waiting for thread to finish")
# #print("waiting for thread to finish")
QtWidgets.QApplication.processEvents()
# self.__clear_fields()
@@ -789,7 +787,7 @@ class Ui(Ui_Semesterapparat):
# thread = QThread()
appnumber = self.active_apparat
# print(links)
# #print(links)
self.availChecker = AvailChecker(links, appnumber, books=books)
# availcheck.moveToThread(thread)
# availcheck.finished.connect(thread.quit)
@@ -839,7 +837,7 @@ class Ui(Ui_Semesterapparat):
app_id, prof_id, deleted
)
# # print(books)
# # #print(books)
# take the dataclass from the tuple
# booklist:list[BookData]=[book[0] for book in books]
self.tableWidget_apparat_media.setRowCount(0)
@@ -848,7 +846,7 @@ class Ui(Ui_Semesterapparat):
book_data = book["bookdata"]
availability = book["available"]
# bd = BookData().from_string(book)
# # print(bd, type(bd))
# # #print(bd, type(bd))
# create a new row below the last one
self.tableWidget_apparat_media.insertRow(
self.tableWidget_apparat_media.rowCount()
@@ -940,11 +938,11 @@ class Ui(Ui_Semesterapparat):
self.drpdwn_prof_name.addItem(prof)
def add_document(self):
# print("Add document")
# #print("Add document")
picker = FilePicker()
files = picker.pick_files()
for file in files:
# print(file)
# #print(file)
filename = file.split("/")[-1]
filetype = filename.split(".")[-1]
self.dokument_list.insertRow(0)
@@ -1016,7 +1014,7 @@ class Ui(Ui_Semesterapparat):
else:
# if file is selected, check for books in the file
if self.dokument_list.currentRow() != -1:
# print("File selected")
# #print("File selected")
file = self.dokument_list.item(
self.dokument_list.currentRow(), 3
).text()
@@ -1074,10 +1072,10 @@ class Ui(Ui_Semesterapparat):
bookdata=book, app_id=app_id, prof_id=prof_id
)
self.update_app_media_list()
# print(len(signatures))
# #print(len(signatures))
def btn_check_file_threaded(self):
# print("Checking file")
# #print("Checking file")
# get active app_id and prof_id
self.tableWidget_apparate.setEnabled(False)
self.tableWidget_apparate.setToolTip(
@@ -1094,18 +1092,18 @@ class Ui(Ui_Semesterapparat):
created = False
if not self.db.checkApparatExistsById(app_id):
# create apparat
# print("Creating apparat")
# #print("Creating apparat")
if not self.btn_save_apparat(False):
return
created = True
if self.dokument_list.rowCount() == 0:
# print("No file selected")
# #print("No file selected")
self.tableWidget_apparate.setEnabled(True)
self.tableWidget_apparate.setToolTip("")
return
else:
# if file is selected, check for books in the file
# print("File selected")
# #print("File selected")
file = self.dokument_list.item(self.dokument_list.currentRow(), 3).text()
file_type = self.dokument_list.item(
@@ -1141,11 +1139,11 @@ class Ui(Ui_Semesterapparat):
signatures = [i for i in signatures if i != ""]
# logger.debug(signatures)
# print("starting thread")
# #print("starting thread")
if prof_id is None:
prof_id = self.db.getProfId(self.profdata)
print("Prof ID is None", prof_id)
# print("Prof ID is None", prof_id)
autoGrabber = BookGrabber(self.active_apparat)
autoGrabber.add_values(
mode="ARRAY", app_id=app_id, prof_id=prof_id, data=signatures
@@ -1248,7 +1246,7 @@ class Ui(Ui_Semesterapparat):
pid=appd.prof.fullname,
)
if clear_fields:
# print("clearing fields")
# #print("clearing fields")
self.__clear_fields()
return True
@@ -1367,7 +1365,7 @@ class Ui(Ui_Semesterapparat):
appnr = self.tableWidget_apparate.item(tableposition, 0).text()
if reminder.result() == QtWidgets.QDialog.DialogCode.Accepted:
data = reminder.return_message()
# print(data)
# #print(data)
self.db.addMessage(
data,
self.active_user,
@@ -1387,10 +1385,8 @@ class Ui(Ui_Semesterapparat):
self.calendarWidget.updateCells()
def open_reminder(self):
if not settings.mail.use_user_name:
print("False")
selected_date = self.calendarWidget.selectedDate().toString("yyyy-MM-dd")
# # print(selected_date)
# # #print(selected_date)
messages = self.db.getMessages(selected_date)
if messages == []:
return
@@ -1401,13 +1397,13 @@ class Ui(Ui_Semesterapparat):
dialog.repaintSignal.connect(lambda: self.calendarWidget.reload(selected_date))
def open_settings(self):
print(settings.dict())
# print(settings.dict())
settingsUI = Settings(self.active_user)
settingsUI.exec()
if settingsUI.result() == QtWidgets.QDialog.DialogCode.Accepted:
settingsUI.save()
print(settings.dict())
# print(settings.dict())
# self.reload()
@@ -1533,7 +1529,7 @@ class Ui(Ui_Semesterapparat):
signature=signature,
prof_id=self.db.getProfId(self.profdata),
)
print(medium.adis_idn, medium.signature)
# print(medium.adis_idn, medium.signature)
def edit_medium(self):
book = self.tableWidget_apparat_media.item(
@@ -1560,10 +1556,10 @@ class Ui(Ui_Semesterapparat):
widget.exec()
if widget.result() == QtWidgets.QDialog.DialogCode.Accepted:
data = bookedit.get_data()
# print(data)
# #print(data)
self.db.updateBookdata(bookdata=data, book_id=book_id)
# self.db.update_bookdata(data)
# print("accepted")
# #print("accepted")
self.update_app_media_list()
else:
return
@@ -1587,7 +1583,7 @@ class Ui(Ui_Semesterapparat):
)
message = f'Soll das Medium "{self.tableWidget_apparat_media.item(self.tableWidget_apparat_media.currentRow(), 0).text()}" wirklich gelöscht werden?'
state = self.confirm_popup(message, title="Löschen?")
# print(state)
# #print(state)
if state == 1:
self.db.deleteBook(book_id)
self.update_app_media_list()
@@ -1599,7 +1595,7 @@ class Ui(Ui_Semesterapparat):
for r in ranges:
for row in range(r.topRow(), r.bottomRow() + 1):
rows.append(row)
# print(rows)
# #print(rows)
message = f"Sollen die {len(rows)} Medien wirklich gelöscht werden?"
state = self.confirm_popup(message, title="Löschen?")
if state == 1:
@@ -1619,12 +1615,12 @@ class Ui(Ui_Semesterapparat):
# return data from dialog if ok is pressed
if framework.result() == QtWidgets.QDialog.DialogCode.Accepted:
data = framework.get_data()
# print(data)
# #print(data)
# return data
selected_apparat_id = self.tableWidget_apparate.item(
self.tableWidget_apparate.currentRow(), 0
).text()
# print(selected_apparat_id)
# #print(selected_apparat_id)
self.db.setNewSemesterDate(
selected_apparat_id, data["semester"], dauerapp=data["dauerapp"]
@@ -1648,7 +1644,7 @@ class Ui(Ui_Semesterapparat):
if not active_apparat_id:
# get column 0 of the selected row
pass
# print(active_apparat_id)
# #print(active_apparat_id)
# profname = self.drpdwn_prof_name.currentText().replace(",", "").split(" ")
# if profname != [""]:
@@ -1669,15 +1665,15 @@ class Ui(Ui_Semesterapparat):
app_subject = self.db.getApparatData(active_apparat_id, app_name)
app_subject = app_subject.apparat.subject
# profname = f"{profname.split(" ")[1]} {profname.split(" ")[0]}"
# print(pid)
# #print(pid)
if prof_id:
pmail = self.db.getSpecificProfData(prof_id, ["mail"])
prof_name = self.db.getSpecificProfData(prof_id, ["fullname"])
else:
pmail = self.prof_mail.text()
# print(prof_name)
# #print(prof_name)
# create a new thread to show the mail interface and send the mail
# print("showing mail dialog")
# #print("showing mail dialog")
self.mail_thread = Mail_Dialog(
app_id=active_apparat_id,
prof_name=prof_name,
@@ -1706,7 +1702,7 @@ class Ui(Ui_Semesterapparat):
).text()
message = f"Soll der Apparat {selected_apparat_id} wirklich gelöscht werden?"
state = self.confirm_popup(message, title="Löschen?")
# print(state)
# #print(state)
pid = self.__get_table_data_field(self.tableWidget_apparate, position[0], 2)
if state == 1:
self.db.deleteApparat(selected_apparat_id)
@@ -1716,7 +1712,7 @@ class Ui(Ui_Semesterapparat):
self.apparats.remove(apparat)
break
self.old_apparats = self.apparats
# print(self.apparats)
# #print(self.apparats)
# remove the row from the table
self.tableWidget_apparate.removeRow(self.tableWidget_apparate.currentRow())
# send mail to prof
@@ -1724,8 +1720,8 @@ class Ui(Ui_Semesterapparat):
def launch_gui():
# print("trying to login")
# print("checking if database available")
# #print("trying to login")
# #print("checking if database available")
logger.info("Starting login dialog")
app = QtWidgets.QApplication(sys.argv)
@@ -1737,11 +1733,11 @@ def launch_gui():
if ui.lresult == 1:
# if login is successful, open main window
# show login dialog
# print(ui.lusername)
# #print(ui.lusername)
MainWindow = QtWidgets.QMainWindow()
aui = Ui(MainWindow, username=ui.lusername)
# print(aui.active_user)
# #print(aui.active_user)
MainWindow.show()
# atexit.register()
atexit.register(tempdelete)
@@ -1758,7 +1754,7 @@ def launch_gui():
if __name__ == "__main__":
# print("This is the main window")
# #print("This is the main window")
# app = QtWidgets.QApplication(sys.argv)
# window = MainWindow()
# app.exec()