def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__(self, parent, name, QtImport.Qt.WindowFlags(fl), "Standard") if not name: self.setObjectName("create_discrete_widget") # Internal variables -------------------------------------------------- self.init_models() # Graphic elements ---------------------------------------------------- self._acq_widget = AcquisitionWidget( self, "acquisition_widget", layout="vertical", acq_params=self._acquisition_parameters, path_template=self._path_template, ) self._data_path_widget = DataPathWidget( self, "create_dc_path_widget", data_model=self._path_template, layout="vertical", ) self._processing_widget = ProcessingWidget( self, data_model=self._processing_parameters) self._comments_widget = CommentsWidget(self) self._comments_widget.setHidden(True) # Layout -------------------------------------------------------------- _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self._acq_widget) _main_vlayout.addWidget(self._data_path_widget) _main_vlayout.addWidget(self._processing_widget) _main_vlayout.addWidget(self._comments_widget) _main_vlayout.addStretch(0) _main_vlayout.setSpacing(6) _main_vlayout.setContentsMargins(2, 2, 2, 2) # SizePolicies -------------------------------------------------------- self._comments_widget.setFixedHeight(100) # Qt signal/slot connections ------------------------------------------ self._acq_widget.acqParametersChangedSignal.connect( self.acq_parameters_changed) self._data_path_widget.pathTemplateChangedSignal.connect( self.path_template_changed) self._acq_widget.madEnergySelectedSignal.connect( self.mad_energy_selected) self._processing_widget.enableProcessingSignal.connect( self._run_processing_toggled) # Other --------------------------------------------------------------- self._processing_widget.processing_widget.run_processing_parallel_cbox.\ setChecked(HWR.beamline.run_processing_parallel)
def __init__(self, parent=None, name="parameter_widget"): QtImport.QWidget.__init__(self, parent) if name is not None: self.setObjectName(name) # Properties ---------------------------------------------------------- # Signals ------------------------------------------------------------ # Slots --------------------------------------------------------------- # Internal variables -------------------------------------------------- self._data_collection = None self._tree_view_item = None self._acquisition_mib = None # Graphic elements ---------------------------------------------------- _dc_parameters_widget = QtImport.QWidget(self) self._data_path_widget = DataPathWidget(_dc_parameters_widget) self._acq_widget = AcquisitionWidget(_dc_parameters_widget, layout="horizontal") self._processing_widget = ProcessingWidget(_dc_parameters_widget) # Layout -------------------------------------------------------------- _dc_parameters_widget_layout = QtImport.QVBoxLayout( _dc_parameters_widget) _dc_parameters_widget_layout.addWidget(self._data_path_widget) _dc_parameters_widget_layout.addWidget(self._acq_widget) _dc_parameters_widget_layout.addWidget(self._processing_widget) _dc_parameters_widget_layout.setContentsMargins(0, 0, 0, 0) _dc_parameters_widget_layout.setSpacing(2) _dc_parameters_widget_layout.addStretch(10) _main_hlayout = QtImport.QHBoxLayout(self) _main_hlayout.addWidget(_dc_parameters_widget) _main_hlayout.setContentsMargins(0, 0, 0, 0) _main_hlayout.setSpacing(2) _main_hlayout.addStretch(0) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self._data_path_widget.data_path_layout.prefix_ledit.textChanged.connect( self._prefix_ledit_change) self._data_path_widget.data_path_layout.run_number_ledit.textChanged.connect( self._run_number_ledit_change) self._acq_widget.madEnergySelectedSignal.connect( self.mad_energy_selected) self._acq_widget.acqParametersChangedSignal.connect( self.acq_parameters_changed)
def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__( self, parent, name, QtImport.Qt.WindowFlags(fl), "Standard" ) if not name: self.setObjectName("create_discrete_widget") # Hardware objects ---------------------------------------------------- # Internal variables -------------------------------------------------- self.init_models() # Graphic elements ---------------------------------------------------- self._acq_widget = AcquisitionWidget( self, "acquisition_widget", layout="vertical", acq_params=self._acquisition_parameters, path_template=self._path_template, ) self._data_path_widget = DataPathWidget( self, "create_dc_path_widget", data_model=self._path_template, layout="vertical", ) self._processing_widget = ProcessingWidget( self, data_model=self._processing_parameters ) # Layout -------------------------------------------------------------- _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self._acq_widget) _main_vlayout.addWidget(self._data_path_widget) _main_vlayout.addWidget(self._processing_widget) _main_vlayout.addStretch(0) _main_vlayout.setSpacing(6) _main_vlayout.setContentsMargins(2, 2, 2, 2) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self._acq_widget.acqParametersChangedSignal.connect(self.acq_parameters_changed) self._data_path_widget.pathTemplateChangedSignal.connect( self.path_template_changed ) self._acq_widget.madEnergySelectedSignal.connect(self.mad_energy_selected) self._processing_widget.enableProcessingSignal.connect( self._run_processing_toggled ) # Other --------------------------------------------------------------- self._processing_widget.processing_widget.run_processing_parallel_cbox.setChecked( api.beamline_setup._get_run_processing_parallel() )
def __init__(self, parent=None, name="parameter_widget"): QtImport.QWidget.__init__(self, parent) if name is not None: self.setObjectName(name) # Properties ---------------------------------------------------------- # Signals ------------------------------------------------------------ # Slots --------------------------------------------------------------- # Internal variables -------------------------------------------------- self._data_collection = None self._tree_view_item = None self._acquisition_mib = None # Graphic elements ---------------------------------------------------- _dc_parameters_widget = QtImport.QWidget(self) self._data_path_widget = DataPathWidget(_dc_parameters_widget) self._acq_widget = AcquisitionWidget(_dc_parameters_widget, layout="horizontal") self._processing_widget = ProcessingWidget(_dc_parameters_widget) # Layout -------------------------------------------------------------- _dc_parameters_widget_layout = QtImport.QVBoxLayout(_dc_parameters_widget) _dc_parameters_widget_layout.addWidget(self._data_path_widget) _dc_parameters_widget_layout.addWidget(self._acq_widget) _dc_parameters_widget_layout.addWidget(self._processing_widget) _dc_parameters_widget_layout.setContentsMargins(0, 0, 0, 0) _dc_parameters_widget_layout.setSpacing(2) _dc_parameters_widget_layout.addStretch(10) _main_hlayout = QtImport.QHBoxLayout(self) _main_hlayout.addWidget(_dc_parameters_widget) _main_hlayout.setContentsMargins(0, 0, 0, 0) _main_hlayout.setSpacing(2) _main_hlayout.addStretch(0) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self._data_path_widget.data_path_layout.prefix_ledit.textChanged.connect( self._prefix_ledit_change ) self._data_path_widget.data_path_layout.run_number_ledit.textChanged.connect( self._run_number_ledit_change ) self._acq_widget.madEnergySelectedSignal.connect(self.mad_energy_selected) self._acq_widget.acqParametersChangedSignal.connect(self.acq_parameters_changed)
class CreateDiscreteWidget(CreateTaskBase): def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__( self, parent, name, QtImport.Qt.WindowFlags(fl), "Standard" ) if not name: self.setObjectName("create_discrete_widget") # Internal variables -------------------------------------------------- self.init_models() # Graphic elements ---------------------------------------------------- self._acq_widget = AcquisitionWidget( self, "acquisition_widget", layout="vertical", acq_params=self._acquisition_parameters, path_template=self._path_template, ) self._data_path_widget = DataPathWidget( self, "create_dc_path_widget", data_model=self._path_template, layout="vertical", ) self._processing_widget = ProcessingWidget( self, data_model=self._processing_parameters ) self._comments_widget = CommentsWidget(self) self._comments_widget.setHidden(True) # Layout -------------------------------------------------------------- _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self._acq_widget) _main_vlayout.addWidget(self._data_path_widget) _main_vlayout.addWidget(self._processing_widget) _main_vlayout.addWidget(self._comments_widget) _main_vlayout.addStretch(0) _main_vlayout.setSpacing(6) _main_vlayout.setContentsMargins(2, 2, 2, 2) # SizePolicies -------------------------------------------------------- self._comments_widget.setFixedHeight(100) # Qt signal/slot connections ------------------------------------------ self._acq_widget.acqParametersChangedSignal.connect(self.acq_parameters_changed) self._data_path_widget.pathTemplateChangedSignal.connect( self.path_template_changed ) self._acq_widget.madEnergySelectedSignal.connect(self.mad_energy_selected) self._processing_widget.enableProcessingSignal.connect( self._run_processing_toggled ) # Other --------------------------------------------------------------- self._processing_widget.processing_widget.run_online_processing_cbox.\ setChecked(HWR.beamline.run_online_processing) def init_models(self): CreateTaskBase.init_models(self) self._processing_parameters = queue_model_objects.ProcessingParameters() has_shutter_less = HWR.beamline.detector.has_shutterless() self._acquisition_parameters.shutterless = has_shutter_less self._acquisition_parameters = \ HWR.beamline.get_default_acquisition_parameters() def set_tunable_energy(self, state): self._acq_widget.set_tunable_energy(state) def single_item_selection(self, tree_item): CreateTaskBase.single_item_selection(self, tree_item) if isinstance(tree_item, queue_item.SampleQueueItem): sample_model = tree_item.get_model() # self._processing_parameters = copy.deepcopy(self._processing_parameters) self._processing_parameters = sample_model.processing_parameters self._processing_widget.update_data_model(self._processing_parameters) elif isinstance(tree_item, queue_item.BasketQueueItem): self.setDisabled(False) elif isinstance(tree_item, queue_item.DataCollectionQueueItem): dc_model = tree_item.get_model() self._acq_widget.use_kappa(False) if not dc_model.is_helical(): if dc_model.is_executed(): self.setDisabled(True) else: self.setDisabled(False) sample_data_model = self.get_sample_item(tree_item).get_model() energy_scan_result = sample_data_model.crystals[0].energy_scan_result self._acq_widget.set_energies(energy_scan_result) # self._acq_widget.disable_inverse_beam(True) self._path_template = dc_model.get_path_template() self._data_path_widget.update_data_model(self._path_template) self._acquisition_parameters =\ dc_model.acquisitions[0].acquisition_parameters self._acq_widget.update_data_model( self._acquisition_parameters, self._path_template ) # self.get_acquisition_widget().use_osc_start(True) if len(dc_model.acquisitions) == 1: HWR.beamline.sample_view.select_shape_with_cpos( self._acquisition_parameters.centred_position ) self._processing_parameters = dc_model.processing_parameters self._processing_widget.update_data_model(self._processing_parameters) else: self.setDisabled(True) else: self.setDisabled(True) def approve_creation(self): result = CreateTaskBase.approve_creation(self) return result def _create_task(self, sample, shape, comments=None): """ Called by the owning widget (task_toolbox_widget) to create a collection. When a data collection group is selected. :param sample: :param shape: :return: """ tasks = [] if isinstance(shape, GraphicsItemPoint): snapshot = HWR.beamline.sample_view.get_snapshot(shape) cpos = copy.deepcopy(shape.get_centred_position()) cpos.snapshot_image = snapshot else: cpos = queue_model_objects.CentredPosition() cpos.snapshot_image = HWR.beamline.sample_view.get_snapshot() tasks.extend(self.create_dc(sample, cpos=cpos)) self._path_template.run_number += 1 return tasks def create_dc( self, sample, run_number=None, start_image=None, num_images=None, osc_start=None, sc=None, cpos=None, inverse_beam=False, ): tasks = [] # Acquisition for start position acq = self._create_acq(sample) if run_number: acq.path_template.run_number = run_number if start_image: acq.acquisition_parameters.first_image = start_image acq.path_template.start_num = start_image if num_images: acq.acquisition_parameters.num_images = num_images acq.path_template.num_files = num_images if osc_start: acq.acquisition_parameters.osc_start = osc_start if inverse_beam: acq.acquisition_parameters.inverse_beam = False acq.acquisition_parameters.centred_position = cpos processing_parameters = copy.deepcopy(self._processing_parameters) data_collection = queue_model_objects.DataCollection( [acq], sample.crystals[0], processing_parameters ) data_collection.set_name(acq.path_template.get_prefix()) data_collection.set_number(acq.path_template.run_number) data_collection.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.NATIVE run_processing_after, run_online_processing = \ self._processing_widget.get_processing_state() data_collection.run_processing_after = run_processing_after if run_online_processing: data_collection.run_online_processing = "Undefined" tasks.append(data_collection) return tasks
class CreateStillScanWidget(CreateTaskBase): def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__( self, parent, name, QtImport.Qt.WindowFlags(fl), "Still" ) if not name: self.setObjectName("create_still_scan_widget") # Hardware objects ---------------------------------------------------- # Internal variables -------------------------------------------------- self.init_models() # Graphic elements ---------------------------------------------------- self._acq_widget = AcquisitionStillWidget( self, "acquisition_widget", layout="vertical", acq_params=self._acquisition_parameters, path_template=self._path_template, ) self._data_path_widget = DataPathWidget( self, "create_dc_path_widget", data_model=self._path_template, layout="vertical", ) self._processing_widget = ProcessingWidget( self, data_model=self._processing_parameters ) # Layout -------------------------------------------------------------- _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self._acq_widget) _main_vlayout.addWidget(self._data_path_widget) _main_vlayout.addWidget(self._processing_widget) _main_vlayout.addStretch(0) _main_vlayout.setSpacing(6) _main_vlayout.setContentsMargins(2, 2, 2, 2) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self._acq_widget.acqParametersChangedSignal.connect(self.acq_parameters_changed) self._data_path_widget.pathTemplateChangedSignal.connect( self.path_template_changed ) self._processing_widget.enableProcessingSignal.connect( self._run_processing_toggled ) # Other --------------------------------------------------------------- self._processing_widget.processing_widget.run_processing_parallel_cbox.setChecked( api.beamline_setup._get_run_processing_parallel() ) def use_osc_start(self, status): pass def update_exp_time_limits(self, status): pass def init_models(self): CreateTaskBase.init_models(self) self._processing_parameters = queue_model_objects.ProcessingParameters() has_shutter_less = api.beamline_setup.detector_has_shutterless() self._acquisition_parameters.shutterless = has_shutter_less self._acquisition_parameters = api.beamline_setup.get_default_acquisition_parameters( "default_acquisition_values" ) self._acquisition_parameters.num_triggers = 1 self._acquisition_parameters.num_images_per_trigger = 1 def set_tunable_energy(self, state): self._acq_widget.set_tunable_energy(state) def update_processing_parameters(self, crystal): self._processing_parameters.space_group = crystal.space_group self._processing_parameters.cell_a = crystal.cell_a self._processing_parameters.cell_alpha = crystal.cell_alpha self._processing_parameters.cell_b = crystal.cell_b self._processing_parameters.cell_beta = crystal.cell_beta self._processing_parameters.cell_c = crystal.cell_c self._processing_parameters.cell_gamma = crystal.cell_gamma self._processing_widget.update_data_model(self._processing_parameters) def single_item_selection(self, tree_item): CreateTaskBase.single_item_selection(self, tree_item) if isinstance(tree_item, queue_item.SampleQueueItem): sample_model = tree_item.get_model() # self._processing_parameters = copy.deepcopy(self._processing_parameters) self._processing_parameters = sample_model.processing_parameters self._processing_widget.update_data_model(self._processing_parameters) elif isinstance(tree_item, queue_item.BasketQueueItem): self.setDisabled(False) elif isinstance(tree_item, queue_item.DataCollectionQueueItem): dc = tree_item.get_model() self._acq_widget.use_kappa(False) if not dc.is_helical(): if dc.is_executed(): self.setDisabled(True) else: self.setDisabled(False) sample_data_model = self.get_sample_item(tree_item).get_model() energy_scan_result = sample_data_model.crystals[0].energy_scan_result self._acq_widget.set_energies(energy_scan_result) # self._acq_widget.disable_inverse_beam(True) self._path_template = dc.get_path_template() self._data_path_widget.update_data_model(self._path_template) self._acquisition_parameters = dc.acquisitions[0].acquisition_parameters self._acq_widget.update_data_model( self._acquisition_parameters, self._path_template ) # self.get_acquisition_widget().use_osc_start(True) if len(dc.acquisitions) == 1: self.select_shape_with_cpos( self._acquisition_parameters.centred_position ) self._processing_parameters = dc.processing_parameters self._processing_widget.update_data_model(self._processing_parameters) else: self.setDisabled(True) else: self.setDisabled(True) def _create_task(self, sample, shape): tasks = [] cpos = queue_model_objects.CentredPosition() cpos.snapshot_image = api.graphics.get_scene_snapshot() tasks.extend(self.create_dc(sample, cpos=cpos)) self._path_template.run_number += 1 return tasks def create_dc( self, sample, run_number=None, start_image=None, num_images=None, osc_start=None, sc=None, cpos=None, inverse_beam=False, ): tasks = [] # Acquisition for start position acq = self._create_acq(sample) if run_number: acq.path_template.run_number = run_number if start_image: acq.acquisition_parameters.first_image = start_image acq.path_template.start_num = start_image if num_images: acq.acquisition_parameters.num_images = num_images acq.path_template.num_files = num_images if osc_start: acq.acquisition_parameters.osc_start = osc_start if inverse_beam: acq.acquisition_parameters.inverse_beam = False acq.acquisition_parameters.centred_position = cpos processing_parameters = copy.deepcopy(self._processing_parameters) dc = queue_model_objects.DataCollection( [acq], sample.crystals[0], processing_parameters ) dc.set_name(acq.path_template.get_prefix()) dc.set_number(acq.path_template.run_number) dc.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.OSC dc.run_processing_after = ( self._processing_widget.processing_widget.run_processing_after_cbox.isChecked() ) if ( self._processing_widget.processing_widget.run_processing_parallel_cbox.isChecked() ): dc.run_processing_parallel = "Still" dc.set_requires_centring(False) tasks.append(dc) return tasks
class CreateDiscreteWidget(CreateTaskBase): def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__( self, parent, name, QtImport.Qt.WindowFlags(fl), "Standard" ) if not name: self.setObjectName("create_discrete_widget") # Hardware objects ---------------------------------------------------- # Internal variables -------------------------------------------------- self.init_models() # Graphic elements ---------------------------------------------------- self._acq_widget = AcquisitionWidget( self, "acquisition_widget", layout="vertical", acq_params=self._acquisition_parameters, path_template=self._path_template, ) self._data_path_widget = DataPathWidget( self, "create_dc_path_widget", data_model=self._path_template, layout="vertical", ) self._processing_widget = ProcessingWidget( self, data_model=self._processing_parameters ) # Layout -------------------------------------------------------------- _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self._acq_widget) _main_vlayout.addWidget(self._data_path_widget) _main_vlayout.addWidget(self._processing_widget) _main_vlayout.addStretch(0) _main_vlayout.setSpacing(6) _main_vlayout.setContentsMargins(2, 2, 2, 2) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self._acq_widget.acqParametersChangedSignal.connect(self.acq_parameters_changed) self._data_path_widget.pathTemplateChangedSignal.connect( self.path_template_changed ) self._acq_widget.madEnergySelectedSignal.connect(self.mad_energy_selected) self._processing_widget.enableProcessingSignal.connect( self._run_processing_toggled ) # Other --------------------------------------------------------------- self._processing_widget.processing_widget.run_processing_parallel_cbox.setChecked( api.beamline_setup._get_run_processing_parallel() ) def init_models(self): CreateTaskBase.init_models(self) # self._energy_scan_result = queue_model_objects.EnergyScanResult() self._processing_parameters = queue_model_objects.ProcessingParameters() has_shutter_less = api.beamline_setup.detector_has_shutterless() self._acquisition_parameters.shutterless = has_shutter_less self._acquisition_parameters = api.beamline_setup.get_default_acquisition_parameters( "default_acquisition_values" ) def set_tunable_energy(self, state): self._acq_widget.set_tunable_energy(state) def update_processing_parameters(self, crystal): self._processing_parameters.space_group = crystal.space_group self._processing_parameters.cell_a = crystal.cell_a self._processing_parameters.cell_alpha = crystal.cell_alpha self._processing_parameters.cell_b = crystal.cell_b self._processing_parameters.cell_beta = crystal.cell_beta self._processing_parameters.cell_c = crystal.cell_c self._processing_parameters.cell_gamma = crystal.cell_gamma self._processing_widget.update_data_model(self._processing_parameters) def single_item_selection(self, tree_item): CreateTaskBase.single_item_selection(self, tree_item) if isinstance(tree_item, queue_item.SampleQueueItem): sample_model = tree_item.get_model() # self._processing_parameters = copy.deepcopy(self._processing_parameters) self._processing_parameters = sample_model.processing_parameters self._processing_widget.update_data_model(self._processing_parameters) elif isinstance(tree_item, queue_item.BasketQueueItem): self.setDisabled(False) elif isinstance(tree_item, queue_item.DataCollectionQueueItem): dc = tree_item.get_model() self._acq_widget.use_kappa(False) if not dc.is_helical(): if dc.is_executed(): self.setDisabled(True) else: self.setDisabled(False) sample_data_model = self.get_sample_item(tree_item).get_model() energy_scan_result = sample_data_model.crystals[0].energy_scan_result self._acq_widget.set_energies(energy_scan_result) # self._acq_widget.disable_inverse_beam(True) self._path_template = dc.get_path_template() self._data_path_widget.update_data_model(self._path_template) self._acquisition_parameters = dc.acquisitions[0].acquisition_parameters self._acq_widget.update_data_model( self._acquisition_parameters, self._path_template ) # self.get_acquisition_widget().use_osc_start(True) if len(dc.acquisitions) == 1: self.select_shape_with_cpos( self._acquisition_parameters.centred_position ) self._processing_parameters = dc.processing_parameters self._processing_widget.update_data_model(self._processing_parameters) else: self.setDisabled(True) else: self.setDisabled(True) def approve_creation(self): result = CreateTaskBase.approve_creation(self) return result # Called by the owning widget (task_toolbox_widget) to create # a collection. When a data collection group is selected. def _create_task(self, sample, shape): tasks = [] if isinstance(shape, GraphicsItemPoint): snapshot = api.graphics.get_scene_snapshot(shape) cpos = copy.deepcopy(shape.get_centred_position()) cpos.snapshot_image = snapshot else: cpos = queue_model_objects.CentredPosition() cpos.snapshot_image = api.graphics.get_scene_snapshot() tasks.extend(self.create_dc(sample, cpos=cpos)) self._path_template.run_number += 1 return tasks def create_dc( self, sample, run_number=None, start_image=None, num_images=None, osc_start=None, sc=None, cpos=None, inverse_beam=False, ): tasks = [] # Acquisition for start position acq = self._create_acq(sample) if run_number: acq.path_template.run_number = run_number if start_image: acq.acquisition_parameters.first_image = start_image acq.path_template.start_num = start_image if num_images: acq.acquisition_parameters.num_images = num_images acq.path_template.num_files = num_images if osc_start: acq.acquisition_parameters.osc_start = osc_start if inverse_beam: acq.acquisition_parameters.inverse_beam = False acq.acquisition_parameters.centred_position = cpos processing_parameters = copy.deepcopy(self._processing_parameters) dc = queue_model_objects.DataCollection( [acq], sample.crystals[0], processing_parameters ) dc.set_name(acq.path_template.get_prefix()) dc.set_number(acq.path_template.run_number) dc.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.NATIVE dc.run_processing_after = ( self._processing_widget.processing_widget.run_processing_after_cbox.isChecked() ) if ( self._processing_widget.processing_widget.run_processing_parallel_cbox.isChecked() ): dc.run_processing_parallel = "Undefined" tasks.append(dc) return tasks def execute_task(self, sample): # All this should be in queue_entry level group_data = { "sessionId": api.session.session_id, "experimentType": "OSC", } gid = api.lims._store_data_collection_group(group_data) sample.lims_group_id = gid task_list = self._create_task(sample, None) task_list[0].lims_group_id = gid param_list = queue_model_objects.to_collect_dict( task_list[0], api.session, sample, None ) api.collect.collect( queue_model_enumerables.COLLECTION_ORIGIN_STR.MXCUBE, param_list )
def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__(self, parent, name, fl, "Helical") if not name: self.setObjectName("create_helical_widget") self.init_models() # Hardware objects ---------------------------------------------------- # Internal variables -------------------------------------------------- self._lines_map = {} # Graphic elements ---------------------------------------------------- self._lines_widget = QtImport.load_ui_file( "helical_line_widget_layout.ui") self._acq_widget = AcquisitionWidget( self, "acquisition_widget", layout="vertical", acq_params=self._acquisition_parameters, path_template=self._path_template, ) self._data_path_widget = DataPathWidget( self, "create_dc_path_widget", data_model=self._path_template, layout="vertical", ) self._processing_widget = ProcessingWidget( self, data_model=self._processing_parameters) self._comments_widget = CommentsWidget(self) # Layout -------------------------------------------------------------- _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self._lines_widget) _main_vlayout.addWidget(self._acq_widget) _main_vlayout.addWidget(self._data_path_widget) _main_vlayout.addWidget(self._processing_widget) _main_vlayout.addWidget(self._comments_widget) _main_vlayout.addStretch(0) _main_vlayout.setSpacing(6) _main_vlayout.setContentsMargins(2, 2, 2, 2) # SizePolicies -------------------------------------------------------- self._comments_widget.setFixedHeight(100) # Qt signal/slot connections ------------------------------------------ self._lines_widget.lines_treewidget.itemSelectionChanged.connect( self.lines_treewidget_selection_changed) self._lines_widget.create_line_button.clicked.connect( self.create_line_button_clicked) self._lines_widget.create_auto_line_button.clicked.connect( self.create_auto_line_button_clicked) self._lines_widget.remove_line_button.clicked.connect( self.remove_line_button_clicked) self._lines_widget.overlay_cbox.stateChanged.connect( self.overlay_toggled) self._lines_widget.overlay_slider.valueChanged.connect( self.overlay_alpha_changed) self._lines_widget.swap_points_button.clicked.connect( self.swap_points_clicked) self._acq_widget.acqParametersChangedSignal.connect( self.acq_parameters_changed) self._acq_widget.madEnergySelectedSignal.connect( self.mad_energy_selected) self._data_path_widget.pathTemplateChangedSignal.connect( self.path_template_changed) self._processing_widget.enableProcessingSignal.connect( self._run_processing_toggled) # Other --------------------------------------------------------------- for col in range(self._lines_widget.lines_treewidget.columnCount()): self._lines_widget.lines_treewidget.resizeColumnToContents(col) # self._processing_widget.processing_widget.\ # run_processing_parallel_cbox.setChecked(False) self._processing_widget.processing_widget.run_processing_parallel_cbox.setChecked( HWR.beamline.run_processing_parallel) self.enable_widgets(False) shapes = HWR.beamline.sample_view.get_shapes() for shape in shapes: if isinstance(shape, GraphicsItemLine): self.shape_created(shape, "Line") HWR.beamline.sample_view.connect("shapeCreated", self.shape_created) HWR.beamline.sample_view.connect("shapeChanged", self.shape_changed) HWR.beamline.sample_view.connect("shapeDeleted", self.shape_deleted) self._comments_widget.setHidden(True)
class CreateHelicalWidget(CreateTaskBase): def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__(self, parent, name, fl, "Helical") if not name: self.setObjectName("create_helical_widget") self.init_models() # Hardware objects ---------------------------------------------------- # Internal variables -------------------------------------------------- self._lines_map = {} # Graphic elements ---------------------------------------------------- self._lines_widget = QtImport.load_ui_file( "helical_line_widget_layout.ui") self._acq_widget = AcquisitionWidget( self, "acquisition_widget", layout="vertical", acq_params=self._acquisition_parameters, path_template=self._path_template, ) self._data_path_widget = DataPathWidget( self, "create_dc_path_widget", data_model=self._path_template, layout="vertical", ) self._processing_widget = ProcessingWidget( self, data_model=self._processing_parameters) self._comments_widget = CommentsWidget(self) # Layout -------------------------------------------------------------- _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self._lines_widget) _main_vlayout.addWidget(self._acq_widget) _main_vlayout.addWidget(self._data_path_widget) _main_vlayout.addWidget(self._processing_widget) _main_vlayout.addWidget(self._comments_widget) _main_vlayout.addStretch(0) _main_vlayout.setSpacing(6) _main_vlayout.setContentsMargins(2, 2, 2, 2) # SizePolicies -------------------------------------------------------- self._comments_widget.setFixedHeight(100) # Qt signal/slot connections ------------------------------------------ self._lines_widget.lines_treewidget.itemSelectionChanged.connect( self.lines_treewidget_selection_changed) self._lines_widget.create_line_button.clicked.connect( self.create_line_button_clicked) self._lines_widget.create_auto_line_button.clicked.connect( self.create_auto_line_button_clicked) self._lines_widget.remove_line_button.clicked.connect( self.remove_line_button_clicked) self._lines_widget.overlay_cbox.stateChanged.connect( self.overlay_toggled) self._lines_widget.overlay_slider.valueChanged.connect( self.overlay_alpha_changed) self._lines_widget.swap_points_button.clicked.connect( self.swap_points_clicked) self._acq_widget.acqParametersChangedSignal.connect( self.acq_parameters_changed) self._acq_widget.madEnergySelectedSignal.connect( self.mad_energy_selected) self._data_path_widget.pathTemplateChangedSignal.connect( self.path_template_changed) self._processing_widget.enableProcessingSignal.connect( self._run_processing_toggled) # Other --------------------------------------------------------------- for col in range(self._lines_widget.lines_treewidget.columnCount()): self._lines_widget.lines_treewidget.resizeColumnToContents(col) # self._processing_widget.processing_widget.\ # run_processing_parallel_cbox.setChecked(False) self._processing_widget.processing_widget.run_processing_parallel_cbox.setChecked( HWR.beamline.run_processing_parallel) self.enable_widgets(False) shapes = HWR.beamline.sample_view.get_shapes() for shape in shapes: if isinstance(shape, GraphicsItemLine): self.shape_created(shape, "Line") HWR.beamline.sample_view.connect("shapeCreated", self.shape_created) HWR.beamline.sample_view.connect("shapeChanged", self.shape_changed) HWR.beamline.sample_view.connect("shapeDeleted", self.shape_deleted) self._comments_widget.setHidden(True) def enable_widgets(self, state): self._acq_widget.setEnabled(state) self._data_path_widget.setEnabled(state) self._processing_widget.setEnabled(state) def init_models(self): CreateTaskBase.init_models(self) self._energy_scan_result = queue_model_objects.EnergyScanResult() self._processing_parameters = queue_model_objects.ProcessingParameters( ) has_shutter_less = HWR.beamline.detector.has_shutterless() self._acquisition_parameters.shutterless = has_shutter_less self._acquisition_parameters = ( HWR.beamline.get_default_acquisition_parameters("helical")) def shape_created(self, shape, shape_type): if shape_type == "Line": self._lines_widget.lines_treewidget.clearSelection() # info_str_list = QStringList() info_str_list = [] info_str_list.append(shape.get_display_name()) info_str_list.append("%d" % shape.get_points_index()[0]) info_str_list.append("%d" % shape.get_points_index()[1]) lines_treewidget_item = QtImport.QTreeWidgetItem( self._lines_widget.lines_treewidget, info_str_list) lines_treewidget_item.setSelected(True) self._lines_map[shape] = lines_treewidget_item self.lines_treewidget_selection_changed() def shape_deleted(self, shape, shape_type): if shape_type == "Line" and self._lines_map.get(shape): shape_index = self._lines_widget.lines_treewidget.indexFromItem( self._lines_map[shape]) self._lines_widget.lines_treewidget.takeTopLevelItem( shape_index.row()) self._lines_map.pop(shape) def approve_creation(self): base_result = CreateTaskBase.approve_creation(self) if len(self._lines_widget.lines_treewidget.selectedItems()) == 0: logging.getLogger("GUI").warning( "No lines selected, please select one or more lines.") return False else: return base_result def select_line_with_cpos(self, start_cpos, end_cpos, num_images): """Selects graphical line which contains two cpositions Adds number of frames next to the graphical line """ self._lines_widget.overlay_slider.setEnabled(False) self._lines_widget.overlay_cbox.setEnabled(False) HWR.beamline.sample_view.de_select_all() for shape in HWR.beamline.sample_view.get_shapes(): if isinstance(shape, GraphicsItemLine): (start_cpos_index, end_cpos_index) = shape.get_points_index() if (start_cpos_index == start_cpos.index and end_cpos_index == end_cpos.index): HWR.beamline.sample_view.select_shape(shape) shape.set_num_images(num_images) self._lines_widget.overlay_slider.setEnabled(True) self._lines_widget.overlay_cbox.setEnabled(True) def single_item_selection(self, tree_item): CreateTaskBase.single_item_selection(self, tree_item) if isinstance(tree_item, queue_item.SampleQueueItem): sample_model = tree_item.get_model() self._processing_parameters = sample_model.processing_parameters # self._processing_parameters = copy.deepcopy(self._processing_parameters) self._processing_widget.update_data_model( self._processing_parameters) elif isinstance(tree_item, queue_item.BasketQueueItem): self.setDisabled(False) elif isinstance(tree_item, queue_item.DataCollectionQueueItem): data_collection = tree_item.get_model() if data_collection.is_helical(): self.setDisabled(tree_item.get_model().is_executed()) self._path_template = data_collection.get_path_template() self._data_path_widget.update_data_model(self._path_template) self._acquisition_parameters = data_collection.acquisitions[ 0].acquisition_parameters if len(data_collection.acquisitions) == 2: start_cpos = data_collection.acquisitions[ 0].acquisition_parameters.centred_position end_cpos = data_collection.acquisitions[ 1].acquisition_parameters.centred_position num_images = data_collection.acquisitions[ 0].acquisition_parameters.num_images self.select_line_with_cpos(start_cpos, end_cpos, num_images) self._acq_widget.update_data_model( self._acquisition_parameters, self._path_template) # self.get_acquisition_widget().use_osc_start(True) self._processing_parameters = data_collection.processing_parameters self._processing_widget.update_data_model( self._processing_parameters) else: self.setDisabled(True) else: self.setDisabled(True) if (isinstance(tree_item, queue_item.SampleQueueItem) or isinstance( tree_item, queue_item.DataCollectionGroupQueueItem) or isinstance(tree_item, queue_item.DataCollectionQueueItem)): self._processing_widget.update_data_model( self._processing_parameters) self._acq_widget.update_data_model(self._acquisition_parameters, self._path_template) def _create_task(self, sample, shape, comments=None): data_collections = [] for shape in self.get_selected_shapes(): snapshot = HWR.beamline.sample_view.get_scene_snapshot(shape) # Acquisition for start position start_acq = self._create_acq(sample) start_graphical_point, end_graphical_point = shape.get_graphical_points( ) start_acq.acquisition_parameters.centred_position = copy.deepcopy( start_graphical_point.get_centred_position()) start_acq.acquisition_parameters.centred_position.snapshot_image = snapshot start_acq.path_template.suffix = HWR.beamline.session.suffix # Add another acquisition for the end position end_acq = self._create_acq(sample) end_acq.acquisition_parameters.centred_position = copy.deepcopy( end_graphical_point.get_centred_position()) end_acq.acquisition_parameters.centred_position.snapshot_image = snapshot end_acq.path_template.suffix = HWR.beamline.session.suffix processing_parameters = copy.deepcopy(self._processing_parameters) dc = queue_model_objects.DataCollection([start_acq, end_acq], sample.crystals[0], processing_parameters) dc.set_name(start_acq.path_template.get_prefix()) dc.set_number(start_acq.path_template.run_number) dc.set_experiment_type(EXPERIMENT_TYPE.HELICAL) dc.set_requires_centring(False) dc.run_processing_after = ( self._processing_widget.processing_widget. run_processing_after_cbox.isChecked()) if (self._processing_widget.processing_widget. run_processing_parallel_cbox.isChecked()): dc.run_processing_parallel = "LineScan" data_collections.append(dc) self._path_template.run_number += 1 return data_collections def lines_treewidget_selection_changed(self): self.enable_widgets( len(self._lines_widget.lines_treewidget.selectedItems()) > 0) self._lines_widget.remove_line_button.setEnabled( len(self._lines_widget.lines_treewidget.selectedItems()) > 0) self._lines_widget.swap_points_button.setEnabled( len(self._lines_widget.lines_treewidget.selectedItems()) > 0) for shape, list_item in self._lines_map.items(): HWR.beamline.sample_view.select_shape(shape, list_item.isSelected()) self._acq_widget.emit_acq_parameters_changed() def create_line_button_clicked(self): HWR.beamline.sample_view.create_line() def create_auto_line_button_clicked(self): HWR.beamline.sample_view.create_auto_line() def remove_line_button_clicked(self): line_to_delete = None for line, treewidget_item in self._lines_map.items(): if treewidget_item.isSelected(): line_to_delete = line break if line_to_delete: HWR.beamline.sample_view.delete_shape(line_to_delete) self.lines_treewidget_selection_changed() def get_selected_shapes(self): selected_lines = [] for line, treewidget_item in self._lines_map.items(): if treewidget_item.isSelected(): selected_lines.append(line) return selected_lines def overlay_toggled(self, state): HWR.beamline.sample_view.set_display_overlay(state) def overlay_alpha_changed(self, alpha_value): for line, treewidget_item in self._lines_map.items(): if treewidget_item.isSelected(): line.set_fill_alpha(alpha_value) def swap_points_clicked(self): for line, treewidget_item in self._lines_map.items(): if treewidget_item.isSelected(): HWR.beamline.sample_view.swap_line_points(line)
def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__(self, parent, name, fl, "Helical") if not name: self.setObjectName("create_helical_widget") self.init_models() # Hardware objects ---------------------------------------------------- # Internal variables -------------------------------------------------- self._lines_map = {} # Graphic elements ---------------------------------------------------- self._lines_widget = QtImport.load_ui_file("helical_line_widget_layout.ui") self._acq_widget = AcquisitionWidget( self, "acquisition_widget", layout="vertical", acq_params=self._acquisition_parameters, path_template=self._path_template, ) self._data_path_widget = DataPathWidget( self, "create_dc_path_widget", data_model=self._path_template, layout="vertical", ) self._processing_widget = ProcessingWidget( self, data_model=self._processing_parameters ) # Layout -------------------------------------------------------------- _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self._lines_widget) _main_vlayout.addWidget(self._acq_widget) _main_vlayout.addWidget(self._data_path_widget) _main_vlayout.addWidget(self._processing_widget) _main_vlayout.addStretch(0) _main_vlayout.setSpacing(6) _main_vlayout.setContentsMargins(2, 2, 2, 2) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self._lines_widget.lines_treewidget.itemSelectionChanged.connect( self.lines_treewidget_selection_changed ) self._lines_widget.create_line_button.clicked.connect( self.create_line_button_clicked ) self._lines_widget.create_auto_line_button.clicked.connect( self.create_auto_line_button_clicked ) self._lines_widget.remove_line_button.clicked.connect( self.remove_line_button_clicked ) self._lines_widget.overlay_cbox.stateChanged.connect(self.overlay_toggled) self._lines_widget.overlay_slider.valueChanged.connect( self.overlay_alpha_changed ) self._lines_widget.swap_points_button.clicked.connect(self.swap_points_clicked) self._acq_widget.acqParametersChangedSignal.connect(self.acq_parameters_changed) self._acq_widget.madEnergySelectedSignal.connect(self.mad_energy_selected) self._data_path_widget.pathTemplateChangedSignal.connect( self.path_template_changed ) self._processing_widget.enableProcessingSignal.connect( self._run_processing_toggled ) # Other --------------------------------------------------------------- for col in range(self._lines_widget.lines_treewidget.columnCount()): self._lines_widget.lines_treewidget.resizeColumnToContents(col) # self._processing_widget.processing_widget.\ # run_processing_parallel_cbox.setChecked(False) self._processing_widget.processing_widget.run_processing_parallel_cbox.setChecked( api.beamline_setup._get_run_processing_parallel() ) self.enable_widgets(False)
class CreateHelicalWidget(CreateTaskBase): def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__(self, parent, name, fl, "Helical") if not name: self.setObjectName("create_helical_widget") self.init_models() # Hardware objects ---------------------------------------------------- # Internal variables -------------------------------------------------- self._lines_map = {} # Graphic elements ---------------------------------------------------- self._lines_widget = QtImport.load_ui_file("helical_line_widget_layout.ui") self._acq_widget = AcquisitionWidget( self, "acquisition_widget", layout="vertical", acq_params=self._acquisition_parameters, path_template=self._path_template, ) self._data_path_widget = DataPathWidget( self, "create_dc_path_widget", data_model=self._path_template, layout="vertical", ) self._processing_widget = ProcessingWidget( self, data_model=self._processing_parameters ) # Layout -------------------------------------------------------------- _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self._lines_widget) _main_vlayout.addWidget(self._acq_widget) _main_vlayout.addWidget(self._data_path_widget) _main_vlayout.addWidget(self._processing_widget) _main_vlayout.addStretch(0) _main_vlayout.setSpacing(6) _main_vlayout.setContentsMargins(2, 2, 2, 2) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self._lines_widget.lines_treewidget.itemSelectionChanged.connect( self.lines_treewidget_selection_changed ) self._lines_widget.create_line_button.clicked.connect( self.create_line_button_clicked ) self._lines_widget.create_auto_line_button.clicked.connect( self.create_auto_line_button_clicked ) self._lines_widget.remove_line_button.clicked.connect( self.remove_line_button_clicked ) self._lines_widget.overlay_cbox.stateChanged.connect(self.overlay_toggled) self._lines_widget.overlay_slider.valueChanged.connect( self.overlay_alpha_changed ) self._lines_widget.swap_points_button.clicked.connect(self.swap_points_clicked) self._acq_widget.acqParametersChangedSignal.connect(self.acq_parameters_changed) self._acq_widget.madEnergySelectedSignal.connect(self.mad_energy_selected) self._data_path_widget.pathTemplateChangedSignal.connect( self.path_template_changed ) self._processing_widget.enableProcessingSignal.connect( self._run_processing_toggled ) # Other --------------------------------------------------------------- for col in range(self._lines_widget.lines_treewidget.columnCount()): self._lines_widget.lines_treewidget.resizeColumnToContents(col) # self._processing_widget.processing_widget.\ # run_processing_parallel_cbox.setChecked(False) self._processing_widget.processing_widget.run_processing_parallel_cbox.setChecked( api.beamline_setup._get_run_processing_parallel() ) self.enable_widgets(False) def enable_widgets(self, state): self._acq_widget.setEnabled(state) self._data_path_widget.setEnabled(state) self._processing_widget.setEnabled(state) def init_models(self): CreateTaskBase.init_models(self) self._energy_scan_result = queue_model_objects.EnergyScanResult() self._processing_parameters = queue_model_objects.ProcessingParameters() has_shutter_less = api.beamline_setup.detector_has_shutterless() self._acquisition_parameters.shutterless = has_shutter_less self._acquisition_parameters = api.beamline_setup.get_default_acquisition_parameters( "default_helical_values" ) def init_api(self): # At startup, if scene loaded from file, then update listwidget shapes = api.graphics.get_shapes() for shape in shapes: if isinstance(shape, GraphicsItemLine): self.shape_created(shape, "Line") api.graphics.connect("shapeCreated", self.shape_created) api.graphics.connect("shapeChanged", self.shape_changed) api.graphics.connect("shapeDeleted", self.shape_deleted) def shape_created(self, shape, shape_type): if shape_type == "Line": self._lines_widget.lines_treewidget.clearSelection() # info_str_list = QStringList() info_str_list = [] info_str_list.append(shape.get_display_name()) info_str_list.append("%d" % shape.get_points_index()[0]) info_str_list.append("%d" % shape.get_points_index()[1]) lines_treewidget_item = QtImport.QTreeWidgetItem( self._lines_widget.lines_treewidget, info_str_list ) lines_treewidget_item.setSelected(True) self._lines_map[shape] = lines_treewidget_item self.lines_treewidget_selection_changed() def shape_deleted(self, shape, shape_type): if shape_type == "Line" and self._lines_map.get(shape): shape_index = self._lines_widget.lines_treewidget.indexFromItem( self._lines_map[shape] ) self._lines_widget.lines_treewidget.takeTopLevelItem(shape_index.row()) self._lines_map.pop(shape) def approve_creation(self): base_result = CreateTaskBase.approve_creation(self) if len(self._lines_widget.lines_treewidget.selectedItems()) == 0: logging.getLogger("GUI").warning( "No lines selected, please select one or more lines." ) return False else: return base_result def update_processing_parameters(self, crystal): self._processing_parameters.space_group = crystal.space_group self._processing_parameters.cell_a = crystal.cell_a self._processing_parameters.cell_alpha = crystal.cell_alpha self._processing_parameters.cell_b = crystal.cell_b self._processing_parameters.cell_beta = crystal.cell_beta self._processing_parameters.cell_c = crystal.cell_c self._processing_parameters.cell_gamma = crystal.cell_gamma self._processing_widget.update_data_model(self._processing_parameters) def select_line_with_cpos(self, start_cpos, end_cpos, num_images): """Selects graphical line which contains two cpositions Adds number of frames next to the graphical line """ self._lines_widget.overlay_slider.setEnabled(False) self._lines_widget.overlay_cbox.setEnabled(False) api.graphics.de_select_all() for shape in api.graphics.get_shapes(): if isinstance(shape, GraphicsItemLine): (start_cpos_index, end_cpos_index) = shape.get_points_index() if ( start_cpos_index == start_cpos.index and end_cpos_index == end_cpos.index ): api.graphics.select_shape(shape) shape.set_num_images(num_images) self._lines_widget.overlay_slider.setEnabled(True) self._lines_widget.overlay_cbox.setEnabled(True) def single_item_selection(self, tree_item): CreateTaskBase.single_item_selection(self, tree_item) if isinstance(tree_item, queue_item.SampleQueueItem): sample_model = tree_item.get_model() self._processing_parameters = sample_model.processing_parameters # self._processing_parameters = copy.deepcopy(self._processing_parameters) self._processing_widget.update_data_model(self._processing_parameters) elif isinstance(tree_item, queue_item.BasketQueueItem): self.setDisabled(False) elif isinstance(tree_item, queue_item.DataCollectionQueueItem): data_collection = tree_item.get_model() if data_collection.is_helical(): self.setDisabled(tree_item.get_model().is_executed()) self._path_template = data_collection.get_path_template() self._data_path_widget.update_data_model(self._path_template) self._acquisition_parameters = data_collection.acquisitions[ 0 ].acquisition_parameters if len(data_collection.acquisitions) == 2: start_cpos = data_collection.acquisitions[ 0 ].acquisition_parameters.centred_position end_cpos = data_collection.acquisitions[ 1 ].acquisition_parameters.centred_position num_images = data_collection.acquisitions[ 0 ].acquisition_parameters.num_images self.select_line_with_cpos(start_cpos, end_cpos, num_images) self._acq_widget.update_data_model( self._acquisition_parameters, self._path_template ) # self.get_acquisition_widget().use_osc_start(True) self._processing_parameters = data_collection.processing_parameters self._processing_widget.update_data_model(self._processing_parameters) else: self.setDisabled(True) else: self.setDisabled(True) if ( isinstance(tree_item, queue_item.SampleQueueItem) or isinstance(tree_item, queue_item.DataCollectionGroupQueueItem) or isinstance(tree_item, queue_item.DataCollectionQueueItem) ): self._processing_widget.update_data_model(self._processing_parameters) self._acq_widget.update_data_model( self._acquisition_parameters, self._path_template ) def _create_task(self, sample, shape): data_collections = [] for shape in self.get_selected_shapes(): snapshot = api.graphics.get_scene_snapshot(shape) # Acquisition for start position start_acq = self._create_acq(sample) start_graphical_point, end_graphical_point = shape.get_graphical_points() start_acq.acquisition_parameters.centred_position = copy.deepcopy( start_graphical_point.get_centred_position() ) start_acq.acquisition_parameters.centred_position.snapshot_image = snapshot start_acq.path_template.suffix = api.session.suffix # Add another acquisition for the end position end_acq = self._create_acq(sample) end_acq.acquisition_parameters.centred_position = copy.deepcopy( end_graphical_point.get_centred_position() ) end_acq.acquisition_parameters.centred_position.snapshot_image = snapshot end_acq.path_template.suffix = api.session.suffix processing_parameters = copy.deepcopy(self._processing_parameters) dc = queue_model_objects.DataCollection( [start_acq, end_acq], sample.crystals[0], processing_parameters ) dc.set_name(start_acq.path_template.get_prefix()) dc.set_number(start_acq.path_template.run_number) dc.set_experiment_type(EXPERIMENT_TYPE.HELICAL) dc.set_requires_centring(False) dc.run_processing_after = ( self._processing_widget.processing_widget.run_processing_after_cbox.isChecked() ) if ( self._processing_widget.processing_widget.run_processing_parallel_cbox.isChecked() ): dc.run_processing_parallel = "LineScan" data_collections.append(dc) self._path_template.run_number += 1 return data_collections def lines_treewidget_selection_changed(self): self.enable_widgets( len(self._lines_widget.lines_treewidget.selectedItems()) > 0 ) self._lines_widget.remove_line_button.setEnabled( len(self._lines_widget.lines_treewidget.selectedItems()) > 0 ) self._lines_widget.swap_points_button.setEnabled( len(self._lines_widget.lines_treewidget.selectedItems()) > 0 ) for shape, list_item in self._lines_map.items(): api.graphics.select_shape(shape, list_item.isSelected()) self._acq_widget.emit_acq_parameters_changed() def create_line_button_clicked(self): api.graphics.create_line() def create_auto_line_button_clicked(self): api.graphics.create_auto_line() def remove_line_button_clicked(self): line_to_delete = None for line, treewidget_item in self._lines_map.items(): if treewidget_item.isSelected(): line_to_delete = line break if line_to_delete: api.graphics.delete_shape(line_to_delete) self.lines_treewidget_selection_changed() def get_selected_shapes(self): selected_lines = [] for line, treewidget_item in self._lines_map.items(): if treewidget_item.isSelected(): selected_lines.append(line) return selected_lines def overlay_toggled(self, state): api.graphics.set_display_overlay(state) def overlay_alpha_changed(self, alpha_value): for line, treewidget_item in self._lines_map.items(): if treewidget_item.isSelected(): line.set_fill_alpha(alpha_value) def swap_points_clicked(self): for line, treewidget_item in self._lines_map.items(): if treewidget_item.isSelected(): api.graphics.swap_line_points(line)
class DCParametersWidget(QtImport.QWidget): def __init__(self, parent=None, name="parameter_widget"): QtImport.QWidget.__init__(self, parent) if name is not None: self.setObjectName(name) # Properties ---------------------------------------------------------- # Signals ------------------------------------------------------------ # Slots --------------------------------------------------------------- # Internal variables -------------------------------------------------- self._data_collection = None self._tree_view_item = None self._acquisition_mib = None # Graphic elements ---------------------------------------------------- _dc_parameters_widget = QtImport.QWidget(self) self._data_path_widget = DataPathWidget(_dc_parameters_widget) self._acq_widget = AcquisitionWidget(_dc_parameters_widget, layout="horizontal") self._processing_widget = ProcessingWidget(_dc_parameters_widget) # Layout -------------------------------------------------------------- _dc_parameters_widget_layout = QtImport.QVBoxLayout(_dc_parameters_widget) _dc_parameters_widget_layout.addWidget(self._data_path_widget) _dc_parameters_widget_layout.addWidget(self._acq_widget) _dc_parameters_widget_layout.addWidget(self._processing_widget) _dc_parameters_widget_layout.setContentsMargins(0, 0, 0, 0) _dc_parameters_widget_layout.setSpacing(2) _dc_parameters_widget_layout.addStretch(10) _main_hlayout = QtImport.QHBoxLayout(self) _main_hlayout.addWidget(_dc_parameters_widget) _main_hlayout.setContentsMargins(0, 0, 0, 0) _main_hlayout.setSpacing(2) _main_hlayout.addStretch(0) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self._data_path_widget.data_path_layout.prefix_ledit.textChanged.connect( self._prefix_ledit_change ) self._data_path_widget.data_path_layout.run_number_ledit.textChanged.connect( self._run_number_ledit_change ) self._acq_widget.madEnergySelectedSignal.connect(self.mad_energy_selected) self._acq_widget.acqParametersChangedSignal.connect(self.acq_parameters_changed) # Other --------------------------------------------------------------- def _prefix_ledit_change(self, new_value): prefix = self._data_collection.acquisitions[0].path_template.get_prefix() self._data_collection.set_name(prefix) self._tree_view_item.setText(0, self._data_collection.get_name()) def _run_number_ledit_change(self, new_value): if str(new_value).isdigit(): self._data_collection.set_number(int(new_value)) self._tree_view_item.setText(0, self._data_collection.get_name()) def acq_parameters_changed(self): if self._tree_view_item is None: # TODO fix this return # TODO get tree view in another way dc_tree_widget = self._tree_view_item.listView().parent().parent() dc_tree_widget.check_for_path_collisions() path_template = self._data_collection.acquisitions[0].path_template path_conflict = api.queue_model.check_for_path_collisions(path_template) def mad_energy_selected(self, name, energy, state): path_template = self._data_collection.acquisitions[0].path_template if state: path_template.mad_prefix = str(name) else: path_template.mad_prefix = "" run_number = api.queue_model.get_next_run_number( path_template ) self._data_path_widget.set_run_number(run_number) self._data_path_widget.set_prefix(path_template.base_prefix) model = self._tree_view_item.get_model() model.set_name(path_template.get_prefix()) self._tree_view_item.setText(0, model.get_name()) def tab_changed(self): if self._tree_view_item: self.populate_parameter_widget(self._tree_view_item) def set_enabled(self, state): self._acq_widget.setEnabled(state) self._data_path_widget.setEnabled(state) self._processing_widget.setEnabled(state) def populate_widget(self, item): data_collection = item.get_model() self._tree_view_item = item self._data_collection = data_collection self._acquisition_mib = DataModelInputBinder( self._data_collection.acquisitions[0].acquisition_parameters ) # The acq_widget sends a signal to the path_widget, and it relies # on that both models upto date, we need to refactor this part # so that both models are set before taking ceratin actions. # This workaround, works for the time beeing. self._data_path_widget._data_model = data_collection.acquisitions[ 0 ].path_template self._acq_widget.set_energies(data_collection.crystal.energy_scan_result) self._acq_widget.update_data_model( data_collection.acquisitions[0].acquisition_parameters, data_collection.acquisitions[0].path_template, ) self._data_path_widget.update_data_model( data_collection.acquisitions[0].path_template ) self._processing_widget.update_data_model(data_collection.processing_parameters) invalid = self._acquisition_mib.validate_all() if invalid: msg = ( "This data collection has one or more incorrect parameters," + " correct the fields marked in red to solve the problem." ) logging.getLogger("GUI").warning(msg)
def __init__(self, parent=None, name=None, flags=0): CreateTaskBase.__init__(self, parent, name, QtImport.Qt.WindowFlags(flags), "Still") if not name: self.setObjectName("create_still_scan_widget") # Hardware objects ---------------------------------------------------- # Internal variables -------------------------------------------------- self.init_models() # Graphic elements ---------------------------------------------------- self._acq_widget = AcquisitionStillWidget( self, "acquisition_widget", layout="vertical", acq_params=self._acquisition_parameters, path_template=self._path_template, ) self._data_path_widget = DataPathWidget( self, "create_dc_path_widget", data_model=self._path_template, layout="vertical", ) self._col_seq_widget = SSXSequenceWidget(self) self._processing_widget = ProcessingWidget( self, data_model=self._processing_parameters) #self._comment_widget = CommentWidget(self) # Layout -------------------------------------------------------------- _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self._acq_widget) _main_vlayout.addWidget(self._data_path_widget) _main_vlayout.addWidget(self._col_seq_widget) _main_vlayout.addWidget(self._processing_widget) #_main_vlayout.addWidget(self._comment_widget) _main_vlayout.addStretch(0) _main_vlayout.setSpacing(6) _main_vlayout.setContentsMargins(2, 2, 2, 2) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self._acq_widget.acqParametersChangedSignal.connect( self.acq_parameters_changed) self._data_path_widget.pathTemplateChangedSignal.connect( self.path_template_changed) self._processing_widget.enableProcessingSignal.connect( self._run_processing_toggled) # Other --------------------------------------------------------------- self._processing_widget.processing_widget.run_processing_parallel_cbox.setChecked( HWR.beamline.run_processing_parallel) #Rename to self._processing_widget.layout self._processing_widget.processing_widget.resolution_cutoff_label.setHidden( False) self._processing_widget.processing_widget.resolution_cutoff_ledit.setHidden( False) self._processing_widget.processing_widget.pdb_file_label.setHidden( False) self._processing_widget.processing_widget.pdb_file_ledit.setHidden( False) self._processing_widget.processing_widget.pdb_file_browse_button.setHidden( False)
class CreateStillScanWidget(CreateTaskBase): def __init__(self, parent=None, name=None, flags=0): CreateTaskBase.__init__(self, parent, name, QtImport.Qt.WindowFlags(flags), "Still") if not name: self.setObjectName("create_still_scan_widget") # Hardware objects ---------------------------------------------------- # Internal variables -------------------------------------------------- self.init_models() # Graphic elements ---------------------------------------------------- self._acq_widget = AcquisitionStillWidget( self, "acquisition_widget", layout="vertical", acq_params=self._acquisition_parameters, path_template=self._path_template, ) self._data_path_widget = DataPathWidget( self, "create_dc_path_widget", data_model=self._path_template, layout="vertical", ) self._col_seq_widget = SSXSequenceWidget(self) self._processing_widget = ProcessingWidget( self, data_model=self._processing_parameters) #self._comment_widget = CommentWidget(self) # Layout -------------------------------------------------------------- _main_vlayout = QtImport.QVBoxLayout(self) _main_vlayout.addWidget(self._acq_widget) _main_vlayout.addWidget(self._data_path_widget) _main_vlayout.addWidget(self._col_seq_widget) _main_vlayout.addWidget(self._processing_widget) #_main_vlayout.addWidget(self._comment_widget) _main_vlayout.addStretch(0) _main_vlayout.setSpacing(6) _main_vlayout.setContentsMargins(2, 2, 2, 2) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self._acq_widget.acqParametersChangedSignal.connect( self.acq_parameters_changed) self._data_path_widget.pathTemplateChangedSignal.connect( self.path_template_changed) self._processing_widget.enableProcessingSignal.connect( self._run_processing_toggled) # Other --------------------------------------------------------------- self._processing_widget.processing_widget.run_processing_parallel_cbox.setChecked( HWR.beamline.run_processing_parallel) #Rename to self._processing_widget.layout self._processing_widget.processing_widget.resolution_cutoff_label.setHidden( False) self._processing_widget.processing_widget.resolution_cutoff_ledit.setHidden( False) self._processing_widget.processing_widget.pdb_file_label.setHidden( False) self._processing_widget.processing_widget.pdb_file_ledit.setHidden( False) self._processing_widget.processing_widget.pdb_file_browse_button.setHidden( False) def use_osc_start(self, status): """ Enables osc start QLineEdit :param status: boolean :return: """ return def update_exp_time_limits(self): """ Updates exposure time limits :return: """ return def init_models(self): """ Inits data model :return: None """ CreateTaskBase.init_models(self) self._processing_parameters = queue_model_objects.ProcessingParameters( ) has_shutter_less = HWR.beamline.detector.has_shutterless() self._acquisition_parameters.shutterless = has_shutter_less self._acquisition_parameters = ( HWR.beamline.get_default_acquisition_parameters()) self._acquisition_parameters.num_triggers = 1 self._acquisition_parameters.num_images_per_trigger = 1 def set_tunable_energy(self, state): """ Sets tunable energy :param state: boolean :return: None """ self._acq_widget.set_tunable_energy(state) def single_item_selection(self, tree_item): """ Method called when a queue item in the tree is selected :param tree_item: queue_item :return: None """ CreateTaskBase.single_item_selection(self, tree_item) if isinstance(tree_item, queue_item.SampleQueueItem): sample_model = tree_item.get_model() # self._processing_parameters = copy.deepcopy(self._processing_parameters) self._processing_parameters = sample_model.processing_parameters self._processing_widget.update_data_model( self._processing_parameters) elif isinstance(tree_item, queue_item.BasketQueueItem): self.setDisabled(False) elif isinstance(tree_item, queue_item.DataCollectionQueueItem): dc_model = tree_item.get_model() self._acq_widget.use_kappa(False) if not dc_model.is_helical(): if dc_model.is_executed(): self.setDisabled(True) else: self.setDisabled(False) sample_data_model = self.get_sample_item(tree_item).get_model() energy_scan_result = sample_data_model.crystals[ 0].energy_scan_result self._acq_widget.set_energies(energy_scan_result) # self._acq_widget.disable_inverse_beam(True) self._path_template = dc_model.get_path_template() self._data_path_widget.update_data_model(self._path_template) self._acquisition_parameters = dc_model.acquisitions[ 0].acquisition_parameters self._acq_widget.update_data_model( self._acquisition_parameters, self._path_template) # self.get_acquisition_widget().use_osc_start(True) if len(dc_model.acquisitions) == 1: HWR.beamline.sample_view.select_shape_with_cpos( self._acquisition_parameters.centred_position) self._processing_parameters = dc_model.processing_parameters self._processing_widget.update_data_model( self._processing_parameters) else: self.setDisabled(True) else: self.setDisabled(True) def _create_task(self, sample, shape, comments=None): """ Creates a new Still scan task :param sample: sample node :param shape: centering point :return: Acquisition item """ tasks = [] cpos = queue_model_objects.CentredPosition() cpos.snapshot_image = HWR.beamline.sample_view.get_snapshot() tasks.extend(self.create_dc(sample, cpos=cpos, comments=comments)) self._path_template.run_number += 1 return tasks def create_dc(self, sample, run_number=None, start_image=None, num_images=None, osc_start=None, sc=None, cpos=None, inverse_beam=False, comments=None): """ Creates a new data collection item :param sample: Sample :param run_number: int :param start_image: int :param num_images: int :param osc_start: float :param sc: :param cpos: centered position :param inverse_beam: boolean :return: """ tasks = [] # Acquisition for start position acq = self._create_acq(sample) if run_number: acq.path_template.run_number = run_number if start_image: acq.acquisition_parameters.first_image = start_image acq.path_template.start_num = start_image if num_images: acq.acquisition_parameters.num_images = num_images acq.path_template.num_files = num_images if osc_start: acq.acquisition_parameters.osc_start = osc_start if inverse_beam: acq.acquisition_parameters.inverse_beam = False acq.acquisition_parameters.centred_position = cpos if comments: acq.acquisition_parameters.comments = comments processing_parameters = copy.deepcopy(self._processing_parameters) data_collection = queue_model_objects.DataCollection( [acq], sample.crystals[0], processing_parameters) data_collection.set_name(acq.path_template.get_prefix()) data_collection.set_number(acq.path_template.run_number) data_collection.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.OSC run_processing_after, run_processing_parallel = \ self._processing_widget.get_processing_state() data_collection.run_processing_after = run_processing_after if run_processing_parallel: data_collection.run_processing_parallel = "Still" data_collection.set_requires_centring(False) tasks.append(data_collection) return tasks
class DCParametersWidget(QtImport.QWidget): def __init__(self, parent=None, name="parameter_widget"): QtImport.QWidget.__init__(self, parent) if name is not None: self.setObjectName(name) # Properties ---------------------------------------------------------- # Signals ------------------------------------------------------------ # Slots --------------------------------------------------------------- # Internal variables -------------------------------------------------- self._data_collection = None self._tree_view_item = None self._acquisition_mib = None # Graphic elements ---------------------------------------------------- _dc_parameters_widget = QtImport.QWidget(self) self._data_path_widget = DataPathWidget(_dc_parameters_widget) self._acq_widget = AcquisitionWidget(_dc_parameters_widget, layout="horizontal") self._processing_widget = ProcessingWidget(_dc_parameters_widget) # Layout -------------------------------------------------------------- _dc_parameters_widget_layout = QtImport.QVBoxLayout( _dc_parameters_widget) _dc_parameters_widget_layout.addWidget(self._data_path_widget) _dc_parameters_widget_layout.addWidget(self._acq_widget) _dc_parameters_widget_layout.addWidget(self._processing_widget) _dc_parameters_widget_layout.setContentsMargins(0, 0, 0, 0) _dc_parameters_widget_layout.setSpacing(2) _dc_parameters_widget_layout.addStretch(10) _main_hlayout = QtImport.QHBoxLayout(self) _main_hlayout.addWidget(_dc_parameters_widget) _main_hlayout.setContentsMargins(0, 0, 0, 0) _main_hlayout.setSpacing(2) _main_hlayout.addStretch(0) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self._data_path_widget.data_path_layout.prefix_ledit.textChanged.connect( self._prefix_ledit_change) self._data_path_widget.data_path_layout.run_number_ledit.textChanged.connect( self._run_number_ledit_change) self._acq_widget.madEnergySelectedSignal.connect( self.mad_energy_selected) self._acq_widget.acqParametersChangedSignal.connect( self.acq_parameters_changed) # Other --------------------------------------------------------------- def _prefix_ledit_change(self, new_value): prefix = self._data_collection.acquisitions[ 0].path_template.get_prefix() self._data_collection.set_name(prefix) self._tree_view_item.setText(0, self._data_collection.get_name()) def _run_number_ledit_change(self, new_value): if str(new_value).isdigit(): self._data_collection.set_number(int(new_value)) self._tree_view_item.setText(0, self._data_collection.get_name()) def acq_parameters_changed(self): if self._tree_view_item is None: return # TODO get tree view in another way dc_tree_widget = self._tree_view_item.listView().parent().parent() dc_tree_widget.check_for_path_collisions() path_template = self._data_collection.acquisitions[0].path_template HWR.beamline.queue_model.check_for_path_collisions(path_template) def mad_energy_selected(self, name, energy, state): path_template = self._data_collection.acquisitions[0].path_template if state: path_template.mad_prefix = str(name) else: path_template.mad_prefix = "" run_number = HWR.beamline.queue_model.get_next_run_number( path_template) self._data_path_widget.set_run_number(run_number) self._data_path_widget.set_prefix(path_template.base_prefix) model = self._tree_view_item.get_model() model.set_name(path_template.get_prefix()) self._tree_view_item.setText(0, model.get_name()) def set_enabled(self, state): self._acq_widget.setEnabled(state) self._data_path_widget.setEnabled(state) self._processing_widget.setEnabled(state) def populate_widget(self, item): data_collection = item.get_model() self._tree_view_item = item self._data_collection = data_collection self._acquisition_mib = DataModelInputBinder( self._data_collection.acquisitions[0].acquisition_parameters) # The acq_widget sends a signal to the path_widget, and it relies # on that both models upto date, we need to refactor this part # so that both models are set before taking ceratin actions. # This workaround, works for the time beeing. self._data_path_widget._data_model = data_collection.acquisitions[ 0].path_template self._acq_widget.set_energies( data_collection.crystal.energy_scan_result) self._acq_widget.update_data_model( data_collection.acquisitions[0].acquisition_parameters, data_collection.acquisitions[0].path_template, ) self._data_path_widget.update_data_model( data_collection.acquisitions[0].path_template) self._processing_widget.update_data_model( data_collection.processing_parameters) invalid = self._acquisition_mib.validate_all() if invalid: msg = ( "This data collection has one or more incorrect parameters," + " correct the fields marked in red to solve the problem.") logging.getLogger("GUI").warning(msg)