add QMessageBox to display existing backup files
This commit is contained in:
parent
b127cc15e2
commit
12dacb73b3
@ -75,6 +75,8 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
|
||||
if Updater.get_update_information(os.getenv('APPIMAGE'))[0]:
|
||||
self.look_for_update()
|
||||
|
||||
self.check_for_backup()
|
||||
|
||||
self.__timer = QtCore.QTimer()
|
||||
self.__backup_path = config_paths() / f'{datetime.datetime.now().strftime("%Y-%m-%d_%H%M%S")}.nmr'
|
||||
self.__timer.start(3*60*1000) # every three minutes
|
||||
@ -1082,6 +1084,33 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
|
||||
NMRWriter(self.management.graphs, self.management.data).export(self.__backup_path)
|
||||
self.status.setText('')
|
||||
|
||||
def check_for_backup(self):
|
||||
backups = []
|
||||
for filename in config_paths().glob('*.nmr'):
|
||||
try:
|
||||
backups.append((filename, datetime.datetime.strptime(filename.stem, "%Y-%m-%d_%H%M%S")))
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
if backups:
|
||||
backup_by_date = sorted(backups, key=lambda x: x[1])
|
||||
msg = QtWidgets.QMessageBox.information(
|
||||
self, 'Backup found',
|
||||
f'{len(backups)} backup files in directory {backup_by_date[-1][0].parent} found.\n\n'
|
||||
f'Latest backup date: {backup_by_date[-1][1]}\n\n'
|
||||
f'Press Ok to load, Cancel to delete backup, Close to do nothing.',
|
||||
QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel | QtWidgets.QMessageBox.Close
|
||||
)
|
||||
|
||||
if msg == QtWidgets.QMessageBox.Ok:
|
||||
self.management.load_files([str(backup_by_date[-1][0])])
|
||||
backup_by_date[-1][0].unlink()
|
||||
elif msg == QtWidgets.QMessageBox.Cancel:
|
||||
backup_by_date[-1][0].unlink()
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
@QtCore.pyqtSlot(name='on_actionCreate_starter_triggered')
|
||||
def create_starter(self):
|
||||
make_starter(os.getenv('APPIMAGE'))
|
||||
|
Loading…
Reference in New Issue
Block a user