From c03865dcbde31820f9ef91764abdbea57d269296 Mon Sep 17 00:00:00 2001 From: WorldTeacher <41587052+WorldTeacher@users.noreply.github.com> Date: Wed, 31 Jan 2024 15:31:25 +0100 Subject: [PATCH] update ui related files & functions --- src/logic/userInterface.py | 324 +++++++++++++++------------- src/ui/Ui_semesterapparat_ui.py | 58 ++--- src/ui/dialogs/Ui_login.py | 3 +- src/ui/semesterapparat_ui.ui | 77 ++++--- src/ui/widgets/Ui_message_widget.py | 2 +- 5 files changed, 259 insertions(+), 205 deletions(-) diff --git a/src/logic/userInterface.py b/src/logic/userInterface.py index 7ea8911..542a00f 100644 --- a/src/logic/userInterface.py +++ b/src/logic/userInterface.py @@ -7,17 +7,16 @@ import sys import tempfile import time from pathlib import Path - +import webbrowser from natsort import natsorted from omegaconf import OmegaConf from PyQt6 import QtCore, QtGui, QtWidgets from PyQt6.QtCore import QDate, QThread, pyqtSignal from PyQt6.QtGui import QColor, QRegularExpressionValidator - from src.logic import c_sort from src.backend.database import Database from src.logic.constants import APP_NRS, PROF_TITLES -from src.logic.dataclass import ApparatData, BookData, MailData +from src.logic.dataclass import ApparatData, BookData, MailData,Subjects from src.logic.log import MyLogger from src.logic.threads import BookGrabber,AvailChecker from src.ui import ( @@ -121,6 +120,7 @@ class MessageCalendar(QtWidgets.QCalendarWidget): ) + class Ui(Ui_Semesterapparat): # use the Ui_MainWindow class from mainwindow.py def __init__(self, MainWindow, username: str) -> None: @@ -158,6 +158,10 @@ class Ui(Ui_Semesterapparat): ) self.calendarWidget.setObjectName("MessageCalendar") self.calendarWidget.clicked.connect(self.open_reminder) + #assign a context menu to the calendar + self.calendarWidget.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu) + self.calendarWidget.customContextMenuRequested.connect(self.calendar_context_menu) + self.tableWidget_apparat_media.horizontalHeader().setSectionResizeMode( QtWidgets.QHeaderView.ResizeMode.Stretch ) @@ -214,13 +218,14 @@ class Ui(Ui_Semesterapparat): self.tableWidget_apparate.doubleClicked.connect(self.load_app_data) self.load_app.hide() print(f"user:{self.active_user}") - userrole = self.db.get_role(self.active_user) + userrole = self.db.getRole(self.active_user) if userrole == "admin": self.tabWidget.setTabVisible(2, True) else: self.tabWidget.setTabVisible(2, False) # self.update_app_media_list() self.populate_prof_dropdown() + self.populate_appfach_dropdown() self.frame.setEnabled(False) # if the focus is changed from the prof name dropdown, set the prof data if the prof exists in the database, otherwise show a message self.drpdwn_prof_name.currentIndexChanged.connect(self.set_prof_data) @@ -263,8 +268,7 @@ class Ui(Ui_Semesterapparat): self.validate_thread.start() # get all current apparats and cache them in a list - self.apparats = self.db.get_all_apparts(deleted=0) - print(self.apparats) + self.apparats = self.db.getAllAparats(deleted=0) self.apparats = natsorted(self.apparats, key=lambda x: x[4], reverse=True) for apparat in self.apparats: @@ -297,6 +301,11 @@ class Ui(Ui_Semesterapparat): self.update_user.clicked.connect(self.update_user_data) self.update_faculty_member.clicked.connect(self.edit_faculty_member_action) + def populate_appfach_dropdown(self): + self.app_fach.clear() + self.app_fach.addItem("") + self.app_fach.setCurrentText("") + self.app_fach.addItems([subject[1] for subject in self.db.getSubjects()]) def tabW1_changed(self): if self.tabWidget.currentIndex() == 1: @@ -315,15 +324,16 @@ class Ui(Ui_Semesterapparat): } params = {key: value for key, value in params.items() if value is not None} ic(params) - retdata = self.db.search_book(params) - + retdata = self.db.searchBook(params) + if retdata == None: + return for book in retdata: - ic(book) + self.book_search_result.insertRow(0) self.book_search_result.setItem(0,0,QtWidgets.QTableWidgetItem(book[0].title)) self.book_search_result.setItem(0,1,QtWidgets.QTableWidgetItem(book[0].signature)) print(book[1]) - self.book_search_result.setItem(0,2,QtWidgets.QTableWidgetItem(self.db.get_apparats_name(book[1],book[2]))) + self.book_search_result.setItem(0,2,QtWidgets.QTableWidgetItem(self.db.getApparatName(book[1],book[2]))) def edit_faculty_member_set_data(self): @@ -332,7 +342,7 @@ class Ui(Ui_Semesterapparat): fullname = name.replace(",","") print(fullname,name) #get the data for the selected member - data = self.db.faculty_data(fullname) + data = self.db.getProfByName(fullname) #set the data print(data) if data == None: @@ -358,12 +368,12 @@ class Ui(Ui_Semesterapparat): username = self.user_create_frame_username.text() password = self.user_create_frame_password.text() role = self.user_frame_userrole.currentText() - if self.db.check_username(username): + if self.db.checkUsername(username): ic("username already exists") # self.user_create_frame_error.setText("Der Nutzername ist bereits vergeben")#TODO: implement error message return userdata = AdminCommands().create_password(password) - self.db.create_user(username=username, password=f"{userdata[1]}{userdata[0]}", salt=userdata[1], role=role) + self.db.createUser(username=username, password=f"{userdata[1]}{userdata[0]}", salt=userdata[1], role=role) self.user_create_frame_username.clear() self.user_create_frame_password.clear() self.user_frame_userrole.setCurrentText("") @@ -372,7 +382,7 @@ class Ui(Ui_Semesterapparat): def delete_user(self): if self.user_delete_confirm.isChecked(): username = self.user_delete_frame_user_select.currentText() - self.db.delete_user(username) + self.db.deleteUser(username) self.user_delete_frame_user_select.removeItem(self.user_delete_frame_user_select.currentIndex()) self.user_delete_confirm.setChecked(False) else: @@ -392,7 +402,7 @@ class Ui(Ui_Semesterapparat): } data = {key: value for key, value in data.items() if value is not None} print(data) - self.db.update_user(username=username,data = data) + self.db.updateUser(username=username,data = data) self.user_edit_frame_user_select.setCurrentText("") self.user_edit_frame_new_password.clear() self.user_edit_frame_role_select.setCurrentText("") @@ -408,9 +418,9 @@ class Ui(Ui_Semesterapparat): if fname != "" and lname != "": return f"{lname} {fname}" #get the data and use new value if it is not none and does not mach the old value - if self.edit_faculty_member_select_member.currentText(""): + if self.edit_faculty_member_select_member.currentText() =="": return - olddata = self.db.get_faculty_members(self.edit_faculty_member_select_member.currentText()) + olddata = self.db.getFacultyMember(self.edit_faculty_member_select_member.currentText()) data = olddata[0] oldlname = data[2] @@ -432,7 +442,7 @@ class Ui(Ui_Semesterapparat): "telnr":telnr, } new_data = {key: value for key, value in new_data.items() if value != ""} - self.db.update_faculty_member(data = new_data,oldlname=oldlname,oldfname=oldfname) + self.db.updateFacultyMember(data = new_data,oldlname=oldlname,oldfname=oldfname) self.add_faculty_member_data() self.edit_faculty_member_new_title.setCurrentText("") self.edit_faculty_member_new_surname.clear() @@ -448,11 +458,11 @@ class Ui(Ui_Semesterapparat): def admin_action_changed(self): action = self.select_action_box.currentText() - roles = self.db.get_roles() + roles = self.db.getRoles() roles = [role[0] for role in roles] #remove duplicates roles = list(dict.fromkeys(roles)) - users = self.db.get_users() + users = self.db.getUsers() users = [user[2] for user in users] users.remove(self.active_user) if "admin" in users: @@ -485,7 +495,7 @@ class Ui(Ui_Semesterapparat): return def add_faculty_member_data(self): - faculty_members = self.db.get_faculty_members() + faculty_members = self.db.getFacultyMembers() names = [f"{member[5]}" for member in faculty_members] self.edit_faculty_member_select_member.clear() self.edit_faculty_member_select_member.addItems(names) @@ -535,7 +545,7 @@ class Ui(Ui_Semesterapparat): self.statistics_table.currentRow(), 0 ).text() # get all apparats from the selected semester - data = self.db.apparats_by_semester(selected_semester) + data = self.db.getApparatsBySemester(selected_semester) # replace keys for german names # split to two lists created = {"Erstellt": data["created"]} @@ -566,8 +576,8 @@ class Ui(Ui_Semesterapparat): print(apparat) #person selected case - open all apparats from this person in the tableWidget self.tableWidget.setRowCount(0) - prof_id = self.db.get_prof_id(apparat.split("(")[0].strip()) - apparats = self.db.get_apparats_by_prof(prof_id) + prof_id = self.db.getProfId(apparat.split("(")[0].strip()) + apparats = self.db.getApparatsByProf(prof_id) for app in apparats: print(app) #set the items 0 = clickable checkbox, 1 = appname, 2 = profname, 3 = fach @@ -645,21 +655,21 @@ class Ui(Ui_Semesterapparat): self.box_dauerapp.addItems(["Ja", "Nein", ""]) self.box_dauerapp.setCurrentText("") #add custom vaules - appnrs = self.db.get_apparat_nrs() + appnrs = self.db.getUnavailableApparatNumbers() apparats = natsorted(appnrs) apparats = [str(apparat) for apparat in apparats] self.box_appnrs.addItems(apparats) - persons = self.db.get_profs() + persons = self.db.getProfs() self.box_person.addItems( [f"{person[3]}, {person[2]}" for person in persons] ) - self.box_fach.addItems(subject[1] for subject in self.db.get_subjects()) - semester = self.db.get_semester() + self.box_fach.addItems(subject[1] for subject in self.db.getSubjects()) + semester = self.db.getSemersters() self.box_erstellsemester.addItems([sem[0] for sem in semester]) self.statistics_table.setRowCount(0) #set data for table and graph in tab 2 tableWidget_3 - data = self.db.get_app_count_by_semester() + data = self.db.getApparatCountBySemester() data = c_sort.custom_sort(data) # self.tabWidget_3.clear() self.tabWidget_3.removeTab(1) @@ -716,7 +726,7 @@ class Ui(Ui_Semesterapparat): # delete all selected apparats print(selected_apparats) for apparat in selected_apparats: - self.db.delete_apparat(apparat, self.generateSemester(today=True)) + self.db.deleteApparat(apparat, self.generateSemester(today=True)) # refresh the table self.tab_changed() self.btn_del_select_apparats.setEnabled(False) @@ -729,7 +739,7 @@ class Ui(Ui_Semesterapparat): "appnr": self.box_appnrs.currentText() if self.box_appnrs.currentText() != "" else None, - "prof_id": self.db.get_prof_id(self.box_person.currentText()) + "prof_id": self.db.getProfId(self.box_person.currentText()) if self.box_person.currentText() != "" else None, "fach": self.box_fach.currentText() @@ -788,13 +798,23 @@ class Ui(Ui_Semesterapparat): def populate_frame(self, appdata: ApparatData): # populate the frame with the data from the database + ic(appdata) self.drpdwn_app_nr.setCurrentText(str(appdata.appnr)) - self.drpdwn_prof_title.setCurrentText(appdata.prof_title) - self.drpdwn_prof_name.setCurrentText(appdata.profname) + self.prof_title.setText(appdata.prof_title) + prof_name = appdata.profname.split(" ") + if len(prof_name) > 2: + fname = " ".join(prof_name[1:]) + lname = prof_name[0] + prof_name = f"{lname}, {fname}" + else: + prof_name = ", ".join(prof_name) + self.drpdwn_prof_name.setCurrentText(prof_name) self.prof_mail.setText(appdata.prof_mail) self.prof_tel_nr.setText(appdata.prof_tel) self.app_name.setText(appdata.appname) + print("changing dropdown app_fach from '' to ", appdata.app_fach) self.app_fach.setCurrentText(appdata.app_fach) + print("changed dropdown app_fach to ", self.app_fach.currentText()) if appdata.semester is not None: self.sem_sommer.setChecked( True if appdata.semester.split(" ")[0] == "SoSe" else False @@ -815,16 +835,25 @@ class Ui(Ui_Semesterapparat): self.prof_id_adis.setText(str(appdata.prof_adis_id)) self.apparat_id_adis.setText(str(appdata.apparat_adis_id)) self.frame.setEnabled(True) + self.validateLoadedData() + + def validateLoadedData(self): + self.validate_prof_mail() + self.validate_prof_name() + self.validate_prof_tel() + self.validate_app_name() + self.validate_app_fach() + self.validate_semester() def update_apparat(self): appdata = ApparatData() - appdata.app_fach = self.app_fach.text() + appdata.app_fach = self.app_fach.currentText() appdata.appname = self.app_name.text() appdata.appnr = self.active_apparat() appdata.dauerapp = self.check_eternal_app.isChecked() appdata.prof_mail = self.prof_mail.text() appdata.prof_tel = self.prof_tel_nr.text() - appdata.prof_title = self.drpdwn_prof_title.currentText() + appdata.prof_title = self.prof_title.text() appdata.profname = self.drpdwn_prof_name.currentText() appdata.semester = ( self.sem_sommer.text() + " " + self.sem_year.text() @@ -835,7 +864,7 @@ class Ui(Ui_Semesterapparat): self.add_files() appdata.apparat_adis_id = self.apparat_id_adis.text() - self.db.update_apparat(appdata) + self.db.updateApparat(appdata) self.update_app_media_list() self.cancel_active_selection.click() @@ -980,13 +1009,14 @@ class Ui(Ui_Semesterapparat): self.prof_tel_nr.clear() return selected_prof = self.drpdwn_prof_name.currentText() - data = self.db.get_prof_data(selected_prof) - prof_title = data["prof_title"] + data = self.db.getProfData(selected_prof) + ic(data) + prof_title = data[2] if prof_title == "None": prof_title = "Kein Titel" - self.drpdwn_prof_title.setCurrentText(prof_title) - self.prof_tel_nr.setText(data["prof_tel"]) - self.prof_mail.setText(data["prof_mail"]) + self.prof_title.setText(prof_title) + self.prof_tel_nr.setText(data[1]) + self.prof_mail.setText(data[0]) def get_index_of_value(self, table_widget, value): for i in range(table_widget.rowCount()): @@ -1010,21 +1040,20 @@ class Ui(Ui_Semesterapparat): self.sem_year.setEnabled(False) self.dokument_list.setRowCount(0) self.chkbx_show_del_media.setEnabled(True) - appdata = self.db.get_app_data(appnr, appname) + appdata = self.db.getApparatData(appnr, appname) self.populate_frame(appdata) self.btn_apparat_save.hide() self.btn_reserve.show() self.drpdwn_app_nr.setDisabled(True) - self.app_fach.setDisabled(True) self.update_app_media_list() self.update_documemt_list() def update_documemt_list(self): app_id = self.active_apparat() - prof_id = self.db.get_prof_id( + prof_id = self.db.getProfId( self.drpdwn_prof_name.currentText().replace(", ", " ") ) - files = self.db.get_files(app_id, prof_id) + files = self.db.getFiles(app_id, prof_id) for file in files: self.dokument_list.insertRow(0) self.dokument_list.setItem(0, 0, QtWidgets.QTableWidgetItem(file[0])) @@ -1054,7 +1083,7 @@ class Ui(Ui_Semesterapparat): self.chkbx_show_del_media.setEnabled(True) self.drpdwn_app_nr.setEnabled(True) self.app_fach.setEnabled(True) - self.app_fach.addItems([subject[1] for subject in self.db.get_subjects()]) + self.app_fach.addItems([subject[1] for subject in self.db.getSubjects()]) self.app_fach.addItem("") self.app_fach.setCurrentText("") if self.tableWidget_apparat_media.rowCount() > 0: @@ -1063,13 +1092,13 @@ class Ui(Ui_Semesterapparat): for item in self.frame.findChildren(QtWidgets.QLineEdit): item.clear() self.drpdwn_app_nr.clear() - self.drpdwn_prof_title.clear() + 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.get_apparat_nrs()] + [str(i) for i in APP_NRS if i not in self.db.getUnavailableApparatNumbers()] ) - self.drpdwn_prof_title.addItems(PROF_TITLES) + valid_input = (0, 0, 0, 0, 0, 0) self.populate_prof_dropdown() # self.horizontalLayout_6.show() @@ -1112,9 +1141,9 @@ class Ui(Ui_Semesterapparat): self.confirm_popup("Bitte mindestens ein Medium hinzufügen!") app_id = self.active_apparat() - prof_id = self.db.get_prof_id(self.drpdwn_prof_name.currentText()) + prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText()) # check if app_id is in database - if not self.db.app_exists(app_id): + if not self.db.checkApparatExists(app_id): # create apparat self.btn_save_apparat() # create a thread that updates the progress label after each medium @@ -1140,7 +1169,7 @@ class Ui(Ui_Semesterapparat): # webdata = WebRequest().get_ppn(book).get_data() # bd: BookData = BibTextTransformer(mode).get_data(webdata).return_data() # bd.signature = book - # self.db.add_medium(bookdata=bd, app_id=app_id, prof_id=prof_id) + # self.db.addBookToDatabase(bookdata=bd, app_id=app_id, prof_id=prof_id) # get all media list books @@ -1166,9 +1195,9 @@ class Ui(Ui_Semesterapparat): self.label_info.setText("Verfügbarkeit wird geprüft, bitte warten...") self.label_info.show() - books = self.db.get_media( + books = self.db.getBooks( self.active_apparat(), - self.db.get_prof_id(self.drpdwn_prof_name.currentText()), + self.db.getProfId(self.drpdwn_prof_name.currentText()), del_state=0, ) @@ -1190,14 +1219,15 @@ class Ui(Ui_Semesterapparat): self.tableWidget_apparat_media.setRowCount(0) self.dokument_list.setRowCount(0) self.frame.setEnabled(False) + self.app_fach.setCurrentText("") for child in self.frame.findChildren(QtWidgets.QLineEdit): child.clear() def update_app_media_list(self): deleted = 0 if not self.chkbx_show_del_media.isChecked() else 1 app_id = self.active_apparat() - prof_id = self.db.get_prof_id(self.drpdwn_prof_name.currentText()) - books: list[dict[int, BookData, int]] = self.db.get_media( + prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText()) + books: list[dict[int, BookData, int]] = self.db.getBooks( app_id, prof_id, deleted ) @@ -1266,12 +1296,19 @@ class Ui(Ui_Semesterapparat): self.tableWidget_apparat_media.itemClicked.connect(self.open_link) def open_link(self, item): + def __openLink(link): + if link == "": + return + if "http" not in link: + link = "https://" + link + + webbrowser.open(link) # get the name of the column columnname = self.tableWidget_apparat_media.horizontalHeaderItem( item.column() ).text() if columnname == "Link": - QtGui.QDesktopServices.openUrl(QtCore.QUrl(item.text())) + __openLink(item.text()) else: pass @@ -1282,7 +1319,7 @@ class Ui(Ui_Semesterapparat): clipboard.setText(text) def populate_prof_dropdown(self): - profs = self.db.get_profs() + profs = self.db.getProfs() # add empty entry to dropdown and set it as current self.drpdwn_prof_name.addItem("Kein Name") for prof in profs: @@ -1308,8 +1345,6 @@ class Ui(Ui_Semesterapparat): # self.db.insert_file(files, self.active_apparat(), self.db.get_prof_id(self.drpdwn_prof_name.currentText())) def open_document(self): - print("trying to open document:") - _selected_doc_name = "" _selected_doc_filetype = "" try: @@ -1325,8 +1360,8 @@ class Ui(Ui_Semesterapparat): except AttributeError: self.confirm_popup("Bitte erst ein Dokument auswählen!") return - print(_selected_doc_name, _selected_doc_filetype) if not _selected_doc_location == "Database": + print("not in database") path = Path(_selected_doc_location) path = path + "/" + _selected_doc_name if os.getenv("OS") == "Windows_NT": @@ -1336,31 +1371,19 @@ class Ui(Ui_Semesterapparat): path = path.resolve() os.system(f"open {path}") else: + print("in database") try: - self.db.recreate_file(_selected_doc_name, self.active_apparat()) + file_loc = self.db.recreateFile(_selected_doc_name, "71",filetype=_selected_doc_filetype) + print(f"filename is {file_loc}") except Exception as e: - self.logger.log_exception(e) - path = config.save_path + _selected_doc_name - # if ~ in path, replace it with the home directory - if "~" in path: - path = path.replace("~", str(Path.home())) - path = Path(path) - if os.getenv("OS") == "Windows_NT": - path = path.resolve() - os.startfile(path) - else: - path = path.resolve() - os.system(f"open {path}") - # filebytes = self.db.get_blob( - # _selected_doc_name, - # self.active_apparat(), - # ) - # # use io.BytesIO to create a file-like object from the bytes and open it in the respective program - # file = io.BytesIO(filebytes) - # file.name = _selected_doc_name - - # QtGui.QDesktopServices.openUrl(QtCore.QUrl(file)) - # print(type(filebytes)) + print(e) + path = Path(file_loc) + if os.getenv("OS") == "Windows_NT": + path = path.resolve() + os.startfile(path) + else: + path = path.resolve() + os.system(f"open {path}") def add_media_from_file(self): def __open_dialog(signatures): @@ -1408,7 +1431,7 @@ class Ui(Ui_Semesterapparat): delete=False, suffix="." + file_type ) temp_file.write( - self.db.get_blob(file_name, int(self.active_apparat())) + self.db.getBlob(file_name, int(self.active_apparat())) ) temp_file.close() file = temp_file.name @@ -1418,20 +1441,20 @@ class Ui(Ui_Semesterapparat): self.confirm_popup("PDF Dateien werden nochnicht unterstützt!") return if file_type == "csv": - signatures = utils.csv_to_list(file) + signatures = csv_to_list(file) data = __open_dialog(signatures) # get the app_id and prof_id app_id = self.active_apparat() - prof_id = self.db.get_prof_id(self.drpdwn_prof_name.currentText()) + prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText()) # add the data to the database for book in data: if type(book) != BookData: continue - self.db.add_medium( + self.db.addBookToDatabase( bookdata=book, app_id=app_id, prof_id=prof_id ) if file_type == "docx": - data = utils.word_docx_to_csv(file) + data = word_docx_to_csv(file) signatures = [ i for i in data["Standnummer"].values @@ -1443,12 +1466,12 @@ class Ui(Ui_Semesterapparat): return # get the app_id and prof_id app_id = self.active_apparat() - prof_id = self.db.get_prof_id(self.drpdwn_prof_name.currentText()) + prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText()) # add the data to the database for book in data: if type(book) != BookData: continue - self.db.add_medium( + self.db.addBookToDatabase( bookdata=book, app_id=app_id, prof_id=prof_id ) self.update_app_media_list() @@ -1461,9 +1484,9 @@ class Ui(Ui_Semesterapparat): "Bitte warten, bis alle Medien hinzugefügt wurden" ) app_id = self.active_apparat() - prof_id = self.db.get_prof_id(self.drpdwn_prof_name.currentText()) + prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText()) # check if apparat in database - if not self.db.app_exists(app_id): + if not app_id in self.db.getUnavailableApparatNumbers(): # create apparat self.btn_save_apparat() if self.dokument_list.rowCount() == 0: @@ -1490,13 +1513,13 @@ class Ui(Ui_Semesterapparat): temp_file = tempfile.NamedTemporaryFile( delete=False, suffix="." + file_type ) - temp_file.write(self.db.get_blob(file_name, int(self.active_apparat()))) + temp_file.write(self.db.getBlob(file_name, int(self.active_apparat()))) temp_file.close() file = temp_file.name print(file) if file_type == "pdf": # Todo: implement parser here - self.confirm_popup("PDF Dateien werden nochnicht unterstützt!") + self.confirm_popup("PDF Dateien werden noch nicht unterstützt!") return if file_type == "csv": signatures = csv_to_list(file) @@ -1535,12 +1558,12 @@ class Ui(Ui_Semesterapparat): def btn_save_apparat(self): def __clear_fields(): self.drpdwn_app_nr.clear() - self.drpdwn_prof_title.clear() + self.prof_title.clear() self.drpdwn_prof_name.clearMask() self.app_name.clear() self.prof_mail.clear() self.prof_tel_nr.clear() - self.app_fach.clear() + self.app_fach.setCurrentText("") self.app_name.clear() self.sem_year.clear() self.dokument_list.setRowCount(0) @@ -1561,8 +1584,8 @@ class Ui(Ui_Semesterapparat): appd.appnr = self.active_apparat() appd.prof_title = ( None - if self.drpdwn_prof_title.currentText() == "Kein Titel" - else self.drpdwn_prof_title.currentText() + if self.prof_title.text() == "" + else self.prof_title.text() ) appd.profname = self.drpdwn_prof_name.currentText() appd.appname = self.app_name.text() @@ -1570,35 +1593,37 @@ class Ui(Ui_Semesterapparat): appd.dauerapp = 1 if self.check_eternal_app.isChecked() else 0 appd.prof_tel = self.prof_tel_nr.text() appd.prof_mail = self.prof_mail.text() - app_fach = self.app_fach.currentText() - curr_fach_alias = self.db.get_subjects_and_aliases() - for fach in curr_fach_alias: - if app_fach in fach: - appd.app_fach = app_fach - break - else: - #create a popup to ask for the correct subject - dialog = QtWidgets.QDialog() - popup = new_subject_ui() - popup.setupUi(dialog) - new_subject = popup.return_state() - dialog.exec() - if dialog.result() == QtWidgets.QDialog.DialogCode.Accepted: - appd.app_fach = new_subject - self.db.add_subject(new_subject) - else: - return + appd.app_fach = self.app_fach.currentText() + appd.erstellsemester = self.generateSemester() + # curr_fach_alias = self.db.get_subjects_and_aliases() + # for fach in curr_fach_alias: + # if app_fach in fach: + # appd.app_fach = app_fach + # break + # else: + # #create a popup to ask for the correct subject + # dialog = QtWidgets.QDialog() + # popup = new_subject_ui() + # popup.setupUi(dialog) + # new_subject = popup.return_state() + # dialog.exec() + # if dialog.result() == QtWidgets.QDialog.DialogCode.Accepted: + # appd.app_fach = new_subject + # self.db.add_subject(new_subject) + # else: + # return appd.deleted = 0 appd.prof_adis_id = self.prof_id_adis.text() appd.apparat_adis_id = self.apparat_id_adis.text() - self.add_files() - if not self.validate_fields(): - pass - self.db.create_apparat(appd) if self.dokument_list.rowCount() > 0: self.add_files() - appdata = self.db.get_apparats() + if not self.validate_fields(): + pass + self.db.createApparat(appd) + if self.dokument_list.rowCount() > 0: + self.add_files() + appdata = self.db.getAllAparats() # merge self.appdata and appdata, remove duplicates self.apparats = list(set(self.apparats + appdata)) self.apparats = natsorted(self.apparats, key=lambda x: x[4], reverse=True) @@ -1623,7 +1648,7 @@ class Ui(Ui_Semesterapparat): } ) self.dokument_list.item(i, 2).setText("") - self.db.insert_file(files, self.active_apparat(), self.db.get_prof_id(self.drpdwn_prof_name.currentText())) + self.db.insertFile(files, self.active_apparat(), self.db.getProfId(self.drpdwn_prof_name.currentText())) def update_apparat_list(self): # get a list of new apparats based on self.apparats and self.old_apparats @@ -1640,7 +1665,7 @@ class Ui(Ui_Semesterapparat): def insert_apparat_into_table(self, apparat): def __dauer_check(apparat): - result = self.db.is_eternal(apparat[0]) + result = self.db.isEternal(apparat[0]) return "Ja" if result == ("True" or "1") else "Nein" self.tableWidget_apparate.insertRow(0) @@ -1654,7 +1679,7 @@ class Ui(Ui_Semesterapparat): 0, 2, QtWidgets.QTableWidgetItem( - self.db.get_prof_name_by_id(apparat[2], add_title=False) + self.db.getProfNameById(apparat[2], add_title=False) ), ) self.tableWidget_apparate.setItem( @@ -1668,10 +1693,18 @@ class Ui(Ui_Semesterapparat): 0, 4, QtWidgets.QTableWidgetItem(__dauer_check(apparat)) ) self.tableWidget_apparate.setItem( - 0, 5, QtWidgets.QTableWidgetItem(str(apparat[13])) + 0, 5, QtWidgets.QTableWidgetItem(str(apparat[11])) ) self.logger.log_info(f"Inserted apparat {apparat[4]}") + def calendar_context_menu(self): + #create a context menu for the calendar + menu = QtWidgets.QMenu() + create_reminder = menu.addAction("Erinnerung erstellen") + create_reminder.triggered.connect(self.reminder(date=self.calendarWidget.selectedDate().toString("yyyy-MM-dd"))) + menu.exec(QtGui.QCursor.pos()) + return menu + def open_context_menu(self, position): menu = QtWidgets.QMenu() extend_action = menu.addAction("Verlängern") @@ -1687,6 +1720,7 @@ class Ui(Ui_Semesterapparat): menu.exec(self.tableWidget_apparate.mapToGlobal(position)) def reminder(self): + self.logger.log_info("Opening reminder dialog") dialog = QtWidgets.QDialog() reminder = reminder_ui() reminder.setupUi(dialog) @@ -1694,7 +1728,7 @@ class Ui(Ui_Semesterapparat): if dialog.result() == QtWidgets.QDialog.DialogCode.Accepted: data = reminder.return_message() print(data) - self.db.add_message( + self.db.addMessage( data, self.active_user, self.active_apparat if self.active_apparat() != "" else None, @@ -1707,7 +1741,7 @@ class Ui(Ui_Semesterapparat): # self.update_app_media_list() def get_reminders(self): - messages = self.db.get_messages() + messages = self.db.getMessages() self.logger.log_info(f"Got {len(messages)} messages from database") self.calendarWidget.setMessages(messages) self.calendarWidget.updateCells() @@ -1722,12 +1756,12 @@ class Ui(Ui_Semesterapparat): return self.message_box.setText(message["message"]) self.line_app_info.setText( - message["apparatnr"] if message["apparatnr"] != None else "/" + message["appnr"] if message["appnr"] != None else "/" ) def __delete_message(): message = messages[self.spin_select_message.value() - 1] - self.db.delete_message(message["id"]) + self.db.deleteMessage(message["id"]) # remove message from list messages.remove(message) self.spin_select_message.setMaximum(len(messages)) @@ -1736,7 +1770,7 @@ class Ui(Ui_Semesterapparat): selected_date = self.calendarWidget.selectedDate().toString("yyyy-MM-dd") print(selected_date) - messages = self.db.get_messages(selected_date) + messages = self.db.getMessages(selected_date) if messages == []: self.message_frame.hide() if self.message_frame.isVisible() else None return @@ -1773,7 +1807,7 @@ class Ui(Ui_Semesterapparat): def reload(self): #create a new connection to the database, refresh table data and replace the old connection self.db = Database() - self.apparats = self.db.get_all_apparts(deleted=0) + self.apparats = self.db.getAllAparats(deleted=0) self.apparats = natsorted(self.apparats, key=lambda x: x[4], reverse=True) self.tableWidget_apparate.setRowCount(0) for apparat in self.apparats: @@ -1793,12 +1827,12 @@ class Ui(Ui_Semesterapparat): book = self.tableWidget_apparat_media.item( self.tableWidget_apparat_media.currentRow(), 1 ).text() - book_id = self.db.request_medium( + book_id = self.db.getBookIdBasedOnSignature( app_id=self.active_apparat(), signature=book, - prof_id=self.db.get_prof_id(self.drpdwn_prof_name.currentText()), + prof_id=self.db.getProfId(self.drpdwn_prof_name.currentText()), ) - data = self.db.get_specific_book(book_id) + data = self.db.getBook(book_id) widget = QtWidgets.QDialog() bookedit = edit_bookdata_ui() bookedit.setupUi(widget) @@ -1809,7 +1843,7 @@ class Ui(Ui_Semesterapparat): if widget.result() == QtWidgets.QDialog.DialogCode.Accepted: data = bookedit.get_data() print(data) - self.db.update_bookdata(data, book_id) + self.db.updateBookdata(data, book_id) # self.db.update_bookdata(data) print("accepted") self.update_app_media_list() @@ -1824,17 +1858,17 @@ class Ui(Ui_Semesterapparat): signature = self.tableWidget_apparat_media.item( self.tableWidget_apparat_media.currentRow(), 1 ).text() - # bookdata= self.db.request_medium(selected_apparat_id,prof_id=self.db.get_prof_id(self.drpdwn_prof_name.currentText()),signature=signature) - book_id = self.db.request_medium( + # bookdata= self.db.getBookIdBasedOnSignature(selected_apparat_id,prof_id=self.db.get_prof_id(self.drpdwn_prof_name.currentText()),signature=signature) + book_id = self.db.getBookIdBasedOnSignature( selected_apparat_id, - prof_id=self.db.get_prof_id(self.drpdwn_prof_name.currentText()), + prof_id=self.db.getProfId(self.drpdwn_prof_name.currentText()), signature=signature, ) 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) print(state) if state == 1: - self.db.delete_medium(book_id) + self.db.deleteBook(book_id) self.update_app_media_list() pass @@ -1862,7 +1896,7 @@ class Ui(Ui_Semesterapparat): # apparat[7]=data["dauerapp"] # break # self.old_apparats = self.apparats - self.db.set_new_sem_date( + self.db.setNewSemesterDate( selected_apparat_id, data["semester"], dauerapp=data["dauerapp"] ) else: @@ -1881,13 +1915,13 @@ class Ui(Ui_Semesterapparat): ).text() general_data = { "Appname": self.app_name.text(), - "AppSubject": self.app_fach.text(), + "AppSubject": self.app_fach.currentText(), "appnr": active_apparat_id, } print(active_apparat_id) mail_prev.appid = active_apparat_id - base_data = self.db.get_prof_data(id=active_apparat_id) - profname = self.db.get_prof_name_by_id(base_data["id"]) + base_data = self.db.getProfData(id=active_apparat_id) + profname = self.db.getProfNameById(base_data["id"]) profname = profname.split(" ") profname = f"{profname[1]} {profname[0]}" pass_data = { @@ -1908,7 +1942,7 @@ class Ui(Ui_Semesterapparat): state = self.confirm_popup(message) print(state) if state == 1: - self.db.delete_apparat( + self.db.deleteApparat( selected_apparat_id, self.generateSemester(today=True) ) # delete the corresponding entry from self.apparats diff --git a/src/ui/Ui_semesterapparat_ui.py b/src/ui/Ui_semesterapparat_ui.py index 8115464..c74ab85 100644 --- a/src/ui/Ui_semesterapparat_ui.py +++ b/src/ui/Ui_semesterapparat_ui.py @@ -1,4 +1,4 @@ -# Form implementation generated from reading ui file 'c:\Users\aky547\GitHub\Semesterapparate-refactor\src\ui\semesterapparat_ui.ui' +# Form implementation generated from reading ui file 'c:\Users\aky547\GitHub\SemesterapparatsManager\src\ui\semesterapparat_ui.ui' # # Created by: PyQt6 UI code generator 6.3.1 # @@ -183,15 +183,6 @@ class Ui_MainWindow(object): self.frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.frame.setObjectName("frame") - self.drpdwn_prof_title = QtWidgets.QComboBox(self.frame) - self.drpdwn_prof_title.setGeometry(QtCore.QRect(110, 50, 69, 22)) - font = QtGui.QFont() - font.setPointSize(9) - font.setBold(False) - font.setWeight(50) - self.drpdwn_prof_title.setFont(font) - self.drpdwn_prof_title.setEditable(True) - self.drpdwn_prof_title.setObjectName("drpdwn_prof_title") self.label_5 = QtWidgets.QLabel(self.frame) self.label_5.setGeometry(QtCore.QRect(250, 20, 91, 21)) font = QtGui.QFont() @@ -487,12 +478,27 @@ class Ui_MainWindow(object): self.gridLayout_6.setContentsMargins(0, 0, 0, 0) self.gridLayout_6.setObjectName("gridLayout_6") self.app_fach = QtWidgets.QComboBox(self.gridLayoutWidget_5) + self.app_fach.setMaximumSize(QtCore.QSize(16777215, 20)) + font = QtGui.QFont() + font.setPointSize(9) + font.setBold(False) + font.setWeight(50) + self.app_fach.setFont(font) self.app_fach.setObjectName("app_fach") self.gridLayout_6.addWidget(self.app_fach, 0, 0, 1, 1) spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) self.gridLayout_6.addItem(spacerItem2, 0, 1, 1, 1) + self.prof_title = QtWidgets.QLineEdit(self.frame) + self.prof_title.setGeometry(QtCore.QRect(110, 50, 71, 20)) + font = QtGui.QFont() + font.setPointSize(9) + font.setBold(False) + font.setWeight(50) + self.prof_title.setFont(font) + self.prof_title.setFocusPolicy(QtCore.Qt.FocusPolicy.StrongFocus) + self.prof_title.setObjectName("prof_title") + self.mail_mand.raise_() self._mand.raise_() - self.drpdwn_prof_title.raise_() self.label_5.raise_() self.sem_winter.raise_() self.label_4.raise_() @@ -508,7 +514,6 @@ class Ui_MainWindow(object): self.label_8.raise_() self.label_9.raise_() self.label_10.raise_() - self.mail_mand.raise_() self.telnr_mand.raise_() self.profname_mand.raise_() self.appname_mand.raise_() @@ -523,6 +528,7 @@ class Ui_MainWindow(object): self.formLayoutWidget_2.raise_() self.check_send_mail.raise_() self.frame_3.raise_() + self.prof_title.raise_() self.frame.raise_() self.dokument_list.raise_() self.gridLayout_2.addWidget(self.app_group_box, 1, 0, 1, 1) @@ -729,8 +735,6 @@ class Ui_MainWindow(object): self.stackedWidget_4.setObjectName("stackedWidget_4") self.stackedWidget_4Page1 = QtWidgets.QWidget() self.stackedWidget_4Page1.setObjectName("stackedWidget_4Page1") - #set focus to page 1 - self.stackedWidget_4.setCurrentIndex(0) self.tabWidget_3 = QtWidgets.QTabWidget(self.stackedWidget_4Page1) self.tabWidget_3.setGeometry(QtCore.QRect(780, 10, 441, 441)) self.tabWidget_3.setObjectName("tabWidget_3") @@ -954,7 +958,7 @@ class Ui_MainWindow(object): spacerItem14 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum) self.gridLayout_11.addItem(spacerItem14, 0, 4, 1, 1) self.edit_faculty_member = QtWidgets.QFrame(self.tab_5) - self.edit_faculty_member.setGeometry(QtCore.QRect(10, 60, 1051, 191)) + self.edit_faculty_member.setGeometry(QtCore.QRect(10, 60, 1051, 241)) self.edit_faculty_member.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel) self.edit_faculty_member.setFrameShadow(QtWidgets.QFrame.Shadow.Raised) self.edit_faculty_member.setObjectName("edit_faculty_member") @@ -970,6 +974,7 @@ class Ui_MainWindow(object): self.label_43.setObjectName("label_43") self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_43) self.edit_faculty_member_new_title = QtWidgets.QComboBox(self.gridLayoutWidget_11) + self.edit_faculty_member_new_title.setEditable(True) self.edit_faculty_member_new_title.setObjectName("edit_faculty_member_new_title") self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.edit_faculty_member_new_title) self.label_44 = QtWidgets.QLabel(self.gridLayoutWidget_11) @@ -1021,12 +1026,12 @@ class Ui_MainWindow(object): self.label_48 = QtWidgets.QLabel(self.gridLayoutWidget_11) self.label_48.setObjectName("label_48") self.formLayout_5.setWidget(1, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_48) - self.lineEdit = QtWidgets.QLineEdit(self.gridLayoutWidget_11) - self.lineEdit.setObjectName("lineEdit") - self.formLayout_5.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit) - self.lineEdit_5 = QtWidgets.QLineEdit(self.gridLayoutWidget_11) - self.lineEdit_5.setObjectName("lineEdit_5") - self.formLayout_5.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit_5) + self.user_faculty_member_new_mail = QtWidgets.QLineEdit(self.gridLayoutWidget_11) + self.user_faculty_member_new_mail.setObjectName("user_faculty_member_new_mail") + self.formLayout_5.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.user_faculty_member_new_mail) + self.user_faculty_member_new_telnr = QtWidgets.QLineEdit(self.gridLayoutWidget_11) + self.user_faculty_member_new_telnr.setObjectName("user_faculty_member_new_telnr") + self.formLayout_5.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.user_faculty_member_new_telnr) self.gridLayout_12.addLayout(self.formLayout_5, 2, 4, 1, 1) self.label_41 = QtWidgets.QLabel(self.gridLayoutWidget_11) self.label_41.setObjectName("label_41") @@ -1150,7 +1155,7 @@ class Ui_MainWindow(object): self.btn_copy_adis_command.setAccessibleDescription("") self.btn_copy_adis_command.setAutoFillBackground(False) icon = QtGui.QIcon() - icon.addPixmap(QtGui.QPixmap("c:\\Users\\aky547\\GitHub\\Semesterapparate-refactor\\src\\ui\\../../../.designer/backup/icons/information.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) + icon.addPixmap(QtGui.QPixmap("c:\\Users\\aky547\\GitHub\\SemesterapparatsManager\\src\\ui\\../../../.designer/backup/icons/information.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off) self.btn_copy_adis_command.setIcon(icon) self.btn_copy_adis_command.setCheckable(False) self.btn_copy_adis_command.setChecked(False) @@ -1226,8 +1231,7 @@ class Ui_MainWindow(object): self.stackedWidget_4.setCurrentIndex(1) self.tabWidget_3.setCurrentIndex(1) QtCore.QMetaObject.connectSlotsByName(MainWindow) - MainWindow.setTabOrder(self.drpdwn_app_nr, self.drpdwn_prof_title) - MainWindow.setTabOrder(self.drpdwn_prof_title, self.drpdwn_prof_name) + MainWindow.setTabOrder(self.drpdwn_app_nr, self.drpdwn_prof_name) MainWindow.setTabOrder(self.drpdwn_prof_name, self.prof_mail) MainWindow.setTabOrder(self.prof_mail, self.prof_tel_nr) MainWindow.setTabOrder(self.prof_tel_nr, self.app_name) @@ -1265,9 +1269,9 @@ class Ui_MainWindow(object): MainWindow.setTabOrder(self.faculty_member_oldmail, self.edit_faculty_member_new_title) MainWindow.setTabOrder(self.edit_faculty_member_new_title, self.edit_faculty_member_new_surname) MainWindow.setTabOrder(self.edit_faculty_member_new_surname, self.user_faculty_member_new_name) - MainWindow.setTabOrder(self.user_faculty_member_new_name, self.lineEdit) - MainWindow.setTabOrder(self.lineEdit, self.lineEdit_5) - MainWindow.setTabOrder(self.lineEdit_5, self.update_faculty_member) + MainWindow.setTabOrder(self.user_faculty_member_new_name, self.user_faculty_member_new_mail) + MainWindow.setTabOrder(self.user_faculty_member_new_mail, self.user_faculty_member_new_telnr) + MainWindow.setTabOrder(self.user_faculty_member_new_telnr, self.update_faculty_member) MainWindow.setTabOrder(self.update_faculty_member, self.box_fach) MainWindow.setTabOrder(self.box_fach, self.box_person) MainWindow.setTabOrder(self.box_person, self.btn_search) diff --git a/src/ui/dialogs/Ui_login.py b/src/ui/dialogs/Ui_login.py index 1c1190d..3e570af 100644 --- a/src/ui/dialogs/Ui_login.py +++ b/src/ui/dialogs/Ui_login.py @@ -71,7 +71,7 @@ class Ui_Dialog(object): hashed_password = hashlib.sha256( password.encode() ).hexdigest() - if len(db.get_users()) == 0: + if len(db.getUsers()) == 0: AdminCommands().create_admin() self.lresult = 1 # Indicate successful login self.lusername = username @@ -80,7 +80,6 @@ class Ui_Dialog(object): self.lresult = 1 # Indicate successful login self.lusername = username self.dialog.accept() - db.close() else: # Credentials are invalid, display a warning if username == "" or password == "": diff --git a/src/ui/semesterapparat_ui.ui b/src/ui/semesterapparat_ui.ui index 1cf7452..3ded8b1 100644 --- a/src/ui/semesterapparat_ui.ui +++ b/src/ui/semesterapparat_ui.ui @@ -376,26 +376,6 @@ QFrame::Raised - - - - 110 - 50 - 69 - 22 - - - - - 9 - 50 - false - - - - true - - @@ -1099,7 +1079,21 @@ - + + + + 16777215 + 20 + + + + + 9 + 50 + false + + + @@ -1117,8 +1111,28 @@ + + + + 110 + 50 + 71 + 20 + + + + + 9 + 50 + false + + + + Qt::StrongFocus + + + mail_mand _mand - drpdwn_prof_title label_5 sem_winter label_4 @@ -1134,7 +1148,6 @@ label_8 label_9 label_10 - mail_mand telnr_mand profname_mand appname_mand @@ -1149,6 +1162,7 @@ formLayoutWidget_2 check_send_mail frame_3 + prof_title frame dokument_list @@ -2230,7 +2244,7 @@ 10 60 1051 - 191 + 241 @@ -2259,7 +2273,11 @@ - + + + true + + @@ -2354,10 +2372,10 @@ - + - + @@ -2832,7 +2850,6 @@ drpdwn_app_nr - drpdwn_prof_title drpdwn_prof_name prof_mail prof_tel_nr @@ -2871,8 +2888,8 @@ edit_faculty_member_new_title edit_faculty_member_new_surname user_faculty_member_new_name - lineEdit - lineEdit_5 + user_faculty_member_new_mail + user_faculty_member_new_telnr update_faculty_member box_fach box_person diff --git a/src/ui/widgets/Ui_message_widget.py b/src/ui/widgets/Ui_message_widget.py index b78daac..c2e9f60 100644 --- a/src/ui/widgets/Ui_message_widget.py +++ b/src/ui/widgets/Ui_message_widget.py @@ -64,4 +64,4 @@ class Ui_Form(object): def delete_message(self): db = Database() print("deleting message") - db.delete_message(self.hidden_id.text()) + db.deleteMessage(self.hidden_id.text())