From 044d2b61cf068065a0fa0f33c8b0be94753eb84b Mon Sep 17 00:00:00 2001 From: MisterMLiL <99662459+MisterMLiL@users.noreply.github.com> Date: Fri, 13 Oct 2023 22:06:24 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20?= =?UTF-8?q?=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20(#79)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- statapp/main_window.py | 5 +++++ statapp/models/fileslc_model.py | 34 +++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/statapp/main_window.py b/statapp/main_window.py index 8f90f37..0af30c7 100644 --- a/statapp/main_window.py +++ b/statapp/main_window.py @@ -109,6 +109,11 @@ class MainWindow(QMainWindow): reply = msgBox.exec_() if reply == QMessageBox.StandardButton.Yes: self.fileModel.saveFile(self.model.getData()) + + data = self.fileModel.loadFile() + if data is not None and data.shape[0] > 0: + self.model.updateAllData(data) + self.isDataChanged = False elif reply == QMessageBox.StandardButton.Cancel: return else: diff --git a/statapp/models/fileslc_model.py b/statapp/models/fileslc_model.py index 23c7679..36f8dfa 100644 --- a/statapp/models/fileslc_model.py +++ b/statapp/models/fileslc_model.py @@ -20,6 +20,8 @@ import numpy as np from PySide2.QtWidgets import QFileDialog, QMessageBox +from statapp.utils import buildMessageBox + class FileSLCModel: def __init__(self): @@ -27,19 +29,43 @@ class FileSLCModel: self.fileName = None def saveFile(self, data): - if not self.fileName: + # pylint: disable=duplicate-code + + if self.fileName: + file = '\nФайл сохранения: ' + self.fileName + + msgBox = buildMessageBox \ + ('Сохранение данных', + "Сохранить данные в текущий файл?" + file, + QMessageBox.Question, + QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, + QMessageBox.Cancel) + + reply = msgBox.exec_() + if reply == QMessageBox.StandardButton.Yes: + np.savetxt(self.fileName, data, delimiter=",", fmt='%10.5f') + return True + if reply == QMessageBox.StandardButton.No: + self.fileName, _ = QFileDialog.getSaveFileName( + None, "Сохранить файл", "", "Text Files (*.txt);;CSV Files (*.csv)" + ) + if self.fileName: + np.savetxt(self.fileName, data, delimiter=",", fmt='%10.5f') + return True + else: self.fileName, _ = QFileDialog.getSaveFileName( None, "Сохранить файл", "", "Text Files (*.txt);;CSV Files (*.csv)" ) - if self.fileName: - np.savetxt(self.fileName, data, delimiter=",") - return True + if self.fileName: + np.savetxt(self.fileName, data, delimiter=",", fmt='%10.5f') + return True return False def loadFile(self): self.fileName, _ = QFileDialog.getOpenFileName( None, "Загрузить файл", "", "Files (*.txt *.csv)" ) + if self.fileName: try: content = np.genfromtxt(self.fileName, delimiter=',', invalid_raise=True, ndmin=2)