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