diff --git a/src/ui/userInterface.py b/src/ui/userInterface.py index 7dcdc5b..2faa3d5 100644 --- a/src/ui/userInterface.py +++ b/src/ui/userInterface.py @@ -53,8 +53,6 @@ from src.ui import ( EditProf ) - - valid_input = (0, 0, 0, 0, 0, 0) @@ -99,6 +97,7 @@ class Ui(Ui_Semesterapparat): QtWidgets.QHeaderView.ResizeMode.Stretch ) self.tableWidget_apparate.setSortingEnabled(True) + self.saveandcreate.hide() # Actions self.actionEinstellungen.triggered.connect(self.open_settings) @@ -179,15 +178,10 @@ class Ui(Ui_Semesterapparat): self.line_3.hide() self.avail_status.hide() self.chkbx_show_del_media.hide() - self.groupBox_2.hide() - self.groupBox.hide() # self.btn_del_select_apparats.setEnabled(False) self.tabWidget.currentChanged.connect(self.tabW1_changed) - - - # create a thread, that continually checks the validity of the inputs self.validate_thread = QThread() self.validate_thread.started.connect(self.thread_check) @@ -201,7 +195,6 @@ class Ui(Ui_Semesterapparat): # if length of apparats changes, update box_apparats # if tab is changed, gather data needed - # Context Menus self.tableWidget_apparate.setContextMenuPolicy( QtCore.Qt.ContextMenuPolicy.CustomContextMenu @@ -215,7 +208,6 @@ class Ui(Ui_Semesterapparat): self.tableWidget_apparat_media.customContextMenuRequested.connect( self.media_context_menu ) - # admin buttons self.select_action_box.currentTextChanged.connect(self.adminActions) @@ -223,31 +215,38 @@ class Ui(Ui_Semesterapparat): self.select_action_box.setCurrentText("") self.admin_action.setLayout(QtWidgets.QVBoxLayout()) self.admin_action.setTitle("") - + # Create instances to be used by the threads in the application self.bookGrabber = [] self.availChecker = None self.mail_thread = None self.autoGrabber = None - + self.elsatab.setLayout(QtWidgets.QVBoxLayout()) self.search_statistics.setLayout(QtWidgets.QVBoxLayout()) - #once inputSignal emits, check state + # once inputSignal emits, check state + + self.steps.hide() + def checkValidInput(self): if valid_input == (1, 1, 1, 1, 1, 1): self.check_file.setEnabled(True) else: self.check_file.setEnabled(False) + def setWidget(self, widget): - #remove all widgets from localwidget - + # remove all widgets from localwidget + self.hideWidget() - #add widget to localwidget + # add widget to localwidget self.admin_action.layout().addWidget(widget) - + def hideWidget(self): try: - widgets = [self.admin_action.layout().itemAt(i).widget() for i in range(self.admin_action.layout().count())] + widgets = [ + self.admin_action.layout().itemAt(i).widget() + for i in range(self.admin_action.layout().count()) + ] except AttributeError: return for widget in widgets: @@ -280,7 +279,7 @@ class Ui(Ui_Semesterapparat): # delete all temporary files tempdelete() sys.exit() - + def get_apparats(self): alist = self.db.getAllAparats(deleted=0) alist = natsorted(alist, key=lambda x: x[4], reverse=True) @@ -307,13 +306,15 @@ class Ui(Ui_Semesterapparat): stats_layout = self.search_statistics.layout() if stats_layout is not None: # delete tabpage, re-add with same name at same position - for widget in [stats_layout.itemAt(i).widget() for i in range(stats_layout.count())]: + for widget in [ + stats_layout.itemAt(i).widget() for i in range(stats_layout.count()) + ]: stats_layout.removeWidget(widget) widget.deleteLater() statistics = SearchStatisticPage() statistics.apparat_open.connect(self.open_apparat) statistics.refreshSignal.connect(self.update_apparat_list) - + stats_layout.addWidget(statistics) # print("searchpage") @@ -325,12 +326,14 @@ class Ui(Ui_Semesterapparat): elsa_layout = self.elsatab.layout() if elsa_layout is not None: # delete tabpage, re-add with same name at same position - widgets = [self.elsatab.layout().itemAt(i).widget() for i in range(self.elsatab.layout().count())] + widgets = [ + self.elsatab.layout().itemAt(i).widget() + for i in range(self.elsatab.layout().count()) + ] for widget in widgets: self.elsatab.layout().removeWidget(widget) widget.deleteLater() - - + elsa_layout.addWidget(ElsaDialog()) print("added") pass @@ -405,8 +408,6 @@ 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.app_group_box.setEnabled(True) - self.groupBox_2.hide() - self.groupBox.hide() self.validateLoadedData() def validateLoadedData(self): @@ -445,7 +446,7 @@ class Ui(Ui_Semesterapparat): self.chkbx_show_del_media.show() self.cancel_active_selection.setEnabled(False) self.add_medium.setEnabled(False) - #update apparat table + # update apparat table self.get_apparats() def confirm_popup(self, message: str, title: str): @@ -542,7 +543,7 @@ class Ui(Ui_Semesterapparat): valid_input = list(valid_input) valid_input[index] = state valid_input = tuple(valid_input) - self.checkValidInput() + self.checkValidInput() def set_state(self): # set state of semester and year @@ -609,8 +610,6 @@ class Ui(Ui_Semesterapparat): self.btn_apparat_save.hide() self.btn_reserve.show() self.chkbx_show_del_media.show() - self.groupBox_2.show() - self.groupBox.show() self.drpdwn_app_nr.setDisabled(True) self.update_app_media_list() @@ -620,7 +619,7 @@ class Ui(Ui_Semesterapparat): def update_documemt_list(self): app_id = self.active_apparat prof_id = self.db.getProfByName( - self.drpdwn_prof_name.currentText().replace(",","") + self.drpdwn_prof_name.currentText().replace(",", "") ).id files = self.db.getFiles(app_id, prof_id) for file in files: @@ -632,10 +631,8 @@ class Ui(Ui_Semesterapparat): self.dokument_list.item(0, 0).setToolTip(file[0]) def btn_create_new_apparat(self): - self.frame_creation_progress.show() - self.groupBox.show() - self.groupBox_2.show() global valid_input + self.steps.show() # *create a new apparat self.btn_apparat_save.show() if self.btn_apparat_save.isHidden() else None # clear dokumemt_list @@ -687,6 +684,8 @@ class Ui(Ui_Semesterapparat): media.exec() mode = media.mode data = media.data + use_any = media.use_any + use_exact = media.use_exact result = media.result() if result == 1: @@ -710,7 +709,14 @@ class Ui(Ui_Semesterapparat): # self.bookGrabber = None bookGrabber = BookGrabber(self.active_apparat) - bookGrabber.add_values(mode=mode, prof_id=prof_id, app_id=app_id, data=data) + bookGrabber.add_values( + mode=mode, + prof_id=prof_id, + app_id=app_id, + data=data, + any_book=use_any, + exact=use_exact, + ) bookGrabber.finished.connect(self.hide_progress_label) bookGrabber.finished.connect(self.update_app_media_list) bookGrabber.updateSignal.connect(self.update_progress_label) @@ -779,6 +785,7 @@ class Ui(Ui_Semesterapparat): # self.grabbers.append(availcheck) def btn_cancel_active_selection(self): + self.steps.hide() # clear the rows of the table self.tableWidget_apparat_media.setRowCount(0) self.dokument_list.setRowCount(0) @@ -787,8 +794,6 @@ class Ui(Ui_Semesterapparat): self.chkbx_show_del_media.hide() self.check_send_mail.hide() self.btn_reserve.hide() - self.groupBox_2.hide() - self.groupBox.hide() self.check_eternal_app.setEnabled(False) # set all radio buttons to unchecked self.sem_sommer.setChecked(False) @@ -965,6 +970,7 @@ class Ui(Ui_Semesterapparat): def add_media_from_file(self): app_id = self.active_apparat prof_id = self.db.getProfId(self.profdata) + def __open_dialog(signatures): dialog = QtWidgets.QDialog() frame = parsed_titles_ui() @@ -1059,7 +1065,7 @@ class Ui(Ui_Semesterapparat): app_id = self.active_apparat ic(self.profdata) prof_id = self.db.getProfId(self.profdata) - + ic(prof_id) # check if apparat in database @@ -1117,7 +1123,7 @@ class Ui(Ui_Semesterapparat): # print("starting thread") if prof_id is None: prof_id = self.db.getProfId(self.profdata) - + print("Prof ID is None", prof_id) autoGrabber = BookGrabber(self.active_apparat) autoGrabber.add_values( @@ -1167,14 +1173,12 @@ class Ui(Ui_Semesterapparat): self.drpdwn_prof_name.clear() self.tableWidget_apparat_media.setRowCount(0) self.app_group_box.setEnabled(False) - self.groupBox_2.hide() - self.groupBox.hide() self.check_send_mail.setChecked(False) self.cancel_active_selection.setEnabled(False) - #check if sem_sommer, sem_winter and check_eternal_app are checked. if yes, set them to unchecked - - + # check if sem_sommer, sem_winter and check_eternal_app are checked. if yes, set them to unchecked + def btn_save_apparat(self, clear_fields=True): + self.steps.hide() if not self.validate_fields(): self.confirm_popup("Bitte alle Pflichtfelder ausfüllen!", title="Fehler") return False @@ -1194,7 +1198,7 @@ class Ui(Ui_Semesterapparat): appd.deleted = 0 appd.prof_adis_id = self.prof_id_adis.text() appd.apparat_adis_id = self.apparat_id_adis.text() - + error = self.db.createApparat(appd) if self.dokument_list.rowCount() > 0: @@ -1206,6 +1210,7 @@ class Ui(Ui_Semesterapparat): # 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) + self.update_apparat_list() # self.btn_load_apparat() @@ -1405,12 +1410,26 @@ class Ui(Ui_Semesterapparat): menu = QtWidgets.QMenu() delete_action = menu.addAction("Löschen") edit_action = menu.addAction("Bearbeiten") + apparat_add_action = menu.addAction("Zum Apparat hinzufügen") menu.addAction(delete_action) menu.addAction(edit_action) + menu.addAction(apparat_add_action) delete_action.triggered.connect(self.delete_medium) edit_action.triggered.connect(self.edit_medium) + apparat_add_action.triggered.connect(self.add_to_apparat) menu.exec(self.tableWidget_apparat_media.mapToGlobal(position)) + def add_to_apparat(self): + """use playwright in background to add medium to apparat""" + signature = self.tableWidget_apparat_media.item( + self.tableWidget_apparat_media.currentRow(), 1 + ).text() + medium = self.db.getBookBasedOnSignature( + self.drpdwn_app_nr.currentText(), + signature=signature, + prof_id=self.db.getProfId(self.profdata), + ) + print(medium.adis_idn, medium.signature) def edit_medium(self): book = self.tableWidget_apparat_media.item( self.tableWidget_apparat_media.currentRow(), 1 @@ -1629,12 +1648,6 @@ def launch_gui(): warning_dialog.setText("Invalid username or password. Please try again.") warning_dialog.setWindowTitle("Login Failed") warning_dialog.exec() - elif ui.lresult == 2: - # TODO: implement admin functionality here - """change passwords for apparats, change passwords for users, list users, create and delete users etc""" - # open a console window - # console = "" - # print("admin") atexit.register(tempdelete)