This commit is contained in:
Dominik Demuth 2024-01-03 13:28:23 +01:00
parent 4a324b4b11
commit b33b211b7b
4 changed files with 18 additions and 13 deletions

View File

@ -17,31 +17,35 @@ from nmreval.lib.logger import handle_exception
sys.excepthook = handle_exception sys.excepthook = handle_exception
from gui_qt import App from gui_qt import App
from gui_qt.Qt import QtCore, QtWidgets, QtGui from gui_qt.Qt import QtCore
app = App(['Team Rocket FTW!']) app = App(['NMReval'])
from gui_qt.main.mainwindow import NMRMainWindow from gui_qt.main.mainwindow import NMRMainWindow
from gui_qt.lib.backup import BackupManager from gui_qt.lib.backup import BackupManager
from gui_qt.lib.update import UpdateDialog
def do_autosave(): def do_autosave():
# autosave and update timestamp in db
success = mplQt.autosave() success = mplQt.autosave()
if success: if success:
backuping.update_last_save() backuping.update_last_save()
# autosave stuff: keep track of instance and their backup files
backuping = BackupManager() backuping = BackupManager()
# look for autosaves in DB without running programs
files = backuping.search_unsaved() files = backuping.search_unsaved()
# tell everyone what autosave files belongs to this process
pid = os.getpid() pid = os.getpid()
bck_name = backuping.create_entry(pid) bck_name = backuping.create_entry(pid)
mplQt = NMRMainWindow(bck_file=bck_name) mplQt = NMRMainWindow(bck_file=bck_name)
# one manual autosave to create the file
do_autosave() do_autosave()
# load all selected autosaves to program
for f in files: for f in files:
mplQt.management.load_files(f) mplQt.management.load_files(f)
f.unlink() f.unlink()
@ -54,5 +58,4 @@ app.aboutToQuit.connect(backuping.close)
mplQt.show() mplQt.show()
sys.exit(app.exec()) sys.exit(app.exec())

View File

@ -6,7 +6,7 @@ from pathlib import Path
from nmreval.configs import config_paths from nmreval.configs import config_paths
from ..Qt import QtCore, QtWidgets from ..Qt import QtCore, QtWidgets
DB_FILE = '/autohome/dominik/nmreval/nmreval.db' DB_FILE = '/tmp/nmreval.db'
class BackupManager(QtCore.QObject): class BackupManager(QtCore.QObject):
@ -119,7 +119,6 @@ class BackupManager(QtCore.QObject):
Path(DB_FILE).unlink() Path(DB_FILE).unlink()
def close(self): def close(self):
print('close db')
self.remove_file() self.remove_file()
self.delete_db_if_empty() self.delete_db_if_empty()

View File

@ -74,7 +74,7 @@ class UpdateDialog(QtWidgets.QDialog):
label_text += '<p>Could not determine if this version is newer, please update manually (if necessary).</p>' label_text += '<p>Could not determine if this version is newer, please update manually (if necessary).</p>'
dialog_bttns = QtWidgets.QDialogButtonBox.Close dialog_bttns = QtWidgets.QDialogButtonBox.Close
elif is_updateble: elif is_updateble:
label_text += '<p>Newer version available. Press Ok to download new version, Cancel to ignore.</p>' label_text += '<p>Different version available. Press Ok to download this version, Cancel to ignore.</p>'
dialog_bttns = QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel dialog_bttns = QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel
else: else:
label_text += '<p>Version may be already up-to-date.</p>' label_text += '<p>Version may be already up-to-date.</p>'
@ -136,7 +136,7 @@ class QRestartWindow(QtWidgets.QMessageBox):
self.setIcon(QtWidgets.QMessageBox.Warning) self.setIcon(QtWidgets.QMessageBox.Warning)
else: else:
self.setText('Download completed!') self.setText('Download completed!')
self.setInformativeText("Press Restart to use new version now") self.setInformativeText("Press Restart to use new AppImage")
self.setDetailedText(f'Location of AppImage: {file_loc}') self.setDetailedText(f'Location of AppImage: {file_loc}')
self.setIcon(QtWidgets.QMessageBox.Information) self.setIcon(QtWidgets.QMessageBox.Information)

View File

@ -82,6 +82,9 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
) )
self.__backup_path = pathlib.Path(bck_file) self.__backup_path = pathlib.Path(bck_file)
if os.getenv('APPIMAGE'):
# ignore AppImages if not running from AppImage
self.look_for_update()
def _init_gui(self): def _init_gui(self):
self.setupUi(self) self.setupUi(self)
@ -1017,9 +1020,10 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
@staticmethod @staticmethod
@QtCore.pyqtSlot(name='on_actionDocumentation_triggered') @QtCore.pyqtSlot(name='on_actionDocumentation_triggered')
def open_doc(): def open_doc():
docpath = '/autohome/dominik/auswerteprogramm3/doc/_build/html/index.html' pass
import webbrowser # docpath = '/autohome/dominik/auswerteprogramm3/doc/_build/html/index.html'
webbrowser.open(docpath) # import webbrowser
# webbrowser.open(docpath)
def dropEvent(self, evt): def dropEvent(self, evt):
if evt.mimeData().hasUrls(): if evt.mimeData().hasUrls():
@ -1106,7 +1110,6 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
QLog(parent=self).show() QLog(parent=self).show()
def autosave(self) -> bool: def autosave(self) -> bool:
# TODO better separate thread may it takes some time to save
self.status.setText('Autosave...') self.status.setText('Autosave...')
success = NMRWriter(self.management.graphs, self.management.data).export(self.__backup_path.with_suffix('.nmr.0')) success = NMRWriter(self.management.graphs, self.management.data).export(self.__backup_path.with_suffix('.nmr.0'))