Commit ab1b7a26 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Save/Backup: Add mutual exclusion on save methode and block backup signal.

Showing with 17 additions and 1 deletion
+17 -1
...@@ -33,7 +33,7 @@ from PyQt5.QtGui import ( ...@@ -33,7 +33,7 @@ from PyQt5.QtGui import (
from PyQt5.QtCore import ( from PyQt5.QtCore import (
Qt, QTranslator, QEvent, QUrl, QTimer, Qt, QTranslator, QEvent, QUrl, QTimer,
QCoreApplication, QCoreApplication, QMutex,
) )
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QMainWindow, QApplication, QAction, QMainWindow, QApplication, QAction,
...@@ -403,6 +403,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -403,6 +403,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
return ts return ts
def setup_timer_backup(self): def setup_timer_backup(self):
self._save_mutex = QMutex()
self._backup_timer = QTimer(self) self._backup_timer = QTimer(self)
ts = self.get_config_backup_freq_to_sec() ts = self.get_config_backup_freq_to_sec()
...@@ -565,6 +566,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -565,6 +566,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if self._study.is_saved: if self._study.is_saved:
return return
self._backup_timer.blockSignals(True)
self._save_mutex.lock()
sql_request_count = self._study.sql_save_request_count() sql_request_count = self._study.sql_save_request_count()
progress = QProgressDialog( progress = QProgressDialog(
"Saving...", None, "Saving...", None,
...@@ -588,6 +592,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -588,6 +592,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self.conf.set_last_study(self._study.filename) self.conf.set_last_study(self._study.filename)
self._save_mutex.unlock()
self._backup_timer.blockSignals(False)
def save_as_study(self): def save_as_study(self):
"""Save current study as new file """Save current study as new file
...@@ -606,6 +613,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -606,6 +613,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if file_name == "": if file_name == "":
return return
self._backup_timer.blockSignals(True)
self._save_mutex.lock()
if file_name.rsplit(".", 1)[-1] == "pamhyr": if file_name.rsplit(".", 1)[-1] == "pamhyr":
logger.debug( logger.debug(
"Pamhyr extention is present : " + "Pamhyr extention is present : " +
...@@ -642,6 +652,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -642,6 +652,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self.conf.set_last_study(self._study.filename) self.conf.set_last_study(self._study.filename)
self._save_mutex.unlock()
self._backup_timer.blockSignals(False)
def _backup(self): def _backup(self):
logger.debug("Backup signal...") logger.debug("Backup signal...")
if not self.conf.backup_enable: if not self.conf.backup_enable:
...@@ -653,6 +666,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -653,6 +666,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
if self._study.is_saved: if self._study.is_saved:
return return
self._save_mutex.lock()
old = self._study.filename old = self._study.filename
file_name = "" file_name = ""
if old == "" or old is None: if old == "" or old is None:
...@@ -693,6 +708,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -693,6 +708,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
logger_exception(e) logger_exception(e)
self._study.filename = old self._study.filename = old
self._save_mutex.unlock()
################## ##################
# MSG AND DIALOG # # MSG AND DIALOG #
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment