From e25a4601074b0a5419c43ae0189bd7c59b08e913 Mon Sep 17 00:00:00 2001 From: Barbara Frosik Date: Mon, 5 Jun 2023 13:31:12 -0500 Subject: [PATCH] fixed issues in beamline tabs when parsing spec --- .../beamlines/aps_34idc/beam_tabs.py | 59 ++++++++++++++----- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/cohere-scripts/beamlines/aps_34idc/beam_tabs.py b/cohere-scripts/beamlines/aps_34idc/beam_tabs.py index c63044e..11708c7 100644 --- a/cohere-scripts/beamlines/aps_34idc/beam_tabs.py +++ b/cohere-scripts/beamlines/aps_34idc/beam_tabs.py @@ -337,6 +337,10 @@ def set_data_dir(self): def save_conf(self): + if not self.main_win.is_exp_exists(): + msg_window('the experiment does not exist, cannot save the config_prep file') + return + conf_map = self.get_prep_config() if len(conf_map) > 0: er_msg = cohere.verify('config_prep', conf_map) @@ -537,6 +541,10 @@ def run_tab(self): def save_conf(self): + if not self.main_win.is_exp_exists(): + msg_window('the experiment does not exist, cannot save the config_disp file') + return + conf_map = self.get_disp_config() if len(conf_map) > 0: er_msg = cohere.verify('config_disp', conf_map) @@ -619,7 +627,7 @@ def __init__(self, parent=None): super(SubInstrTab, self).__init__(parent) - def init(self, tabs, main_window): + def init(self, instr_tab, main_window): """ Creates and initializes the 'Instrument' tab. Parameters @@ -630,6 +638,7 @@ def init(self, tabs, main_window): nothing """ self.main_window = main_window + self.instr_tab = instr_tab self.spec_widget = QWidget() spec_layout = QFormLayout() @@ -667,7 +676,7 @@ def init(self, tabs, main_window): self.detector.textChanged.connect(lambda: set_overriden(self.detector)) - def load_tab(self, conf_map, specfile, diff): + def load_tab(self, conf_map): """ It verifies given configuration file, reads the parameters, and fills out the window. Parameters @@ -678,7 +687,7 @@ def load_tab(self, conf_map, specfile, diff): ------- nothing """ - self.parse_spec(specfile, diff) + self.parse_spec() # if parameters are configured, override the readings from spec file if 'energy' in conf_map: @@ -762,7 +771,7 @@ def get_instr_config(self): return conf_map - def parse_spec(self, specfile, diffractometer): + def parse_spec(self): """ Calls utility function to parse spec file. Displas the parsed parameters in the window with blue text. Parameters @@ -774,6 +783,17 @@ def parse_spec(self, specfile, diffractometer): """ scan = str(self.main_window.scan_widget.text()) if len(scan) == 0: + msg_window ('cannot parse spec, scan not defined') + return + + diffractometer = self.instr_tab.diffractometer.text() + if len(diffractometer) == 0: + msg_window ('cannot parse spec, diffractometer not defined') + return + + specfile = self.instr_tab.spec_file_button.text() + if len(specfile) == 0: + msg_window ('cannot parse spec, specfile not defined') return import beamlines.aps_34idc.diffractometers as diff @@ -787,6 +807,8 @@ def parse_spec(self, specfile, diffractometer): last_scan = int(scan.split('-')[-1].split(',')[-1]) spec_dict = instr.parse_spec(specfile, last_scan, diff_obj) + if spec_dict is None: + return if 'energy' in spec_dict: self.energy.setText(str(spec_dict['energy'])) self.energy.setStyleSheet('color: blue') @@ -838,9 +860,9 @@ def toggle_config(self): else: self.add_config = True self.extended.spec_widget.show() - self.extended.parse_spec(self.spec_file_button.text(), self.diffractometer.text()) - if self.main_win.is_exp_exists(): - self.save_conf() + self.extended.parse_spec() + + self.save_conf() def init(self, tabs, main_window): @@ -861,7 +883,7 @@ def init(self, tabs, main_window): else: self.add_config = True self.extended = SubInstrTab() - self.extended.init(tabs, main_window) + self.extended.init(self, main_window) tab_layout = QVBoxLayout() gen_layout = QFormLayout() @@ -912,11 +934,12 @@ def load_tab(self, conf_map): if os.path.isfile(specfile): self.spec_file_button.setStyleSheet("Text-align:left") self.spec_file_button.setText(specfile) - if self.add_config: - self.extended.load_tab(conf_map, specfile, diff) else: msg_window('The specfile file ' + specfile + ' in config file does not exist') + if self.add_config: + self.extended.load_tab(conf_map) + def set_spec_file(self): """ @@ -929,17 +952,17 @@ def set_spec_file(self): ------- noting """ - self.specfile = select_file(os.getcwd()) - if self.specfile is not None: + specfile = select_file(os.getcwd()) + if specfile is not None: self.spec_file_button.setStyleSheet("Text-align:left") - self.spec_file_button.setText(self.specfile) - self.save_conf() + self.spec_file_button.setText(specfile) if self.add_config: - self.extended.parse_spec(self.specfile, self.diffractometer.text()) + self.extended.parse_spec() else: - self.specfile = None self.spec_file_button.setText('') + self.save_conf() + def clear_conf(self): self.diffractometer.setText('') @@ -1000,6 +1023,10 @@ def save_conf(self): ------- nothing """ + if not self.main_win.is_exp_exists(): + msg_window('the experiment does not exist, cannot save the config_instr file') + return + conf_map = self.get_instr_config() # verify that disp configuration is ok er_msg = cohere.verify('config_instr', conf_map)