@@ -539,23 +539,34 @@ 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 ()
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
+
543
549
session = Session ()
544
550
if '.csv' in filepath :
545
551
filepath = [filepath ]
546
552
if isinstance (filepath , (list , tuple )):
547
- session .load (None , filepath )
548
553
dirname = os .path .dirname (filepath [0 ])
549
554
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 )
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 ))
552
562
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
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 ))
559
570
560
571
def open (self ):
561
572
if self ._ask_to_save_if_unsaved_modifications ():
@@ -583,11 +594,14 @@ def open_recent_file(self):
583
594
QMessageBox .warning (self , "Warning" , "File {} could not be found" .format (filepath ))
584
595
585
596
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 )
597
+ try :
598
+ session = Session ({k : v for k , v in self .data .items () if self ._display_in_grid (k , v )})
599
+ session .save (filepath )
600
+ self .set_current_file (filepath )
601
+ self .unsaved_modifications = False
602
+ self .statusBar ().showMessage ("Arrays saved in file {}" .format (filepath ), 4000 )
603
+ except Exception as e :
604
+ QMessageBox .critical (self , "Error" , "Something went wrong during save in file {}:\n {}" .format (filepath , e ))
591
605
592
606
def save (self ):
593
607
"""
0 commit comments