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_() reply = msgBox.exec_()
if reply == QMessageBox.StandardButton.Yes: if reply == QMessageBox.StandardButton.Yes:
self.fileModel.saveFile(self.model.getData()) 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: elif reply == QMessageBox.StandardButton.Cancel:
return return
else: else:

View File

@ -20,6 +20,8 @@
import numpy as np import numpy as np
from PySide2.QtWidgets import QFileDialog, QMessageBox from PySide2.QtWidgets import QFileDialog, QMessageBox
from statapp.utils import buildMessageBox
class FileSLCModel: class FileSLCModel:
def __init__(self): def __init__(self):
@ -27,12 +29,35 @@ class FileSLCModel:
self.fileName = None self.fileName = None
def saveFile(self, data): 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( self.fileName, _ = QFileDialog.getSaveFileName(
None, "Сохранить файл", "", "Text Files (*.txt);;CSV Files (*.csv)" None, "Сохранить файл", "", "Text Files (*.txt);;CSV Files (*.csv)"
) )
if self.fileName: if self.fileName:
np.savetxt(self.fileName, data, delimiter=",") 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=",", fmt='%10.5f')
return True return True
return False return False
@ -40,6 +65,7 @@ class FileSLCModel:
self.fileName, _ = QFileDialog.getOpenFileName( self.fileName, _ = QFileDialog.getOpenFileName(
None, "Загрузить файл", "", "Files (*.txt *.csv)" None, "Загрузить файл", "", "Files (*.txt *.csv)"
) )
if self.fileName: if self.fileName:
try: try:
content = np.genfromtxt(self.fileName, delimiter=',', invalid_raise=True, ndmin=2) content = np.genfromtxt(self.fileName, delimiter=',', invalid_raise=True, ndmin=2)