forked from IPKM/nmreval
added first version of a backup system (#37)
Co-authored-by: Dominik Demuth <dominik.demuth@physik.tu-darmstadt.de> Reviewed-on: IPKM/nmreval#37
This commit is contained in:
parent
2fbaa94109
commit
43285b4bd5
@ -7,6 +7,7 @@ import uuid
|
||||
from math import isnan
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
from numpy import errstate, floor, log10
|
||||
from pyqtgraph import GraphicsObject, getConfigOption, mkColor
|
||||
|
||||
@ -137,7 +138,13 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow):
|
||||
r = self.plotItem.getViewBox().viewRange()
|
||||
for i in [0, 1]:
|
||||
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:
|
||||
r[i] = tuple(r[i])
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
@ -9,6 +10,7 @@ from numpy import geomspace, linspace
|
||||
from pyqtgraph import ViewBox
|
||||
|
||||
from nmreval.configs import *
|
||||
from nmreval.io.sessionwriter import NMRWriter
|
||||
|
||||
from .management import UpperManagement
|
||||
from ..Qt import QtGui, QtPrintSupport
|
||||
@ -73,6 +75,11 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
|
||||
if Updater.get_update_information(os.getenv('APPIMAGE'))[0]:
|
||||
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):
|
||||
self.setupUi(self)
|
||||
make_action_icons(self)
|
||||
@ -1020,6 +1027,9 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
|
||||
def close(self):
|
||||
write_state({'History': {'recent path': str(self.path)}})
|
||||
|
||||
# remove backup file when closing
|
||||
self.__savepath.unlink(missing_ok=True)
|
||||
|
||||
super().close()
|
||||
|
||||
def read_state(self):
|
||||
@ -1043,3 +1053,8 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
|
||||
|
||||
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('')
|
||||
|
@ -180,7 +180,10 @@ class UpperManagement(QtCore.QObject):
|
||||
graph.active = active
|
||||
graph.listWidget.blockSignals(True)
|
||||
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)
|
||||
|
||||
# set unchecked in tree and hide/show in plot
|
||||
|
Loading…
Reference in New Issue
Block a user