Skip to content

Commit 886ae8a

Browse files
committed
updated _open_file()
1 parent a84f19c commit 886ae8a

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

larray_editor/editor.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -539,34 +539,29 @@ def new(self):
539539
self.statusBar().showMessage("Viewer has been reset", 4000)
540540

541541
def _open_file(self, filepath):
542-
def _update_arrays(current_file_name, session):
543-
self._reset()
544-
self.set_current_file(current_file_name)
545-
self._add_arrays(session)
546-
self._listwidget.setCurrentRow(0)
547-
self.unsaved_modifications = False
548-
549542
session = Session()
550543
if '.csv' in filepath:
551544
filepath = [filepath]
552545
if isinstance(filepath, (list, tuple)):
553-
dirname = os.path.dirname(filepath[0])
554-
basenames = [os.path.basename(fpath) for fpath in filepath]
555-
try:
556-
session.load(None, filepath)
557-
_update_arrays(dirname, session)
558-
self.statusBar().showMessage("CSV files {} loaded".format(' ,'.join(basenames)), 4000)
559-
except Exception as e:
560-
QMessageBox.critical(self, "Error", "Something went wrong during load of CSV files {}:\n{}"
561-
.format(' ,'.join(basenames), e))
546+
current_file_name = os.path.dirname(filepath[0])
547+
display_name = ','.join(os.path.basename(fpath) for fpath in filepath)
548+
names = filepath
549+
filepath = None
562550
else:
563-
try:
564-
session.load(filepath)
565-
_update_arrays(filepath, session)
566-
self.statusBar().showMessage("File {} loaded".format(os.path.basename(filepath), 4000))
567-
except Exception as e:
568-
QMessageBox.critical(self, "Error", "Something went wrong during load of file {}:\n{}"
569-
.format(filepath, e))
551+
names = None
552+
current_file_name = filepath
553+
display_name = os.path.basename(filepath)
554+
try:
555+
session.load(filepath, names)
556+
self._reset()
557+
self.set_current_file(current_file_name)
558+
self._add_arrays(session)
559+
self._listwidget.setCurrentRow(0)
560+
self.unsaved_modifications = False
561+
self.statusBar().showMessage("Loaded: {}".format(display_name), 4000)
562+
except Exception as e:
563+
QMessageBox.critical(self, "Error", "Something went wrong during load of file(s) {}:\n{}"
564+
.format(filepath, e))
570565

571566
def open(self):
572567
if self._ask_to_save_if_unsaved_modifications():

0 commit comments

Comments
 (0)