added first version of a backup system (#37)

Co-authored-by: Dominik Demuth <dominik.demuth@physik.tu-darmstadt.de>
Reviewed-on: #37
This commit is contained in:
Dominik Demuth 2023-04-05 17:50:06 +00:00
parent 2fbaa94109
commit 43285b4bd5
3 changed files with 27 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import uuid
from math import isnan from math import isnan
from pathlib import Path from pathlib import Path
import numpy as np
from numpy import errstate, floor, log10 from numpy import errstate, floor, log10
from pyqtgraph import GraphicsObject, getConfigOption, mkColor from pyqtgraph import GraphicsObject, getConfigOption, mkColor
@ -137,7 +138,13 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow):
r = self.plotItem.getViewBox().viewRange() r = self.plotItem.getViewBox().viewRange()
for i in [0, 1]: for i in [0, 1]:
if self.log[i]: if self.log[i]:
r[i] = tuple([10**x for x in r[i]]) tmp = [np.nan, np.nan]
for j, x in enumerate(r[i]):
try:
tmp[j] = 10**x
except OverflowError:
pass
r[i] = tuple(tmp)
else: else:
r[i] = tuple(r[i]) r[i] = tuple(r[i])

View File

@ -1,5 +1,6 @@
from __future__ import annotations from __future__ import annotations
import datetime
import os import os
import pathlib import pathlib
import re import re
@ -9,6 +10,7 @@ from numpy import geomspace, linspace
from pyqtgraph import ViewBox from pyqtgraph import ViewBox
from nmreval.configs import * from nmreval.configs import *
from nmreval.io.sessionwriter import NMRWriter
from .management import UpperManagement from .management import UpperManagement
from ..Qt import QtGui, QtPrintSupport from ..Qt import QtGui, QtPrintSupport
@ -73,6 +75,11 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
if Updater.get_update_information(os.getenv('APPIMAGE'))[0]: if Updater.get_update_information(os.getenv('APPIMAGE'))[0]:
self.look_for_update() self.look_for_update()
self.__timer = QtCore.QTimer()
self.__savepath = config_paths() / f'{datetime.datetime.now().strftime("%Y-%m-%d_%H%M%S")}.nmr'
self.__timer.start(0.2*60*1000) # every three minutese
self.__timer.timeout.connect(self._autosave)
def _init_gui(self): def _init_gui(self):
self.setupUi(self) self.setupUi(self)
make_action_icons(self) make_action_icons(self)
@ -1020,6 +1027,9 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
def close(self): def close(self):
write_state({'History': {'recent path': str(self.path)}}) write_state({'History': {'recent path': str(self.path)}})
# remove backup file when closing
self.__savepath.unlink(missing_ok=True)
super().close() super().close()
def read_state(self): def read_state(self):
@ -1043,3 +1053,8 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
QLog(parent=self).show() QLog(parent=self).show()
def _autosave(self):
# TODO better separate thread may it takes some time to save
self.status.setText('Autosave...')
NMRWriter(self.management.graphs, self.management.data).export(self.__savepath)
self.status.setText('')

View File

@ -180,7 +180,10 @@ class UpperManagement(QtCore.QObject):
graph.active = active graph.active = active
graph.listWidget.blockSignals(True) graph.listWidget.blockSignals(True)
for i, l in enumerate(g['in_legend']): for i, l in enumerate(g['in_legend']):
graph.listWidget.item(i).setCheckState(l) try:
graph.listWidget.item(i).setCheckState(QtCore.Qt.Checked if l else QtCore.Qt.Unchecked)
except AttributeError:
pass
graph.listWidget.blockSignals(False) graph.listWidget.blockSignals(False)
# set unchecked in tree and hide/show in plot # set unchecked in tree and hide/show in plot