fix: исправлен формат сохранения файлов (#79)

This commit is contained in:
MisterMLiL 2023-10-13 22:06:24 +03:00 committed by GitHub
parent dd765ae981
commit 044d2b61cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 4 deletions

View File

@ -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:

View File

@ -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)