fix file opening, add from file, fix display bug

This commit is contained in:
WorldTeacher
2024-02-07 11:40:04 +01:00
parent e602325678
commit 185a97cc45

View File

@@ -40,6 +40,8 @@ from src.ui import (
)
# from src.logic.webrequest import BibTextTransformer, WebRequest
from src.backend.admin_console import AdminCommands
from src.backend.create_file import recreateFile
from src.backend.delete_temp_contents import delete_temp_contents
from src.logic.csvparser import csv_to_list
from src.logic.wordparser import word_docx_to_csv
from icecream import ic
@@ -247,6 +249,9 @@ class Ui(Ui_Semesterapparat):
self.progress_label.hide()
self.message_frame.hide()
self.btn_reserve.hide()
self.label_20.hide()
self.line_3.hide()
self.avail_status.hide()
self.check_deletable.stateChanged.connect(self.gridchange)
self.tableWidget.horizontalHeader().setSectionResizeMode(
QtWidgets.QHeaderView.ResizeMode.Stretch
@@ -1177,6 +1182,8 @@ class Ui(Ui_Semesterapparat):
return
def check_availability(self):
def _update_progress(state):
self.avail_status.setText( "{}/{}".format(state[0], state[1]))
# get all links from the table
# if no index in tableWidget_apparat_media is selected, check all
if self.tableWidget_apparat_media.currentRow() == -1:
@@ -1192,13 +1199,14 @@ class Ui(Ui_Semesterapparat):
self.tableWidget_apparat_media.currentRow(), 1
).text()
]
self.label_info.setText("Verfügbarkeit wird geprüft, bitte warten...")
self.label_info.show()
items = len(links)
self.label_20.setText("Verfügbarkeit wird geprüft, bitte warten...")
self.label_20.show()
self.avail_status.setText(f"0/{items}")
books = self.db.getBooks(
self.active_apparat(),
self.db.getProfId(self.drpdwn_prof_name.currentText()),
del_state=0,
deleted=0,
)
thread = QThread()
@@ -1210,6 +1218,7 @@ class Ui(Ui_Semesterapparat):
availcheck.finished.connect(availcheck.deleteLater)
availcheck.finished.connect(self.hide_progress_label)
availcheck.finished.connect(self.update_app_media_list)
availcheck.updateProgress.connect(_update_progress)
availcheck.start()
self.thread = thread
self.grabbers.append(availcheck)
@@ -1361,9 +1370,8 @@ class Ui(Ui_Semesterapparat):
self.confirm_popup("Bitte erst ein Dokument auswählen!")
return
if not _selected_doc_location == "Database":
print("not in database")
path = Path(_selected_doc_location)
path = path + "/" + _selected_doc_name
path:Path = path + "/" + _selected_doc_name
if os.getenv("OS") == "Windows_NT":
path = path.resolve()
os.startfile(path)
@@ -1371,19 +1379,12 @@ class Ui(Ui_Semesterapparat):
path = path.resolve()
os.system(f"open {path}")
else:
print("in database")
try:
file_loc = self.db.recreateFile(_selected_doc_name, "71",filetype=_selected_doc_filetype)
print(f"filename is {file_loc}")
except Exception as e:
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}")
recreateFile(_selected_doc_name,self.active_apparat() ,filetype=_selected_doc_filetype)
# # if ~ in path, replace it with the home directory
# if "~" in path:
# path = path.replace("~", str(Path.home()))
# path = Path(path)
def add_media_from_file(self):
def __open_dialog(signatures):
@@ -1478,6 +1479,7 @@ class Ui(Ui_Semesterapparat):
print(len(signatures))
def btn_check_file_threaded(self):
print("Checking file")
# get active app_id and prof_id
self.tableWidget_apparate.setEnabled(False)
self.tableWidget_apparate.setToolTip(
@@ -1486,16 +1488,19 @@ class Ui(Ui_Semesterapparat):
app_id = self.active_apparat()
prof_id = self.db.getProfId(self.drpdwn_prof_name.currentText())
# check if apparat in database
if not app_id in self.db.getUnavailableApparatNumbers():
#if app_id not in database, create apparat
if not self.db.checkApparatExistsById(app_id):
# create apparat
print("Creating apparat")
self.btn_save_apparat()
if self.dokument_list.rowCount() == 0:
print("No file selected")
self.tableWidget_apparate.setEnabled(True)
self.tableWidget_apparate.setToolTip("")
return
else:
# if file is selected, check for books in the file
if self.dokument_list.currentRow() != -1:
print("File selected")
file = self.dokument_list.item(self.dokument_list.currentRow(), 3).text()
@@ -1509,14 +1514,7 @@ class Ui(Ui_Semesterapparat):
self.dokument_list.currentRow(), 0
).text()
if file_location == "Database":
# create a temporaty file to use, delete it after use
temp_file = tempfile.NamedTemporaryFile(
delete=False, suffix="." + file_type
)
temp_file.write(self.db.getBlob(file_name, int(self.active_apparat())))
temp_file.close()
file = temp_file.name
print(file)
file = recreateFile(file_name,app_id,file_type,open=False)
if file_type == "pdf":
# Todo: implement parser here
self.confirm_popup("PDF Dateien werden noch nicht unterstützt!")
@@ -1533,6 +1531,8 @@ class Ui(Ui_Semesterapparat):
]
signatures = [i for i in signatures if i != ""]
ic(signatures)
print("starting thread")
thread = QThread()
grabber = BookGrabber("ARRAY", signatures, app_id, prof_id)
grabber.moveToThread(thread)
@@ -1664,9 +1664,9 @@ class Ui(Ui_Semesterapparat):
self.old_apparats = self.apparats
def insert_apparat_into_table(self, apparat):
ic(apparat)
def __dauer_check(apparat):
result = self.db.isEternal(apparat[0])
return "Ja" if result == ("True" or "1") else "Nein"
return "Ja" if apparat[7] == 1 else "Nein"
self.tableWidget_apparate.insertRow(0)
self.tableWidget_apparate.setItem(
@@ -1693,7 +1693,7 @@ class Ui(Ui_Semesterapparat):
0, 4, QtWidgets.QTableWidgetItem(__dauer_check(apparat))
)
self.tableWidget_apparate.setItem(
0, 5, QtWidgets.QTableWidgetItem(str(apparat[11]))
0, 5, QtWidgets.QTableWidgetItem(str(apparat[13]))
)
self.logger.log_info(f"Inserted apparat {apparat[4]}")
@@ -1827,12 +1827,12 @@ class Ui(Ui_Semesterapparat):
book = self.tableWidget_apparat_media.item(
self.tableWidget_apparat_media.currentRow(), 1
).text()
book_id = self.db.getBookIdBasedOnSignature(
data = self.db.getBookBasedOnSignature(
app_id=self.active_apparat(),
signature=book,
prof_id=self.db.getProfId(self.drpdwn_prof_name.currentText()),
)
data = self.db.getBook(book_id)
widget = QtWidgets.QDialog()
bookedit = edit_bookdata_ui()
bookedit.setupUi(widget)
@@ -1997,6 +1997,8 @@ def launch_gui():
# open a console window
# console = ""
print("admin")
# atexit.register(aui.thread.terminate)
atexit.register(delete_temp_contents)
if __name__ == "__main__":