format code
This commit is contained in:
@@ -22,10 +22,12 @@ from .reportUi import ReportUi
|
||||
backup = Backup()
|
||||
cat = Catalogue()
|
||||
|
||||
|
||||
def getShortcut(shortcuts, name):
|
||||
shortcut = [cut for cut in shortcuts if cut["name"] == name][0]
|
||||
return shortcut["current"]
|
||||
|
||||
|
||||
class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
def __init__(self):
|
||||
super(MainUI, self).__init__()
|
||||
@@ -43,10 +45,12 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.actionBericht_erstellen.triggered.connect(self.generateReport)
|
||||
self.actionDokumentation_ffnen.triggered.connect(self.openDocumentation)
|
||||
self.actionBeenden.triggered.connect(self.shutdown)
|
||||
|
||||
def __mail():
|
||||
webbrowser.open(f"mailto:{__email__}")
|
||||
|
||||
self.actionProblem_melden.triggered.connect(__mail)
|
||||
#if close button is pressed call shutdown
|
||||
# if close button is pressed call shutdown
|
||||
self.closeEvent = self.shutdown
|
||||
# Buttons
|
||||
self.btn_show_lentmedia.clicked.connect(self.showUser)
|
||||
@@ -96,25 +100,28 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
else:
|
||||
log.warning("Backup disabled")
|
||||
self.show()
|
||||
|
||||
|
||||
def shutdown(self, *args):
|
||||
#kill documentation thread
|
||||
# kill documentation thread
|
||||
log.info("Shutting down")
|
||||
if config.documentation:
|
||||
self.docu.terminate()
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
def assignShortcuts(self):
|
||||
shortcuts = config.shortcuts
|
||||
shortcuts = OmegaConf.to_container(shortcuts)
|
||||
#convert to dictconfig
|
||||
|
||||
# convert to dictconfig
|
||||
|
||||
self.actionDokumentation_ffnen.setShortcut(getShortcut(shortcuts, "Hilfe"))
|
||||
self.actionAusleihhistorie.setShortcut(getShortcut(shortcuts, "Ausleihhistorie"))
|
||||
self.actionBericht_erstellen.setShortcut(getShortcut(shortcuts, "Bericht_erstellen"))
|
||||
self.actionAusleihhistorie.setShortcut(
|
||||
getShortcut(shortcuts, "Ausleihhistorie")
|
||||
)
|
||||
self.actionBericht_erstellen.setShortcut(
|
||||
getShortcut(shortcuts, "Bericht_erstellen")
|
||||
)
|
||||
self.actionNutzer.setShortcut(getShortcut(shortcuts, "Nutzer"))
|
||||
self.actionRueckgabemodus.setShortcut(getShortcut(shortcuts, "Rueckgabemodus"))
|
||||
self.actionRueckgabemodus.setShortcut(getShortcut(shortcuts, "Rueckgabemodus"))
|
||||
|
||||
def generateReport(self):
|
||||
log.info("Generating Report")
|
||||
@@ -138,20 +145,22 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
settings = Settings()
|
||||
settings.exec()
|
||||
result = settings.result()
|
||||
print(settings.settingschanged, settings.restart_required)
|
||||
if result == 1:
|
||||
#dialog to ask if program should be restarted
|
||||
# print(settings.settingschanged, settings.restart_required)
|
||||
if result == 1 and settings.restart_required:
|
||||
# dialog to ask if program should be restarted
|
||||
dialog = QtWidgets.QMessageBox()
|
||||
dialog.setWindowTitle("Einstellungen geändert")
|
||||
dialog.setIcon(QtWidgets.QMessageBox.Icon.Information)
|
||||
dialog.setWindowIcon(Icon("settings").icon)
|
||||
dialog.setText("Einstellungen wurden geändert\nProgramm neu starten?")
|
||||
dialog.setWindowIcon(Icon("restart").icon)
|
||||
dialog.setText(
|
||||
"Einstellungen wurden geändert\nDas Programm muss neu gestartet werden?"
|
||||
)
|
||||
dialog.setStandardButtons(
|
||||
QtWidgets.QMessageBox.StandardButton.Yes
|
||||
| QtWidgets.QMessageBox.StandardButton.No
|
||||
)
|
||||
dialog.setDefaultButton(QtWidgets.QMessageBox.StandardButton.No)
|
||||
#translate buttons
|
||||
# translate buttons
|
||||
yes = dialog.button(QtWidgets.QMessageBox.StandardButton.Yes)
|
||||
yes.setText("Ja")
|
||||
no = dialog.button(QtWidgets.QMessageBox.StandardButton.No)
|
||||
@@ -161,7 +170,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
if result == QtWidgets.QMessageBox.StandardButton.Yes:
|
||||
self.restart()
|
||||
# reload settings
|
||||
#print(config)
|
||||
# print(config)
|
||||
|
||||
def openDocumentation(self):
|
||||
log.info("Opening Documentation")
|
||||
@@ -175,18 +184,15 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
dialog.setText("Dokumentation nicht verfügbar")
|
||||
dialog.exec()
|
||||
|
||||
|
||||
|
||||
|
||||
def restart(self):
|
||||
#log restart
|
||||
# log restart
|
||||
log.info("Restarting Program")
|
||||
import os
|
||||
|
||||
python_executable = sys.executable
|
||||
args = sys.argv[:]
|
||||
args.insert(0, sys.executable)
|
||||
os.execvp(python_executable, args)
|
||||
|
||||
|
||||
def changeMode(self):
|
||||
log.info("Changing Mode, current mode is {}", self.activeState)
|
||||
@@ -201,13 +207,13 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.label_7.hide()
|
||||
self.nextReturnDate.hide()
|
||||
self.mediaOverview.setRowCount(0)
|
||||
self.activeUser = None #! remove if last user should be kept
|
||||
self.activeUser = None #! remove if last user should be kept
|
||||
if self.activeState == "Rückgabe":
|
||||
if stayReturn:
|
||||
self.activateReturnMode()
|
||||
else: self.activateLoanMode()
|
||||
|
||||
|
||||
else:
|
||||
self.activateLoanMode()
|
||||
|
||||
else:
|
||||
self.activateReturnMode()
|
||||
|
||||
@@ -225,7 +231,9 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.activeState = "Ausleihe"
|
||||
if self.input_userno.text() == "" or self.input_username.text() == "":
|
||||
self.input_file_ident.setEnabled(False)
|
||||
self.input_file_ident.setPlaceholderText("Bitte zuerst Nutzerdaten eingeben")
|
||||
self.input_file_ident.setPlaceholderText(
|
||||
"Bitte zuerst Nutzerdaten eingeben"
|
||||
)
|
||||
else:
|
||||
self.input_file_ident.setEnabled(True)
|
||||
|
||||
@@ -240,7 +248,9 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.mode.setText("Rückgabe")
|
||||
self.input_file_ident.setEnabled(True)
|
||||
self.input_file_ident.setPlaceholderText("Buchidentifikation eingeben")
|
||||
self.input_username.setPlaceholderText("Bitte erst in den Ausleihmodus wechseln")
|
||||
self.input_username.setPlaceholderText(
|
||||
"Bitte erst in den Ausleihmodus wechseln"
|
||||
)
|
||||
self.input_userno.setPlaceholderText("Bitte erst in den Ausleihmodus wechseln")
|
||||
|
||||
def showUser(self):
|
||||
@@ -256,12 +266,10 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
dialog.exec()
|
||||
return
|
||||
|
||||
self.user_ui = UserUI(
|
||||
self.activeUser
|
||||
)
|
||||
self.user_ui = UserUI(self.activeUser)
|
||||
# self.user_ui.setFields("John Doe", "123456789", "test@mail.com")
|
||||
self.user_ui.show()
|
||||
|
||||
|
||||
def setUserData(self):
|
||||
log.info("Setting User Data")
|
||||
self.input_username.setText(str(self.activeUser.username))
|
||||
@@ -291,7 +299,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
|
||||
def checkUser(self, fieldname, data):
|
||||
log.info(f"Checking User {fieldname}, {data}")
|
||||
#print("Checking User", fieldname, data)
|
||||
# print("Checking User", fieldname, data)
|
||||
# set fieldname as key and data as variable
|
||||
user = self.db.checkUserExists(fieldname, data)
|
||||
if not user:
|
||||
@@ -311,16 +319,16 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
multi.exec()
|
||||
self.activeUser = multi.userdata
|
||||
else:
|
||||
#print("User found", user[0])
|
||||
# print("User found", user[0])
|
||||
self.activeUser = user[0]
|
||||
|
||||
if self.activeUser is not None:
|
||||
log.info(f"User found {self.activeUser}")
|
||||
#print("User found", self.activeUser)
|
||||
# print("User found", self.activeUser)
|
||||
self.setUserData()
|
||||
self.input_file_ident.setFocus()
|
||||
self.mode.setText("Ausleihe")
|
||||
#print(self.activeUser.__dict__)
|
||||
# print(self.activeUser.__dict__)
|
||||
loans = self.db.getActiveLoans(self.activeUser.id)
|
||||
log.debug("Active Loans", loans)
|
||||
self.btn_show_lentmedia.setText(loans)
|
||||
@@ -339,6 +347,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.input_file_ident.setEnabled(True)
|
||||
self.input_file_ident.setPlaceholderText("Buchidentifikation eingeben")
|
||||
self.input_file_ident.setFocus()
|
||||
|
||||
def moveToLine(self, line):
|
||||
log.debug("Moving to Line", line)
|
||||
line.setFocus()
|
||||
@@ -356,7 +365,9 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
dialog.setWindowTitle("Ungültige Eingabe")
|
||||
dialog.setIcon(QtWidgets.QMessageBox.Icon.Warning)
|
||||
dialog.setWindowIcon(Icon("warning").overwriteColor("#EA3323"))
|
||||
dialog.setText("Eingabe ist nicht in der Datenbank\nBitte prüfen und erneut eingeben")
|
||||
dialog.setText(
|
||||
"Eingabe ist nicht in der Datenbank\nBitte prüfen und erneut eingeben"
|
||||
)
|
||||
dialog.exec()
|
||||
self.input_file_ident.setFocus()
|
||||
self.input_file_ident.clear()
|
||||
@@ -376,6 +387,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
return
|
||||
self.mediaAdd(value)
|
||||
self.input_file_ident.setFocus()
|
||||
|
||||
def mediaAdd(self, identifier):
|
||||
log.info("Adding Media", identifier=identifier)
|
||||
self.input_file_ident.clear()
|
||||
@@ -404,7 +416,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
|
||||
elif book_id:
|
||||
if isinstance(book_id, list) and len(book_id) > 1:
|
||||
#print("Multiple Books found")
|
||||
# print("Multiple Books found")
|
||||
# TODO: implement book selection dialog
|
||||
return
|
||||
else:
|
||||
@@ -413,7 +425,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
# check if book is already loaned
|
||||
loaned = self.db.checkLoanState(book_id[0])
|
||||
if loaned:
|
||||
#print("Book already loaned")
|
||||
# print("Book already loaned")
|
||||
self.setStatusTipMessage("Buch bereits entliehen")
|
||||
# dialog with yes no to create new entry
|
||||
dialog = QtWidgets.QMessageBox()
|
||||
@@ -434,9 +446,11 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
return
|
||||
newentry = NewEntry([book_id[0]])
|
||||
newentry.exec()
|
||||
if newentry.result() == 1: # only create dialog if new entry was created
|
||||
if (
|
||||
newentry.result() == 1
|
||||
): # only create dialog if new entry was created
|
||||
self.setStatusTipMessage("Neues Exemplar hinzugefügt")
|
||||
#print(created_ids)
|
||||
# print(created_ids)
|
||||
self.input_file_ident.setEnabled(True)
|
||||
newentries = newentry.newIds
|
||||
if newentries:
|
||||
@@ -446,7 +460,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
log.info("inserted duplicated book into database")
|
||||
return
|
||||
else:
|
||||
#print("Book not loaned, loaning now")
|
||||
# print("Book not loaned, loaning now")
|
||||
self.loanMedia(user_id, book_id)
|
||||
|
||||
def loanMedia(self, user_id, book_id):
|
||||
@@ -457,7 +471,7 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.duedate.date().toString("yyyy-MM-dd"),
|
||||
)
|
||||
media = self.db.getMedia(book_id[0])
|
||||
#print(media)
|
||||
# print(media)
|
||||
self.mediaOverview.insertRow(0)
|
||||
self.mediaOverview.setItem(0, 0, QtWidgets.QTableWidgetItem(media.signature))
|
||||
self.mediaOverview.setItem(0, 1, QtWidgets.QTableWidgetItem(media.title))
|
||||
@@ -473,19 +487,19 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.input_file_ident.setEnabled(True)
|
||||
|
||||
def returnMedia(self, identifier):
|
||||
#print("Returning Media", identifier)
|
||||
# print("Returning Media", identifier)
|
||||
# get book id from database
|
||||
# self.
|
||||
identifier = Book(
|
||||
isbn=identifier, title=identifier, signature=identifier, ppn=identifier
|
||||
)
|
||||
book_id = self.db.checkMediaExists(identifier)
|
||||
#print(book_id)
|
||||
# print(book_id)
|
||||
if book_id:
|
||||
# check if book is already loaned
|
||||
loaned = self.db.checkLoanState(book_id[0])
|
||||
if loaned:
|
||||
#print("Book already loaned, returning now")
|
||||
# print("Book already loaned, returning now")
|
||||
user = self.db.getUserByLoan(book_id[0])
|
||||
# set userdata in lineedits
|
||||
self.activeUser = user
|
||||
@@ -494,7 +508,9 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
book_id[0], self.currentDate.toString("yyyy-MM-dd")
|
||||
)
|
||||
self.mediaOverview.insertRow(0)
|
||||
self.mediaOverview.setItem(0, 0, QtWidgets.QTableWidgetItem(book.signature))
|
||||
self.mediaOverview.setItem(
|
||||
0, 0, QtWidgets.QTableWidgetItem(book.signature)
|
||||
)
|
||||
self.mediaOverview.setItem(0, 1, QtWidgets.QTableWidgetItem(book.title))
|
||||
self.mediaOverview.setItem(
|
||||
0, 2, QtWidgets.QTableWidgetItem("Zurückgegeben")
|
||||
@@ -504,15 +520,13 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
self.db.getActiveLoans(self.activeUser.id)
|
||||
)
|
||||
else:
|
||||
#print("Book not loaned")
|
||||
# print("Book not loaned")
|
||||
self.setStatusTipMessage("Buch nicht entliehen")
|
||||
self.input_file_ident.clear()
|
||||
else:
|
||||
log.error("Book not found, identifier", identifier)
|
||||
#print("Book not found")
|
||||
#self.input_file_ident.setPlaceholderText(f"Buch {identifier} nicht gefunden")
|
||||
|
||||
|
||||
# print("Book not found")
|
||||
# self.input_file_ident.setPlaceholderText(f"Buch {identifier} nicht gefunden")
|
||||
|
||||
def setStatusTipMessage(self, message):
|
||||
dialog = QtWidgets.QMessageBox()
|
||||
@@ -521,13 +535,15 @@ class MainUI(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
dialog.setWindowIcon(Icon("error").overwriteColor("#EA3323"))
|
||||
dialog.setText(message)
|
||||
dialog.exec()
|
||||
|
||||
|
||||
def exit_handler():
|
||||
log.info(
|
||||
"Exiting, creating backup, renaming inactive users, creating report if day matches"
|
||||
)
|
||||
restore_config()
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
#print(backup.backup)
|
||||
# print(backup.backup)
|
||||
# generate report if monday
|
||||
if datetime.datetime.now().weekday() == config.report.report_day:
|
||||
log.info("Generating Report")
|
||||
@@ -561,6 +577,8 @@ def exit_handler():
|
||||
dialog.exec()
|
||||
log.info("Exiting")
|
||||
sys.exit()
|
||||
|
||||
|
||||
def launch(*argv):
|
||||
options = sys.argv
|
||||
if argv:
|
||||
@@ -588,22 +606,24 @@ def launch(*argv):
|
||||
atexit.register(exit_handler)
|
||||
sys.exit(app.exec())
|
||||
# sys.exit(app.exec())
|
||||
#print("Launching Main UI")
|
||||
#print(options)
|
||||
QtCore.QLocale().setDefault(QtCore.QLocale(QtCore.QLocale.Language.German, QtCore.QLocale.Country.Germany))
|
||||
# print("Launching Main UI")
|
||||
# print(options)
|
||||
QtCore.QLocale().setDefault(
|
||||
QtCore.QLocale(QtCore.QLocale.Language.German, QtCore.QLocale.Country.Germany)
|
||||
)
|
||||
SYSTEM_LANGUAGE = QtCore.QLocale().system().name()
|
||||
|
||||
|
||||
# Load base QT translations from the normal place
|
||||
app = QtWidgets.QApplication([])
|
||||
main_ui = MainUI()
|
||||
#translate ui to system language
|
||||
# translate ui to system language
|
||||
if SYSTEM_LANGUAGE:
|
||||
translator = QtCore.QTranslator()
|
||||
#do not use ascii encoding
|
||||
# do not use ascii encoding
|
||||
translator.load(f"qt_{SYSTEM_LANGUAGE}", "translations")
|
||||
translator.load("app.qm", "translations")
|
||||
app.installTranslator(translator)
|
||||
|
||||
app.installTranslator(translator)
|
||||
|
||||
atexit.register(exit_handler)
|
||||
sys.exit(app.exec())
|
||||
# sys.exit(app.exec())
|
||||
|
||||
Reference in New Issue
Block a user