Skip to content

fix #75 : display a message when saving or loading a file failed #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions larray_editor/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,23 +539,29 @@ def new(self):
self.statusBar().showMessage("Viewer has been reset", 4000)

def _open_file(self, filepath):
self._reset()
session = Session()
if '.csv' in filepath:
filepath = [filepath]
if isinstance(filepath, (list, tuple)):
session.load(None, filepath)
dirname = os.path.dirname(filepath[0])
basenames = [os.path.basename(fpath) for fpath in filepath]
self.set_current_file(dirname)
self.statusBar().showMessage("CSV files {} loaded".format(' ,'.join(basenames)), 4000)
current_file_name = os.path.dirname(filepath[0])
display_name = ','.join(os.path.basename(fpath) for fpath in filepath)
names = filepath
filepath = None
else:
session.load(filepath)
self.set_current_file(filepath)
self.statusBar().showMessage("File {} loaded".format(os.path.basename(filepath)), 4000)
self._add_arrays(session)
self._listwidget.setCurrentRow(0)
self.unsaved_modifications = False
names = None
current_file_name = filepath
display_name = os.path.basename(filepath)
try:
session.load(filepath, names)
self._reset()
self.set_current_file(current_file_name)
self._add_arrays(session)
self._listwidget.setCurrentRow(0)
self.unsaved_modifications = False
self.statusBar().showMessage("Loaded: {}".format(display_name), 4000)
except Exception as e:
QMessageBox.critical(self, "Error", "Something went wrong during load of file(s) {}:\n{}"
.format(display_name, e))

def open(self):
if self._ask_to_save_if_unsaved_modifications():
Expand Down Expand Up @@ -583,11 +589,14 @@ def open_recent_file(self):
QMessageBox.warning(self, "Warning", "File {} could not be found".format(filepath))

def _save_data(self, filepath):
session = Session({k: v for k, v in self.data.items() if self._display_in_grid(k, v)})
session.save(filepath)
self.set_current_file(filepath)
self.unsaved_modifications = False
self.statusBar().showMessage("Arrays saved in file {}".format(filepath), 4000)
try:
session = Session({k: v for k, v in self.data.items() if self._display_in_grid(k, v)})
session.save(filepath)
self.set_current_file(filepath)
self.unsaved_modifications = False
self.statusBar().showMessage("Arrays saved in file {}".format(filepath), 4000)
except Exception as e:
QMessageBox.critical(self, "Error", "Something went wrong during save in file {}:\n{}".format(filepath, e))

def save(self):
"""
Expand Down