mirror of
https://github.com/shizand/statapp.git
synced 2024-12-23 12:12:59 +03:00
fix: исправлен формат сохранения файлов (#79)
This commit is contained in:
parent
dd765ae981
commit
044d2b61cf
@ -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:
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user