diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index 16076aa66995693272a70bc063afe17d93b61341..f4d8bad7fbe785ef4b198f2c13f4ab07f60599f0 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -33,7 +33,7 @@ from PyQt5.QtGui import ( from PyQt5.QtCore import ( Qt, QTranslator, QEvent, QUrl, QTimer, - QCoreApplication, + QCoreApplication, QMutex, ) from PyQt5.QtWidgets import ( QMainWindow, QApplication, QAction, @@ -403,6 +403,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): return ts def setup_timer_backup(self): + self._save_mutex = QMutex() self._backup_timer = QTimer(self) ts = self.get_config_backup_freq_to_sec() @@ -565,6 +566,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): if self._study.is_saved: return + self._backup_timer.blockSignals(True) + self._save_mutex.lock() + sql_request_count = self._study.sql_save_request_count() progress = QProgressDialog( "Saving...", None, @@ -588,6 +592,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): self.conf.set_last_study(self._study.filename) + self._save_mutex.unlock() + self._backup_timer.blockSignals(False) + def save_as_study(self): """Save current study as new file @@ -606,6 +613,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): if file_name == "": return + self._backup_timer.blockSignals(True) + self._save_mutex.lock() + if file_name.rsplit(".", 1)[-1] == "pamhyr": logger.debug( "Pamhyr extention is present : " + @@ -642,6 +652,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): self.conf.set_last_study(self._study.filename) + self._save_mutex.unlock() + self._backup_timer.blockSignals(False) + def _backup(self): logger.debug("Backup signal...") if not self.conf.backup_enable: @@ -653,6 +666,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): if self._study.is_saved: return + self._save_mutex.lock() + old = self._study.filename file_name = "" if old == "" or old is None: @@ -693,6 +708,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): logger_exception(e) self._study.filename = old + self._save_mutex.unlock() ################## # MSG AND DIALOG #