@@ -539,23 +539,29 @@ def new(self):
539
539
self .statusBar ().showMessage ("Viewer has been reset" , 4000 )
540
540
541
541
def _open_file (self , filepath ):
542
- self ._reset ()
543
542
session = Session ()
544
543
if '.csv' in filepath :
545
544
filepath = [filepath ]
546
545
if isinstance (filepath , (list , tuple )):
547
- session .load (None , filepath )
548
- dirname = os .path .dirname (filepath [0 ])
549
- basenames = [os .path .basename (fpath ) for fpath in filepath ]
550
- self .set_current_file (dirname )
551
- self .statusBar ().showMessage ("CSV files {} loaded" .format (' ,' .join (basenames )), 4000 )
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
552
550
else :
553
- session .load (filepath )
554
- self .set_current_file (filepath )
555
- self .statusBar ().showMessage ("File {} loaded" .format (os .path .basename (filepath )), 4000 )
556
- self ._add_arrays (session )
557
- self ._listwidget .setCurrentRow (0 )
558
- self .unsaved_modifications = False
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 (display_name , e ))
559
565
560
566
def open (self ):
561
567
if self ._ask_to_save_if_unsaved_modifications ():
@@ -583,11 +589,14 @@ def open_recent_file(self):
583
589
QMessageBox .warning (self , "Warning" , "File {} could not be found" .format (filepath ))
584
590
585
591
def _save_data (self , filepath ):
586
- session = Session ({k : v for k , v in self .data .items () if self ._display_in_grid (k , v )})
587
- session .save (filepath )
588
- self .set_current_file (filepath )
589
- self .unsaved_modifications = False
590
- self .statusBar ().showMessage ("Arrays saved in file {}" .format (filepath ), 4000 )
592
+ try :
593
+ session = Session ({k : v for k , v in self .data .items () if self ._display_in_grid (k , v )})
594
+ session .save (filepath )
595
+ self .set_current_file (filepath )
596
+ self .unsaved_modifications = False
597
+ self .statusBar ().showMessage ("Arrays saved in file {}" .format (filepath ), 4000 )
598
+ except Exception as e :
599
+ QMessageBox .critical (self , "Error" , "Something went wrong during save in file {}:\n {}" .format (filepath , e ))
591
600
592
601
def save (self ):
593
602
"""
0 commit comments