@@ -337,6 +337,10 @@ def set_data_dir(self):
337337
338338
339339 def save_conf (self ):
340+ if not self .main_win .is_exp_exists ():
341+ msg_window ('the experiment does not exist, cannot save the config_prep file' )
342+ return
343+
340344 conf_map = self .get_prep_config ()
341345 if len (conf_map ) > 0 :
342346 er_msg = cohere .verify ('config_prep' , conf_map )
@@ -537,6 +541,10 @@ def run_tab(self):
537541
538542
539543 def save_conf (self ):
544+ if not self .main_win .is_exp_exists ():
545+ msg_window ('the experiment does not exist, cannot save the config_disp file' )
546+ return
547+
540548 conf_map = self .get_disp_config ()
541549 if len (conf_map ) > 0 :
542550 er_msg = cohere .verify ('config_disp' , conf_map )
@@ -619,7 +627,7 @@ def __init__(self, parent=None):
619627 super (SubInstrTab , self ).__init__ (parent )
620628
621629
622- def init (self , tabs , main_window ):
630+ def init (self , instr_tab , main_window ):
623631 """
624632 Creates and initializes the 'Instrument' tab.
625633 Parameters
@@ -630,6 +638,7 @@ def init(self, tabs, main_window):
630638 nothing
631639 """
632640 self .main_window = main_window
641+ self .instr_tab = instr_tab
633642
634643 self .spec_widget = QWidget ()
635644 spec_layout = QFormLayout ()
@@ -667,7 +676,7 @@ def init(self, tabs, main_window):
667676 self .detector .textChanged .connect (lambda : set_overriden (self .detector ))
668677
669678
670- def load_tab (self , conf_map , specfile , diff ):
679+ def load_tab (self , conf_map ):
671680 """
672681 It verifies given configuration file, reads the parameters, and fills out the window.
673682 Parameters
@@ -678,7 +687,7 @@ def load_tab(self, conf_map, specfile, diff):
678687 -------
679688 nothing
680689 """
681- self .parse_spec (specfile , diff )
690+ self .parse_spec ()
682691
683692 # if parameters are configured, override the readings from spec file
684693 if 'energy' in conf_map :
@@ -762,7 +771,7 @@ def get_instr_config(self):
762771 return conf_map
763772
764773
765- def parse_spec (self , specfile , diffractometer ):
774+ def parse_spec (self ):
766775 """
767776 Calls utility function to parse spec file. Displas the parsed parameters in the window with blue text.
768777 Parameters
@@ -774,6 +783,17 @@ def parse_spec(self, specfile, diffractometer):
774783 """
775784 scan = str (self .main_window .scan_widget .text ())
776785 if len (scan ) == 0 :
786+ msg_window ('cannot parse spec, scan not defined' )
787+ return
788+
789+ diffractometer = self .instr_tab .diffractometer .text ()
790+ if len (diffractometer ) == 0 :
791+ msg_window ('cannot parse spec, diffractometer not defined' )
792+ return
793+
794+ specfile = self .instr_tab .spec_file_button .text ()
795+ if len (specfile ) == 0 :
796+ msg_window ('cannot parse spec, specfile not defined' )
777797 return
778798
779799 import beamlines .aps_34idc .diffractometers as diff
@@ -787,6 +807,8 @@ def parse_spec(self, specfile, diffractometer):
787807
788808 last_scan = int (scan .split ('-' )[- 1 ].split (',' )[- 1 ])
789809 spec_dict = instr .parse_spec (specfile , last_scan , diff_obj )
810+ if spec_dict is None :
811+ return
790812 if 'energy' in spec_dict :
791813 self .energy .setText (str (spec_dict ['energy' ]))
792814 self .energy .setStyleSheet ('color: blue' )
@@ -838,9 +860,9 @@ def toggle_config(self):
838860 else :
839861 self .add_config = True
840862 self .extended .spec_widget .show ()
841- self .extended .parse_spec (self . spec_file_button . text (), self . diffractometer . text () )
842- if self . main_win . is_exp_exists ():
843- self .save_conf ()
863+ self .extended .parse_spec ()
864+
865+ self .save_conf ()
844866
845867
846868 def init (self , tabs , main_window ):
@@ -861,7 +883,7 @@ def init(self, tabs, main_window):
861883 else :
862884 self .add_config = True
863885 self .extended = SubInstrTab ()
864- self .extended .init (tabs , main_window )
886+ self .extended .init (self , main_window )
865887
866888 tab_layout = QVBoxLayout ()
867889 gen_layout = QFormLayout ()
@@ -912,11 +934,12 @@ def load_tab(self, conf_map):
912934 if os .path .isfile (specfile ):
913935 self .spec_file_button .setStyleSheet ("Text-align:left" )
914936 self .spec_file_button .setText (specfile )
915- if self .add_config :
916- self .extended .load_tab (conf_map , specfile , diff )
917937 else :
918938 msg_window ('The specfile file ' + specfile + ' in config file does not exist' )
919939
940+ if self .add_config :
941+ self .extended .load_tab (conf_map )
942+
920943
921944 def set_spec_file (self ):
922945 """
@@ -929,17 +952,17 @@ def set_spec_file(self):
929952 -------
930953 noting
931954 """
932- self . specfile = select_file (os .getcwd ())
933- if self . specfile is not None :
955+ specfile = select_file (os .getcwd ())
956+ if specfile is not None :
934957 self .spec_file_button .setStyleSheet ("Text-align:left" )
935- self .spec_file_button .setText (self .specfile )
936- self .save_conf ()
958+ self .spec_file_button .setText (specfile )
937959 if self .add_config :
938- self .extended .parse_spec (self . specfile , self . diffractometer . text () )
960+ self .extended .parse_spec ()
939961 else :
940- self .specfile = None
941962 self .spec_file_button .setText ('' )
942963
964+ self .save_conf ()
965+
943966
944967 def clear_conf (self ):
945968 self .diffractometer .setText ('' )
@@ -1000,6 +1023,10 @@ def save_conf(self):
10001023 -------
10011024 nothing
10021025 """
1026+ if not self .main_win .is_exp_exists ():
1027+ msg_window ('the experiment does not exist, cannot save the config_instr file' )
1028+ return
1029+
10031030 conf_map = self .get_instr_config ()
10041031 # verify that disp configuration is ok
10051032 er_msg = cohere .verify ('config_instr' , conf_map )
0 commit comments