From c6ff076881f02c56abfee58cbe757397b2535fe3 Mon Sep 17 00:00:00 2001 From: WorldTeacher <41587052+WorldTeacher@users.noreply.github.com> Date: Wed, 3 Jul 2024 15:13:59 +0200 Subject: [PATCH] add files --- __main__.py | 5 +- src/ui/Ui_semesterapparat_ui.py | 2 + src/ui/__init__.py | 2 + src/ui/semesterapparat_ui.ui | 6 + src/ui/userInterface.py | 250 +++++++++++++++----------------- 5 files changed, 127 insertions(+), 138 deletions(-) diff --git a/__main__.py b/__main__.py index 39ae395..ca54153 100644 --- a/__main__.py +++ b/__main__.py @@ -1,4 +1,3 @@ -from src.logic import userInterface - +from src import UI if __name__ == "__main__": - userInterface.launch_gui() + UI() \ No newline at end of file diff --git a/src/ui/Ui_semesterapparat_ui.py b/src/ui/Ui_semesterapparat_ui.py index e208e91..1912057 100644 --- a/src/ui/Ui_semesterapparat_ui.py +++ b/src/ui/Ui_semesterapparat_ui.py @@ -388,6 +388,7 @@ class Ui_MainWindow(object): self.drpdwn_prof_name.setInputMethodHints(QtCore.Qt.InputMethodHint.ImhNone) self.drpdwn_prof_name.setEditable(True) self.drpdwn_prof_name.setInsertPolicy(QtWidgets.QComboBox.InsertPolicy.InsertAlphabetically) + self.drpdwn_prof_name.setPlaceholderText("") self.drpdwn_prof_name.setFrame(True) self.drpdwn_prof_name.setObjectName("drpdwn_prof_name") self.mail_mand = QtWidgets.QLabel(parent=self.app_group_box) @@ -1430,6 +1431,7 @@ class Ui_MainWindow(object): self._mand.setText(_translate("MainWindow", "*")) self.check_eternal_app.setText(_translate("MainWindow", "Dauerapparat")) self.sem_sommer.setText(_translate("MainWindow", "Sommer")) + self.drpdwn_prof_name.setToolTip(_translate("MainWindow", "Nachname, Vorname")) self.mail_mand.setText(_translate("MainWindow", "*")) self.label_3.setStatusTip(_translate("MainWindow", "sdvosdvsdv")) self.label_3.setText(_translate("MainWindow", "Prof. Titel")) diff --git a/src/ui/__init__.py b/src/ui/__init__.py index 7565485..73d9474 100644 --- a/src/ui/__init__.py +++ b/src/ui/__init__.py @@ -13,6 +13,7 @@ from .dialogs import ( popus_confirm, reminder_ui, About, + ElsaAddEntry, ) from .Ui_semesterapparat_ui import Ui_MainWindow as Ui_Semesterapparat from .widgets import ( @@ -22,6 +23,7 @@ from .widgets import ( StatusWidget, CalendarEntry, MessageCalendar, + SearchStatisticPage, # ) path = pathlib.Path(__file__).parent.absolute() diff --git a/src/ui/semesterapparat_ui.ui b/src/ui/semesterapparat_ui.ui index 7c68071..f7db1e4 100644 --- a/src/ui/semesterapparat_ui.ui +++ b/src/ui/semesterapparat_ui.ui @@ -932,6 +932,9 @@ Qt::StrongFocus + + Nachname, Vorname + Qt::ImhNone @@ -941,6 +944,9 @@ QComboBox::InsertAlphabetically + + + true diff --git a/src/ui/userInterface.py b/src/ui/userInterface.py index a29943c..0b358ee 100644 --- a/src/ui/userInterface.py +++ b/src/ui/userInterface.py @@ -13,7 +13,6 @@ from omegaconf import OmegaConf from PyQt6 import QtCore, QtGui, QtWidgets from PyQt6.QtCore import QDate, QThread from PyQt6.QtGui import QRegularExpressionValidator -from src.transformers.transformers import DictToTable from src import Icon from src.backend import ( @@ -35,7 +34,6 @@ from src.logic import ( csv_to_list, elsa_word_to_csv, word_docx_to_csv, - ZoteroController, ) from src.ui import ( About, @@ -54,8 +52,8 @@ from src.ui import ( popus_confirm, reminder_ui, SearchStatisticPage, + ElsaAddEntry, ) -from src.ui.dialogs.elsa_add_entry import ElsaAddEntry config = OmegaConf.load("config.yaml") @@ -208,6 +206,7 @@ class Ui(Ui_Semesterapparat): self.validate_thread = QThread() self.validate_thread.started.connect(self.thread_check) self.validate_thread.start() + self.add_medium.setEnabled(False) # get all current apparats and cache them in a list self.apparats = self.get_apparats() @@ -258,6 +257,7 @@ class Ui(Ui_Semesterapparat): self.check_file_elsa.clicked.connect(self.parseDokumentElsa) self.btn_open_document_elsa.clicked.connect(self.openDocumentElsa) self.quote_entry.clicked.connect(self.elsa_table_entry) + self.quote_entry.setEnabled(False) # admin buttons self.user_frame_addUser.clicked.connect(self.add_user) @@ -279,6 +279,7 @@ class Ui(Ui_Semesterapparat): def toggleButton(self, button): if button.isChecked(): button.setChecked(False) + self.validate_semester() def open_about(self): About().exec() @@ -289,15 +290,10 @@ class Ui(Ui_Semesterapparat): sys.exit() def elsa_table_entry(self): - dtt = DictToTable() - zot = ZoteroController() data = ElsaAddEntry() - selected_row = self.elsa_table.currentRow() - # print all rows in the table - for i in range(self.elsa_table.rowCount()): - print(self.elsa_table.item(i, 0).text()) - mediatype = self.table_elsa_list.item(selected_row, 11).text() + selected_row = self.table_elsa_list.currentRow() signature = self.table_elsa_list.item(selected_row, 10).text() + mediatype = self.table_elsa_list.item(selected_row, 11).text() data.searchIdent.setText(signature) if mediatype == "Zeitschriftenaufsätze": data.btn_zs.click() @@ -327,6 +323,7 @@ class Ui(Ui_Semesterapparat): self.elsa_semester.setText("") self.dokument_list_elsa.setRowCount(0) self.table_elsa_list.setRowCount(0) + self.quote_entry.setEnabled(False) def generateTodayDateElsa(self): self.elsa_date.setText(QDate.currentDate().toString("dd.MM.yyyy")) @@ -343,6 +340,7 @@ class Ui(Ui_Semesterapparat): return self.db.updateElsaApparat(elsa_id, prof, semester, date) self.elsa_update.setEnabled(False) + self.cancel_elsa_creation() def save_elsa(self): if ( @@ -363,6 +361,7 @@ class Ui(Ui_Semesterapparat): self.refresh_elsa_table() self.elsa_prof.clear() self.elsa_prof.addItem(prof) + self.quote_entry.setEnabled(False) def refresh_elsa_table(self): self.elsa_table.setRowCount(0) @@ -389,7 +388,7 @@ class Ui(Ui_Semesterapparat): if self.elsa_prof.currentText() == prof: self.logger.log_info("Same prof, stopping") return - + self.create_frame_elsa.setEnabled(True) self.dokument_list_elsa.setRowCount(0) self.table_elsa_list.setRowCount(0) self.elsa_cancel_create.setEnabled(True) @@ -401,11 +400,11 @@ class Ui(Ui_Semesterapparat): elsa_id = apparat[0] print(elsa_id) break - if elsa_id is None: - return self.elsa_date.setText(date) self.elsa_semester.setText(semester) self.elsa_prof.setCurrentText(prof) + if elsa_id is None: + return documents = self.db.getElsaFiles(elsa_id) for document in documents: print(document) @@ -421,50 +420,46 @@ class Ui(Ui_Semesterapparat): 0, 3, QtWidgets.QTableWidgetItem("Database") ) scans = self.db.getElsaMedia(elsa_id) - ic(scans) if scans == []: self.create_frame_elsa.setEnabled(True) - else: - pass - for scan in scans: - self.table_elsa_list.insertRow(0) - self.table_elsa_list.setItem( - 0, 0, QtWidgets.QTableWidgetItem(scan["work_author"]) - ) - self.table_elsa_list.setItem( - 0, 1, QtWidgets.QTableWidgetItem(scan["section_author"]) - ) - self.table_elsa_list.setItem( - 0, 2, QtWidgets.QTableWidgetItem(scan["year"]) - ) - self.table_elsa_list.setItem( - 0, 3, QtWidgets.QTableWidgetItem(scan["issue"]) - ) - self.table_elsa_list.setItem( - 0, 4, QtWidgets.QTableWidgetItem(scan["edition"]) - ) - self.table_elsa_list.setItem( - 0, 5, QtWidgets.QTableWidgetItem(scan["work_title"]) - ) - self.table_elsa_list.setItem( - 0, 6, QtWidgets.QTableWidgetItem(scan["chapter_title"]) - ) - self.table_elsa_list.setItem( - 0, 7, QtWidgets.QTableWidgetItem(scan["pages"]) - ) - self.table_elsa_list.setItem( - 0, 8, QtWidgets.QTableWidgetItem(scan["location"]) - ) - self.table_elsa_list.setItem( - 0, 9, QtWidgets.QTableWidgetItem(scan["publisher"]) - ) - self.table_elsa_list.setItem( - 0, 10, QtWidgets.QTableWidgetItem(scan["signature"]) - ) - self.table_elsa_list.setItem( - 0, 11, QtWidgets.QTableWidgetItem(scan["type"]) - ) - self.create_frame_elsa.setEnabled(True) + + print(scans) + # remove all rows from the table + + for scan in scans: + print("Inserting row") + print(scan["type"]) + self.setElsaRow(scan) + + self.quote_entry.setEnabled(True) + # self.cancel_elsa_creation() + + def setElsaRow(self, scan): + self.table_elsa_list.insertRow(0) + self.table_elsa_list.setItem( + 0, 0, QtWidgets.QTableWidgetItem(scan["work_author"]) + ) + self.table_elsa_list.setItem( + 0, 1, QtWidgets.QTableWidgetItem(scan["section_author"]) + ) + self.table_elsa_list.setItem(0, 2, QtWidgets.QTableWidgetItem(scan["year"])) + self.table_elsa_list.setItem(0, 3, QtWidgets.QTableWidgetItem(scan["issue"])) + self.table_elsa_list.setItem(0, 4, QtWidgets.QTableWidgetItem(scan["edition"])) + self.table_elsa_list.setItem( + 0, 5, QtWidgets.QTableWidgetItem(scan["work_title"]) + ) + self.table_elsa_list.setItem( + 0, 6, QtWidgets.QTableWidgetItem(scan["chapter_title"]) + ) + self.table_elsa_list.setItem(0, 7, QtWidgets.QTableWidgetItem(scan["pages"])) + self.table_elsa_list.setItem(0, 8, QtWidgets.QTableWidgetItem(scan["location"])) + self.table_elsa_list.setItem( + 0, 9, QtWidgets.QTableWidgetItem(scan["publisher"]) + ) + self.table_elsa_list.setItem( + 0, 10, QtWidgets.QTableWidgetItem(scan["signature"]) + ) + self.table_elsa_list.setItem(0, 11, QtWidgets.QTableWidgetItem(scan["type"])) def addDokumentElsa(self): print("Add document") @@ -532,46 +527,10 @@ class Ui(Ui_Semesterapparat): self.elsa_date.text(), ) for row in data: - self.table_elsa_list.insertRow(0) - ic(row) - self.table_elsa_list.setItem( - 0, 0, QtWidgets.QTableWidgetItem(row["work_author"]) - ) - self.table_elsa_list.setItem( - 0, 1, QtWidgets.QTableWidgetItem(row["section_author"]) - ) - self.table_elsa_list.setItem( - 0, 2, QtWidgets.QTableWidgetItem(row["year"]) - ) - self.table_elsa_list.setItem( - 0, 3, QtWidgets.QTableWidgetItem(row["issue"]) - ) - self.table_elsa_list.setItem( - 0, 4, QtWidgets.QTableWidgetItem(row["edition"]) - ) - self.table_elsa_list.setItem( - 0, 5, QtWidgets.QTableWidgetItem(row["chapter_title"]) - ) - self.table_elsa_list.setItem( - 0, 6, QtWidgets.QTableWidgetItem(row["work_title"]) - ) - self.table_elsa_list.setItem( - 0, 7, QtWidgets.QTableWidgetItem(row["pages"]) - ) - self.table_elsa_list.setItem( - 0, 8, QtWidgets.QTableWidgetItem(row["location"]) - ) - self.table_elsa_list.setItem( - 0, 9, QtWidgets.QTableWidgetItem(row["publisher"]) - ) - self.table_elsa_list.setItem( - 0, 10, QtWidgets.QTableWidgetItem(row["signature"]) - ) - self.table_elsa_list.setItem( - 0, 11, QtWidgets.QTableWidgetItem(row["type"]) - ) + self.setElsaRow(row) self.db.addElsaMedia(row, elsa_id) + self.quote_entry.setEnabled(True) def openDocumentElsa(self): # open the selected document @@ -962,6 +921,7 @@ class Ui(Ui_Semesterapparat): self.check_send_mail.show() self.chkbx_show_del_media.show() self.cancel_active_selection.setEnabled(False) + self.add_medium.setEnabled(False) def confirm_popup(self, message: str, title: str): popup = popus_confirm(title=title) @@ -1041,7 +1001,7 @@ class Ui(Ui_Semesterapparat): and ( (self.sem_sommer.isChecked() or self.sem_winter.isChecked()) and self.sem_year.text() != "" - and len(self.sem_year.text()) == 4 + and len(self.sem_year.text()) >= 4 ) or self.check_eternal_app.isChecked() ): @@ -1098,6 +1058,7 @@ class Ui(Ui_Semesterapparat): def load_app_data(self, app_id=None): self.cancel_active_selection.setEnabled(True) + self.add_medium.setEnabled(True) if isinstance(app_id, str): # double click the tableWidget_apparate row with the given app_id row, column = self.get_index_of_value(self.tableWidget_apparate, app_id) @@ -1150,13 +1111,14 @@ class Ui(Ui_Semesterapparat): self.dokument_list.setRowCount(0) self.cancel_active_selection.setEnabled(True) self.app_group_box.setEnabled(True) - + self.add_medium.setEnabled(True) self.sem_year.setEnabled(True) self.sem_sommer.setEnabled(True) self.sem_winter.setEnabled(True) self.chkbx_show_del_media.setEnabled(True) self.drpdwn_app_nr.setEnabled(True) self.app_fach.setEnabled(True) + self.check_send_mail.show() if self.tableWidget_apparat_media.rowCount() > 0: self.tableWidget_apparat_media.setRowCount(0) @@ -1167,9 +1129,8 @@ class Ui(Ui_Semesterapparat): self.prof_title.clear() self.drpdwn_prof_name.clear() # set drop down menu for apparat numbers to only available numbers - self.drpdwn_app_nr.addItems( - [str(i) for i in APP_NRS if i not in self.db.getUnavailableApparatNumbers()] - ) + taken_app_nrs = self.db.getUnavailableApparatNumbers() + self.drpdwn_app_nr.addItems([str(i) for i in APP_NRS if i not in taken_app_nrs]) valid_input = (0, 0, 0, 0, 0, 0) self.populate_prof_dropdown() @@ -1199,11 +1160,11 @@ class Ui(Ui_Semesterapparat): data = media.data result = media.result() - self.progress_label.show() - self.line_2.show() - self.label_info.show() - self.progress_label.setText("Bitte warten...") if result == 1: + self.progress_label.show() + self.line_2.show() + self.label_info.show() + self.progress_label.setText("Bitte warten...") if data == []: self.confirm_popup( "Bitte mindestens ein Medium hinzufügen!", title="Fehler" @@ -1212,7 +1173,7 @@ class Ui(Ui_Semesterapparat): app_id = self.active_apparat prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText()) # check if app_id is in database - if not self.db.checkApparatExists(app_id): + if self.db.checkApparatExistsById(app_id) is False: # create apparat self.btn_save_apparat(False) # create a thread that updates the progress label after each medium @@ -1225,9 +1186,9 @@ class Ui(Ui_Semesterapparat): bookGrabber.updateSignal.connect(self.update_progress_label) bookGrabber.start() - # while self.bookGrabber[-1].isRunning(): - # print("waiting for thread to finish") - # QtWidgets.QApplication.processEvents() + while bookGrabber.isRunning(): + print("waiting for thread to finish") + QtWidgets.QApplication.processEvents() self.__clear_fields() @@ -1302,6 +1263,7 @@ class Ui(Ui_Semesterapparat): # set all radio buttons to unchecked self.sem_sommer.setChecked(False) self.sem_winter.setChecked(False) + self.add_medium.setEnabled(False) for child in self.app_group_box.findChildren(QtWidgets.QLineEdit): child.clear() @@ -1706,7 +1668,10 @@ class Ui(Ui_Semesterapparat): self.add_files() if not self.validate_fields(): pass - self.db.createApparat(appd) + error = self.db.createApparat(appd) + if error is not None: + self.confirm_popup(error.__str__(), title="Fehler") + return # if self.dokument_list.rowCount() > 0: # self.add_files() appdata = self.db.getAllAparats() @@ -1719,7 +1684,10 @@ class Ui(Ui_Semesterapparat): if self.check_send_mail.isChecked(): self.contact_prof( - apparat=appd.appnr, mail="Information zum Semesterapparat", location="" + apparat=appd.appnr, + mail="Information zum Semesterapparat", + location="", + pid=appd.profname, ) if clear_fields: print("clearing fields") @@ -1752,17 +1720,9 @@ class Ui(Ui_Semesterapparat): ) def update_apparat_list(self): - # get a list of new apparats based on self.apparats and self.old_apparats - new_apparats = [ - apparat for apparat in self.apparats if apparat not in self.old_apparats - ] - print(new_apparats) - # insert the new apparats into the table - for apparat in new_apparats: + self.tableWidget_apparate.setRowCount(0) + for apparat in self.apparats: self.insert_apparat_into_table(apparat) - # sort the table by apparat number using natural sorting - self.tableWidget_apparate.sortItems(0, QtCore.Qt.SortOrder.AscendingOrder) - self.old_apparats = self.apparats def insert_apparat_into_table(self, apparat): # ic(apparat) @@ -1811,12 +1771,14 @@ class Ui(Ui_Semesterapparat): column = self.tableWidget_apparate.columnAt(position.x()) pos = (str(row), str(column)) pid = self.__get_table_data_field(self.tableWidget_apparate, pos[0], 2) - + app_id = self.__get_table_data_field(self.tableWidget_apparate, pos[0], 0) ic(pos, pid) extend_action.triggered.connect(self.extend_apparat) delete_action.triggered.connect(lambda: self.delete_apparat(pos)) # pass pos to contact_prof - contact_action.triggered.connect(lambda: self.contact_prof(pid=pid)) + contact_action.triggered.connect( + lambda: self.contact_prof(pid=pid, apparat=app_id) + ) remind_action.triggered.connect(self.reminder) menu.exec(self.tableWidget_apparate.mapToGlobal(position)) @@ -2011,47 +1973,64 @@ class Ui(Ui_Semesterapparat): return table.item(row, column).text() def __contact_dialog(self, apparat, location: tuple | str, mail=None, pid=""): - ic(location, pid) + ic(location, pid, apparat) active_apparat_id = ( self.drpdwn_app_nr.currentText() if apparat is None else apparat ) + if not active_apparat_id: + # get column 0 of the selected row + pass print(active_apparat_id) - profname = self.drpdwn_prof_name.currentText().replace(",", "").split(" ") - profname = f"{profname[1]} {profname[0]}" + # profname = self.drpdwn_prof_name.currentText().replace(",", "").split(" ") + # if profname != [""]: + # profname = f"{profname[1]} {profname[0]}" + # if pid == "": + # pid = profname # get the row of the clicked cell prof_id = self.db.getProfId(pid) - if profname == "Name Kein": - profname = pid - - profname = f"{profname.split(" ")[1]} {profname.split(" ")[0]}" - print(profname, pid) + # if profname == "Name Kein": + # profname = pid + if self.app_name.text() != "": + app_name = self.app_name.text() + else: + app_name = self.db.getApparatName(active_apparat_id, prof_id) + if self.app_fach.currentText() != "": + app_subject = self.app_fach.currentText() + else: + app_subject = self.db.getApparatData(active_apparat_id, app_name) + app_subject = app_subject.app_fach + # profname = f"{profname.split(" ")[1]} {profname.split(" ")[0]}" + 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) # create a new thread to show the mail interface and send the mail print("showing mail dialog") self.mail_thread = Mail_Dialog( app_id=active_apparat_id, - prof_name=pid, + prof_name=prof_name, prof_mail=pmail, - app_name=self.app_name.text(), - app_subject=self.app_fach.currentText(), + app_name=app_name, + app_subject=app_subject, default_mail=mail if mail != "" else "Information zum Semesterapparat", ) self.mail_thread.show() - def contact_prof(self, location="", apparat=None, mail="", pid=""): - print(apparat) - print("location", location) + def contact_prof(self, apparat="", location="", mail="", pid=""): + ic(apparat) + ic(location) if self.active_apparat == "": if apparat is False: self.confirm_popup( "Bitte erst einen Apparat auswählen!", title="Apparat auswählen" ) return + self.__contact_dialog(apparat, mail=mail, pid=pid, location=location) def delete_apparat(self, position): @@ -2080,7 +2059,8 @@ class Ui(Ui_Semesterapparat): def launch_gui(): print("trying to login") print("checking if database available") - + log = MyLogger("login") + log.log_info("Starting login dialog") app = QtWidgets.QApplication(sys.argv) login_dialog = QtWidgets.QDialog() ui = login_ui()