mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Save/Backup: Add mutual exclusion on save methode and block backup signal.
This commit is contained in:
1 parent
53456cf7fa
commit
ab1b7a2605
1 file changed
+17
-1
+17
-1
@@ -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 #
|
||||
|
||||
Reference in new issue
Block a user