move medienadder back into own file

This commit is contained in:
WorldTeacher
2024-07-02 12:42:56 +02:00
parent f0f0ef74c1
commit b12e45ec9f

View File

@@ -56,24 +56,10 @@ from src.ui import (
SearchStatisticPage, SearchStatisticPage,
) )
from src.ui.dialogs.elsa_add_entry import ElsaAddEntry from src.ui.dialogs.elsa_add_entry import ElsaAddEntry
config = OmegaConf.load("config.yaml") config = OmegaConf.load("config.yaml")
class Medien(medienadder_ui):
def __init__(self) -> None:
self.logger = MyLogger("Medien")
super().__init__()
self.mode = ""
self.data = []
def get_list_data(self) -> list:
signatures = self.listWidget.findItems("*", QtCore.Qt.MatchFlag.MatchWildcard)
return [signature.text() for signature in signatures]
def get_mode(self) -> str:
return self.comboBox.currentText()
valid_input = (0, 0, 0, 0, 0, 0) valid_input = (0, 0, 0, 0, 0, 0)
@@ -280,7 +266,7 @@ class Ui(Ui_Semesterapparat):
self.update_faculty_member.clicked.connect(self.edit_faculty_member_action) self.update_faculty_member.clicked.connect(self.edit_faculty_member_action)
# Create instances to be used by the threads in the application # Create instances to be used by the threads in the application
self.bookGrabber = None self.bookGrabber = []
self.availChecker = None self.availChecker = None
self.mail_thread = None self.mail_thread = None
self.autoGrabber = None self.autoGrabber = None
@@ -375,6 +361,8 @@ class Ui(Ui_Semesterapparat):
self.db.createElsaApparat(date, prof, semester) self.db.createElsaApparat(date, prof, semester)
self.cancel_elsa_creation() self.cancel_elsa_creation()
self.refresh_elsa_table() self.refresh_elsa_table()
self.elsa_prof.clear()
self.elsa_prof.addItem(prof)
def refresh_elsa_table(self): def refresh_elsa_table(self):
self.elsa_table.setRowCount(0) self.elsa_table.setRowCount(0)
@@ -397,6 +385,7 @@ class Ui(Ui_Semesterapparat):
date = self.elsa_table.item(self.elsa_table.currentRow(), 1).text() date = self.elsa_table.item(self.elsa_table.currentRow(), 1).text()
semester = self.elsa_table.item(self.elsa_table.currentRow(), 2).text() semester = self.elsa_table.item(self.elsa_table.currentRow(), 2).text()
self.elsa_update.setEnabled(True) self.elsa_update.setEnabled(True)
self.elsa_save.setEnabled(False)
if self.elsa_prof.currentText() == prof: if self.elsa_prof.currentText() == prof:
self.logger.log_info("Same prof, stopping") self.logger.log_info("Same prof, stopping")
return return
@@ -476,6 +465,7 @@ class Ui(Ui_Semesterapparat):
0, 11, QtWidgets.QTableWidgetItem(scan["type"]) 0, 11, QtWidgets.QTableWidgetItem(scan["type"])
) )
self.create_frame_elsa.setEnabled(True) self.create_frame_elsa.setEnabled(True)
def addDokumentElsa(self): def addDokumentElsa(self):
print("Add document") print("Add document")
picker = FilePicker() picker = FilePicker()
@@ -1005,6 +995,7 @@ class Ui(Ui_Semesterapparat):
Icon("valid_false", widget) Icon("valid_false", widget)
mand.setText("*") mand.setText("*")
self.change_state(index, 0) self.change_state(index, 0)
def validate_prof_name(self): def validate_prof_name(self):
if ( if (
self.app_group_box.isEnabled() self.app_group_box.isEnabled()
@@ -1013,6 +1004,7 @@ class Ui(Ui_Semesterapparat):
self.__setValidState(self.valid_check_profname, 1, self.profname_mand, 0) self.__setValidState(self.valid_check_profname, 1, self.profname_mand, 0)
else: else:
self.__setValidState(self.valid_check_profname, 0, self.profname_mand, 0) self.__setValidState(self.valid_check_profname, 0, self.profname_mand, 0)
def validate_prof_mail(self): def validate_prof_mail(self):
if self.app_group_box.isEnabled(): if self.app_group_box.isEnabled():
if self.prof_mail.hasAcceptableInput(): if self.prof_mail.hasAcceptableInput():
@@ -1021,6 +1013,7 @@ class Ui(Ui_Semesterapparat):
self.__setValidState(self.valid_check_mail, 0, self.mail_mand, 1) self.__setValidState(self.valid_check_mail, 0, self.mail_mand, 1)
else: else:
self.__setValidState(self.valid_check_mail, 0, self.mail_mand, 1) self.__setValidState(self.valid_check_mail, 0, self.mail_mand, 1)
def validate_prof_tel(self): def validate_prof_tel(self):
if self.app_group_box.isEnabled(): if self.app_group_box.isEnabled():
if self.prof_tel_nr.text() != "" and self.prof_tel_nr.hasAcceptableInput(): if self.prof_tel_nr.text() != "" and self.prof_tel_nr.hasAcceptableInput():
@@ -1029,11 +1022,13 @@ class Ui(Ui_Semesterapparat):
self.__setValidState(self.valid_check_telnr, 0, self.telnr_mand, 2) self.__setValidState(self.valid_check_telnr, 0, self.telnr_mand, 2)
else: else:
self.__setValidState(self.valid_check_telnr, 0, self.telnr_mand, 2) self.__setValidState(self.valid_check_telnr, 0, self.telnr_mand, 2)
def validate_app_name(self): def validate_app_name(self):
if self.app_group_box.isEnabled() and self.app_name.hasAcceptableInput(): if self.app_group_box.isEnabled() and self.app_name.hasAcceptableInput():
self.__setValidState(self.valid_check_appname, 1, self.appname_mand, 3) self.__setValidState(self.valid_check_appname, 1, self.appname_mand, 3)
else: else:
self.__setValidState(self.valid_check_appname, 0, self.appname_mand, 3) self.__setValidState(self.valid_check_appname, 0, self.appname_mand, 3)
def validate_app_fach(self): def validate_app_fach(self):
if self.app_group_box.isEnabled() and self.app_fach.currentText() != "": if self.app_group_box.isEnabled() and self.app_fach.currentText() != "":
self.__setValidState(self.valid_check_app_fach, 1, self.fach_mand, 4) self.__setValidState(self.valid_check_app_fach, 1, self.fach_mand, 4)
@@ -1198,23 +1193,21 @@ class Ui(Ui_Semesterapparat):
self.confirm_popup("Bitte erst einen Apparat auswählen!", title="Fehler") self.confirm_popup("Bitte erst einen Apparat auswählen!", title="Fehler")
return return
def __new_ui(): media = medienadder_ui()
dialog = QtWidgets.QDialog() media.exec()
frame = Medien() mode = media.mode
frame.setupUi(dialog) data = media.data
dialog.exec() result = media.result()
mode = frame.get_mode()
data = frame.get_list_data()
return mode, data, dialog.result()
self.progress_label.show() self.progress_label.show()
self.line_2.show() self.line_2.show()
self.label_info.show() self.label_info.show()
self.progress_label.setText("Bitte warten...") self.progress_label.setText("Bitte warten...")
mode, data, result = __new_ui()
if result == 1: if result == 1:
if data == []: if data == []:
self.confirm_popup("Bitte mindestens ein Medium hinzufügen!") self.confirm_popup(
"Bitte mindestens ein Medium hinzufügen!", title="Fehler"
)
app_id = self.active_apparat app_id = self.active_apparat
prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText()) prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText())
@@ -1224,18 +1217,18 @@ class Ui(Ui_Semesterapparat):
self.btn_save_apparat(False) self.btn_save_apparat(False)
# create a thread that updates the progress label after each medium # create a thread that updates the progress label after each medium
self.bookGrabber = BookGrabber( # self.bookGrabber = None
mode=mode, prof_id=prof_id, app_id=app_id, data=data bookGrabber = BookGrabber()
) bookGrabber.add_values(mode=mode, prof_id=prof_id, app_id=app_id, data=data)
self.bookGrabber.finished.connect(self.bookGrabber.deleteLater) bookGrabber.finished.connect(self.hide_progress_label)
self.bookGrabber.finished.connect(self.hide_progress_label) bookGrabber.finished.connect(self.update_app_media_list)
self.bookGrabber.finished.connect(self.update_app_media_list) bookGrabber.updateSignal.connect(self.update_progress_label)
self.bookGrabber.updateSignal.connect(self.update_progress_label)
bookGrabber.start()
# while self.bookGrabber[-1].isRunning():
# print("waiting for thread to finish")
# QtWidgets.QApplication.processEvents()
self.bookGrabber.start()
while self.bookGrabber.isRunning():
print("waiting for thread to finish")
QtWidgets.QApplication.processEvents()
self.__clear_fields() self.__clear_fields()
else: else:
@@ -1397,15 +1390,18 @@ class Ui(Ui_Semesterapparat):
return return
if "http" not in link: if "http" not in link:
link = "https://" + link link = "https://" + link
return link
webbrowser.open(link) #
# get the name of the column # get the name of the column
columnname = self.tableWidget_apparat_media.horizontalHeaderItem( columnname = self.tableWidget_apparat_media.horizontalHeaderItem(
item.column() item.column()
).text() ).text()
if columnname == "Link": if columnname == "Link":
__openLink(item.text()) link = __openLink(item.text())
if link is not None:
webbrowser.open(link)
return
else: else:
pass pass
@@ -1438,7 +1434,7 @@ class Ui(Ui_Semesterapparat):
# set tooltip of row 3 to the file path for each row # set tooltip of row 3 to the file path for each row
self.dokument_list.item(0, 3).setToolTip(file) self.dokument_list.item(0, 3).setToolTip(file)
# self.db.insert_file(files, self.active_apparat, self.db.get_prof_id(self.drpdwn_prof_name.currentText())) # self.add_files()
def open_document(self): def open_document(self):
_selected_doc_name = "" _selected_doc_name = ""
@@ -1458,7 +1454,8 @@ class Ui(Ui_Semesterapparat):
return return
if not _selected_doc_location == "Database": if not _selected_doc_location == "Database":
path = Path(_selected_doc_location) path = Path(_selected_doc_location)
path: Path = path + "/" + _selected_doc_name path: Path = path.resolve()
path = path + "/" + _selected_doc_name
if os.getenv("OS") == "Windows_NT": if os.getenv("OS") == "Windows_NT":
path = path.resolve() path = path.resolve()
os.startfile(path) os.startfile(path)
@@ -1586,6 +1583,7 @@ class Ui(Ui_Semesterapparat):
print("Creating apparat") print("Creating apparat")
self.btn_save_apparat(False) self.btn_save_apparat(False)
created = True created = True
prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText())
if self.dokument_list.rowCount() == 0: if self.dokument_list.rowCount() == 0:
print("No file selected") print("No file selected")
self.tableWidget_apparate.setEnabled(True) self.tableWidget_apparate.setEnabled(True)
@@ -1630,27 +1628,30 @@ class Ui(Ui_Semesterapparat):
signatures = [i for i in signatures if i != ""] signatures = [i for i in signatures if i != ""]
# ic(signatures) # ic(signatures)
print("starting thread") print("starting thread")
self.autoGrabber = BookGrabber(
autoGrabber = BookGrabber()
autoGrabber.add_values(
mode="ARRAY", app_id=app_id, prof_id=prof_id, data=signatures mode="ARRAY", app_id=app_id, prof_id=prof_id, data=signatures
) )
self.label_info.show() self.label_info.show()
self.progress_label.show() self.progress_label.show()
self.line_2.show() self.line_2.show()
# grabber.finished.connect(thread.quit) # grabber.finished.connect(thread.quit)
self.autoGrabber.finished.connect(self.autoGrabber.deleteLater) # self.autoGrabber.finished.connect(self.autoGrabber.deleteLater)
self.autoGrabber.finished.connect(self.hide_progress_label) autoGrabber.finished.connect(self.hide_progress_label)
self.autoGrabber.finished.connect(self.unlock_apparate) autoGrabber.finished.connect(self.unlock_apparate)
self.autoGrabber.updateSignal.connect(self.update_progress_label)
autoGrabber.updateSignal.connect(self.update_progress_label)
# worker.finished.connect(worker.deleteLater) # worker.finished.connect(worker.deleteLater)
self.autoGrabber.start() autoGrabber.start()
while self.autoGrabber.isRunning(): while autoGrabber.isRunning():
QtWidgets.QApplication.processEvents() QtWidgets.QApplication.processEvents()
# end of thread # end of thread
# self.autoGrabber.exit() # self.autoGrabber.exit()
self.update_app_media_list() # self.__clear_fields()
self.__clear_fields() # self.btn_cancel_active_selection()
self.btn_cancel_active_selection()
def unlock_apparate(self): def unlock_apparate(self):
self.tableWidget_apparate.setEnabled(True) self.tableWidget_apparate.setEnabled(True)
self.tableWidget_apparate.setToolTip("") self.tableWidget_apparate.setToolTip("")
@@ -1743,6 +1744,7 @@ class Ui(Ui_Semesterapparat):
} }
) )
self.dokument_list.item(i, 2).setText("") self.dokument_list.item(i, 2).setText("")
self.db.insertFile( self.db.insertFile(
files, files,
self.active_apparat, self.active_apparat,
@@ -1808,11 +1810,13 @@ class Ui(Ui_Semesterapparat):
row = self.tableWidget_apparate.rowAt(position.y()) row = self.tableWidget_apparate.rowAt(position.y())
column = self.tableWidget_apparate.columnAt(position.x()) column = self.tableWidget_apparate.columnAt(position.x())
pos = (str(row), str(column)) pos = (str(row), str(column))
ic(pos) pid = self.__get_table_data_field(self.tableWidget_apparate, pos[0], 2)
ic(pos, pid)
extend_action.triggered.connect(self.extend_apparat) extend_action.triggered.connect(self.extend_apparat)
delete_action.triggered.connect(lambda: self.delete_apparat(pos)) delete_action.triggered.connect(lambda: self.delete_apparat(pos))
# pass pos to contact_prof # pass pos to contact_prof
contact_action.triggered.connect(self.contact_prof) contact_action.triggered.connect(lambda: self.contact_prof(pid=pid))
remind_action.triggered.connect(self.reminder) remind_action.triggered.connect(self.reminder)
menu.exec(self.tableWidget_apparate.mapToGlobal(position)) menu.exec(self.tableWidget_apparate.mapToGlobal(position))
@@ -2071,9 +2075,6 @@ class Ui(Ui_Semesterapparat):
self.tableWidget_apparate.removeRow(self.tableWidget_apparate.currentRow()) self.tableWidget_apparate.removeRow(self.tableWidget_apparate.currentRow())
# send mail to prof # send mail to prof
self.contact_prof(mail="deleted", apparat=selected_apparat_id, pid=pid) self.contact_prof(mail="deleted", apparat=selected_apparat_id, pid=pid)
# if state==QtWidgets.QDialog.DialogCode.Accepted:
# self.db.delete_apparat(selected_apparat_id)
# pass
def launch_gui(): def launch_gui():