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)
Esempio n. 2
0
    def __init__(self,
                 parent=None,
                 name='',
                 fl=0,
                 data_model=None,
                 layout=None):
        QtGui.QWidget.__init__(self, parent, QtCore.Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._base_image_dir = None
        self._base_process_dir = None
        self.path_conflict_state = False

        if data_model is None:
            self._data_model = queue_model_objects.PathTemplate()
        else:
            self._data_model = data_model

        self._data_model_pm = DataModelInputBinder(self._data_model)

        # Graphic elements ----------------------------------------------------
        if layout == "vertical":
            self.data_path_layout = uic.loadUi(
                os.path.join(
                    os.path.dirname(__file__),
                    "ui_files/Qt4_data_path_widget_vertical_layout.ui"))
        else:
            self.data_path_layout = uic.loadUi(
                os.path.join(
                    os.path.dirname(__file__),
                    "ui_files/Qt4_data_path_widget_horizontal_layout.ui"))

        # Layout --------------------------------------------------------------
        self.main_layout = QtGui.QVBoxLayout(self)
        self.main_layout.addWidget(self.data_path_layout)
        self.main_layout.setSpacing(0)
        self.main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.main_layout)

        # Qt signal/slot connections ------------------------------------------
        self.data_path_layout.prefix_ledit.textChanged.connect(
            self._prefix_ledit_change)
        self.data_path_layout.run_number_ledit.textChanged.connect(
            self._run_number_ledit_change)
        self.data_path_layout.browse_button.clicked.connect(
            self._browse_clicked)
        self.data_path_layout.folder_ledit.textChanged.connect(
            self._folder_ledit_change)

        # Other ---------------------------------------------------------------
        self._data_model_pm.bind_value_update(
            'base_prefix', self.data_path_layout.prefix_ledit, str, None)

        self._data_model_pm.bind_value_update(
            'run_number', self.data_path_layout.run_number_ledit, int,
            QtGui.QIntValidator(0, 1000, self))
    def populate_widget(self, tree_view_item):
        self._tree_view_item = tree_view_item

        if isinstance(tree_view_item, Qt4_queue_item.XrayCenteringQueueItem):
            self._data_collection = tree_view_item.get_model().reference_image_collection
        else:
            self._data_collection = tree_view_item.get_model()
        executed = self._data_collection.is_executed()

        self._acq_widget.setEnabled(not executed)
        self._data_path_widget.setEnabled(not executed)

        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 = self._data_collection.\
             acquisitions[0].path_template
        self._data_path_widget.update_data_model(self._data_collection.\
              acquisitions[0].path_template)

        self._acq_widget.update_data_model(\
             self._data_collection.acquisitions[0].acquisition_parameters,
             self._data_collection.acquisitions[0].path_template)
        #self._acq_widget.use_osc_start(False)
        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)
Esempio n. 4
0
    def __init__(self, parent=None, name=None, fl=0, data_model=None):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        if data_model is None:
            self._model = queue_model_objects.ProcessingParameters()
        else:
            self._model = data_model

        self._model_mib = DataModelInputBinder(self._model)

        self.processing_widget = self.acq_widget_layout = loadUi(
            os.path.join(os.path.dirname(__file__),
                         "ui_files/Qt4_processing_widget_vertical_layout.ui"))

        self.main_layout = QVBoxLayout(self)
        self.main_layout.addWidget(self.processing_widget)
        self.main_layout.setSpacing(0)
        self.main_layout.setContentsMargins(0, 0, 0, 0)

        self.processing_widget.space_group_combo.\
            addItems(queue_model_enumerables.XTAL_SPACEGROUPS)

        self._model_mib.bind_value_update('cell_a',
                                          self.processing_widget.a_ledit,
                                          float, None)

        self._model_mib.bind_value_update('cell_alpha',
                                          self.processing_widget.alpha_ledit,
                                          float, None)

        self._model_mib.bind_value_update('cell_b',
                                          self.processing_widget.b_ledit,
                                          float, None)

        self._model_mib.bind_value_update('cell_beta',
                                          self.processing_widget.beta_ledit,
                                          float, None)

        self._model_mib.bind_value_update('cell_c',
                                          self.processing_widget.c_ledit,
                                          float, None)

        self._model_mib.bind_value_update('cell_gamma',
                                          self.processing_widget.gamma_ledit,
                                          float, None)

        self._model_mib.bind_value_update(
            'num_residues', self.processing_widget.num_residues_ledit, float,
            None)

        self.processing_widget.space_group_combo.activated.\
             connect(self._space_group_change)
        self.processing_widget.run_processing_after_cbox.stateChanged.\
             connect(self._run_processing_after_toggled)
        self.processing_widget.run_processing_parallel_cbox.stateChanged.\
             connect(self._run_processing_parallel_toggled)
Esempio n. 5
0
    def __init__(self, parent = None, name = None, fl = 0, acq_params = None, 
                 path_template = None, layout = None):
        """
        Descript. :
        """ 

        QtGui.QWidget.__init__(self, parent, QtCore.Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params
        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)
        self.acq_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
                                "ui_files/Qt4_acquisition_widget_vertical_simple_layout.ui"))

        # Layout --------------------------------------------------------------
        main_layout = QtGui.QVBoxLayout(self)
        main_layout.addWidget(self.acq_widget)
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget.num_images_cbox.activated.connect(self.update_num_images)
        self.acq_widget.detector_mode_combo.activated.connect(self.detector_mode_changed)
        self.acq_widget.osc_start_cbox.toggled.connect(self.osc_start_cbox_click)

        # Other ---------------------------------------------------------------
        self.energy_validator = QtGui.QDoubleValidator(0, 25, 5, self)
        self.resolution_validator = QtGui.QDoubleValidator(0, 15, 3, self)
        self.transmission_validator = QtGui.QDoubleValidator(0, 100, 3, self)
        self.exp_time_validator = QtGui.QDoubleValidator(0, 10000, 5, self)
        self.acq_widget.osc_start_ledit.setEnabled(False)
        self.acq_widget.kappa_ledit.setEnabled(False)
        self.acq_widget.kappa_phi_ledit.setEnabled(False) 
        self.acq_widget.num_images_cbox.setCurrentIndex(1)
    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 populate_widget(self, tree_view_item):
        self._tree_view_item = tree_view_item
        self._data_collection = tree_view_item.get_model().reference_image_collection
        executed = self._data_collection.is_executed()

        self._acq_widget.setEnabled(not executed)
        self._data_path_widget.setEnabled(not executed)
        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 = self._data_collection.\
             acquisitions[0].path_template
        self._data_path_widget.update_data_model(self._data_collection.\
              acquisitions[0].path_template)

        self._acq_widget.update_data_model(\
             self._data_collection.acquisitions[0].acquisition_parameters,
             self._data_collection.acquisitions[0].path_template)
        #self._acq_widget.use_osc_start(False)
        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("user_level_log").\
                warning(msg)
    def __init__(self, parent=None, name='gphl_setup_widget'):
        QtGui.QWidget.__init__(self,parent)
        if name is not None:
            self.setObjectName(name)

        # Properties ----------------------------------------------------------

        # Signals ------------------------------------------------------------

        # Slots ---------------------------------------------------------------
        dispatcher.connect(self._refresh_interface, 'model_update',
                           dispatcher.Any)

        # Hardware objects ----------------------------------------------------

        # Internal variables -------------------------------------------------
        self._widget_data = OrderedDict()
        self._data_object = GphlAcquisitionData()
        self._pulldowns = {}
        self._parameter_mib = DataModelInputBinder(self._data_object)

        # Graphic elements ----------------------------------------------------
        _parameters_widget = self._parameters_widget = QtGui.QWidget(self)
        QtGui.QGridLayout(_parameters_widget)
        _parameters_widget.layout().setColumnStretch(2, 1)

        # Layout --------------------------------------------------------------
        # This seems to be necessary to make widget visible
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_parameters_widget)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
    def __init__(self, parent=None, name=None, fl=0, xray_imaging_params=None):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if xray_imaging_params is None: 
            self._xray_imaging_parameters = \
               queue_model_objects.XrayImagingParameters()
        else:
            self._xray_imaging_parameters = xray_imaging_params 

        self._xray_imaging_mib = DataModelInputBinder(self._xray_imaging_parameters)

        self._parameters_widget = loadUi(os.path.join(\
             os.path.dirname(__file__),
             "ui_files/Qt4_xray_imaging_parameters_widget_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QVBoxLayout(self)
        __main_vlayout.addWidget(self._parameters_widget)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)
    def populate_widget(self, beam_energies={}, **kw):

        data_object = self._data_object = GphlAcquisitionData()
        parameter_mib = self._parameter_mib = DataModelInputBinder(data_object)
        widget_data = self._widget_data

        skip_fields = []
        for tag in self.beam_energy_tags[len(beam_energies):]:
            skip_fields.append(tag)
            skip_fields.append(self._get_label_name(tag))
        if not beam_energies:
            skip_fields.append('beam_energies_label')

        for tag, tt in widget_data.items():
            if tag in skip_fields:
                tt[0].hide()
            else:
                widget, w_type, validator, value = tt
                widget.show()

                if tag in kw:
                    value = kw[tag]
                elif tag in self.beam_energy_tags:
                    ii = self.beam_energy_tags.index(tag)
                    if ii < len(beam_energies):
                        name = list(beam_energies)[ii]
                        value = beam_energies[name]
                        label_tag = self._get_label_name(tag)
                        setattr(data_object, label_tag, name)

                setattr(data_object, tag, value)
                parameter_mib.bind_value_update(tag, widget, w_type, validator)

        parameter_mib.init_bindings()
Esempio n. 11
0
    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.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.acq_widget.use_osc_start(True)

        self.path_widget.update_data_model(data_collection.\
                                           acquisitions[0].path_template)

        self.processing_widget.update_data_model(data_collection.\
                                                 processing_parameters)

        if data_collection.acquisitions[0].acquisition_parameters.\
                centred_position.snapshot_image:
            image = data_collection.acquisitions[0].\
                acquisition_parameters.centred_position.snapshot_image
            ration = image.height() / float(image.width())
            image = image.scaled(400, 400 * ration, QtCore.Qt.KeepAspectRatio)
            self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))

        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("user_level_log").\
                warning(msg)
Esempio n. 12
0
    def __init__(self, parent = None, name = '', fl = 0, data_model = None, 
                 layout = None):
        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._base_image_dir = None
        self._base_process_dir = None
        self.path_conflict_state = False
        self.enable_macros = False
        
        if data_model is None:
            self._data_model = queue_model_objects.PathTemplate()
        else:
            self._data_model = data_model
        
        self._data_model_pm = DataModelInputBinder(self._data_model)

        # Graphic elements ----------------------------------------------------
        if layout == "vertical":
            self.data_path_layout = loadUi(\
                 os.path.join(os.path.dirname(__file__),
                 "ui_files/Qt4_data_path_widget_vertical_layout.ui"))
        else:
            self.data_path_layout = loadUi(\
                 os.path.join(os.path.dirname(__file__),
                 "ui_files/Qt4_data_path_widget_horizontal_layout.ui"))

        # Layout --------------------------------------------------------------
        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self.data_path_layout)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

        # Qt signal/slot connections ------------------------------------------ 
        self.data_path_layout.prefix_ledit.textChanged.\
             connect(self._prefix_ledit_change)
        self.data_path_layout.run_number_ledit.textChanged.\
             connect(self._run_number_ledit_change)
        self.data_path_layout.browse_button.clicked.\
             connect(self._browse_clicked)
        self.data_path_layout.folder_ledit.textChanged.\
             connect(self._folder_ledit_change)
        self.data_path_layout.compression_cbox.toggled.\
             connect(self._compression_toggled)

        # Other ---------------------------------------------------------------
        self._data_model_pm.bind_value_update('base_prefix', 
             self.data_path_layout.prefix_ledit, str, None)
        
        self._data_model_pm.bind_value_update('run_number', 
             self.data_path_layout.run_number_ledit,
             int, QIntValidator(0, 1000, self))
    def populate_widget(self, tree_view_item):
        self._tree_view_item = tree_view_item
        advanced_model = tree_view_item.get_model()
        self._data_collection = advanced_model.reference_image_collection
        executed = self._data_collection.is_executed()

        self._acq_widget.setEnabled(not executed)
        self._data_path_widget.setEnabled(not executed)

        image = advanced_model.grid_object.get_snapshot()
        try:
            image = image.scaled(427, 320, QtCore.Qt.KeepAspectRatio)
            self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))
        except:
            pass

        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 = self._data_collection.\
             acquisitions[0].path_template
        self._data_path_widget.update_data_model(self._data_collection.\
              acquisitions[0].path_template)

        self._acq_widget.update_data_model(\
             self._data_collection.acquisitions[0].acquisition_parameters,
             self._data_collection.acquisitions[0].path_template)
        #self._acq_widget.use_osc_start(False)
        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("user_level_log").\
                warning(msg)
    def __init__(self, parent=None, name=None, fl=0, xray_imaging_params=None):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if xray_imaging_params is None:
            self._xray_imaging_parameters = \
               queue_model_objects.XrayImagingParameters()
        else:
            self._xray_imaging_parameters = xray_imaging_params

        self._xray_imaging_mib = DataModelInputBinder(
            self._xray_imaging_parameters)

        self._parameters_widget = loadUi(os.path.join(\
             os.path.dirname(__file__),
             "ui_files/Qt4_xray_imaging_parameters_widget_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QVBoxLayout(self)
        __main_vlayout.addWidget(self._parameters_widget)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)
Esempio n. 15
0
    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.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.acq_widget.use_osc_start(True)

        self.path_widget.update_data_model(data_collection.\
                                           acquisitions[0].path_template)
        
        self.processing_widget.update_data_model(data_collection.\
                                                 processing_parameters)

        if data_collection.acquisitions[0].acquisition_parameters.\
                centred_position.snapshot_image:
            image = data_collection.acquisitions[0].\
                acquisition_parameters.centred_position.snapshot_image
            ration = image.height() / float(image.width())
            image = image.scaled(400, 400 * ration, QtCore.Qt.KeepAspectRatio)
            self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))

        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("user_level_log").\
                warning(msg)
    def populate_widget(self, tree_view_item):
        self._tree_view_item = tree_view_item
        advanced_model = tree_view_item.get_model()
        self._data_collection = advanced_model.reference_image_collection
        executed = self._data_collection.is_executed()

        self._acq_widget.setEnabled(not executed)
        self._data_path_widget.setEnabled(not executed)


        image = advanced_model.grid_object.get_snapshot()
        try:
           image = image.scaled(427, 320, QtCore.Qt.KeepAspectRatio)
           self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))
        except:
           pass 

        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 = self._data_collection.\
             acquisitions[0].path_template
        self._data_path_widget.update_data_model(self._data_collection.\
              acquisitions[0].path_template)

        self._acq_widget.update_data_model(\
             self._data_collection.acquisitions[0].acquisition_parameters,
             self._data_collection.acquisitions[0].path_template)
        #self._acq_widget.use_osc_start(False)
        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("user_level_log").\
                warning(msg)
Esempio n. 17
0
class CharParametersWidget(QtGui.QWidget):
    """
    Descript. : 
    """

    def __init__(self, parent = None, name = "parameter_widget"):
        """
        Descript. :
        """

        QtGui.QWidget.__init__(self, parent)

        if name is not None: 
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._char = None
        self._char_params = queue_model_objects.CharacterisationParameters()
        self._char_params_mib = DataModelInputBinder(self._char_params)
        self._tree_view_item = None
        self.previous_energy = None
        
        self.add_dc_cb = None
        
        # Graphic elements ----------------------------------------------------
        rone_widget = QtGui.QWidget(self)
        self.reference_img_widget = ReferenceImageWidget(rone_widget)
        self.acq_widget = self.reference_img_widget.acq_widget
        self.path_widget = self.reference_img_widget.path_widget
        self.position_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
                                          'ui_files/Qt4_snapshot_widget_layout.ui'))
        self.position_widget.setMinimumSize(450, 340)

        rtwo_widget = QtGui.QWidget(self)
        self.char_type_widget = CharTypeWidget(rtwo_widget)
        self.routine_dc_widget = self.char_type_widget.routine_dc_page
        self.sad_widget = self.char_type_widget.sad_page
        self.rad_dmg_char_widget = self.char_type_widget.rad_damage_page
        self.opt_parameters_widget = OptimisationParametersWidgetLayout(self)
        
        rtree_widget = QtGui.QWidget(self)
        self.rad_dmg_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
             'ui_files/Qt4_radiation_damage_model_widget_layout.ui'))
        self.vertical_dimension_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
             'ui_files/Qt4_vertical_crystal_dimension_widget_layout.ui'))

        # Layout --------------------------------------------------------------
        rone_widget_layout = QtGui.QHBoxLayout(self)
        rone_widget_layout.addWidget(self.reference_img_widget)
        rone_widget_layout.addWidget(self.position_widget)
        #rone_widget_layout.addStretch(0)
        rone_widget_layout.setSpacing(2)
        rone_widget_layout.setContentsMargins(0, 0, 0, 0)
        rone_widget.setLayout(rone_widget_layout)

        rtwo_widget_layout = QtGui.QHBoxLayout(self)
        rtwo_widget_layout.addWidget(self.char_type_widget)
        rtwo_widget_layout.addWidget(self.opt_parameters_widget)
        rtwo_widget_layout.addStretch(0)
        rtwo_widget_layout.setSpacing(2)
        rtwo_widget_layout.setContentsMargins(0, 0, 0, 0)
        rtwo_widget.setLayout(rtwo_widget_layout)

        rtree_widget_layout = QtGui.QHBoxLayout(self)
        rtree_widget_layout.addWidget(self.rad_dmg_widget)
        rtree_widget_layout.addWidget(self.vertical_dimension_widget)
        rtree_widget_layout.addStretch(0)
        rtree_widget_layout.setSpacing(2)
        rtree_widget_layout.setContentsMargins(0, 0, 0, 0)
        rtree_widget.setLayout(rtree_widget_layout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(rone_widget)
        _main_vlayout.addWidget(rtwo_widget)
        _main_vlayout.addWidget(rtree_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(_main_vlayout)

        # SizePolicies -------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.toggle_permitted_range(self.opt_parameters_widget.\
             opt_param_widget.permitted_range_cbx.isChecked())

        self.opt_parameters_widget.opt_param_widget.permitted_range_cbx.\
             toggled.connect(self.toggle_permitted_range)

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update('min_dose',
                                                 self.routine_dc_widget.dose_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('min_time',
                                                 self.routine_dc_widget.time_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('use_min_dose',
                                                 self.routine_dc_widget.min_dose_radio,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('use_min_time',
                                                 self.routine_dc_widget.min_time_radio,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('account_rad_damage',
                                                 self.routine_dc_widget.radiation_damage_cbx,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('auto_res',
                                                 self.sad_widget.automatic_resolution_radio,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('sad_res',
                                                 self.sad_widget.sad_resolution_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.5, 20, 3, self))

        self._char_params_mib.bind_value_update('opt_sad',
                                                 self.sad_widget.optimised_sad_cbx,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('determine_rad_params',
                                                 self.rad_dmg_char_widget.rad_damage_cbx,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('burn_osc_start',
                                                 self.rad_dmg_char_widget.burn_osc_start_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('burn_osc_interval',
                                                 self.rad_dmg_char_widget.burn_osc_interval_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
             'use_aimed_resolution',
             self.opt_parameters_widget.opt_param_widget.maximum_res_cbx,
             bool,
             None)

        self._char_params_mib.bind_value_update(
             'use_aimed_multiplicity',
             self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx,
             bool,
             None)

        self._char_params_mib.bind_value_update(
             'aimed_resolution',
             self.opt_parameters_widget.opt_param_widget.maximum_res_ledit,
             float,
             QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(\
             'aimed_multiplicity',
             self.opt_parameters_widget.opt_param_widget.aimed_mult_ledit,
             float,
             QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(
             'aimed_i_sigma',
             self.opt_parameters_widget.opt_param_widget.i_over_sigma_ledit,
             float,
             QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(
             'aimed_completness',
             self.opt_parameters_widget.opt_param_widget.aimed_comp_ledit,
             float,
             QtGui.QDoubleValidator(0.01, 1000, 2, self))
        
        self._char_params_mib.bind_value_update(
             'strategy_complexity',
             self.opt_parameters_widget.opt_param_widget.start_comp_cbox,
             int,
             None)

        self._char_params_mib.bind_value_update(
             'use_permitted_rotation',
             self.opt_parameters_widget.opt_param_widget.permitted_range_cbx,
             bool,
             None)

        self._char_params_mib.bind_value_update(
             'permitted_phi_start',
             self.opt_parameters_widget.opt_param_widget.phi_start_ledit,
             float,
             QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
             'permitted_phi_end',
             self.opt_parameters_widget.opt_param_widget.phi_end_ledit,
             float,
             QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
             'low_res_pass_strat',
             self.opt_parameters_widget.opt_param_widget.low_res_pass_cbx,
             bool,
             None)

        self._char_params_mib.bind_value_update('rad_suscept',
                                                 self.rad_dmg_widget.sensetivity_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('beta',
                                                 self.rad_dmg_widget.beta_over_gray_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('gamma',
                                                 self.rad_dmg_widget.gamma_over_gray_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('max_crystal_vdim',
                                                self.vertical_dimension_widget.max_vdim_ledit,
                                                float,
                                                QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('min_crystal_vdim',
                                                self.vertical_dimension_widget.min_vdim_ledit,
                                                float,
                                                QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('min_crystal_vphi',
                                                self.vertical_dimension_widget.min_vphi_ledit,
                                                float,
                                                QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('max_crystal_vphi',
                                                self.vertical_dimension_widget.max_vphi_ledit,
                                                float,
                                                QtGui.QDoubleValidator(0.0, 1000, 2, self))

        #self._char_params_mib.bind_value_update('space_group',
        #                                        self.vertical_dimension_widget.space_group_ledit,
        #                                        str,
        #                                        None)


        self.vertical_dimension_widget.space_group_ledit.\
             addItems(queue_model_enumerables.XTAL_SPACEGROUPS)

        self.char_type_widget.charact_type_tbox.currentChanged.connect(\
             self.update_char_type)
        self.rad_dmg_char_widget.rad_damage_cbx.toggled.connect(\
             self.enable_opt_parameters_widget)
        self.opt_parameters_widget.opt_param_widget.maximum_res_cbx.\
             toggled.connect(self.enable_maximum_res_ledit)
        self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx.\
             toggled.connect(self.enable_aimed_mult_ledit)
        self.path_widget.data_path_layout.prefix_ledit.textChanged.\
             connect(self._prefix_ledit_change)
        self.path_widget.data_path_layout.run_number_ledit.textChanged.\
             connect(self._run_number_ledit_change)
        self.vertical_dimension_widget.space_group_ledit.activated.\
             connect(self._space_group_change)
        #QtCore.QObject.connect(QtGui.QApplication, QtCore.SIGNAL('tab_changed'),
        #                   self.tab_changed)

    def _space_group_change(self, index):
        """
        Descript. :
        """
        self._char_params.space_group = queue_model_enumerables.\
                                        XTAL_SPACEGROUPS[index]

    def _set_space_group(self, space_group):
        """
        Descript. :
        """
        index  = 0
        
        if space_group in queue_model_enumerables.XTAL_SPACEGROUPS:
            index = queue_model_enumerables.XTAL_SPACEGROUPS.index(space_group)

        self._space_group_change(index)
        self.vertical_dimension_widget.space_group_ledit.setCurrentIndex(index)

    def _prefix_ledit_change(self, new_value):
        """
        Descript. :
        """
        prefix = self._data_collection.acquisitions[0].\
                 path_template.get_prefix()
        self._char.set_name(prefix)
        self._tree_view_item.setText(0, self._char.get_name())

    def _run_number_ledit_change(self, new_value):
        """
        Descript. :
        """
        if str(new_value).isdigit():
            self._char.set_number(int(new_value))
            self._tree_view_item.setText(0, self._char.get_name())

    def enable_aimed_mult_ledit(self, state):
        """
        Descript. :
        """
        self.opt_parameters_widget.opt_param_widget.aimed_mult_ledit.setEnabled(state)

    def enable_maximum_res_ledit(self, state):
        """
        Descript. :
        """
        self.opt_parameters_widget.opt_param_widget.maximum_res_ledit.setEnabled(state)

    def update_char_type(self, index):
        """
        Descript. :
        """
        self._char_params.experiment_type = index
    
    def toggle_permitted_range(self, status):
        """
        Descript. :
        """
        self.opt_parameters_widget.opt_param_widget.phi_start_ledit.setEnabled(status)
        self.opt_parameters_widget.opt_param_widget.phi_end_ledit.setEnabled(status)

    def enable_opt_parameters_widget(self, state):
        """
        Descript. :
        """
        if not self._char.is_executed():
            self.opt_parameters_widget.setEnabled(not state)
        else:
            self.opt_parameters_widget.setEnabled(False)

    def tab_changed(self):
        """
        Descript. :
        """
        if self._tree_view_item:
            self.populate_parameter_widget(self._tree_view_item)

    def set_enabled(self, state):
        """
        Descript. :
        """
        self.char_type_widget.setEnabled(state)
        self.routine_dc_widget.setEnabled(state)
        self.sad_widget.setEnabled(state)
        self.rad_dmg_char_widget.setEnabled(state)
        self.reference_img_widget.setEnabled(state)
        self.acq_widget.setEnabled(state)
        self.path_widget.setEnabled(state)
        self.opt_parameters_widget.setEnabled(state)
        self.rad_dmg_widget.setEnabled(state)
        self.vertical_dimension_widget.setEnabled(state)

    def populate_parameter_widget(self, tree_view_item):
        """
        Descript. :
        """
        self._tree_view_item = tree_view_item
        self._char = tree_view_item.get_model()
        self._data_collection = self._char.reference_image_collection
        self._char_params = self._char.characterisation_parameters
        self._char_params_mib.set_model(self._char.characterisation_parameters)
        self._set_space_group(self._char_params.space_group)
       
        self.acq_widget.update_data_model(self._char.reference_image_collection.\
                                          acquisitions[0].acquisition_parameters,
                                          self._char.reference_image_collection.\
                                          acquisitions[0].path_template)
        
        self.path_widget.update_data_model(self._char.reference_image_collection.\
                                           acquisitions[0].path_template)
        
        if self._data_collection.acquisitions[0].acquisition_parameters.\
                centred_position.snapshot_image:
            image = self._data_collection.acquisitions[0].\
                acquisition_parameters.centred_position.snapshot_image
            ration = image.height() / float(image.width())
            image = image.scaled(400, 400 * ration, QtCore.Qt.KeepAspectRatio)
            self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))

        self.toggle_permitted_range(self._char_params.use_permitted_rotation)
        self.enable_opt_parameters_widget(self._char_params.determine_rad_params)
        self.enable_maximum_res_ledit(self._char_params.use_aimed_resolution)
        self.enable_aimed_mult_ledit(self._char_params.use_aimed_multiplicity)
       
        item = self.char_type_widget.charact_type_tbox.\
               widget(self._char_params.experiment_type)
       
        self.char_type_widget.charact_type_tbox.setCurrentWidget(item)
        self.char_type_widget.toggle_time_dose()
        crystal = self._char.reference_image_collection.crystal
        self.acq_widget.set_energies(crystal.energy_scan_result)

    def set_beamline_setup(self, bl_setup):
        """
        Descript. :
        """
        self.acq_widget.set_beamline_setup(bl_setup)
class XrayImagingParametersWidget(QWidget):

    def __init__(self, parent=None, name=None, fl=0, xray_imaging_params=None):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if xray_imaging_params is None: 
            self._xray_imaging_parameters = \
               queue_model_objects.XrayImagingParameters()
        else:
            self._xray_imaging_parameters = xray_imaging_params 

        self._xray_imaging_mib = DataModelInputBinder(self._xray_imaging_parameters)

        self._parameters_widget = loadUi(os.path.join(\
             os.path.dirname(__file__),
             "ui_files/Qt4_xray_imaging_parameters_widget_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QVBoxLayout(self)
        __main_vlayout.addWidget(self._parameters_widget)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------

        # Other --------------------------------------------------------------- 

    def set_beamline_setup(self, beamline_setup):
        """Sets beamline setup and links qt gui with data model
        """
        self._beamline_setup_hwobj = beamline_setup

        self._xray_imaging_mib.\
             bind_value_update('camera_hw_binning',
                               self._parameters_widget.camera_hw_binning_combo,
                               int,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('camera_hw_roi',
                               self._parameters_widget.camera_hw_roi_combo,
                               int,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('store_data',
                               self._parameters_widget.store_data_cbox,
                               bool,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('live_display',
                               self._parameters_widget.live_display_cbox,
                               bool,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('pre_flat_field_frames',
                               self._parameters_widget.pre_flat_cbox,
                               bool,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('post_flat_field_frames',
                               self._parameters_widget.post_flat_cbox,
                               bool,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('apply_pre_flat_field_frames',
                               self._parameters_widget.apply_flat_cbox,
                               bool,
                               None)
 
    def update_data_model(self, xray_imaging_parameters):
        """
        Descript. :
        """
        self._xray_imaging_parameters = xray_imaging_parameters
        self._xray_imaging_mib.set_model(xray_imaging_parameters)
Esempio n. 19
0
class DataPathWidget(QWidget):

    pathTemplateChangedSignal = pyqtSignal()

    def __init__(self, parent = None, name = '', fl = 0, data_model = None, 
                 layout = None):
        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._base_image_dir = None
        self._base_process_dir = None
        self.path_conflict_state = False
        self.enable_macros = False
        
        if data_model is None:
            self._data_model = queue_model_objects.PathTemplate()
        else:
            self._data_model = data_model
        
        self._data_model_pm = DataModelInputBinder(self._data_model)

        # Graphic elements ----------------------------------------------------
        if layout == "vertical":
            self.data_path_layout = loadUi(\
                 os.path.join(os.path.dirname(__file__),
                 "ui_files/Qt4_data_path_widget_vertical_layout.ui"))
        else:
            self.data_path_layout = loadUi(\
                 os.path.join(os.path.dirname(__file__),
                 "ui_files/Qt4_data_path_widget_horizontal_layout.ui"))

        # Layout --------------------------------------------------------------
        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self.data_path_layout)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

        # Qt signal/slot connections ------------------------------------------ 
        self.data_path_layout.prefix_ledit.textChanged.\
             connect(self._prefix_ledit_change)
        self.data_path_layout.run_number_ledit.textChanged.\
             connect(self._run_number_ledit_change)
        self.data_path_layout.browse_button.clicked.\
             connect(self._browse_clicked)
        self.data_path_layout.folder_ledit.textChanged.\
             connect(self._folder_ledit_change)
        self.data_path_layout.compression_cbox.toggled.\
             connect(self._compression_toggled)

        # Other ---------------------------------------------------------------
        self._data_model_pm.bind_value_update('base_prefix', 
             self.data_path_layout.prefix_ledit, str, None)
        
        self._data_model_pm.bind_value_update('run_number', 
             self.data_path_layout.run_number_ledit,
             int, QIntValidator(0, 1000, self))

        #self._data_model_pm.bind_value_update('compression',
        #     self.data_path_layout.compression_cbox, bool, None)

    def _browse_clicked(self):
        """
        Descript. :
        """
        file_dialog = QFileDialog(self)
        file_dialog.setNameFilter("%s*" % self._base_image_dir)

        selected_dir = str(file_dialog.getExistingDirectory(\
            self, "Select a directory", self._base_image_dir))
        selecte_dir = os.path.dirname(selected_dir)

        if selected_dir is not None and len(selected_dir) > 0:
            self.set_directory(selected_dir)

    def _prefix_ledit_change(self, new_value):
        """
        Descript. :
        """
        cursor_pos = self.data_path_layout.prefix_ledit.cursorPosition()

        if len(new_value) > 0:
            available_chars = string.ascii_lowercase + string.ascii_uppercase + \
                              string.digits + "-_"
            if self.enable_macros:
                available_chars += "%"
            new_value = ''.join(i for i in str(new_value) if i in available_chars)

        if len(new_value) > 50:
            logging.getLogger("GUI").\
                error("Current prefix is to long (max 50 characters are allowed)")
            new_value = new_value[:-1]

        self.data_path_layout.prefix_ledit.setText(new_value)
        self.data_path_layout.prefix_ledit.setCursorPosition(cursor_pos)

        self._data_model.base_prefix = str(new_value)
        self.update_file_name()
        self.pathTemplateChangedSignal.emit()

    def _run_number_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self._data_model.run_number = int(new_value)
            self.data_path_layout.run_number_ledit.setText(str(new_value))

            self.update_file_name()
            self.pathTemplateChangedSignal.emit()
        else:
            self.data_path_layout.run_number_ledit.setText(str(self._data_model.run_number))
            Qt4_widget_colors.set_widget_color(self.data_path_layout.folder_ledit,
                                               Qt4_widget_colors.LIGHT_YELLOW)

    def _folder_ledit_change(self, new_value):        
        """
        Descript. :
        """
        base_image_dir = self._base_image_dir
        base_proc_dir = self._base_process_dir
        new_sub_dir = str(new_value).strip(' ')

        cursor_pos = self.data_path_layout.folder_ledit.cursorPosition()
        if len(new_value) > 0:
            available_chars = string.ascii_lowercase + string.ascii_uppercase + \
                              string.digits + "-_/" 
            if self.enable_macros:
                available_chars += "%"
            new_value = ''.join(i for i in str(new_value) if i in available_chars)

        self.data_path_layout.folder_ledit.setText(new_value)
        self.data_path_layout.folder_ledit.setCursorPosition(cursor_pos)

        if len(new_sub_dir) > 0:
            if new_sub_dir[0] == os.path.sep:
                new_sub_dir = new_sub_dir[1:]
            new_image_directory = os.path.join(base_image_dir, str(new_sub_dir))
            new_proc_dir = os.path.join(base_proc_dir, str(new_sub_dir))
        else:
            new_image_directory = base_image_dir
            new_proc_dir = base_proc_dir


        self._data_model.directory = new_image_directory
        self._data_model.process_directory = new_proc_dir 
        Qt4_widget_colors.set_widget_color(self.data_path_layout.folder_ledit,
                                           Qt4_widget_colors.WHITE)

        self.pathTemplateChangedSignal.emit()

    def _compression_toggled(self, state):
        self._data_model.compression = state
        self.update_file_name()
        self.pathTemplateChangedSignal.emit()

    def update_file_name(self):
        """
        Descript. : updates filename if prefix or run number changed
                    at start values are initalized before precision is set.
                    so a check for isdigit is done to be on the safe side
        """
        if str(self._data_model.precision).isdigit():
            file_name = self._data_model.get_image_file_name()
            file_name = file_name.replace('%' + str(self._data_model.precision) + 'd',
                                          int(self._data_model.precision) * '#' )
            file_name = file_name.strip(' ')
            self.data_path_layout.file_name_value_label.setText(file_name)

    def set_data_path(self, path):
        """
        Descript. :
        """
        (dir_name, file_name) = os.path.split(path)
        self.set_directory(dir_name)
        file_name = file_name.replace('%' + str(self._data_model.precision) + 'd',
                                      int(self._data_model.precision) * '#' )
        self.data_path_layout.file_name_value_label.setText(file_name)
    
    def set_directory(self, directory):
        """
        Descript. :
        """
        base_image_dir = self._base_image_dir
        dir_parts = directory.split(base_image_dir) 

        if len(dir_parts) > 1:
            sub_dir = dir_parts[1]
            self._data_model.directory = directory
            self.data_path_layout.folder_ledit.setText(sub_dir)
        else:
            self.data_path_layout.folder_ledit.setText('')
            self._data_model.directory = base_image_dir

        self.data_path_layout.base_path_ledit.setText(base_image_dir)       

    def set_run_number(self, run_number):
        """
        Descript. :
        """
        self._data_model.run_number = int(run_number)
        self.data_path_layout.run_number_ledit.setText(str(run_number))

    def set_prefix(self, base_prefix):
        """
        Descript. :
        """
        self._data_model.base_prefix = str(base_prefix)
        self.data_path_layout.prefix_ledit.setText(str(base_prefix))
        file_name = self._data_model.get_image_file_name()
        file_name = file_name.replace('%' + str(self._data_model.precision) + 'd',
                                      int(self._data_model.precision) * '#' )
        self.data_path_layout.file_name_value_label.setText(file_name)

    def update_data_model(self, data_model):
        """
        Descript. :
        """
        self._data_model = data_model
        self.set_data_path(data_model.get_image_path())
        self._data_model_pm.set_model(data_model)

    def indicate_path_conflict(self, conflict):
        """
        Descript. :
        """
        if conflict:
            Qt4_widget_colors.set_widget_color(\
                self.data_path_layout.prefix_ledit,
                Qt4_widget_colors.LIGHT_RED,
                QPalette.Base)
            Qt4_widget_colors.set_widget_color(\
                self.data_path_layout.run_number_ledit,
                Qt4_widget_colors.LIGHT_RED,
                QPalette.Base)
            Qt4_widget_colors.set_widget_color(\
                self.data_path_layout.folder_ledit,
                Qt4_widget_colors.LIGHT_RED,
                QPalette.Base)

            logging.getLogger("GUI").\
                error('The current path settings will overwrite data ' + \
                      'from another task. Correct the problem before ' + \
                      'adding to queue')
        else:
            # We had a conflict previous, but its corrected now !
            if self.path_conflict_state:
                logging.getLogger("GUI").info('Path valid')

                Qt4_widget_colors.set_widget_color(\
                    self.data_path_layout.prefix_ledit,
                    Qt4_widget_colors.WHITE,
                    QPalette.Base)
                Qt4_widget_colors.set_widget_color(\
                    self.data_path_layout.run_number_ledit,
                    Qt4_widget_colors.WHITE,
                    QPalette.Base)
                Qt4_widget_colors.set_widget_color(\
                    self.data_path_layout.folder_ledit,
                    Qt4_widget_colors.WHITE,
                    QPalette.Base)
        self.path_conflict_state = conflict
    def __init__(self, parent = None, name = None, fl = 0, acq_params = None,
                 path_template = None, layout = 'horizontal'):
        """
        Descript. :
        """
        QtGui.QWidget.__init__(self, parent, QtCore.Qt.WindowFlags(fl))
        
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------
        self.previous_energy = 0
        self.enable_parameter_update = True 

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.\
                                           AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)

        if layout == "horizontal":
            self.acq_widget_layout = uic.loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_horizontal_layout.ui"))
        else:
            self.acq_widget_layout = uic.loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_vertical_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QtGui.QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.energies_combo.activated.connect(\
             self.energy_selected)
        self.acq_widget_layout.mad_cbox.toggled.connect(\
             self.use_mad)
        self.acq_widget_layout.inverse_beam_cbx.toggled.connect(\
             self.set_use_inverse_beam)
        self.acq_widget_layout.first_image_ledit.textChanged.connect(\
             self.first_image_ledit_change)
        self.acq_widget_layout.num_images_ledit.textChanged.connect(\
             self.num_images_ledit_change)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(\
             self.detector_roi_mode_changed)

        overlap_ledit = self.acq_widget_layout.findChild(\
            QtGui.QLineEdit, "overlap_ledit")
        if overlap_ledit is not None:
            overlap_ledit.textChanged.connect(self.overlap_changed)

        self.acq_widget_layout.subwedge_size_ledit.textChanged.connect(\
             self.subwedge_size_ledit_change)

        # Other --------------------------------------------------------------- 
        self.acq_widget_layout.subwedge_size_ledit.setDisabled(True)
        self.acq_widget_layout.energies_combo.setDisabled(True)
        self.acq_widget_layout.energies_combo.addItems(['ip: -', 'pk: -', 'rm1: -', 'rm2: -'])

        self.osc_start_validator = QtGui.QDoubleValidator(-10000, 10000, 4, self)
        self.osc_range_validator = QtGui.QDoubleValidator(-10000, 10000, 4, self)
        self.kappa_validator = QtGui.QDoubleValidator(0, 360, 4, self)
        self.kappa_phi_validator = QtGui.QDoubleValidator(0, 360, 4, self)
        self.energy_validator = QtGui.QDoubleValidator(0, 25, 4, self)
        self.resolution_validator = QtGui.QDoubleValidator(0, 15, 3, self)
        self.transmission_validator = QtGui.QDoubleValidator(0, 100, 3, self)
        self.exp_time_validator = QtGui.QDoubleValidator(0.0001, 10000, 4, self)
        self.first_img_validator = QtGui.QIntValidator(0, 99999, self)
        self.num_img_validator = QtGui.QIntValidator(1, 99999, self) 
        self.disable_inverse_beam(True)
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)
class GphlSetupWidget(QtGui.QWidget):
    """Superclass for GPhL interface widgets"""

    def __init__(self, parent=None, name='gphl_setup_widget'):
        QtGui.QWidget.__init__(self,parent)
        if name is not None:
            self.setObjectName(name)

        # Properties ----------------------------------------------------------

        # Signals ------------------------------------------------------------

        # Slots ---------------------------------------------------------------
        dispatcher.connect(self._refresh_interface, 'model_update',
                           dispatcher.Any)

        # Hardware objects ----------------------------------------------------

        # Internal variables -------------------------------------------------
        self._widget_data = OrderedDict()
        self._data_object = GphlAcquisitionData()
        self._pulldowns = {}
        self._parameter_mib = DataModelInputBinder(self._data_object)

        # Graphic elements ----------------------------------------------------
        _parameters_widget = self._parameters_widget = QtGui.QWidget(self)
        QtGui.QGridLayout(_parameters_widget)
        _parameters_widget.layout().setColumnStretch(2, 1)

        # Layout --------------------------------------------------------------
        # This seems to be necessary to make widget visible
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_parameters_widget)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

    def setEnabled(self, value):
        super(GphlSetupWidget, self).setEnabled(value)
        for tag in self._widget_data:
            self.set_parameter_enabled(tag, value, warn=False)

    def set_parameter_enabled(self, tag, value, warn=True):
        tt = self._widget_data.get(tag)
        if tt:
            if hasattr(tt[0], 'setEnabled'):
                tt[0].setEnabled(value)
            elif warn:
                logging.getLogger().warning(
                    "%s Widget has no attribute setEnabled" % tag
                )
        elif warn:
            logging.getLogger().warning(
                "%s field not found in GphlSetupWidget" % tag
            )

    def get_data_object(self):
        return self._data_object

    def populate_widget(self, **kw):

        self._data_object = data_object = GphlAcquisitionData()
        self._parameter_mib.bindings.clear()
        # NB must be done here to set empty model, and also in subclasses:
        self._parameter_mib.set_model(data_object)
        for field_name, tags in self._pulldowns.items():
            widget = self._widget_data[field_name][0]
            widget.clear()
            widget.addItems(list(QtCore.QString(tag) for tag in tags))
            widget.setCurrentIndex(0)

    def set_parameter_value(self, name, value):
        """Set value - NB ComboBoxes are set by text, not index"""
        if hasattr(self._data_object, name):
            tags = self._pulldowns.get(name)
            if tags is None:
                # Not a pulldown
                setattr(self._data_object, name, value)
            else:
                # This is a pulldown
                if value in tags:
                    indx = tags.index(value)
                    setattr(self._data_object, name, indx)

                else:
                    raise ValueError(
                        "GPhL acquisition widget %s pulldown has no value %s"
                        % (name, value)
                    )

            self._parameter_mib._update_widget(name, None)
        else:
            raise ValueError(
                "GPhL acquisition widget has no parameter named %s" % name
            )

    def get_parameter_value(self, name):
        """Return value of parameter <name> or None if it does not exist

        NB ComboBoxes return text values, not indices

        NB, the attributes defined on the _data_object depend on context,
        so it is practical not to get errors for unknown names """
        if hasattr(self._data_object, name):
            tags = self._pulldowns.get(name)
            if tags is None:
                # Not a pulldown
                return getattr(self._data_object, name)
            else:
                # This is a pulldown - get text from index
                return tags[getattr(self._data_object, name)]
        else:
            return None

    def _get_label_name(self, name):
        return name + '_label'

    def _refresh_interface(self, field_name, data_binder):
        """Refresh interface when values change"""
        pass
Esempio n. 22
0
    def __init__(self, parent=None, name=None, fl=0):
        """
        Descript. :
        """

        CreateTaskBase.__init__(self, parent, name, fl, 'Characterisation')
        self.setObjectName("create_char_widget")

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._vertical_dimension_widget = None
        self._current_selected_item = None
        self.init_models()
        self._char_params_mib = DataModelInputBinder(self._char_params)

        # Graphic elements ----------------------------------------------------
        self._acq_widget = \
            AcquisitionWidgetSimple(self, acq_params = self._acquisition_parameters,
                                    path_template = self._path_template)

        self._data_path_widget = DataPathWidget(self,
                                                data_model=self._path_template,
                                                layout='vertical')

        self._vertical_dimension_widget = loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_vertical_crystal_dimension_widget_layout.ui'))

        self._char_widget = loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_characterise_simple_widget_vertical_layout.ui'))

        # Layout --------------------------------------------------------------
        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._char_widget)
        _main_vlayout.addWidget(self._vertical_dimension_widget)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.setSpacing(6)
        _main_vlayout.addStretch(0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.path_template_changed)
        self._acq_widget.acqParametersChangedSignal.\
             connect(self.acq_parameters_changed)

        self._vertical_dimension_widget.space_group_ledit.activated.\
             connect(self._space_group_change)
        #self.connect(induced_burn_cbx, QtCore.SIGNAL("toggled(bool)"),
        #             self.use_induced_burn)

        self._char_widget.characterisation_gbox.toggled.connect(\
             self.characterisation_gbox_toggled)
        self._char_widget.wait_result_cbx.toggled.connect(\
             self.wait_results_cbx_toggled)
        self._char_widget.execute_plan_cbx.toggled.connect(\
             self.run_diffraction_plan_cbx_toggled)

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update(
            'opt_sad', self._char_widget.optimised_sad_cbx, bool, None)

        self._char_params_mib.bind_value_update(
            'account_rad_damage', self._char_widget.account_rad_dmg_cbx, bool,
            None)

        #self._char_params_mib.bind_value_update('determine_rad_params',
        #                                        induced_burn_cbx,
        #                                        bool, None)

        self._char_params_mib.bind_value_update(
            'strategy_complexity', self._char_widget.start_comp_cbox, int,
            None)

        self._char_params_mib.\
            bind_value_update('max_crystal_vdim',
                              self._vertical_dimension_widget.max_vdim_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vdim',
                              self._vertical_dimension_widget.min_vdim_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vphi',
                              self._vertical_dimension_widget.min_vphi_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('max_crystal_vphi',
                              self._vertical_dimension_widget.max_vphi_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._vertical_dimension_widget.space_group_ledit.addItems(
            XTAL_SPACEGROUPS)
Esempio n. 23
0
    def __init__(self, parent=None, name=None, fl=0, data_model=None):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        if data_model is None:
            self._model = queue_model_objects.ProcessingParameters()
        else:
            self._model = data_model

        self._model_mib = DataModelInputBinder(self._model)

        self.processing_widget = self.acq_widget_layout = loadUi(
                           os.path.join(os.path.dirname(__file__),
                           "ui_files/Qt4_processing_widget_vertical_layout.ui"))
      
        self.main_layout = QVBoxLayout(self)
        self.main_layout.addWidget(self.processing_widget)
        self.main_layout.setSpacing(0)
        self.main_layout.setContentsMargins(0, 0, 0, 0)
       
        self.processing_widget.space_group_combo.\
            addItems(queue_model_enumerables.XTAL_SPACEGROUPS)
        
        self._model_mib.bind_value_update('cell_a',
                                          self.processing_widget.a_ledit,
                                          float,
                                          None)
        
        self._model_mib.bind_value_update('cell_alpha',
                                          self.processing_widget.alpha_ledit,
                                          float,
                                          None)

        self._model_mib.bind_value_update('cell_b',
                                          self.processing_widget.b_ledit,
                                          float,
                                          None)

        self._model_mib.bind_value_update('cell_beta',
                                          self.processing_widget.beta_ledit,
                                          float,
                                          None)  

        self._model_mib.bind_value_update('cell_c',
                                          self.processing_widget.c_ledit,
                                          float,
                                          None)

        self._model_mib.bind_value_update('cell_gamma',
                                          self.processing_widget.gamma_ledit,
                                          float,
                                          None)  
        
        self._model_mib.bind_value_update('num_residues',
                                          self.processing_widget.num_residues_ledit,
                                          float,
                                          None)

        self.processing_widget.space_group_combo.activated.\
             connect(self._space_group_change)    
        self.processing_widget.run_processing_after_cbox.stateChanged.\
             connect(self._run_processing_after_toggled)
        self.processing_widget.run_processing_parallel_cbox.stateChanged.\
             connect(self._run_processing_parallel_toggled)
    def __init__(self,
                 parent=None,
                 name=None,
                 fl=0,
                 acq_params=None,
                 path_template=None,
                 layout='horizontal'):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None
        self._diffractometer_hwobj = None

        # Internal variables --------------------------------------------------
        self.previous_energy = 0

        # If the acq. widget is used with grids then total osc range is not
        # equal to num_images * osc_range, but num_images_per_line * osc_range
        # For grids the osc total range is updated when a grid is selected

        self.grid_mode = False

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.\
                                           AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(
            self._acquisition_parameters)

        if layout == "horizontal":
            self.acq_widget_layout = loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_horizontal_layout.ui"))
            self.use_osc_start(False)
        else:
            self.acq_widget_layout = loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_vertical_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.osc_start_cbox.stateChanged.connect(\
             self.fix_osc_start)
        self.acq_widget_layout.exp_time_ledit.textChanged.connect(\
             self.exposure_time_ledit_changed)
        self.acq_widget_layout.first_image_ledit.textChanged.connect(\
             self.first_image_ledit_change)
        self.acq_widget_layout.num_images_ledit.textChanged.connect(\
             self.num_images_ledit_change)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(\
             self.detector_roi_mode_changed)
        self.acq_widget_layout.energies_combo.activated.connect(\
             self.energy_selected)
        self.acq_widget_layout.mad_cbox.toggled.connect(\
             self.use_mad)
        self.acq_widget_layout.osc_start_ledit.textEdited.connect(\
             self.osc_start_ledit_changed)
        self.acq_widget_layout.osc_range_ledit.textEdited.connect(\
             self.osc_range_per_frame_ledit_changed)
        self.acq_widget_layout.osc_total_range_ledit.textEdited.connect(\
             self.osc_total_range_ledit_changed)
        self.acq_widget_layout.energy_ledit.textEdited.connect(\
             self.energy_ledit_changed)
        self.acq_widget_layout.transmission_ledit.textEdited.connect(\
             self.transmission_ledit_changed)
        self.acq_widget_layout.resolution_ledit.textEdited.connect(\
             self.resolution_ledit_changed)
        self.acq_widget_layout.kappa_ledit.textEdited.connect(\
             self.kappa_ledit_changed)
        self.acq_widget_layout.kappa_phi_ledit.textEdited.connect(\
             self.kappa_phi_ledit_changed)

        if self.acq_widget_layout.findChild(QLineEdit, "overlap_ledit"):
            self.acq_widget_layout.overlap_ledit.textChanged.connect(\
                 self.overlap_changed)
        if self.acq_widget_layout.findChild(QCheckBox, "max_osc_range_cbx"):
            self.acq_widget_layout.max_osc_range_cbx.toggled.connect(\
                 self.max_osc_range_toggled)

        # Other ---------------------------------------------------------------
        self.value_changed_list = []

        self.acq_widget_layout.energies_combo.setDisabled(True)
        self.acq_widget_layout.energies_combo.addItems(\
             ['ip: -', 'pk: -', 'rm1: -', 'rm2: -'])

        self.osc_start_validator = QDoubleValidator(\
             -10000, 10000, 4, self.acq_widget_layout.osc_start_ledit)
        self.osc_range_per_frame_validator = QDoubleValidator(\
             0, 10000, 4, self.acq_widget_layout.osc_range_ledit)
        self.osc_total_range_validator = QDoubleValidator(\
             0, 10000, 4, self.acq_widget_layout.osc_total_range_ledit)
        self.kappa_validator = QDoubleValidator(\
             0, 360, 4, self.acq_widget_layout.kappa_ledit)
        self.kappa_phi_validator = QDoubleValidator(\
             0, 360, 4, self.acq_widget_layout.kappa_phi_ledit)
        self.energy_validator = QDoubleValidator(\
             4, 25, 4, self.acq_widget_layout.energy_ledit)
        self.resolution_validator = QDoubleValidator(\
             0, 15, 3, self.acq_widget_layout.resolution_ledit)
        self.transmission_validator = QDoubleValidator(\
             0, 100, 3, self.acq_widget_layout.transmission_ledit)
        self.exp_time_validator = QDoubleValidator(\
             0.0001, 10000, 7, self.acq_widget_layout.exp_time_ledit)
        self.first_img_validator = QIntValidator(\
             0, 99999, self.acq_widget_layout.first_image_ledit)
        self.num_img_validator = QIntValidator(\
             1, 99999, self.acq_widget_layout.num_images_ledit)
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)
class AcquisitionWidget(QWidget):

    acqParametersChangedSignal = pyqtSignal(list)
    madEnergySelectedSignal = pyqtSignal(str, float, bool)

    def __init__(self,
                 parent=None,
                 name=None,
                 fl=0,
                 acq_params=None,
                 path_template=None,
                 layout='horizontal'):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None
        self._diffractometer_hwobj = None

        # Internal variables --------------------------------------------------
        self.previous_energy = 0

        # If the acq. widget is used with grids then total osc range is not
        # equal to num_images * osc_range, but num_images_per_line * osc_range
        # For grids the osc total range is updated when a grid is selected

        self.grid_mode = False

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.\
                                           AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(
            self._acquisition_parameters)

        if layout == "horizontal":
            self.acq_widget_layout = loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_horizontal_layout.ui"))
            self.use_osc_start(False)
        else:
            self.acq_widget_layout = loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_vertical_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.osc_start_cbox.stateChanged.connect(\
             self.fix_osc_start)
        self.acq_widget_layout.exp_time_ledit.textChanged.connect(\
             self.exposure_time_ledit_changed)
        self.acq_widget_layout.first_image_ledit.textChanged.connect(\
             self.first_image_ledit_change)
        self.acq_widget_layout.num_images_ledit.textChanged.connect(\
             self.num_images_ledit_change)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(\
             self.detector_roi_mode_changed)
        self.acq_widget_layout.energies_combo.activated.connect(\
             self.energy_selected)
        self.acq_widget_layout.mad_cbox.toggled.connect(\
             self.use_mad)
        self.acq_widget_layout.osc_start_ledit.textEdited.connect(\
             self.osc_start_ledit_changed)
        self.acq_widget_layout.osc_range_ledit.textEdited.connect(\
             self.osc_range_per_frame_ledit_changed)
        self.acq_widget_layout.osc_total_range_ledit.textEdited.connect(\
             self.osc_total_range_ledit_changed)
        self.acq_widget_layout.energy_ledit.textEdited.connect(\
             self.energy_ledit_changed)
        self.acq_widget_layout.transmission_ledit.textEdited.connect(\
             self.transmission_ledit_changed)
        self.acq_widget_layout.resolution_ledit.textEdited.connect(\
             self.resolution_ledit_changed)
        self.acq_widget_layout.kappa_ledit.textEdited.connect(\
             self.kappa_ledit_changed)
        self.acq_widget_layout.kappa_phi_ledit.textEdited.connect(\
             self.kappa_phi_ledit_changed)

        if self.acq_widget_layout.findChild(QLineEdit, "overlap_ledit"):
            self.acq_widget_layout.overlap_ledit.textChanged.connect(\
                 self.overlap_changed)
        if self.acq_widget_layout.findChild(QCheckBox, "max_osc_range_cbx"):
            self.acq_widget_layout.max_osc_range_cbx.toggled.connect(\
                 self.max_osc_range_toggled)

        # Other ---------------------------------------------------------------
        self.value_changed_list = []

        self.acq_widget_layout.energies_combo.setDisabled(True)
        self.acq_widget_layout.energies_combo.addItems(\
             ['ip: -', 'pk: -', 'rm1: -', 'rm2: -'])

        self.osc_start_validator = QDoubleValidator(\
             -10000, 10000, 4, self.acq_widget_layout.osc_start_ledit)
        self.osc_range_per_frame_validator = QDoubleValidator(\
             0, 10000, 4, self.acq_widget_layout.osc_range_ledit)
        self.osc_total_range_validator = QDoubleValidator(\
             0, 10000, 4, self.acq_widget_layout.osc_total_range_ledit)
        self.kappa_validator = QDoubleValidator(\
             0, 360, 4, self.acq_widget_layout.kappa_ledit)
        self.kappa_phi_validator = QDoubleValidator(\
             0, 360, 4, self.acq_widget_layout.kappa_phi_ledit)
        self.energy_validator = QDoubleValidator(\
             4, 25, 4, self.acq_widget_layout.energy_ledit)
        self.resolution_validator = QDoubleValidator(\
             0, 15, 3, self.acq_widget_layout.resolution_ledit)
        self.transmission_validator = QDoubleValidator(\
             0, 100, 3, self.acq_widget_layout.transmission_ledit)
        self.exp_time_validator = QDoubleValidator(\
             0.0001, 10000, 7, self.acq_widget_layout.exp_time_ledit)
        self.first_img_validator = QIntValidator(\
             0, 99999, self.acq_widget_layout.first_image_ledit)
        self.num_img_validator = QIntValidator(\
             1, 99999, self.acq_widget_layout.num_images_ledit)
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)

    def use_max_osc_range(self, state):
        self.acq_widget_layout.max_osc_range_cbx.setEnabled(state)

    def fix_osc_start(self, state):
        """
        Fix osc start, so the lineEdit do not change when osc is changed
        """
        self.acq_widget_layout.osc_start_ledit.setEnabled(state)

    def update_osc_start(self, new_value):
        """
        Updates osc line edit
        """
        if "osc_start" not in self.value_changed_list and \
           not self.acq_widget_layout.osc_start_ledit.hasFocus() and \
           not self.acq_widget_layout.osc_start_cbox.isChecked():
            osc_start_value = 0
            try:
                osc_start_value = round(float(new_value), 2)
            except TypeError:
                pass

            self.acq_widget_layout.osc_start_ledit.setText(
                str(osc_start_value))
            self._acquisition_parameters.osc_start = osc_start_value

            #self.update_osc_total_range_limits()
            #self.update_num_images_limits()

    def osc_start_ledit_changed(self, osc_start):
        """Fixes osc start edit"""
        if "osc_start" not in self.value_changed_list:
            self.value_changed_list.append("osc_start")
        self.update_osc_total_range_limits()
        self.update_num_images_limits()
        self.emit_acq_parameters_changed()

    def update_osc_start_limits(self):
        """In the plate mode sets osc start limits"""
        self.update_osc_total_range_limits()
        self.update_num_images_limits()

    def osc_range_per_frame_ledit_changed(self, new_value):
        self.update_osc_total_range()
        self.update_num_images_limits()
        self.update_exp_time_limits()
        self.emit_acq_parameters_changed()

    def update_osc_range_per_frame_limits(self):
        try:
            max_osc_speed = self._diffractometer_hwobj.get_osc_max_speed()
            top_limit = max_osc_speed * float(
                self.acq_widget_layout.exp_time_ledit.text())

            self.osc_range_per_frame_validator.setTop(top_limit)
            tool_tip = "Oscillation range per frame limits 0 : " +\
                       "%0.4f\n4 digits precision." % top_limit

            self.acq_widget_layout.osc_range_ledit.setToolTip(tool_tip)
            self._acquisition_mib.validate_all()
        except:
            pass

    def update_osc_total_range(self):
        self.acq_widget_layout.osc_total_range_ledit.blockSignals(True)
        if not self.grid_mode:
            try:
                self.acq_widget_layout.osc_total_range_ledit.setText(str(\
                     float(self.acq_widget_layout.osc_range_ledit.text()) * \
                     float(self.acq_widget_layout.num_images_ledit.text())))
            except:
                pass
        self.acq_widget_layout.osc_total_range_ledit.blockSignals(False)

    def update_total_exp_time(self):
        try:
            self.acq_widget_layout.total_exp_time_ledit.setText("%.2f" % \
                 (float(self.acq_widget_layout.exp_time_ledit.text()) * \
                  float(self.acq_widget_layout.num_images_ledit.text())))
        except:
            pass

    def osc_total_range_ledit_changed(self, new_value):
        if not self.grid_mode:
            try:
                num_images = int(float(new_value) / \
                   float(self.acq_widget_layout.osc_range_ledit.text()))
                self.acq_widget_layout.num_images_ledit.blockSignals(True)
                self.acq_widget_layout.num_images_ledit.setText("%d" %
                                                                num_images)
                self._acquisition_parameters.num_images = num_images
                self.acq_widget_layout.num_images_ledit.blockSignals(False)
            except:
                pass
            self.emit_acq_parameters_changed()

    def update_osc_total_range_limits(self, num_images=None):
        """Updates osc totol range. Limits are changed if a plate is used.
           - For simple oscillation osc_range is defined by osc_start and 
             osc_start top limit.
           - For mesh osc_range is defined by number of images per line
             and osc in the middle of mesh  
        """
        if self._diffractometer_hwobj.in_plate_mode():
            if hasattr(self.parent(), "set_osc_total_range"):
                self.parent().set_osc_total_range(num_images)
                self._acquisition_mib.validate_all()

    def update_exp_time_limits(self):
        try:
            exp_time_limits = self._beamline_setup_hwobj.detector_hwobj.get_exposure_time_limits(
            )
            max_osc_speed = self._diffractometer_hwobj.get_osc_max_speed()
            top_limit = float(
                self.acq_widget_layout.osc_range_ledit.text()) / max_osc_speed
            limits = (max(exp_time_limits[0], top_limit), exp_time_limits[1])

            self.update_detector_exp_time_limits(limits)
        except:
            pass

    def update_kappa(self, new_value):
        """
        Updates kappa value
        """
        if not self.acq_widget_layout.kappa_ledit.hasFocus() and \
           new_value:
            self.acq_widget_layout.kappa_ledit.setText(str(new_value))
            self.emit_acq_parameters_changed()

    def update_kappa_phi(self, new_value):
        """
        Descript. :
        """
        if not self.acq_widget_layout.kappa_phi_ledit.hasFocus() and \
           new_value:
            self.acq_widget_layout.kappa_phi_ledit.setText(str(new_value))
            self.emit_acq_parameters_changed()

    def use_osc_start(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.osc_start_cbox.setVisible(state)
        self.acq_widget_layout.osc_start_label.setVisible(not state)
        self.acq_widget_layout.osc_start_ledit.setEnabled(not state)

    def use_kappa(self, state):
        """
        Descript. :
        """
        if self._diffractometer_hwobj is not None:
            if self._diffractometer_hwobj.in_plate_mode():
                state = False
        self.acq_widget_layout.kappa_label.setEnabled(state)
        self.acq_widget_layout.kappa_ledit.setEnabled(state)
        self.acq_widget_layout.kappa_phi_label.setEnabled(state)
        self.acq_widget_layout.kappa_phi_ledit.setEnabled(state)

    def set_beamline_setup(self, beamline_setup):
        """
        Descript. :
        """
        self._beamline_setup_hwobj = beamline_setup
        limits_dict = self._beamline_setup_hwobj.get_acquisition_limit_values()
        self._diffractometer_hwobj = self._beamline_setup_hwobj.diffractometer_hwobj

        if 'osc_range' in limits_dict:
            limits = tuple(map(float, limits_dict['osc_range'].split(',')))
            (lower, upper) = limits
            self.osc_start_validator.setRange(lower, upper, 4)
            self.osc_range_per_frame_validator.setRange(lower, upper, 4)
            self.osc_total_range_validator.setRange(lower, upper, 4)

        self._acquisition_mib.bind_value_update(
            'osc_start', self.acq_widget_layout.osc_start_ledit, float,
            self.osc_start_validator)

        self._acquisition_mib.bind_value_update(
            'osc_range', self.acq_widget_layout.osc_range_ledit, float,
            self.osc_range_per_frame_validator)

        self._acquisition_mib.bind_value_update(
            'osc_total_range', self.acq_widget_layout.osc_total_range_ledit,
            float, self.osc_total_range_validator)

        if 'kappa' in limits_dict:
            limits = tuple(map(float, limits_dict['kappa'].split(',')))
            (lower, upper) = limits
            self.kappa_validator.setRange(lower, upper, 4)
        self._acquisition_mib.bind_value_update(
            'kappa', self.acq_widget_layout.kappa_ledit, float,
            self.kappa_validator)

        if 'kappa_phi' in limits_dict:
            limits = tuple(map(float, limits_dict['kappa_phi'].split(',')))
            (lower, upper) = limits
            self.kappa_phi_validator.setRange(lower, upper, 4)
        self._acquisition_mib.bind_value_update(
            'kappa_phi', self.acq_widget_layout.kappa_phi_ledit, float,
            self.kappa_phi_validator)

        if 'exposure_time' in limits_dict:
            limits = tuple(map(float, limits_dict['exposure_time'].split(',')))
            (lower, upper) = limits
            self.exp_time_validator.setRange(lower, upper, 6)

        self._acquisition_mib.bind_value_update(
            'exp_time', self.acq_widget_layout.exp_time_ledit, float,
            self.exp_time_validator)

        if 'number_of_images' in limits_dict:
            limits = tuple(
                map(float, limits_dict['number_of_images'].split(',')))
            (lower, upper) = limits
            self.num_img_validator.setRange(lower, upper)
            self.first_img_validator.setRange(lower, upper)

        self._acquisition_mib.bind_value_update(
            'first_image', self.acq_widget_layout.first_image_ledit, int,
            self.first_img_validator)

        self._acquisition_mib.bind_value_update(
            'num_images', self.acq_widget_layout.num_images_ledit, int,
            self.num_img_validator)

        num_passes = self.acq_widget_layout.findChild(QLineEdit,
                                                      "num_passes_ledit")

        if num_passes:
            self._acquisition_mib.\
                bind_value_update('num_passes', num_passes, int,
                                  QIntValidator(1, 1000, self))

        overlap_ledit = self.acq_widget_layout.findChild(
            QLineEdit, "overlap_ledit")

        if overlap_ledit:
            self._acquisition_mib.\
                bind_value_update('overlap', overlap_ledit, float,
                                  QDoubleValidator(-1000, 1000, 2, self))

        self._acquisition_mib.\
             bind_value_update('energy',
                               self.acq_widget_layout.energy_ledit,
                               float,
                               self.energy_validator)
        self.update_energy_limits(
            (self.energy_validator.bottom(), self.energy_validator.top()))

        self._acquisition_mib.\
             bind_value_update('transmission',
                               self.acq_widget_layout.transmission_ledit,
                               float,
                               self.transmission_validator)
        self.update_transmission_limits((self.transmission_validator.bottom(),
                                         self.transmission_validator.top()))

        self._acquisition_mib.\
             bind_value_update('resolution',
                               self.acq_widget_layout.resolution_ledit,
                               float,
                               self.resolution_validator)
        #self.update_resolution_limits((self.resolution_validator.bottom(),
        #                               self.resolution_validator.top()))

        self._acquisition_mib.\
             bind_value_update('shutterless',
                               self.acq_widget_layout.shutterless_cbx,
                               bool,
                               None)

        self.set_tunable_energy(beamline_setup.tunable_wavelength())

        has_shutter_less = self._beamline_setup_hwobj.detector_has_shutterless(
        )
        self.acq_widget_layout.shutterless_cbx.setEnabled(has_shutter_less)
        self.acq_widget_layout.shutterless_cbx.setChecked(has_shutter_less)

        if self._beamline_setup_hwobj.disable_num_passes():
            num_passes = self.acq_widget_layout.findChild(
                QLineEdit, "num_passes_ledit")
            if num_passes:
                num_passes.setDisabled(True)

        self.init_detector_roi_modes()

    def first_image_ledit_change(self, new_value):
        """
        Descript. :
        """
        #if str(new_value).isdigit():
        #    #self._path_template.start_num = int(new_value)
        #    #widget = self.acq_widget_layout.first_image_ledit
        self.emit_acq_parameters_changed()

    def exposure_time_ledit_changed(self, new_values):
        """If the exposure time changes we have to check the osc speed
           and if necessary update osc range per frame
        """
        self.update_osc_range_per_frame_limits()
        self.update_osc_total_range_limits()
        self.update_total_exp_time()
        self.emit_acq_parameters_changed()

    def num_images_ledit_change(self, new_value):
        """
        Descript. :
        """
        if str(new_value).isdigit():
            #self._path_template.num_files = int(new_value)
            self.update_osc_range_per_frame_limits()
            self.update_osc_total_range_limits()
            self.update_osc_total_range()
            self.update_total_exp_time()
        self.emit_acq_parameters_changed()

    def overlap_changed(self, new_value):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj:
            has_shutter_less = self._beamline_setup_hwobj.detector_has_shutterless(
            )
        else:
            has_shutter_less = True

        if has_shutter_less:
            try:
                new_value = float(new_value)
            except ValueError:
                pass

            if new_value != 0:
                self.acq_widget_layout.shutterless_cbx.setEnabled(False)
                self.acq_widget_layout.shutterless_cbx.setChecked(False)
                self._acquisition_parameters.shutterless = False
            else:
                self.acq_widget_layout.shutterless_cbx.setEnabled(True)
                self.acq_widget_layout.shutterless_cbx.setChecked(True)
                self._acquisition_parameters.shutterless = True

    def use_mad(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.energies_combo.setEnabled(state)
        if state:
            (name, energy) = self.get_mad_energy()

            if energy != 0:
                self.update_energy(energy)
            self.madEnergySelectedSignal.emit(name, energy, state)
        else:
            self.update_energy(self.previous_energy)
            energy = self._beamline_setup_hwobj.energy_hwobj.getCurrentEnergy()
            self.madEnergySelectedSignal.emit('', self.previous_energy, state)

    def max_osc_range_toggled(self, state):
        self.update_osc_total_range_limits()

    def get_mad_energy(self):
        """
        Descript. :
        """
        energy_str = str(self.acq_widget_layout.energies_combo.currentText())
        (name, value) = energy_str.split(':')

        name = name.strip()
        value = value.strip()
        value = 0 if (value == '-') else float(value)

        return (name, value)

    def set_energies(self, energy_scan_result):
        """
        Descript. :
        """
        self.acq_widget_layout.energies_combo.clear()

        inflection = ('ip: %.4f' % energy_scan_result.inflection) if \
                     energy_scan_result.inflection else 'ip: -'

        peak = ('pk: %.4f' % energy_scan_result.peak) if \
               energy_scan_result.peak else 'pk: -'

        first_remote = ('rm1: %.4f' % energy_scan_result.first_remote) if \
                       energy_scan_result.first_remote else 'rm1: -'

        second_remote = ('rm2: %.4f' % energy_scan_result.second_remote) if \
                        energy_scan_result.second_remote else 'rm2: -'

        self.acq_widget_layout.energies_combo.\
             addItems([inflection, peak, first_remote, second_remote])

    def energy_selected(self, index):
        """
        Descript. :
        """
        if self.acq_widget_layout.mad_cbox.isChecked():
            (name, energy) = self.get_mad_energy()
            if energy != 0:
                self.update_energy(energy)

            self.madEnergySelectedSignal.emit(name, energy, True)

    def energy_ledit_changed(self, new_value):
        if "energy" not in self.value_changed_list:
            self.value_changed_list.append("energy")
        self.emit_acq_parameters_changed()

    def update_energy(self, energy, wav=None):
        """
        Descript. :
        """
        if "energy" not in self.value_changed_list and \
           not self.acq_widget_layout.energy_ledit.hasFocus():
            self.acq_widget_layout.energy_ledit.setText(str(energy))
        self.emit_acq_parameters_changed()

    def transmission_ledit_changed(self, transmission):
        if "transmission" not in self.value_changed_list:
            self.value_changed_list.append("transmission")
        self.emit_acq_parameters_changed()

    def update_transmission(self, transmission):
        if "transmission" not in self.value_changed_list:
            self.acq_widget_layout.transmission_ledit.setText(
                str(transmission))
        self.emit_acq_parameters_changed()

    def resolution_ledit_changed(self, resolution):
        if "resolution" not in self.value_changed_list:
            self.value_changed_list.append("resolution")
        self.emit_acq_parameters_changed()

    def update_resolution(self, resolution):
        if "resolution" not in self.value_changed_list and \
           not self.acq_widget_layout.resolution_ledit.hasFocus():
            self.acq_widget_layout.resolution_ledit.setText(str(resolution))
        self.emit_acq_parameters_changed()

    def update_energy_limits(self, limits):
        if limits:
            self.energy_validator.setBottom(limits[0])
            self.energy_validator.setTop(limits[1])
            self.acq_widget_layout.energy_ledit.setToolTip(\
               "Energy limits %0.4f : %0.4f keV\n" % \
               (limits[0], limits[1]) + \
               "4 digits precision.")
            self._acquisition_mib.validate_all()

    def update_transmission_limits(self, limits):
        if limits:
            self.transmission_validator.setBottom(limits[0])
            self.transmission_validator.setTop(limits[1])
            self.acq_widget_layout.transmission_ledit.setToolTip(\
               "Transmission limits %0.2f : %0.2f %%\n" % \
               (limits[0], limits[1]) + \
               "2 digits precision.")
            self._acquisition_mib.validate_all()

    def update_resolution_limits(self, limits):
        if limits:
            self.resolution_validator.setBottom(limits[0])
            self.resolution_validator.setTop(limits[1])
            self.acq_widget_layout.resolution_ledit.setToolTip(
               "Resolution limits %0.4f : %0.4f %s\n" % \
               (limits[0], limits[1], chr(197)) +
               "4 digits precision.")
            self._acquisition_mib.validate_all()

    def update_detector_exp_time_limits(self, limits):
        if limits:
            self.exp_time_validator.setRange(limits[0], limits[1], 6)
            self.acq_widget_layout.exp_time_ledit.setToolTip(
               "Exposure time limits %0.6f s : %0.1f s\n" % \
               (limits[0], limits[1]) + \
               "6 digits precision.")
            self._acquisition_mib.validate_all()

    def update_num_images_limits(self, num_images_limits=None):
        """Updates number of images limit. Method used if plate mode.
        """

        self._acquisition_mib.validate_all()

        return
        if self._diffractometer_hwobj.in_plate_mode():
            if num_images_limits is None:
                try:
                    osc_start = float(
                        self.acq_widget_layout.osc_start_ledit.text())
                    osc_range = float(
                        self.acq_widget_layout.osc_range_ledit.text())
                except ValueError:
                    return

                if osc_range == 0:
                    return

                num_images_limits = int((self.osc_start_validator.top() - \
                                         osc_start) / osc_range)

            self.num_img_validator.setTop(num_images_limits)
            self.acq_widget_layout.num_images_ledit.setToolTip(\
                "Number of images limits : %d" % num_images_limits)
            self._acquisition_mib.validate_all()

    def init_detector_roi_modes(self):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            roi_modes = self._beamline_setup_hwobj.detector_hwobj.get_roi_modes(
            )
            if (len(roi_modes) > 0
                    and self.acq_widget_layout.detector_roi_mode_combo.count()
                    == 0):
                for roi_mode in roi_modes:
                    self.acq_widget_layout.detector_roi_mode_combo.\
                         addItem(roi_mode)
                self.acq_widget_layout.detector_roi_mode_label.setEnabled(True)
                self.acq_widget_layout.detector_roi_mode_combo.setEnabled(True)
                #self._acquisition_mib.bind_value_update('detector_roi_mode',
                #               self.acq_widget_layout.detector_roi_mode_combo,
                ##               str,
                #               None)

    def update_detector_roi_mode(self, roi_mode_index):
        """
        Descript. :
        """
        if roi_mode_index is not None and \
           self.acq_widget_layout.detector_roi_mode_combo.count() > 0:
            self.acq_widget_layout.detector_roi_mode_combo.\
                 setCurrentIndex(roi_mode_index)

    def detector_roi_mode_changed(self, roi_mode_index):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            self._beamline_setup_hwobj.detector_hwobj.set_roi_mode(
                roi_mode_index)

    def kappa_ledit_changed(self, new_value):
        if "kappa" not in self.value_changed_list:
            self.value_changed_list.append("kappa")
        self.emit_acq_parameters_changed()

    def kappa_phi_ledit_changed(self, new_value):
        if "kappa_phi" not in self.value_changed_list:
            self.value_changed_list.append("kappa_phi")
        self.emit_acq_parameters_changed()

    def update_data_model(self, acquisition_parameters, path_template):
        """
        Descript. :
        """
        self._acquisition_parameters = acquisition_parameters
        self._path_template = path_template
        self._acquisition_mib.set_model(acquisition_parameters)

        #Update mad widgets
        mad = True if self._path_template.mad_prefix != '' else False

        if mad:
            mad_prefix = str(self._path_template.mad_prefix)
            index = MAD_ENERGY_COMBO_NAMES[str(mad_prefix)]
            self.acq_widget_layout.energies_combo.setCurrentIndex(index)
            self.acq_widget_layout.mad_cbox.setChecked(True)
            self.acq_widget_layout.energies_combo.setEnabled(True)
        else:
            self.acq_widget_layout.mad_cbox.setChecked(False)
            self.acq_widget_layout.energies_combo.setEnabled(False)
            self.acq_widget_layout.energies_combo.setCurrentIndex(0)

        #self.update_osc_start_limits()
        #self.update_osc_total_range()
        self.emit_acq_parameters_changed()

    def set_tunable_energy(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.energy_ledit.setEnabled(state)
        self.acq_widget_layout.mad_cbox.setEnabled(state)
        self.acq_widget_layout.energies_combo.setEnabled(state)

    def check_parameter_conflict(self):
        return self._acquisition_mib.validate_all()

    def emit_acq_parameters_changed(self):
        self.acqParametersChangedSignal.emit(
            self._acquisition_mib.validate_all())
Esempio n. 26
0
    def __init__(self, *args):
        """
        Descript. :
        """
        BlissWidget.__init__(self, *args)

        # Internal variables ------------------------------------------------
        self.sample = queue_model_objects.Sample()
        self.crystal = self.sample.crystals[0]
        self.sample_mib = DataModelInputBinder(self.sample)
        self.crystal_mib = DataModelInputBinder(self.crystal)

        # Signals ------------------------------------------------------------

        # Slots --------------------------------------------------------------
        self.defineSlot("populate_sample_details", ({}))

        # Graphic elements ----------------------------------------------------
        _info_widget = QWidget(self)
        self.crystal_widget = loadUi(\
             os.path.join(os.path.dirname(__file__),
             "widgets/ui_files/Qt4_crystal_widget_layout.ui"))
        self.sample_info_widget = loadUi(
            os.path.join(os.path.dirname(__file__),
                         "widgets/ui_files/Qt4_sample_info_widget_layout.ui"))
        #self.ispyb_sample_info_widget = ISPyBSampleInfoWidget(self)

        # Layout --------------------------------------------------------------
        _info_widget_hlayout = QHBoxLayout(_info_widget)
        _info_widget_hlayout.addWidget(self.sample_info_widget)
        _info_widget_hlayout.addWidget(self.crystal_widget)
        _info_widget_hlayout.addStretch(0)
        _info_widget_hlayout.setSpacing(0)
        _info_widget_hlayout.setContentsMargins(2, 2, 2, 2)

        _main_hlayout = QVBoxLayout(self)
        _main_hlayout.addWidget(_info_widget)
        #_main_hlayout.addWidget(self.ispyb_sample_info_widget)
        _main_hlayout.addStretch(0)
        _main_hlayout.setSpacing(0)
        _main_hlayout.setContentsMargins(2, 2, 2, 2)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------

        # Other ---------------------------------------------------------------
        self.crystal_mib.bind_value_update(
            'space_group', self.crystal_widget.space_group_value_label, str,
            None)

        self.crystal_mib.bind_value_update(
            'protein_acronym', self.crystal_widget.protein_acronym_value_label,
            str, None)

        self.crystal_mib.bind_value_update('cell_a',
                                           self.crystal_widget.a_value_label,
                                           str, None)

        self.crystal_mib.bind_value_update(
            'cell_alpha', self.crystal_widget.alpha_value_label, str, None)

        self.crystal_mib.bind_value_update('cell_b',
                                           self.crystal_widget.b_value_label,
                                           str, None)

        self.crystal_mib.bind_value_update(
            'cell_beta', self.crystal_widget.beta_value_label, str, None)

        self.crystal_mib.bind_value_update('cell_c',
                                           self.crystal_widget.c_value_label,
                                           str, None)

        self.crystal_mib.bind_value_update(
            'cell_gamma', self.crystal_widget.gamma_value_label, str, None)

        self.sample_mib.bind_value_update(
            'name', self.sample_info_widget.name_value_label, str, None)

        self.sample_mib.bind_value_update(
            'code', self.sample_info_widget.data_matrix_value_label, str, None)

        self.sample_mib.bind_value_update(
            'holder_length', self.sample_info_widget.holder_length_value_label,
            str, None)

        self.sample_mib.bind_value_update(
            'lims_sample_location',
            self.sample_info_widget.sample_location_value_label, str, None)

        self.sample_mib.bind_value_update(
            'lims_container_location',
            self.sample_info_widget.basket_location_value_label, str, None)
class DCParametersWidget(QWidget):
    def __init__(self, parent=None, name="parameter_widget"):

        QWidget.__init__(self, parent)
        if name is not None:
            self.setObjectName(name)

        # Properties ----------------------------------------------------------

        # Signals ------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------
        self._data_collection = None
        self.add_dc_cb = None
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _dc_parameters_widget = 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 = 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 = 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 set_beamline_setup(self, bl_setup):
        self._acq_widget.set_beamline_setup(bl_setup)
        self._beamline_setup_hwobj = bl_setup

    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 = self.queue_model_hwobj.\
                        check_for_path_collisions(path_template)

    def __add_data_collection(self):
        return self.add_dc_cb(self._data_collection, self.collection_type)

    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 = self._beamline_setup_hwobj.queue_model_hwobj.\
          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)
Esempio n. 28
0
class DCParametersWidget(QtGui.QWidget):
    def __init__(self, parent=None, name="parameter_widget"):

        QtGui.QWidget.__init__(self, parent)
        if name is not None:
            self.setObjectName(name)

        # Properties ----------------------------------------------------------

        # Signals ------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------
        self._data_collection = None
        self.add_dc_cb = None
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _dc_parameters_widget = QtGui.QWidget(self)
        self.caution_pixmap = Qt4_Icons.load("Caution2.png")
        self.path_widget = DataPathWidget(_dc_parameters_widget)
        self.acq_widget = AcquisitionWidget(_dc_parameters_widget,
                                            layout='horizontal')
        #self.acq_widget.setFixedHeight(170)
        self.processing_widget = ProcessingWidget(_dc_parameters_widget)
        self.position_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__),
                         'ui_files/Qt4_snapshot_widget_layout.ui'))
        #self.position_widget.setMinimumSize(310, 210)

        # Layout --------------------------------------------------------------
        _dc_parameters_widget_layout = QtGui.QVBoxLayout(self)
        _dc_parameters_widget_layout.addWidget(self.path_widget)
        _dc_parameters_widget_layout.addWidget(self.acq_widget)
        _dc_parameters_widget_layout.addWidget(self.processing_widget)
        _dc_parameters_widget_layout.setSpacing(2)
        _dc_parameters_widget_layout.addStretch(0)
        _dc_parameters_widget_layout.setContentsMargins(0, 0, 0, 0)
        _dc_parameters_widget.setLayout(_dc_parameters_widget_layout)

        _main_hlayout = QtGui.QHBoxLayout(self)
        _main_hlayout.addWidget(_dc_parameters_widget)
        _main_hlayout.addWidget(self.position_widget)
        _main_hlayout.setSpacing(2)
        _main_hlayout.setContentsMargins(0, 0, 0, 0)
        _main_hlayout.addStretch(0)
        self.setLayout(_main_hlayout)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.path_widget.data_path_layout.prefix_ledit.textChanged.connect(
            self._prefix_ledit_change)
        self.path_widget.data_path_layout.run_number_ledit.textChanged.connect(
            self._run_number_ledit_change)
        self.connect(self.acq_widget, QtCore.SIGNAL('mad_energy_selected'),
                     self.mad_energy_selected)
        self.connect(self.acq_widget, QtCore.SIGNAL("path_template_changed"),
                     self.handle_path_conflict)

        #QtCore.QObject.connect(QtGui.QApplication, QtCore.SIGNAL('tab_changed'),
        #                       self.tab_changed)

        # Other ---------------------------------------------------------------
        Qt4_widget_colors.set_widget_color(self.path_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.acq_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.processing_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.position_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)

    def set_beamline_setup(self, bl_setup):
        self.acq_widget.set_beamline_setup(bl_setup)
        self._beamline_setup_hwobj = bl_setup

    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 handle_path_conflict(self, widget, new_value):
        if self._tree_view_item is None:
            #TODO fix this
            return

        dc_tree_widget = self._tree_view_item.listView().parent()
        dc_tree_widget.check_for_path_collisions()
        path_template = self._data_collection.acquisitions[0].path_template
        path_conflict = self.queue_model_hwobj.\
                        check_for_path_collisions(path_template)

        if new_value != '':
            if path_conflict:
                logging.getLogger("user_level_log").\
                    error('The current path settings will overwrite data' +\
                          ' from another task. Correct the problem before collecting')

                widget.setPaletteBackgroundColor(widget_colors.LIGHT_RED)
            else:
                widget.setPaletteBackgroundColor(widget_colors.WHITE)

    def __add_data_collection(self):
        return self.add_dc_cb(self._data_collection, self.collection_type)

    def mad_energy_selected(self, name, energy, state):
        path_template = self._data_collection.acquisitions[0].path_template

        if state:
            path_template.mad_prefix = name
        else:
            path_template.mad_prefix = ''

        run_number = self._beamline_setup_hwobj.queue_model_hwobj.\
          get_next_run_number(path_template)

        self.path_widget.set_run_number(run_number)
        self.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.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.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.acq_widget.use_osc_start(True)

        self.path_widget.update_data_model(data_collection.\
                                           acquisitions[0].path_template)

        self.processing_widget.update_data_model(data_collection.\
                                                 processing_parameters)

        if data_collection.acquisitions[0].acquisition_parameters.\
                centred_position.snapshot_image:
            image = data_collection.acquisitions[0].\
                acquisition_parameters.centred_position.snapshot_image
            ration = image.height() / float(image.width())
            image = image.scaled(400, 400 * ration, QtCore.Qt.KeepAspectRatio)
            self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))

        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("user_level_log").\
                warning(msg)
Esempio n. 29
0
    def __init__(self, parent=None, name="parameter_widget"):
        """
        Descript. :
        """

        QtGui.QWidget.__init__(self, parent)

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._char = None
        self._char_params = queue_model_objects.CharacterisationParameters()
        self._char_params_mib = DataModelInputBinder(self._char_params)
        self._tree_view_item = None
        self.previous_energy = None

        self.add_dc_cb = None

        # Graphic elements ----------------------------------------------------
        rone_widget = QtGui.QWidget(self)
        self.reference_img_widget = ReferenceImageWidget(rone_widget)
        self.acq_widget = self.reference_img_widget.acq_widget
        self.path_widget = self.reference_img_widget.path_widget
        self.position_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__),
                         'ui_files/Qt4_snapshot_widget_layout.ui'))
        self.position_widget.setMinimumSize(450, 340)

        rtwo_widget = QtGui.QWidget(self)
        self.char_type_widget = CharTypeWidget(rtwo_widget)
        self.routine_dc_widget = self.char_type_widget.routine_dc_page
        self.sad_widget = self.char_type_widget.sad_page
        self.rad_dmg_char_widget = self.char_type_widget.rad_damage_page
        self.opt_parameters_widget = OptimisationParametersWidgetLayout(self)

        rtree_widget = QtGui.QWidget(self)
        self.rad_dmg_widget = uic.loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_radiation_damage_model_widget_layout.ui'))
        self.vertical_dimension_widget = uic.loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_vertical_crystal_dimension_widget_layout.ui'))

        # Layout --------------------------------------------------------------
        rone_widget_layout = QtGui.QHBoxLayout(self)
        rone_widget_layout.addWidget(self.reference_img_widget)
        rone_widget_layout.addWidget(self.position_widget)
        #rone_widget_layout.addStretch(0)
        rone_widget_layout.setSpacing(2)
        rone_widget_layout.setContentsMargins(0, 0, 0, 0)
        rone_widget.setLayout(rone_widget_layout)

        rtwo_widget_layout = QtGui.QHBoxLayout(self)
        rtwo_widget_layout.addWidget(self.char_type_widget)
        rtwo_widget_layout.addWidget(self.opt_parameters_widget)
        rtwo_widget_layout.addStretch(0)
        rtwo_widget_layout.setSpacing(2)
        rtwo_widget_layout.setContentsMargins(0, 0, 0, 0)
        rtwo_widget.setLayout(rtwo_widget_layout)

        rtree_widget_layout = QtGui.QHBoxLayout(self)
        rtree_widget_layout.addWidget(self.rad_dmg_widget)
        rtree_widget_layout.addWidget(self.vertical_dimension_widget)
        rtree_widget_layout.addStretch(0)
        rtree_widget_layout.setSpacing(2)
        rtree_widget_layout.setContentsMargins(0, 0, 0, 0)
        rtree_widget.setLayout(rtree_widget_layout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(rone_widget)
        _main_vlayout.addWidget(rtwo_widget)
        _main_vlayout.addWidget(rtree_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(_main_vlayout)

        # SizePolicies -------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.toggle_permitted_range(self.opt_parameters_widget.\
             opt_param_widget.permitted_range_cbx.isChecked())

        self.opt_parameters_widget.opt_param_widget.permitted_range_cbx.\
             toggled.connect(self.toggle_permitted_range)

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update(
            'min_dose', self.routine_dc_widget.dose_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'min_time', self.routine_dc_widget.time_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'use_min_dose', self.routine_dc_widget.min_dose_radio, bool, None)

        self._char_params_mib.bind_value_update(
            'use_min_time', self.routine_dc_widget.min_time_radio, bool, None)

        self._char_params_mib.bind_value_update(
            'account_rad_damage', self.routine_dc_widget.radiation_damage_cbx,
            bool, None)

        self._char_params_mib.bind_value_update(
            'auto_res', self.sad_widget.automatic_resolution_radio, bool, None)

        self._char_params_mib.bind_value_update(
            'sad_res', self.sad_widget.sad_resolution_ledit, float,
            QtGui.QDoubleValidator(0.5, 20, 3, self))

        self._char_params_mib.bind_value_update(
            'opt_sad', self.sad_widget.optimised_sad_cbx, bool, None)

        self._char_params_mib.bind_value_update(
            'determine_rad_params', self.rad_dmg_char_widget.rad_damage_cbx,
            bool, None)

        self._char_params_mib.bind_value_update(
            'burn_osc_start', self.rad_dmg_char_widget.burn_osc_start_ledit,
            float, QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'burn_osc_interval',
            self.rad_dmg_char_widget.burn_osc_interval_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'use_aimed_resolution',
            self.opt_parameters_widget.opt_param_widget.maximum_res_cbx, bool,
            None)

        self._char_params_mib.bind_value_update(
            'use_aimed_multiplicity',
            self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx, bool,
            None)

        self._char_params_mib.bind_value_update(
            'aimed_resolution',
            self.opt_parameters_widget.opt_param_widget.maximum_res_ledit,
            float, QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(\
             'aimed_multiplicity',
             self.opt_parameters_widget.opt_param_widget.aimed_mult_ledit,
             float,
             QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'aimed_i_sigma',
            self.opt_parameters_widget.opt_param_widget.i_over_sigma_ledit,
            float, QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'aimed_completness',
            self.opt_parameters_widget.opt_param_widget.aimed_comp_ledit,
            float, QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'strategy_complexity',
            self.opt_parameters_widget.opt_param_widget.start_comp_cbox, int,
            None)

        self._char_params_mib.bind_value_update(
            'use_permitted_rotation',
            self.opt_parameters_widget.opt_param_widget.permitted_range_cbx,
            bool, None)

        self._char_params_mib.bind_value_update(
            'permitted_phi_start',
            self.opt_parameters_widget.opt_param_widget.phi_start_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'permitted_phi_end',
            self.opt_parameters_widget.opt_param_widget.phi_end_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'low_res_pass_strat',
            self.opt_parameters_widget.opt_param_widget.low_res_pass_cbx, bool,
            None)

        self._char_params_mib.bind_value_update(
            'rad_suscept', self.rad_dmg_widget.sensetivity_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'beta', self.rad_dmg_widget.beta_over_gray_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'gamma', self.rad_dmg_widget.gamma_over_gray_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'max_crystal_vdim', self.vertical_dimension_widget.max_vdim_ledit,
            float, QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'min_crystal_vdim', self.vertical_dimension_widget.min_vdim_ledit,
            float, QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'min_crystal_vphi', self.vertical_dimension_widget.min_vphi_ledit,
            float, QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'max_crystal_vphi', self.vertical_dimension_widget.max_vphi_ledit,
            float, QtGui.QDoubleValidator(0.0, 1000, 2, self))

        #self._char_params_mib.bind_value_update('space_group',
        #                                        self.vertical_dimension_widget.space_group_ledit,
        #                                        str,
        #                                        None)


        self.vertical_dimension_widget.space_group_ledit.\
             addItems(queue_model_enumerables.XTAL_SPACEGROUPS)

        self.char_type_widget.charact_type_tbox.currentChanged.connect(\
             self.update_char_type)
        self.rad_dmg_char_widget.rad_damage_cbx.toggled.connect(\
             self.enable_opt_parameters_widget)
        self.opt_parameters_widget.opt_param_widget.maximum_res_cbx.\
             toggled.connect(self.enable_maximum_res_ledit)
        self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx.\
             toggled.connect(self.enable_aimed_mult_ledit)
        self.path_widget.data_path_layout.prefix_ledit.textChanged.\
             connect(self._prefix_ledit_change)
        self.path_widget.data_path_layout.run_number_ledit.textChanged.\
             connect(self._run_number_ledit_change)
        self.vertical_dimension_widget.space_group_ledit.activated.\
             connect(self._space_group_change)
Esempio n. 30
0
    def __init__(self, parent=None, name=None, fl=0):
        """
        Descript. :
        """

        CreateTaskBase.__init__(self, parent, name, fl, 'Characterisation')

        if not name:
            self.setName("create_char_widget")

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._current_selected_item = None
        self.init_models()
        self._char_params_mib = DataModelInputBinder(self._char_params)

        # Graphic elements ----------------------------------------------------
        self._acq_widget = \
            AcquisitionWidgetSimple(self, acq_params = self._acquisition_parameters,
                                    path_template = self._path_template)

        self._data_path_gbox = QtGui.QGroupBox('Data location', self)
        self._data_path_widget = DataPathWidget(self._data_path_gbox,
                                                data_model=self._path_template,
                                                layout='vertical')

        self._vertical_dimension_widget = uic.loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_vertical_crystal_dimension_widget_layout.ui'))

        self._char_widget = uic.loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_characterise_simple_widget_vertical_layout.ui'))

        gbox = self._char_widget.findChild(QtGui.QGroupBox,
                                           "characterisation_gbox")
        p = gbox.palette()
        p.setColor(QtGui.QPalette.Window, QtCore.Qt.red)
        p.setColor(QtGui.QPalette.Highlight, QtCore.Qt.red)
        gbox.setPalette(p)

        # Layout --------------------------------------------------------------
        _data_path_gbox_layout = QtGui.QVBoxLayout(self)
        _data_path_gbox_layout.addWidget(self._data_path_widget)
        _data_path_gbox_layout.setSpacing(0)
        _data_path_gbox_layout.setContentsMargins(0, 0, 0, 0)
        self._data_path_gbox.setLayout(_data_path_gbox_layout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_gbox)
        _main_vlayout.addWidget(self._char_widget)
        _main_vlayout.addWidget(self._vertical_dimension_widget)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(_main_vlayout)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update(
            'opt_sad', self._char_widget.optimised_sad_cbx, bool, None)

        self._char_params_mib.bind_value_update(
            'account_rad_damage', self._char_widget.account_rad_dmg_cbx, bool,
            None)

        #self._char_params_mib.bind_value_update('determine_rad_params',
        #                                        induced_burn_cbx,
        #                                        bool, None)

        self._char_params_mib.bind_value_update(
            'strategy_complexity', self._char_widget.start_comp_cbox, int,
            None)

        self._char_params_mib.\
            bind_value_update('max_crystal_vdim',
                              self._vertical_dimension_widget.max_vdim_ledit, float,
                              QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vdim',
                              self._vertical_dimension_widget.min_vdim_ledit, float,
                              QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vphi',
                              self._vertical_dimension_widget.min_vphi_ledit, float,
                              QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('max_crystal_vphi',
                              self._vertical_dimension_widget.max_vphi_ledit, float,
                              QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._vertical_dimension_widget.space_group_ledit.addItems(
            XTAL_SPACEGROUPS)

        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._vertical_dimension_widget.space_group_ledit.activated.\
             connect(self._space_group_change)

        self.connect(self._data_path_widget,
                     QtCore.SIGNAL("pathTemplateChanged"),
                     self.handle_path_conflict)
Esempio n. 31
0
class ProcessingWidget(QWidget):

    enableProcessingSignal = pyqtSignal(bool, bool)

    def __init__(self, parent=None, name=None, fl=0, data_model=None):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        if data_model is None:
            self._model = queue_model_objects.ProcessingParameters()
        else:
            self._model = data_model

        self._model_mib = DataModelInputBinder(self._model)

        self.processing_widget = self.acq_widget_layout = loadUi(
                           os.path.join(os.path.dirname(__file__),
                           "ui_files/Qt4_processing_widget_vertical_layout.ui"))
      
        self.main_layout = QVBoxLayout(self)
        self.main_layout.addWidget(self.processing_widget)
        self.main_layout.setSpacing(0)
        self.main_layout.setContentsMargins(0, 0, 0, 0)
       
        self.processing_widget.space_group_combo.\
            addItems(queue_model_enumerables.XTAL_SPACEGROUPS)
        
        self._model_mib.bind_value_update('cell_a',
                                          self.processing_widget.a_ledit,
                                          float,
                                          None)
        
        self._model_mib.bind_value_update('cell_alpha',
                                          self.processing_widget.alpha_ledit,
                                          float,
                                          None)

        self._model_mib.bind_value_update('cell_b',
                                          self.processing_widget.b_ledit,
                                          float,
                                          None)

        self._model_mib.bind_value_update('cell_beta',
                                          self.processing_widget.beta_ledit,
                                          float,
                                          None)  

        self._model_mib.bind_value_update('cell_c',
                                          self.processing_widget.c_ledit,
                                          float,
                                          None)

        self._model_mib.bind_value_update('cell_gamma',
                                          self.processing_widget.gamma_ledit,
                                          float,
                                          None)  
        
        self._model_mib.bind_value_update('num_residues',
                                          self.processing_widget.num_residues_ledit,
                                          float,
                                          None)

        self.processing_widget.space_group_combo.activated.\
             connect(self._space_group_change)    
        self.processing_widget.run_processing_after_cbox.stateChanged.\
             connect(self._run_processing_after_toggled)
        self.processing_widget.run_processing_parallel_cbox.stateChanged.\
             connect(self._run_processing_parallel_toggled)

    def _space_group_change(self, index):
        self._model.space_group = queue_model_enumerables.\
            XTAL_SPACEGROUPS[index]

    def _set_space_group(self, space_group):
        index = 0

        if space_group in queue_model_enumerables.XTAL_SPACEGROUPS:
            index = queue_model_enumerables.XTAL_SPACEGROUPS.index(space_group)
        
        self._space_group_change(index)
        self.processing_widget.space_group_combo.setCurrentIndex(index)

    def update_data_model(self, model):
        self._model = model
        self._model_mib.set_model(model)
        self._set_space_group(model.space_group)

    def _run_processing_after_toggled(self, state):
        self.enableProcessingSignal.emit(\
             self.processing_widget.run_processing_after_cbox.isChecked(),
             self.processing_widget.run_processing_parallel_cbox.isChecked())

    def _run_processing_parallel_toggled(self, state):
        self.enableProcessingSignal.emit(\
             self.processing_widget.run_processing_after_cbox.isChecked(),
             self.processing_widget.run_processing_parallel_cbox.isChecked())
Esempio n. 32
0
class DataPathWidget(QWidget):

    pathTemplateChangedSignal = pyqtSignal()

    def __init__(self, parent = None, name = '', fl = 0, data_model = None, 
                 layout = None):
        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._base_image_dir = None
        self._base_process_dir = None
        self.path_conflict_state = False
        self.enable_macros = False
        
        if data_model is None:
            self._data_model = queue_model_objects.PathTemplate()
        else:
            self._data_model = data_model
        
        self._data_model_pm = DataModelInputBinder(self._data_model)

        # Graphic elements ----------------------------------------------------
        if layout == "vertical":
            self.data_path_layout = loadUi(\
                 os.path.join(os.path.dirname(__file__),
                 "ui_files/Qt4_data_path_widget_vertical_layout.ui"))
        else:
            self.data_path_layout = loadUi(\
                 os.path.join(os.path.dirname(__file__),
                 "ui_files/Qt4_data_path_widget_horizontal_layout.ui"))

        # Layout --------------------------------------------------------------
        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self.data_path_layout)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

        # Qt signal/slot connections ------------------------------------------ 
        self.data_path_layout.prefix_ledit.textChanged.\
             connect(self._prefix_ledit_change)
        self.data_path_layout.run_number_ledit.textChanged.\
             connect(self._run_number_ledit_change)
        self.data_path_layout.browse_button.clicked.\
             connect(self._browse_clicked)
        self.data_path_layout.folder_ledit.textChanged.\
             connect(self._folder_ledit_change)

        # Other ---------------------------------------------------------------
        self._data_model_pm.bind_value_update('base_prefix', 
             self.data_path_layout.prefix_ledit, str, None)
        
        self._data_model_pm.bind_value_update('run_number', 
             self.data_path_layout.run_number_ledit,
             int, QIntValidator(0, 1000, self))

    def _browse_clicked(self):
        """
        Descript. :
        """
        file_dialog = QFileDialog(self)
        file_dialog.setNameFilter("%s*" % self._base_image_dir)

        selected_dir = str(file_dialog.getExistingDirectory(\
            self, "Select a directory", self._base_image_dir))
        selecte_dir = os.path.dirname(selected_dir)

        if selected_dir is not None and len(selected_dir) > 0:
            self.set_directory(selected_dir)

    def _prefix_ledit_change(self, new_value):
        """
        Descript. :
        """
        cursor_pos = self.data_path_layout.prefix_ledit.cursorPosition()

        if len(new_value) > 0:
            available_chars = string.ascii_lowercase + string.ascii_uppercase + \
                              string.digits + "-_"
            if self.enable_macros:
                available_chars += "%"
            new_value = ''.join(i for i in str(new_value) if i in available_chars)

        if len(new_value) > 50:
            logging.getLogger("GUI").\
                error("Current prefix is to long (max 50 characters are allowed)")
            new_value = new_value[:-1]

        self.data_path_layout.prefix_ledit.setText(new_value)
        self.data_path_layout.prefix_ledit.setCursorPosition(cursor_pos)

        self._data_model.base_prefix = str(new_value)
        self.update_file_name()
        self.pathTemplateChangedSignal.emit()

    def _run_number_ledit_change(self, new_value):
        """
        Descript. :
        """
        if str(new_value).isdigit():
            self.set_run_number(new_value)

            self.update_file_name()
            self.pathTemplateChangedSignal.emit()

    def _folder_ledit_change(self, new_value):        
        """
        Descript. :
        """
        base_image_dir = self._base_image_dir
        base_proc_dir = self._base_process_dir
        new_sub_dir = str(new_value).strip(' ')

        cursor_pos = self.data_path_layout.folder_ledit.cursorPosition()
        if len(new_value) > 0:
            available_chars = string.ascii_lowercase + string.ascii_uppercase + \
                              string.digits + "-_/" 
            if self.enable_macros:
                available_chars += "%"
            new_value = ''.join(i for i in str(new_value) if i in available_chars)

        self.data_path_layout.folder_ledit.setText(new_value)
        self.data_path_layout.folder_ledit.setCursorPosition(cursor_pos)

        if len(new_sub_dir) > 0:
            if new_sub_dir[0] == os.path.sep:
                new_sub_dir = new_sub_dir[1:]
            new_image_directory = os.path.join(base_image_dir, str(new_sub_dir))
            new_proc_dir = os.path.join(base_proc_dir, str(new_sub_dir))
        else:
            new_image_directory = base_image_dir
            new_proc_dir = base_proc_dir


        self._data_model.directory = new_image_directory
        self._data_model.process_directory = new_proc_dir 
        Qt4_widget_colors.set_widget_color(self.data_path_layout.folder_ledit,
                                           Qt4_widget_colors.WHITE)

        self.pathTemplateChangedSignal.emit()

    def update_file_name(self):
        """
        Descript. : updates filename if prefix or run number changed
                    at start values are initalized before precision is set.
                    so a check for isdigit is done to be on the safe side
        """
        if str(self._data_model.precision).isdigit():
            file_name = self._data_model.get_image_file_name()
            file_name = file_name.replace('%' + self._data_model.precision + 'd',
                                          int(self._data_model.precision) * '#' )
            file_name = file_name.strip(' ')
            self.data_path_layout.file_name_value_label.setText(file_name)

    def set_data_path(self, path):
        """
        Descript. :
        """
        (dir_name, file_name) = os.path.split(path)
        self.set_directory(dir_name)
        file_name = file_name.replace('%' + self._data_model.precision + 'd',
                                      int(self._data_model.precision) * '#' )
        self.data_path_layout.file_name_value_label.setText(file_name)
    
    def set_directory(self, directory):
        """
        Descript. :
        """
        base_image_dir = self._base_image_dir
        dir_parts = directory.split(base_image_dir) 

        if len(dir_parts) > 1:
            sub_dir = dir_parts[1]
            self._data_model.directory = directory
            self.data_path_layout.folder_ledit.setText(sub_dir)
        else:
            self.data_path_layout.folder_ledit.setText('')
            self._data_model.directory = base_image_dir

        self.data_path_layout.base_path_ledit.setText(base_image_dir)       

    def set_run_number(self, run_number):
        """
        Descript. :
        """
        self._data_model.run_number = int(run_number)
        self.data_path_layout.run_number_ledit.setText(str(run_number))

    def set_prefix(self, base_prefix):
        """
        Descript. :
        """
        self._data_model.base_prefix = str(base_prefix)
        self.data_path_layout.prefix_ledit.setText(str(base_prefix))
        file_name = self._data_model.get_image_file_name()
        file_name = file_name.replace('%' + self._data_model.precision + 'd',
                                      int(self._data_model.precision) * '#' )
        self.data_path_layout.file_name_value_label.setText(file_name)

    def update_data_model(self, data_model):
        """
        Descript. :
        """
        self._data_model = data_model
        self.set_data_path(data_model.get_image_path())
        self._data_model_pm.set_model(data_model)

    def indicate_path_conflict(self, conflict):
        """
        Descript. :
        """
        if conflict:
            Qt4_widget_colors.set_widget_color(\
                self.data_path_layout.prefix_ledit,
                Qt4_widget_colors.LIGHT_RED,
                QPalette.Base)
            Qt4_widget_colors.set_widget_color(\
                self.data_path_layout.run_number_ledit,
                Qt4_widget_colors.LIGHT_RED,
                QPalette.Base)
            Qt4_widget_colors.set_widget_color(\
                self.data_path_layout.folder_ledit,
                Qt4_widget_colors.LIGHT_RED,
                QPalette.Base)

            logging.getLogger("GUI").\
                error('The current path settings will overwrite data ' + \
                      'from another task. Correct the problem before ' + \
                      'adding to queue')
        else:
            # We had a conflict previous, but its corrected now !
            if self.path_conflict_state:
                logging.getLogger("GUI").info('Path valid')

                Qt4_widget_colors.set_widget_color(\
                    self.data_path_layout.prefix_ledit,
                    Qt4_widget_colors.WHITE,
                    QPalette.Base)
                Qt4_widget_colors.set_widget_color(\
                    self.data_path_layout.run_number_ledit,
                    Qt4_widget_colors.WHITE,
                    QPalette.Base)
                Qt4_widget_colors.set_widget_color(\
                    self.data_path_layout.folder_ledit,
                    Qt4_widget_colors.WHITE,
                    QPalette.Base)
        self.path_conflict_state = conflict
Esempio n. 33
0
class CreateCharWidget(CreateTaskBase):
    """
    Descript. :
    """
    def __init__(self, parent=None, name=None, fl=0):
        """
        Descript. :
        """

        CreateTaskBase.__init__(self, parent, name, fl, 'Characterisation')
        self.setObjectName("create_char_widget")

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._vertical_dimension_widget = None
        self._current_selected_item = None
        self.init_models()
        self._char_params_mib = DataModelInputBinder(self._char_params)

        # Graphic elements ----------------------------------------------------
        self._acq_widget = \
            AcquisitionWidgetSimple(self, acq_params = self._acquisition_parameters,
                                    path_template = self._path_template)

        self._data_path_widget = DataPathWidget(self,
                                                data_model=self._path_template,
                                                layout='vertical')

        self._vertical_dimension_widget = loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_vertical_crystal_dimension_widget_layout.ui'))

        self._char_widget = loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_characterise_simple_widget_vertical_layout.ui'))

        # Layout --------------------------------------------------------------
        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._char_widget)
        _main_vlayout.addWidget(self._vertical_dimension_widget)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.setSpacing(6)
        _main_vlayout.addStretch(0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.path_template_changed)
        self._acq_widget.acqParametersChangedSignal.\
             connect(self.acq_parameters_changed)

        self._vertical_dimension_widget.space_group_ledit.activated.\
             connect(self._space_group_change)
        #self.connect(induced_burn_cbx, QtCore.SIGNAL("toggled(bool)"),
        #             self.use_induced_burn)

        self._char_widget.characterisation_gbox.toggled.connect(\
             self.characterisation_gbox_toggled)
        self._char_widget.wait_result_cbx.toggled.connect(\
             self.wait_results_cbx_toggled)
        self._char_widget.execute_plan_cbx.toggled.connect(\
             self.run_diffraction_plan_cbx_toggled)

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update(
            'opt_sad', self._char_widget.optimised_sad_cbx, bool, None)

        self._char_params_mib.bind_value_update(
            'account_rad_damage', self._char_widget.account_rad_dmg_cbx, bool,
            None)

        #self._char_params_mib.bind_value_update('determine_rad_params',
        #                                        induced_burn_cbx,
        #                                        bool, None)

        self._char_params_mib.bind_value_update(
            'strategy_complexity', self._char_widget.start_comp_cbox, int,
            None)

        self._char_params_mib.\
            bind_value_update('max_crystal_vdim',
                              self._vertical_dimension_widget.max_vdim_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vdim',
                              self._vertical_dimension_widget.min_vdim_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vphi',
                              self._vertical_dimension_widget.min_vphi_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('max_crystal_vphi',
                              self._vertical_dimension_widget.max_vphi_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._vertical_dimension_widget.space_group_ledit.addItems(
            XTAL_SPACEGROUPS)

    def enable_compression(self, state):
        CreateTaskBase.enable_compression(self, False)

    def use_induced_burn(self, state):
        """
        Descript. :
        """
        self._acquisition_parameters.induce_burn = state

    def _space_group_change(self, index):
        """
        Descript. :
        """
        self._char_params.space_group = queue_model_enumerables.\
                                        XTAL_SPACEGROUPS[index]

    def _set_space_group(self, space_group):
        """
        Descript. :
        """
        index = 0

        if self._vertical_dimension_widget:
            if space_group in XTAL_SPACEGROUPS:
                index = XTAL_SPACEGROUPS.index(space_group)

            self._space_group_change(index)
            self._vertical_dimension_widget.space_group_ledit.\
                 setCurrentIndex(index)

    def init_models(self):
        """
        Descript. :
        """
        CreateTaskBase.init_models(self)
        self._init_models()

    def _init_models(self):
        """
        Descript. :
        """
        self._char = queue_model_objects.Characterisation()
        self._char_params = self._char.characterisation_parameters
        self._processing_parameters = queue_model_objects.ProcessingParameters(
        )
        self._set_space_group(self._processing_parameters.space_group)

        if self._beamline_setup_hwobj is not None:
            self._acquisition_parameters = self._beamline_setup_hwobj.\
                get_default_char_acq_parameters()

            self._char_params = self._beamline_setup_hwobj.\
                                get_default_characterisation_parameters()
        else:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters(
            )

        self._path_template.reference_image_prefix = 'ref'
        # The num images drop down default value is 1
        # we would like it to be 2
        self._acquisition_parameters.num_images = 2
        self._char.characterisation_software =\
            queue_model_enumerables.COLLECTION_ORIGIN.EDNA
        self._path_template.num_files = 2
        self._path_template.compression = False
        self._acquisition_parameters.shutterless = False

    def single_item_selection(self, tree_item):
        """
        Descript. :
        """
        CreateTaskBase.single_item_selection(self, tree_item)

        if isinstance(tree_item, Qt4_queue_item.SampleQueueItem):
            #self._init_models()
            if self._char_params.space_group == "":
                sample_model = tree_item.get_model()
                self._set_space_group(
                    sample_model.processing_parameters.space_group)
            #self._acq_widget.update_data_model(self._acquisition_parameters,
            #                                   self._path_template)
            #self._char_params_mib.set_model(self._char_params)
        elif isinstance(tree_item, Qt4_queue_item.BasketQueueItem):
            self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.CharacterisationQueueItem):
            if tree_item.get_model().is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

            self._char = tree_item.get_model()

            if self._char.get_path_template():
                self._path_template = self._char.get_path_template()

            self._data_path_widget.update_data_model(self._path_template)

            data_collection = self._char.reference_image_collection

            self._char_params = self._char.characterisation_parameters
            self._char_params_mib.set_model(self._char_params)

            self._acquisition_parameters = data_collection.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(data_collection.acquisitions) == 1:
                self.select_shape_with_cpos(self._acquisition_parameters.\
                                            centred_position)

            self._processing_parameters = data_collection.processing_parameters
        else:
            self.setDisabled(True)

    def update_processing_parameters(self, crystal):
        """
        Descript. :
        """
        self._processing_parameters.space_group = crystal.space_group
        self._char_params.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

    def approve_creation(self):
        """
        Descript. :
        """
        result = CreateTaskBase.approve_creation(self)
        selected_shapes = self._graphics_manager_hwobj.get_selected_shapes()

        for shape in selected_shapes:
            if isinstance(shape, GraphicsItemPoint):
                result = True
        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):
        """
        Descript. :
        """
        tasks = []

        if not shape or not isinstance(shape, GraphicsItemPoint):
            cpos = queue_model_objects.CentredPosition()
            cpos.snapshot_image = self._graphics_manager_hwobj.get_scene_snapshot(
            )
        else:
            # Shapes selected and sample is mounted, get the
            # centred positions for the shapes
            snapshot = self._graphics_manager_hwobj.\
                        get_scene_snapshot(shape)
            cpos = copy.deepcopy(shape.get_centred_position())
            cpos.snapshot_image = snapshot

        char_params = copy.deepcopy(self._char_params)
        acq = self._create_acq(sample)
        dc = queue_model_objects.\
                DataCollection([acq], sample.crystals[0],
                               self._processing_parameters)

        # Reference images for characterisations should be taken 90 deg apart
        # this is achived by setting overap to -89
        acq.acquisition_parameters.overlap = -89
        acq.acquisition_parameters.centred_position = cpos

        dc.acquisitions[0] = acq
        dc.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.EDNA_REF
        dc.run_processing_parallel = False

        char = queue_model_objects.Characterisation(dc, char_params)
        char.set_name(dc.acquisitions[0].\
                      path_template.get_prefix())
        char.set_number(dc.acquisitions[0].\
                        path_template.run_number)
        char.run_characterisation = self._char_widget.characterisation_gbox.isChecked(
        )
        char.wait_result = self._char_widget.wait_result_cbx.isChecked()
        char.run_diffraction_plan = self._char_widget.execute_plan_cbx.isChecked(
        )

        tasks.append(char)
        self._path_template.run_number += 1

        return tasks

    def characterisation_gbox_toggled(self, state):
        if self._char:
            self._char.run_characterisation = state

    def wait_results_cbx_toggled(self, state):
        if self._char:
            self._char.wait_result = state

    def run_diffraction_plan_cbx_toggled(self, state):
        if self._char:
            self._char.run_diffraction_plan = state
Esempio n. 34
0
class DCParametersWidget(QtGui.QWidget):
    def __init__(self, parent = None, name = "parameter_widget"):

        QtGui.QWidget.__init__(self, parent)
        if name is not None:
            self.setObjectName(name) 

        # Properties ----------------------------------------------------------

        # Signals ------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------
        self._data_collection = None
        self.add_dc_cb = None
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _dc_parameters_widget = QtGui.QWidget(self)
        self._data_path_widget = DataPathWidget(_dc_parameters_widget)
        self._acq_widget = AcquisitionWidget(_dc_parameters_widget, 
                                            layout = 'horizontal')
        #self._acq_widget.setFixedHeight(170)
        self._processing_widget = ProcessingWidget(_dc_parameters_widget)
        _snapshot_widget = QtGui.QWidget(self)
        self.position_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
                                          'ui_files/Qt4_snapshot_widget_layout.ui'))
        
        # Layout --------------------------------------------------------------
        _dc_parameters_widget_layout = QtGui.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(0)

        _snapshots_vlayout = QtGui.QVBoxLayout(_snapshot_widget)
        _snapshots_vlayout.addWidget(self.position_widget)
        _snapshots_vlayout.setContentsMargins(0, 0, 0, 0)
        _snapshots_vlayout.setSpacing(2)
        _snapshots_vlayout.addStretch(10)

        _main_hlayout = QtGui.QHBoxLayout(self)
        _main_hlayout.addWidget(_dc_parameters_widget)
        _main_hlayout.addWidget(_snapshot_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 set_beamline_setup(self, bl_setup):
        self._acq_widget.set_beamline_setup(bl_setup)
        self._beamline_setup_hwobj = bl_setup

    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 
        dc_tree_widget = self._tree_view_item.listView().parent()
        dc_tree_widget.check_for_path_collisions()
        path_template = self._data_collection.acquisitions[0].path_template
        path_conflict = self.queue_model_hwobj.\
                        check_for_path_collisions(path_template)
        if new_value != '':
            if path_conflict:
                logging.getLogger("user_level_log").\
                    error('The current path settings will overwrite data' +\
                          ' from another task. Correct the problem before collecting')

                widget.setPaletteBackgroundColor(widget_colors.LIGHT_RED)
            else:
                widget.setPaletteBackgroundColor(widget_colors.WHITE)

    def __add_data_collection(self):
        return self.add_dc_cb(self._data_collection, self.collection_type)
    
    def mad_energy_selected(self, name, energy, state):
        path_template = self._data_collection.acquisitions[0].path_template

        if state:
            path_template.mad_prefix = name
        else:
            path_template.mad_prefix = ''

        run_number = self._beamline_setup_hwobj.queue_model_hwobj.\
          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)

        if data_collection.acquisitions[0].acquisition_parameters.\
                centred_position.snapshot_image:
            image = data_collection.acquisitions[0].\
                acquisition_parameters.centred_position.snapshot_image
            ration = image.height() / float(image.width())
            image = image.scaled(400, 400 * ration, QtCore.Qt.KeepAspectRatio)
            self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))

        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("user_level_log").\
                warning(msg)
class AcquisitionWidgetSimple(QtGui.QWidget):
    """
    Descript. :
    """
    def __init__(self, parent = None, name = None, fl = 0, acq_params = None, 
                 path_template = None, layout = None):
        """
        Descript. :
        """ 

        QtGui.QWidget.__init__(self, parent, QtCore.Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------
        self.enable_parameter_update = True

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params
        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)
        self.acq_widget_layout = uic.loadUi(os.path.join(os.path.dirname(\
            __file__), "ui_files/Qt4_acquisition_widget_vertical_simple_layout.ui"))

        # Layout --------------------------------------------------------------
        main_layout = QtGui.QVBoxLayout(self)
        main_layout.addWidget(self.acq_widget_layout)
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.num_images_cbox.activated.connect(\
             self.update_num_images)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(\
             self.detector_roi_mode_changed)

        # Other ---------------------------------------------------------------
        self.energy_validator = QtGui.QDoubleValidator(0, 25, 5, self)
        self.resolution_validator = QtGui.QDoubleValidator(0, 15, 3, self)
        self.transmission_validator = QtGui.QDoubleValidator(0, 100, 3, self)
        self.exp_time_validator = QtGui.QDoubleValidator(0, 10000, 5, self)
        #self.acq_widget_layout.osc_start_ledit.setEnabled(False)
        #self.acq_widget_layout.kappa_ledit.setEnabled(False)
        #self.acq_widget_layout.kappa_phi_ledit.setEnabled(False) 
        self.acq_widget_layout.num_images_cbox.setCurrentIndex(1)

        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)

    def set_enable_parameter_update(self, state):
        self.enable_parameter_update = state

    def update_osc_start(self, new_value):
        """
        Descript. :
        """
        if self.enable_parameter_update:
            osc_start_value = 0
            try:
               osc_start_value = round(float(new_value), 2)
            except TypeError:
               pass
            self.acq_widget_layout.osc_start_ledit.setText(\
                 "%.2f" % osc_start_value)
            #self._acquisition_parameters.osc_start = osc_start_value

    def update_kappa(self, new_value):
        """
        Descript. :
        """
        if self.enable_parameter_update:
            self.acq_widget_layout.kappa_ledit.setText(\
                 "%.2f" % float(new_value))

    def update_kappa_phi(self, new_value):
        """
        Descript. :
        """
        if self.enable_parameter_update:
            self.acq_widget_layout.kappa_phi_ledit.setText(\
                 "%.2f" % float(new_value))

    def use_kappa(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.kappa_ledit.setDisabled(state)

    def use_kappa_phi(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.kappa_phi_ledit.setDisabled(state)
    
    def update_num_images(self, index = None, num_images = None):
        """
        Descript. :
        """
        if index is not None:
            if index is 0:
                self._acquisition_parameters.num_images = 1
                self._path_template.num_files = 1
            elif index is 1:
                self._acquisition_parameters.num_images = 2
                self._path_template.num_files = 2
            elif index is 2:
                self._acquisition_parameters.num_images = 4
                self._path_template.num_files = 4

        if num_images:
            if self.acq_widget_layout.num_images_cbox.count() > 3:
                self.acq_widget_layout.num_images_cbox.removeItem(4)
        
            if num_images is 1:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(0)    
            elif num_images is 2:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(1)
            elif num_images is 4:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(2)
            else:
                self.acq_widget_layout.num_images_cbox.addItem(str(num_images))
                self.acq_widget_layout.num_images_cbox.setCurrenIndex(3)

            self._path_template.num_files = num_images

    def use_mad(self, state):
        """
        Descript. :
        """
        pass

    def get_mad_energy(self):
        """
        Descript. :
        """
        pass

    def set_energies(self, energy_scan_result):
        """
        Descript. :
        """
        pass

    def energy_selected(self, index):
        """
        Descript. :
        """
        pass

    def set_beamline_setup(self, beamline_setup):
        """
        Descript. :
        """
        self._beamline_setup_hwobj = beamline_setup
        limits_dict = self._beamline_setup_hwobj.get_acquisition_limit_values()
        if 'osc_range' in limits_dict:
            limits = tuple(map(float, limits_dict['osc_range'].split(',')))
            (lower, upper) = limits
            osc_start_validator = QtGui.QDoubleValidator(lower, upper, 4, self)
            osc_range_validator = QtGui.QDoubleValidator(lower, upper, 4, self)
        else:
            osc_start_validator = QtGui.QDoubleValidator(-10000, 10000, 4, self)
            osc_range_validator = QtGui.QDoubleValidator(-10000, 10000, 4, self)

        self._acquisition_mib.bind_value_update('osc_start', 
                                                self.acq_widget_layout.osc_start_ledit,
                                                float, 
                                                osc_start_validator)

        self._acquisition_mib.bind_value_update('osc_range', 
                                                self.acq_widget_layout.osc_range_ledit,
                                                float, 
                                                osc_range_validator)

        kappa_validator = QtGui.QDoubleValidator(-30, 180, 2, self)
        self._acquisition_mib.bind_value_update('kappa', 
                                                self.acq_widget_layout.kappa_ledit,
                                                float, 
                                                kappa_validator)

        kappa_phi_validator = QtGui.QDoubleValidator(-30, 180, 2, self)
        self._acquisition_mib.bind_value_update('kappa_phi', 
                                                self.acq_widget_layout.kappa_phi_ledit,
                                                float, 
                                                kappa_phi_validator)

        self._acquisition_mib.bind_value_update('exp_time',
                              self.acq_widget_layout.exp_time_ledit,
                              float, 
                              self.exp_time_validator)

        self._acquisition_mib.\
             bind_value_update('energy',
                               self.acq_widget_layout.energy_ledit,
                               float,
                               self.energy_validator)
        self.acq_widget_layout.energy_ledit.setToolTip(\
             "Energy limits %0.3f : %0.3f" % \
             (self.energy_validator.bottom(), self.energy_validator.top()))

        self._acquisition_mib.\
             bind_value_update('transmission',
                            self.acq_widget_layout.transmission_ledit,
                            float,
                            self.transmission_validator)

        self._acquisition_mib.\
             bind_value_update('resolution',
                               self.acq_widget_layout.resolution_ledit,
                               float,
                               self.resolution_validator)
 
        self.set_tunable_energy(beamline_setup.tunable_wavelength())

    def set_energy(self, energy, wav):
        """
        Descript. :
        """
        #self._acquisition_parameters.energy = energy
        if self.enable_parameter_update:
            self.acq_widget_layout.energy_ledit.setText(\
                 "%.4f" % float(energy))

    def update_transmission(self, transmission):
        """
        Descript. :
        """
        if self.enable_parameter_update:
            self.acq_widget_layout.transmission_ledit.setText(\
                 "%.2f" % float(transmission))
        #self._acquisition_parameters.transmission = float(transmission)

    def update_resolution(self, resolution):
        """
        Descript. :
        """
        if self.enable_parameter_update:
            self.acq_widget_layout.resolution_ledit.setText("%.3f" % float(resolution))
        #self._acquisition_parameters.resolution = float(resolution)

    def update_energy_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.energy_validator.setBottom(limits[0])
            self.energy_validator.setTop(limits[1])
            self.acq_widget_layout.energy_ledit.setToolTip(
               "Energy limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_transmission_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.transmission_validator.setBottom(limits[0])
            self.transmission_validator.setTop(limits[1])
            self.acq_widget_layout.transmission_ledit.setToolTip(
               "Transmission limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_resolution_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.resolution_validator.setBottom(limits[0])
            self.resolution_validator.setTop(limits[1])
            self.acq_widget_layout.resolution_ledit.setToolTip(
               "Resolution limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_detector_exp_time_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.exp_time_validator.setBottom(limits[0])
            self.exp_time_validator.setTop(limits[1])
            self.acq_widget_layout.exp_time_ledit.setToolTip(
               "Exposure time limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def init_detector_roi_modes(self):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            roi_modes = self._beamline_setup_hwobj._get_roi_modes()
            if (len(roi_modes) > 0 and
                self.acq_widget_layout.detector_roi_mode_combo.count() == 0):
                for roi_mode in roi_modes: 
                    self.acq_widget_layout.detector_roi_mode_combo.\
                         addItem(roi_mode)
                self.acq_widget_layout.detector_roi_mode_label.setEnabled(True)
                self.acq_widget_layout.detector_roi_mode_combo.setEnabled(True)
                #self._acquisition_mib.bind_value_update('detector_roi_mode',
                #               self.acq_widget_layout.detector_roi_mode_combo,
                #               str,
                #               None)

    def update_detector_roi_mode(self, roi_mode_index):
        """
        Descript. :
        """
        if self.acq_widget_layout.detector_roi_mode_combo.count() > 0:
            self.acq_widget_layout.detector_roi_mode_combo.\
                 setCurrentIndex(roi_mode_index)

    def detector_roi_mode_changed(self, roi_mode_index):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            self._beamline_setup_hwobj.detector_hwobj.set_roi_mode(roi_mode_index)
 
    def update_data_model(self, acquisition_parameters, path_template):
        """
        Descript. :
        """
        self._acquisition_parameters = acquisition_parameters
        self._acquisition_mib.set_model(acquisition_parameters)
        self._path_template = path_template
        self.update_num_images(None, acquisition_parameters.num_images)

    def set_tunable_energy(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.energy_ledit.setEnabled(state)

    def use_osc_start(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.osc_start_ledit.setEnabled(state)

    def check_parameter_conflict(self):
        """
        Descript. :
        """
        return len(self._acquisition_mib.validate_all()) > 0
class AcquisitionWidgetSimple(QWidget):
    """
    Descript. :
    """
    acqParametersChangedSignal = pyqtSignal(list)
    madEnergySelectedSignal = pyqtSignal(str, float, bool)

    def __init__(self, parent = None, name = None, fl = 0, acq_params = None, 
                 path_template = None, layout = None):
        """
        Descript. :
        """ 

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None
        self._diffractometer_hwobj = None

        # Internal variables --------------------------------------------------
        self.value_changed_list = []

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params
        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)
        self.acq_widget_layout = loadUi(os.path.join(os.path.dirname(\
            __file__), "ui_files/Qt4_acquisition_widget_vertical_simple_layout.ui"))

        # Layout --------------------------------------------------------------
        main_layout = QVBoxLayout(self)
        main_layout.addWidget(self.acq_widget_layout)
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.osc_start_cbox.stateChanged.connect(\
             self.use_osc_start)
        self.acq_widget_layout.num_images_cbox.activated.connect(\
             self.update_num_images)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(\
             self.detector_roi_mode_changed)

        # Other ---------------------------------------------------------------
        self.osc_start_validator = QDoubleValidator(\
             -10000, 10000, 4, self.acq_widget_layout.osc_start_ledit)
        self.osc_range_validator = QDoubleValidator(\
             -10000, 10000, 4, self.acq_widget_layout.osc_range_ledit)
        self.kappa_validator = QDoubleValidator(\
             0, 360, 4, self.acq_widget_layout.kappa_ledit)
        self.kappa_phi_validator = QDoubleValidator(\
             0, 360, 4, self.acq_widget_layout.kappa_phi_ledit)
        self.energy_validator = QDoubleValidator(\
             0, 25, 5, self.acq_widget_layout.energy_ledit)
        self.resolution_validator = QDoubleValidator(\
             0, 15, 3, self.acq_widget_layout.resolution_ledit)
        self.transmission_validator = QDoubleValidator(\
             0, 100, 3, self.acq_widget_layout.transmission_ledit)
        self.exp_time_validator = QDoubleValidator(\
             0, 10000, 6, self.acq_widget_layout.exp_time_ledit)
        self.acq_widget_layout.num_images_cbox.setCurrentIndex(1)

        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)

    def set_osc_start_limits(self, limits):
        if not None in limits:
            self.osc_start_validator.setRange(limits[0], limits[1], 4)

    def update_osc_start(self, new_value):
        """
        Descript. :
        """
        if not self.acq_widget_layout.osc_start_cbox.hasFocus():
            self.acq_widget_layout.osc_start_ledit.setText(str(new_value))

    def update_kappa(self, new_value):
        """
        Descript. :
        """
        if not self.acq_widget_layout.kappa_ledit.hasFocus():
            self.acq_widget_layout.kappa_ledit.setText(str(new_value))

    def update_kappa_phi(self, new_value):
        """
        Descript. :
        """
        if not self.acq_widget_layout.kappa_phi_ledit.hasFocus():
            self.acq_widget_layout.kappa_phi_ledit.setText(str(new_value))

    def use_kappa(self, state):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            if self._beamline_setup_hwobj.diffractometer_hwobj.in_plate_mode():
                state = False
        self.acq_widget_layout.kappa_label.setEnabled(state)
        self.acq_widget_layout.kappa_ledit.setEnabled(state)
        self.acq_widget_layout.kappa_phi_label.setEnabled(state)
        self.acq_widget_layout.kappa_phi_ledit.setEnabled(state)

    def use_max_osc_range(self, state):
        pass

    def update_num_images(self, index = None, num_images = None):
        """
        Descript. :
        """
        if index is not None:
            if index is 0:
                self._acquisition_parameters.num_images = 1
                self._path_template.num_files = 1
            elif index is 1:
                self._acquisition_parameters.num_images = 2
                self._path_template.num_files = 2
            elif index is 2:
                self._acquisition_parameters.num_images = 4
                self._path_template.num_files = 4

        if num_images:
            if self.acq_widget_layout.num_images_cbox.count() > 3:
                self.acq_widget_layout.num_images_cbox.removeItem(4)
        
            if num_images is 1:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(0)    
            elif num_images is 2:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(1)
            elif num_images is 4:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(2)
            else:
                self.acq_widget_layout.num_images_cbox.addItem(str(num_images))
                self.acq_widget_layout.num_images_cbox.setCurrenIndex(3)

            self._path_template.num_files = num_images

    def use_mad(self, state):
        """
        Descript. :
        """
        pass

    def get_mad_energy(self):
        """
        Descript. :
        """
        pass

    def set_energies(self, energy_scan_result):
        """
        Descript. :
        """
        pass

    def energy_selected(self, index):
        """
        Descript. :
        """
        pass

    def set_beamline_setup(self, beamline_setup):
        """
        Descript. :
        """
        self._beamline_setup_hwobj = beamline_setup
        self._diffractometer_hwobj = self._beamline_setup_hwobj.diffractometer_hwobj
        limits_dict = self._beamline_setup_hwobj.get_acquisition_limit_values()

        if 'osc_range' in limits_dict:
            limits = tuple(map(float, limits_dict['osc_range'].split(',')))
            (lower, upper) = limits
            self.osc_start_validator.setRange(lower, upper, 4)
            self.osc_range_validator.setRange(lower, upper, 4)

        self._acquisition_mib.bind_value_update('osc_start', 
                                                self.acq_widget_layout.osc_start_ledit,
                                                float, 
                                                self.osc_start_validator)

        self._acquisition_mib.bind_value_update('osc_range', 
                                                self.acq_widget_layout.osc_range_ledit,
                                                float, 
                                                self.osc_range_validator)

        if 'kappa' in limits_dict:
            limits = tuple(map(float, limits_dict['kappa'].split(',')))
            (lower, upper) = limits
            self.kappa_validator.setRange(lower, upper, 4)
        self._acquisition_mib.bind_value_update('kappa', 
                                                self.acq_widget_layout.kappa_ledit,
                                                float,
                                                self.kappa_validator)

        if 'kappa_phi' in limits_dict:
            limits = tuple(map(float, limits_dict['kappa_phi'].split(',')))
            (lower, upper) = limits
            self.kappa_phi_validator.setRange(lower, upper, 4)
        self._acquisition_mib.bind_value_update('kappa_phi',     
                                                self.acq_widget_layout.kappa_phi_ledit,
                                                float,
                                                self.kappa_phi_validator)

        if 'exposure_time' in limits_dict:
            limits = tuple(map(float, limits_dict['exposure_time'].split(',')))
            (lower, upper) = limits
            self.exp_time_validator.setRange(lower, upper, 6)

        self._acquisition_mib.bind_value_update('exp_time',
                              self.acq_widget_layout.exp_time_ledit,
                              float, 
                              self.exp_time_validator)

        self._acquisition_mib.\
             bind_value_update('energy',
                               self.acq_widget_layout.energy_ledit,
                               float,
                               self.energy_validator)
        self.acq_widget_layout.energy_ledit.setToolTip(\
             "Energy limits %0.3f : %0.3f" % \
             (self.energy_validator.bottom(), self.energy_validator.top()))

        self._acquisition_mib.\
             bind_value_update('transmission',
                            self.acq_widget_layout.transmission_ledit,
                            float,
                            self.transmission_validator)

        self._acquisition_mib.\
             bind_value_update('resolution',
                               self.acq_widget_layout.resolution_ledit,
                               float,
                               self.resolution_validator)
 
        self.set_tunable_energy(beamline_setup.tunable_wavelength())

        if self._beamline_setup_hwobj.diffractometer_hwobj.in_plate_mode():
            self.acq_widget_layout.num_images_cbox.clear()
            self.acq_widget_layout.num_images_cbox.addItem("1")
            self.acq_widget_layout.num_images_cbox.setCurrentIndex(0)
 
        self.init_detector_roi_modes()

    def set_energy(self, energy, wav):
        """
        Descript. :
        """
        if not self.acq_widget_layout.energy_ledit.hasFocus():
            self.acq_widget_layout.energy_ledit.setText(str(energy))

    def update_transmission(self, transmission):
        """
        Descript. :
        """
        if self.acq_widget_layout.transmission_ledit.hasFocus():
            self.acq_widget_layout.transmission_ledit.setText(str(transmission))

    def update_resolution(self, resolution):
        """
        Descript. :
        """
        if not self.acq_widget_layout.resolution_ledit.hasFocus():
            self.acq_widget_layout.resolution_ledit.setText(str(resolution))

    def update_energy_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.energy_validator.setBottom(limits[0])
            self.energy_validator.setTop(limits[1])
            self.acq_widget_layout.energy_ledit.setToolTip(
               "Energy limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_transmission_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.transmission_validator.setBottom(limits[0])
            self.transmission_validator.setTop(limits[1])
            self.acq_widget_layout.transmission_ledit.setToolTip(
               "Transmission limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_resolution_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.resolution_validator.setBottom(limits[0])
            self.resolution_validator.setTop(limits[1])
            self.acq_widget_layout.resolution_ledit.setToolTip(
               "Resolution limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_detector_exp_time_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.exp_time_validator.setBottom(limits[0])
            self.exp_time_validator.setTop(limits[1])
            self.acq_widget_layout.exp_time_ledit.setToolTip(
               "Exposure time limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_energy(self, energy, wav):
        """
        Descript. :
        """
        if "energy" not in self.value_changed_list and \
           not self.acq_widget_layout.energy_ledit.hasFocus():
            self.acq_widget_layout.energy_ledit.setText("%.4f" % float(energy))

    def init_detector_roi_modes(self):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            roi_modes = self._beamline_setup_hwobj._get_roi_modes()
            if (len(roi_modes) > 0 and
                self.acq_widget_layout.detector_roi_mode_combo.count() == 0):
                for roi_mode in roi_modes: 
                    self.acq_widget_layout.detector_roi_mode_combo.\
                         addItem(roi_mode)
                self.acq_widget_layout.detector_roi_mode_label.setEnabled(True)
                self.acq_widget_layout.detector_roi_mode_combo.setEnabled(True)
                #self._acquisition_mib.bind_value_update('detector_roi_mode',
                #               self.acq_widget_layout.detector_roi_mode_combo,
                #               str,
                #               None)

    def update_osc_range_limits(self, limits=None):
        pass

    def update_exp_time_limits(self):
        exp_time_limits = self._beamline_setup_hwobj.detector_hwobj.get_exposure_time_limits()
        max_osc_speed = self._diffractometer_hwobj.get_osc_max_speed()
        top_limit = float(self.acq_widget_layout.osc_range_ledit.text()) / max_osc_speed
        limits = (max(exp_time_limits[0], top_limit), exp_time_limits[1])

        self.update_detector_exp_time_limits(limits)

    def update_detector_roi_mode(self, roi_mode_index):
        """
        Descript. :
        """
        if self.acq_widget_layout.detector_roi_mode_combo.count() > 0:
            self.acq_widget_layout.detector_roi_mode_combo.\
                 setCurrentIndex(roi_mode_index)

    def update_osc_range_limits(self, limits=None):
        pass

    def detector_roi_mode_changed(self, roi_mode_index):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            self._beamline_setup_hwobj.detector_hwobj.set_roi_mode(roi_mode_index)
 
    def update_data_model(self, acquisition_parameters, path_template):
        """
        Descript. :
        """
        self._acquisition_parameters = acquisition_parameters
        self._acquisition_mib.set_model(acquisition_parameters)
        self._path_template = path_template
        self.update_num_images(None, acquisition_parameters.num_images)

    def set_tunable_energy(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.energy_ledit.setEnabled(state)

    def use_osc_start(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.osc_start_ledit.setEnabled(state)

    def check_parameter_conflict(self):
        """
        Descript. :
        """
        return self._acquisition_mib.validate_all()
class AdvancedParametersWidget(QtGui.QWidget):
    def __init__(self, parent = None, name = "advanced_parameters_widget"):
        QtGui.QWidget.__init__(self, parent)

        # Hardware objects ----------------------------------------------------
        self._queue_model_hwobj = None
        self._beamline_setup_hwobj = None

        # Internal values -----------------------------------------------------
        self._data_collection = None
        self._tree_view_item = None

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        _dc_parameters_widget = QtGui.QWidget(self)
        self._data_path_widget = DataPathWidget(_dc_parameters_widget)
        self._acq_widget = AcquisitionWidget(_dc_parameters_widget,
                                            layout = 'horizontal')
        #self._acq_widget.setFixedHeight(170)
        _snapshot_widget = QtGui.QWidget(self)
        self.position_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
                                          'ui_files/Qt4_snapshot_widget_layout.ui'))

        # Layout --------------------------------------------------------------
        _dc_parameters_widget_layout = QtGui.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.setSpacing(2)
        _dc_parameters_widget_layout.addStretch(10)
        _dc_parameters_widget_layout.setContentsMargins(0, 0, 0, 0)

        _snapshots_vlayout = QtGui.QVBoxLayout(_snapshot_widget)
        _snapshots_vlayout.addWidget(self.position_widget)
        _snapshots_vlayout.setContentsMargins(0, 0, 0, 0)
        _snapshots_vlayout.setSpacing(2)
        _snapshots_vlayout.addStretch(10)

        _main_hlayout = QtGui.QHBoxLayout(self)
        _main_hlayout.addWidget(_dc_parameters_widget)
        _main_hlayout.addWidget(_snapshot_widget)
        _main_hlayout.setSpacing(2)
        _main_hlayout.setContentsMargins(2, 2, 2, 2)
        _main_hlayout.addStretch(0)

        # 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.handle_path_conflict)

        # Ohter ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.acq_widget_layout.mad_cbox.hide()
        self._acq_widget.acq_widget_layout.energies_combo.hide()
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        self._acq_widget.acq_widget_layout.inverse_beam_cbx.hide()
        self._acq_widget.acq_widget_layout.shutterless_cbx.hide()
        self._acq_widget.acq_widget_layout.subwedge_size_label.hide()
        self._acq_widget.acq_widget_layout.subwedge_size_ledit.hide()

    def set_beamline_setup(self, bl_setup):
        self._beamline_setup_hwobj = bl_setup
        self._acq_widget.set_beamline_setup(bl_setup)

    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 handle_path_conflict(self):
        if self._tree_view_item:
            dc_tree_widget = self._tree_view_item.listView().parent()
            dc_tree_widget.check_for_path_collisions()
            path_template = self._data_collection.acquisitions[0].path_template
            path_conflict = self.queue_model_hwobj.\
                        check_for_path_collisions(path_template)

            if path_conflict:
                logging.getLogger("user_level_log").\
                    error('The current path settings will overwrite data' +\
                          ' from another task. Correct the problem before collecting')
                Qt4_widget_colors.set_widget_color(widget, Qt4_widget_colors.LIGHT_RED)
            else:
                Qt4_widget_colors.set_widget_color(widget, Qt4_widget_colors.LIGHT_WHITE)

    def mad_energy_selected(self, name, energy, state):
        path_template = self._data_collection.acquisitions[0].path_template

        if state:
            path_template.mad_prefix = name
        else:
            path_template.mad_prefix = ''

        run_number = self._beamline_setup_hwobj.queue_model_hwobj.\
          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_widget(self._tree_view_item)

    def populate_widget(self, tree_view_item):
        self._tree_view_item = tree_view_item
        advanced_model = tree_view_item.get_model()
        self._data_collection = advanced_model.reference_image_collection
        executed = self._data_collection.is_executed()

        self._acq_widget.setEnabled(not executed)
        self._data_path_widget.setEnabled(not executed)


        image = advanced_model.grid_object.get_snapshot()
        try:
           image = image.scaled(427, 320, QtCore.Qt.KeepAspectRatio)
           self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))
        except:
           pass 

        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 = self._data_collection.\
             acquisitions[0].path_template
        self._data_path_widget.update_data_model(self._data_collection.\
              acquisitions[0].path_template)

        self._acq_widget.update_data_model(\
             self._data_collection.acquisitions[0].acquisition_parameters,
             self._data_collection.acquisitions[0].path_template)
        #self._acq_widget.use_osc_start(False)
        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("user_level_log").\
                warning(msg)
Esempio n. 38
0
    def __init__(self, parent = None, name = None, fl = 0, data_model = None):

        QtGui.QWidget.__init__(self, parent, QtCore.Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        if data_model is None:
            self._model = queue_model_objects.ProcessingParameters()
        else:
            self._model = data_model

        self._model_mib = DataModelInputBinder(self._model)

        self.processing_widget = self.acq_widget_layout = uic.loadUi(
                           os.path.join(os.path.dirname(__file__),
                           "ui_files/Qt4_processing_widget_vertical_layout.ui"))
      
        self.main_layout = QtGui.QVBoxLayout(self)
        self.main_layout.addWidget(self.processing_widget)
        self.main_layout.setSpacing(0)
        self.main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.main_layout)  
       
        self.processing_widget.findChild(QtGui.QComboBox, 'space_group_cbox').\
            addItems(queue_model_enumerables.XTAL_SPACEGROUPS)
        
        self._model_mib.bind_value_update('cell_a',
                                          self.processing_widget.findChild(QtGui.QLineEdit, 'a_ledit'),
                                          float,
                                          None)
        
        self._model_mib.bind_value_update('cell_alpha',
                                          self.processing_widget.findChild(QtGui.QLineEdit, 'alpha_ledit'),
                                          float,
                                          None)

        self._model_mib.bind_value_update('cell_b',
                                          self.processing_widget.findChild(QtGui.QLineEdit, 'b_ledit'),
                                          float,
                                          None)

        self._model_mib.bind_value_update('cell_beta',
                                          self.processing_widget.findChild(QtGui.QLineEdit, 'beta_ledit'),
                                          float,
                                          None)  

        self._model_mib.bind_value_update('cell_c',
                                          self.processing_widget.findChild(QtGui.QLineEdit, 'c_ledit'),
                                          float,
                                          None)

        self._model_mib.bind_value_update('cell_gamma',
                                          self.processing_widget.findChild(QtGui.QLineEdit, 'gamma_ledit'),
                                          float,
                                          None)  
        
        self._model_mib.bind_value_update('num_residues',
                                          self.processing_widget.findChild(QtGui.QLineEdit, 'num_residues_ledit'),
                                          float,
                                          None)

        self.connect(self.processing_widget.findChild(QtGui.QComboBox, 'space_group_cbox'),
                     QtCore.SIGNAL("activated(int)"),
                     self._space_group_change)    
class AcquisitionWidget(QtGui.QWidget):
    """
    Descript. :
    """
  
    acqParametersChangedSignal = QtCore.pyqtSignal()
    madEnergySelectedSignal = QtCore.pyqtSignal(str, float, bool)

    def __init__(self, parent = None, name = None, fl = 0, acq_params = None,
                 path_template = None, layout = 'horizontal'):
        """
        Descript. :
        """
        QtGui.QWidget.__init__(self, parent, QtCore.Qt.WindowFlags(fl))
        
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------
        self.previous_energy = 0
        self.enable_parameter_update = True 

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.\
                                           AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)

        if layout == "horizontal":
            self.acq_widget_layout = uic.loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_horizontal_layout.ui"))
        else:
            self.acq_widget_layout = uic.loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_vertical_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QtGui.QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.energies_combo.activated.connect(\
             self.energy_selected)
        self.acq_widget_layout.mad_cbox.toggled.connect(\
             self.use_mad)
        self.acq_widget_layout.inverse_beam_cbx.toggled.connect(\
             self.set_use_inverse_beam)
        self.acq_widget_layout.first_image_ledit.textChanged.connect(\
             self.first_image_ledit_change)
        self.acq_widget_layout.num_images_ledit.textChanged.connect(\
             self.num_images_ledit_change)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(\
             self.detector_roi_mode_changed)

        overlap_ledit = self.acq_widget_layout.findChild(\
            QtGui.QLineEdit, "overlap_ledit")
        if overlap_ledit is not None:
            overlap_ledit.textChanged.connect(self.overlap_changed)

        self.acq_widget_layout.subwedge_size_ledit.textChanged.connect(\
             self.subwedge_size_ledit_change)

        # Other --------------------------------------------------------------- 
        self.acq_widget_layout.subwedge_size_ledit.setDisabled(True)
        self.acq_widget_layout.energies_combo.setDisabled(True)
        self.acq_widget_layout.energies_combo.addItems(['ip: -', 'pk: -', 'rm1: -', 'rm2: -'])

        self.osc_start_validator = QtGui.QDoubleValidator(-10000, 10000, 4, self)
        self.osc_range_validator = QtGui.QDoubleValidator(-10000, 10000, 4, self)
        self.kappa_validator = QtGui.QDoubleValidator(0, 360, 4, self)
        self.kappa_phi_validator = QtGui.QDoubleValidator(0, 360, 4, self)
        self.energy_validator = QtGui.QDoubleValidator(0, 25, 4, self)
        self.resolution_validator = QtGui.QDoubleValidator(0, 15, 3, self)
        self.transmission_validator = QtGui.QDoubleValidator(0, 100, 3, self)
        self.exp_time_validator = QtGui.QDoubleValidator(0.0001, 10000, 4, self)
        self.first_img_validator = QtGui.QIntValidator(0, 99999, self)
        self.num_img_validator = QtGui.QIntValidator(1, 99999, self) 
        self.disable_inverse_beam(True)
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)

    def set_enable_parameter_update(self, state):
        self.enable_parameter_update = state

    def update_osc_start(self, new_value):
        """
        Descript. :
        """
        if self.enable_parameter_update:
            osc_start_value = 0
            try:
               osc_start_value = round(float(new_value), 2)
            except TypeError:
               pass
            self.update_num_image_limits()
            self.acq_widget_layout.osc_start_ledit.setText("%.2f" % osc_start_value)
            #self._acquisition_parameters.osc_start = osc_start_value

    def update_kappa(self, new_value):
        if self.enable_parameter_update:
            self.acq_widget_layout.kappa_ledit.setText("%.2f" % float(new_value))
            #self._acquisition_parameters.kappa = float(new_value)

    def update_kappa_phi(self, new_value):
        if self.enable_parameter_update:
            self.acq_widget_layout.kappa_phi_ledit.setText("%.2f" % float(new_value))
            #self._acquisition_parameters.kappa_phi = float(new_value)

    def use_osc_start(self, state):
        self.acq_widget_layout.osc_start_label.setEnabled(state)
        self.acq_widget_layout.osc_start_ledit.setEnabled(state)

    def use_kappa(self, state):
        self.acq_widget_layout.kappa_label.setEnabled(state)
        self.acq_widget_layout.kappa_ledit.setEnabled(state)

    def use_kappa_phi(self, state):
        self.acq_widget_layout.kappa_phi_label.setEnabled(state)
        self.acq_widget_layout.kappa_phi_ledit.setEnabled(state)
            
    def set_beamline_setup(self, beamline_setup):
        """
        Descript. :
        """
        self._beamline_setup_hwobj = beamline_setup
        limits_dict = self._beamline_setup_hwobj.get_acquisition_limit_values()

        if 'osc_range' in limits_dict:
            limits = tuple(map(float, limits_dict['osc_range'].split(',')))
            (lower, upper) = limits
            self.osc_start_validator.setRange(lower, upper, 4)
            self.osc_range_validator.setRange(lower, upper, 4)

        self._acquisition_mib.bind_value_update('osc_start', 
                                                self.acq_widget_layout.osc_start_ledit,
                                                float, 
                                                self.osc_start_validator)

        self._acquisition_mib.bind_value_update('osc_range', 
                                                self.acq_widget_layout.osc_range_ledit,
                                                float, 
                                                self.osc_range_validator)

        if self.acq_widget_layout.findChild(QtGui.QLineEdit, "kappa_ledit"):
            if 'kappa' in limits_dict:
                limits = tuple(map(float, limits_dict['kappa'].split(',')))
                (lower, upper) = limits
                self.kappa_validator.setRange(lower, upper, 4)
            self._acquisition_mib.bind_value_update('kappa', 
                 self.acq_widget_layout.kappa_ledit, float, self.kappa_validator)

        if self.acq_widget_layout.findChild(QtGui.QLineEdit, "kappa_phi_ledit"):
            if 'kappa_phi' in limits_dict:
                limits = tuple(map(float, limits_dict['kappa_phi'].split(',')))
                (lower, upper) = limits
                self.kappa_phi_validator.setRange(lower, upper, 4)
            self._acquisition_mib.bind_value_update('kappa_phi',     
                 self.acq_widget_layout.kappa_phi_ledit, float, self.kappa_phi_validator)

        if 'exposure_time' in limits_dict:
            limits = tuple(map(float, limits_dict['exposure_time'].split(',')))
            (lower, upper) = limits
            self.exp_time_valdidator.setRange(lower, upper, 5)
        
        self._acquisition_mib.bind_value_update('exp_time', 
                                                self.acq_widget_layout.exp_time_ledit,
                                                float, 
                                                self.exp_time_validator)

        if 'number_of_images' in limits_dict:
            limits = tuple(map(int, limits_dict['number_of_images'].split(',')))
            (lower, upper) = limits
            self.num_img_valdidator.setRange(lower, upper)
            self.first_img_valdidator.setRange(lower, upper)
        
        self._acquisition_mib.bind_value_update('first_image', 
                                                self.acq_widget_layout.first_image_ledit,
                                                int, 
                                                self.first_img_validator)

        self._acquisition_mib.bind_value_update('num_images', 
                                                self.acq_widget_layout.num_images_ledit,
                                                int, 
                                                self.num_img_validator)

        num_passes = self.acq_widget_layout.findChild(QtGui.QLineEdit, "num_passes_ledit")

        if num_passes:
            self._acquisition_mib.\
                bind_value_update('num_passes', num_passes, int,
                                  QtGui.QIntValidator(1, 1000, self))

        overlap_ledit = self.acq_widget_layout.findChild(QtGui.QLineEdit, "overlap_ledit")

        if overlap_ledit:
            self._acquisition_mib.\
                bind_value_update('overlap', overlap_ledit, float,
                                  QtGui.QDoubleValidator(-1000, 1000, 2, self))

        self._acquisition_mib.\
             bind_value_update('energy',
                               self.acq_widget_layout.energy_ledit,
                               float,
                               self.energy_validator)

        self._acquisition_mib.\
             bind_value_update('transmission',
                               self.acq_widget_layout.transmission_ledit,
                               float,
                               self.transmission_validator)

        self._acquisition_mib.\
             bind_value_update('resolution',
                               self.acq_widget_layout.resolution_ledit,
                               float,
                               self.resolution_validator)

        self._acquisition_mib.\
             bind_value_update('inverse_beam',
                               self.acq_widget_layout.inverse_beam_cbx,
                               bool,
                               None)

        self._acquisition_mib.\
             bind_value_update('shutterless',
                               self.acq_widget_layout.shutterless_cbx,
                               bool,
                               None)

        """self.acq_widget_layout.osc_start_ledit.setToolTip(\
               "Oscillation start limits %0.2f : %0.2f" %(\
               self.osc_start_validator.bottom(),
               self.osc_start_validator.top()))

        self.acq_widget_layout.osc_range_ledit.setToolTip(\
               "Oscillation range limits %0.2f : %0.2f" %(\
               self.osc_ra_validator.bottom(),
               self.osc_start_validator.top()))""" 

        self.set_tunable_energy(beamline_setup.tunable_wavelength())

        has_shutter_less = self._beamline_setup_hwobj.detector_has_shutterless()
        self.acq_widget_layout.shutterless_cbx.setEnabled(has_shutter_less)
        self.acq_widget_layout.shutterless_cbx.setChecked(has_shutter_less)

        if self._beamline_setup_hwobj.disable_num_passes():
            num_passes = self.acq_widget_layout.findChild(QtGui.QLineEdit, "num_passes_ledit")
            if num_passes:
                num_passes.setDisabled(True)

    def first_image_ledit_change(self, new_value):
        """
        Descript. :
        """
        if str(new_value).isdigit():
            self._path_template.start_num = int(new_value)
            widget = self.acq_widget_layout.first_image_ledit
            self.acqParametersChangedSignal.emit()

    def num_images_ledit_change(self, new_value):
        """
        Descript. :
        """
        if str(new_value).isdigit():
            self._path_template.num_files = int(new_value)
            widget = self.acq_widget_layout.num_images_ledit
            self.acqParametersChangedSignal.emit()

    def overlap_changed(self, new_value):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj:
            has_shutter_less = self._beamline_setup_hwobj.detector_has_shutterless()
        else:
            has_shutter_less = True

        if has_shutter_less:
            try:
                new_value = float(new_value)
            except ValueError:
                pass

            if new_value != 0:
                self.acq_widget_layout.shutterless_cbx.setEnabled(False)
                self.acq_widget_layout.shutterless_cbx.setChecked(False)
                self._acquisition_parameters.shutterless = False
            else:
                self.acq_widget_layout.shutterless_cbx.setEnabled(True)
                self.acq_widget_layout.shutterless_cbx.setChecked(True)
                self._acquisition_parameters.shutterless = True

    def use_mad(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.energies_combo.setEnabled(state)
        if state:
            (name, energy) = self.get_mad_energy()

            if energy != 0:
                self.set_energy(energy, 0)
            self.madEnergySelectedSignal.emit(name, energy, state)
        else:
            self.set_energy(self.previous_energy, 0)
            energy = self._beamline_setup_hwobj.energy_hwobj.getCurrentEnergy()
            self.madEnergySelectedSignal.emit('', self.previous_energy, state)

    def set_use_inverse_beam(self, state):
        """
        Descript. :
        """
        if state:
            self.acq_widget_layout.subwedge_size_ledit.setEnabled(True)
        else:
            self.acq_widget_layout.subwedge_size_ledit.setDisabled(True)

    def use_inverse_beam(self):
        """
        Descript. :
        """
        return self.acq_widget_layout.inverse_beam_cbx.isChecked()

    def get_num_subwedges(self):
        """
        Descript. :
        """
        return int(self.acq_widget_layout.subwedge_size_ledit.text())

    def subwedge_size_ledit_change(self, new_value):
        """
        Descript. :
        """
        accept_input = False
        if str(new_value).isdigit() and \
           int(new_value) < self._acquisition_parameters.num_images:
            accept_input = True

        if accept_input:
            Qt4_widget_colors.set_widget_color(
                 self.acq_widget_layout.subwedge_size_ledit,
                 Qt4_widget_colors.WHITE,
                 QtGui.QPalette.Base)
        else:
            Qt4_widget_colors.set_widget_color(\
                 self.acq_widget_layout.subwedge_size_ledit,
                 Qt4_widget_colors.LIGHT_RED,
                 QtGui.QPalette.Base) 

    def get_mad_energy(self):
        """
        Descript. :
        """
        energy_str = str(self.acq_widget_layout.energies_combo.currentText())
        (name, value) = energy_str.split(':')
        
        name = name.strip()
        value = value.strip()
        value = 0 if (value == '-') else float(value)

        return (name, value)

    def set_energies(self, energy_scan_result):
        """
        Descript. :
        """
        self.acq_widget_layout.energies_combo.clear()

        inflection = ('ip: %.4f' % energy_scan_result.inflection) if \
                     energy_scan_result.inflection else 'ip: -'

        peak = ('pk: %.4f' % energy_scan_result.peak) if \
               energy_scan_result.peak else 'pk: -'

        first_remote = ('rm1: %.4f' % energy_scan_result.first_remote) if \
                       energy_scan_result.first_remote else 'rm1: -'

        second_remote = ('rm2: %.4f' % energy_scan_result.second_remote) if \
                        energy_scan_result.second_remote else 'rm2: -'

        self.acq_widget_layout.energies_combo.\
             addItems([inflection, peak, first_remote, second_remote])

    def energy_selected(self, index):
        """
        Descript. :
        """
        if self.acq_widget_layout.mad_cbox.isChecked():
            (name, energy) = self.get_mad_energy()
            if energy != 0:
                self.set_energy(energy, 0)

            self.madEnergySelectedSignal.emit(name, energy, True)

    def set_energy(self, energy, wav):
        """
        Descript. :
        """
        self.acq_widget_layout.energy_ledit.setText("%.4f" % float(energy))

    def update_transmission(self, transmission):
        """
        Descript. :
        """
        if self.enable_parameter_update:
            self.acq_widget_layout.transmission_ledit.setText("%.2f" % float(transmission))

    def update_resolution(self, resolution):
        """
        Descript. :
        """
        if self.enable_parameter_update:
            self.acq_widget_layout.resolution_ledit.setText("%.3f" % float(resolution))

    def update_energy_limits(self, limits):
        if limits:
            self.energy_validator.setBottom(limits[0])
            self.energy_validator.setTop(limits[1])
            self.acq_widget_layout.energy_ledit.setToolTip(\
               "Energy limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_transmission_limits(self, limits):
        if limits:
            self.transmission_validator.setBottom(limits[0])
            self.transmission_validator.setTop(limits[1])
            self.acq_widget_layout.transmission_ledit.setToolTip(\
               "Transmission limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_resolution_limits(self, limits):
        if limits:
            self.resolution_validator.setBottom(limits[0])
            self.resolution_validator.setTop(limits[1])
            self.acq_widget_layout.resolution_ledit.setToolTip(
               "Resolution limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_detector_exp_time_limits(self, limits):
        if limits:
            self.exp_time_validator.setRange(limits[0], limits[1], 4)
            self.acq_widget_layout.exp_time_ledit.setToolTip(
               "Exposure time limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_osc_range_limits(self, exp_time):
        osc_range = 40.0 * exp_time
        self.osc_range_validator.setRange(0, osc_range, 4)
        self.acq_widget_layout.osc_range_ledit.setToolTip(
              "Oscillation range limits %0.2f : %0.2f" %(0, osc_range))
        self._acquisition_mib.validate_all()

    def update_num_image_limits(self):
        try:
           osc_start = float(self.acq_widget_layout.osc_start_ledit.text())
           osc_range = float(self.acq_widget_layout.osc_range_ledit.text())
        except ValueError:
           return

        if osc_range == 0:
            return
        if self._beamline_setup_hwobj.diffractometer_hwobj.in_plate_mode():
            num_image_limit = int((self.osc_start_validator.top() - osc_start) / osc_range)
        else:
            num_image_limit = 99999

        self.num_img_validator.setTop(num_image_limit)
        self.acq_widget_layout.num_images_ledit.setToolTip(\
              "Number of frames limit : %d" % num_image_limit)
        self._acquisition_mib.validate_all()

    def init_detector_roi_modes(self):
        if self._beamline_setup_hwobj is not None:
            roi_modes = self._beamline_setup_hwobj._get_roi_modes()
            if (len(roi_modes) > 0 and
                self.acq_widget_layout.detector_roi_mode_combo.count() == 0):
                for roi_mode in roi_modes:
                    self.acq_widget_layout.detector_roi_mode_combo.\
                         addItem(roi_mode)
                self.acq_widget_layout.detector_roi_mode_label.setEnabled(True)
                self.acq_widget_layout.detector_roi_mode_combo.setEnabled(True)
                #self._acquisition_mib.bind_value_update('detector_roi_mode',
                #               self.acq_widget_layout.detector_roi_mode_combo,
                ##               str,
                #               None)

    def update_detector_roi_mode(self, roi_mode_index):
        if self.acq_widget_layout.detector_roi_mode_combo.count() > 0:
            self.acq_widget_layout.detector_roi_mode_combo.\
                 setCurrentIndex(roi_mode_index)

    def detector_roi_mode_changed(self, roi_mode_index):
        if self._beamline_setup_hwobj is not None:
            self._beamline_setup_hwobj.detector_hwobj.set_roi_mode(roi_mode_index)

    def update_data_model(self, acquisition_parameters, path_template):
        """
        Descript. :
        """
        self._acquisition_parameters = acquisition_parameters
        self._path_template = path_template
        self._acquisition_mib.set_model(acquisition_parameters)
        
        #Update mad widgets
        mad = True if self._path_template.mad_prefix != '' else False

        if mad:
            mad_prefix = self._path_template.mad_prefix
            index = MAD_ENERGY_COMBO_NAMES[mad_prefix]
            self.acq_widget_layout.energies_combo.setCurrentIndex(index)
            self.acq_widget_layout.mad_cbox.setChecked(True)
            self.acq_widget_layout.energies_combo.setEnabled(True)
        else:
            self.acq_widget_layout.mad_cbox.setChecked(False)
            self.acq_widget_layout.energies_combo.setEnabled(False)
            self.acq_widget_layout.energies_combo.setCurrentIndex(0)

    def set_tunable_energy(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.energy_ledit.setEnabled(state)
        self.acq_widget_layout.mad_cbox.setEnabled(state)
        self.acq_widget_layout.energies_combo.setEnabled(state)

    def disable_inverse_beam(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.inverse_beam_cbx.setDisabled(state)
        self.acq_widget_layout.subwedge_size_label.setDisabled(state)
        self.acq_widget_layout.subwedge_size_ledit.setDisabled(state)

    def hide_aperture(self, state):
        """
        Descript. :
        """
        pass
Esempio n. 40
0
class CharParametersWidget(QtGui.QWidget):
    """
    Descript. : 
    """
    def __init__(self, parent=None, name="parameter_widget"):
        """
        Descript. :
        """

        QtGui.QWidget.__init__(self, parent)

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._char = None
        self._char_params = queue_model_objects.CharacterisationParameters()
        self._char_params_mib = DataModelInputBinder(self._char_params)
        self._tree_view_item = None
        self.previous_energy = None

        self.add_dc_cb = None

        # Graphic elements ----------------------------------------------------
        rone_widget = QtGui.QWidget(self)
        self.reference_img_widget = ReferenceImageWidget(rone_widget)
        self.acq_widget = self.reference_img_widget.acq_widget
        self.path_widget = self.reference_img_widget.path_widget
        self.position_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__),
                         'ui_files/Qt4_snapshot_widget_layout.ui'))
        self.position_widget.setMinimumSize(450, 340)

        rtwo_widget = QtGui.QWidget(self)
        self.char_type_widget = CharTypeWidget(rtwo_widget)
        self.routine_dc_widget = self.char_type_widget.routine_dc_page
        self.sad_widget = self.char_type_widget.sad_page
        self.rad_dmg_char_widget = self.char_type_widget.rad_damage_page
        self.opt_parameters_widget = OptimisationParametersWidgetLayout(self)

        rtree_widget = QtGui.QWidget(self)
        self.rad_dmg_widget = uic.loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_radiation_damage_model_widget_layout.ui'))
        self.vertical_dimension_widget = uic.loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_vertical_crystal_dimension_widget_layout.ui'))

        # Layout --------------------------------------------------------------
        rone_widget_layout = QtGui.QHBoxLayout(self)
        rone_widget_layout.addWidget(self.reference_img_widget)
        rone_widget_layout.addWidget(self.position_widget)
        #rone_widget_layout.addStretch(0)
        rone_widget_layout.setSpacing(2)
        rone_widget_layout.setContentsMargins(0, 0, 0, 0)
        rone_widget.setLayout(rone_widget_layout)

        rtwo_widget_layout = QtGui.QHBoxLayout(self)
        rtwo_widget_layout.addWidget(self.char_type_widget)
        rtwo_widget_layout.addWidget(self.opt_parameters_widget)
        rtwo_widget_layout.addStretch(0)
        rtwo_widget_layout.setSpacing(2)
        rtwo_widget_layout.setContentsMargins(0, 0, 0, 0)
        rtwo_widget.setLayout(rtwo_widget_layout)

        rtree_widget_layout = QtGui.QHBoxLayout(self)
        rtree_widget_layout.addWidget(self.rad_dmg_widget)
        rtree_widget_layout.addWidget(self.vertical_dimension_widget)
        rtree_widget_layout.addStretch(0)
        rtree_widget_layout.setSpacing(2)
        rtree_widget_layout.setContentsMargins(0, 0, 0, 0)
        rtree_widget.setLayout(rtree_widget_layout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(rone_widget)
        _main_vlayout.addWidget(rtwo_widget)
        _main_vlayout.addWidget(rtree_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(_main_vlayout)

        # SizePolicies -------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.toggle_permitted_range(self.opt_parameters_widget.\
             opt_param_widget.permitted_range_cbx.isChecked())

        self.opt_parameters_widget.opt_param_widget.permitted_range_cbx.\
             toggled.connect(self.toggle_permitted_range)

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update(
            'min_dose', self.routine_dc_widget.dose_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'min_time', self.routine_dc_widget.time_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'use_min_dose', self.routine_dc_widget.min_dose_radio, bool, None)

        self._char_params_mib.bind_value_update(
            'use_min_time', self.routine_dc_widget.min_time_radio, bool, None)

        self._char_params_mib.bind_value_update(
            'account_rad_damage', self.routine_dc_widget.radiation_damage_cbx,
            bool, None)

        self._char_params_mib.bind_value_update(
            'auto_res', self.sad_widget.automatic_resolution_radio, bool, None)

        self._char_params_mib.bind_value_update(
            'sad_res', self.sad_widget.sad_resolution_ledit, float,
            QtGui.QDoubleValidator(0.5, 20, 3, self))

        self._char_params_mib.bind_value_update(
            'opt_sad', self.sad_widget.optimised_sad_cbx, bool, None)

        self._char_params_mib.bind_value_update(
            'determine_rad_params', self.rad_dmg_char_widget.rad_damage_cbx,
            bool, None)

        self._char_params_mib.bind_value_update(
            'burn_osc_start', self.rad_dmg_char_widget.burn_osc_start_ledit,
            float, QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'burn_osc_interval',
            self.rad_dmg_char_widget.burn_osc_interval_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'use_aimed_resolution',
            self.opt_parameters_widget.opt_param_widget.maximum_res_cbx, bool,
            None)

        self._char_params_mib.bind_value_update(
            'use_aimed_multiplicity',
            self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx, bool,
            None)

        self._char_params_mib.bind_value_update(
            'aimed_resolution',
            self.opt_parameters_widget.opt_param_widget.maximum_res_ledit,
            float, QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(\
             'aimed_multiplicity',
             self.opt_parameters_widget.opt_param_widget.aimed_mult_ledit,
             float,
             QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'aimed_i_sigma',
            self.opt_parameters_widget.opt_param_widget.i_over_sigma_ledit,
            float, QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'aimed_completness',
            self.opt_parameters_widget.opt_param_widget.aimed_comp_ledit,
            float, QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'strategy_complexity',
            self.opt_parameters_widget.opt_param_widget.start_comp_cbox, int,
            None)

        self._char_params_mib.bind_value_update(
            'use_permitted_rotation',
            self.opt_parameters_widget.opt_param_widget.permitted_range_cbx,
            bool, None)

        self._char_params_mib.bind_value_update(
            'permitted_phi_start',
            self.opt_parameters_widget.opt_param_widget.phi_start_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'permitted_phi_end',
            self.opt_parameters_widget.opt_param_widget.phi_end_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'low_res_pass_strat',
            self.opt_parameters_widget.opt_param_widget.low_res_pass_cbx, bool,
            None)

        self._char_params_mib.bind_value_update(
            'rad_suscept', self.rad_dmg_widget.sensetivity_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'beta', self.rad_dmg_widget.beta_over_gray_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'gamma', self.rad_dmg_widget.gamma_over_gray_ledit, float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'max_crystal_vdim', self.vertical_dimension_widget.max_vdim_ledit,
            float, QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'min_crystal_vdim', self.vertical_dimension_widget.min_vdim_ledit,
            float, QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'min_crystal_vphi', self.vertical_dimension_widget.min_vphi_ledit,
            float, QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
            'max_crystal_vphi', self.vertical_dimension_widget.max_vphi_ledit,
            float, QtGui.QDoubleValidator(0.0, 1000, 2, self))

        #self._char_params_mib.bind_value_update('space_group',
        #                                        self.vertical_dimension_widget.space_group_ledit,
        #                                        str,
        #                                        None)


        self.vertical_dimension_widget.space_group_ledit.\
             addItems(queue_model_enumerables.XTAL_SPACEGROUPS)

        self.char_type_widget.charact_type_tbox.currentChanged.connect(\
             self.update_char_type)
        self.rad_dmg_char_widget.rad_damage_cbx.toggled.connect(\
             self.enable_opt_parameters_widget)
        self.opt_parameters_widget.opt_param_widget.maximum_res_cbx.\
             toggled.connect(self.enable_maximum_res_ledit)
        self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx.\
             toggled.connect(self.enable_aimed_mult_ledit)
        self.path_widget.data_path_layout.prefix_ledit.textChanged.\
             connect(self._prefix_ledit_change)
        self.path_widget.data_path_layout.run_number_ledit.textChanged.\
             connect(self._run_number_ledit_change)
        self.vertical_dimension_widget.space_group_ledit.activated.\
             connect(self._space_group_change)
        #QtCore.QObject.connect(QtGui.QApplication, QtCore.SIGNAL('tab_changed'),
        #                   self.tab_changed)

    def _space_group_change(self, index):
        """
        Descript. :
        """
        self._char_params.space_group = queue_model_enumerables.\
                                        XTAL_SPACEGROUPS[index]

    def _set_space_group(self, space_group):
        """
        Descript. :
        """
        index = 0

        if space_group in queue_model_enumerables.XTAL_SPACEGROUPS:
            index = queue_model_enumerables.XTAL_SPACEGROUPS.index(space_group)

        self._space_group_change(index)
        self.vertical_dimension_widget.space_group_ledit.setCurrentIndex(index)

    def _prefix_ledit_change(self, new_value):
        """
        Descript. :
        """
        prefix = self._data_collection.acquisitions[0].\
                 path_template.get_prefix()
        self._char.set_name(prefix)
        self._tree_view_item.setText(0, self._char.get_name())

    def _run_number_ledit_change(self, new_value):
        """
        Descript. :
        """
        if str(new_value).isdigit():
            self._char.set_number(int(new_value))
            self._tree_view_item.setText(0, self._char.get_name())

    def enable_aimed_mult_ledit(self, state):
        """
        Descript. :
        """
        self.opt_parameters_widget.opt_param_widget.aimed_mult_ledit.setEnabled(
            state)

    def enable_maximum_res_ledit(self, state):
        """
        Descript. :
        """
        self.opt_parameters_widget.opt_param_widget.maximum_res_ledit.setEnabled(
            state)

    def update_char_type(self, index):
        """
        Descript. :
        """
        self._char_params.experiment_type = index

    def toggle_permitted_range(self, status):
        """
        Descript. :
        """
        self.opt_parameters_widget.opt_param_widget.phi_start_ledit.setEnabled(
            status)
        self.opt_parameters_widget.opt_param_widget.phi_end_ledit.setEnabled(
            status)

    def enable_opt_parameters_widget(self, state):
        """
        Descript. :
        """
        if not self._char.is_executed():
            self.opt_parameters_widget.setEnabled(not state)
        else:
            self.opt_parameters_widget.setEnabled(False)

    def tab_changed(self):
        """
        Descript. :
        """
        if self._tree_view_item:
            self.populate_parameter_widget(self._tree_view_item)

    def set_enabled(self, state):
        """
        Descript. :
        """
        self.char_type_widget.setEnabled(state)
        self.routine_dc_widget.setEnabled(state)
        self.sad_widget.setEnabled(state)
        self.rad_dmg_char_widget.setEnabled(state)
        self.reference_img_widget.setEnabled(state)
        self.acq_widget.setEnabled(state)
        self.path_widget.setEnabled(state)
        self.opt_parameters_widget.setEnabled(state)
        self.rad_dmg_widget.setEnabled(state)
        self.vertical_dimension_widget.setEnabled(state)

    def populate_parameter_widget(self, tree_view_item):
        """
        Descript. :
        """
        self._tree_view_item = tree_view_item
        self._char = tree_view_item.get_model()
        self._data_collection = self._char.reference_image_collection
        self._char_params = self._char.characterisation_parameters
        self._char_params_mib.set_model(self._char.characterisation_parameters)
        self._set_space_group(self._char_params.space_group)

        self.acq_widget.update_data_model(self._char.reference_image_collection.\
                                          acquisitions[0].acquisition_parameters,
                                          self._char.reference_image_collection.\
                                          acquisitions[0].path_template)

        self.path_widget.update_data_model(self._char.reference_image_collection.\
                                           acquisitions[0].path_template)

        if self._data_collection.acquisitions[0].acquisition_parameters.\
                centred_position.snapshot_image:
            image = self._data_collection.acquisitions[0].\
                acquisition_parameters.centred_position.snapshot_image
            ration = image.height() / float(image.width())
            image = image.scaled(400, 400 * ration, QtCore.Qt.KeepAspectRatio)
            self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))

        self.toggle_permitted_range(self._char_params.use_permitted_rotation)
        self.enable_opt_parameters_widget(
            self._char_params.determine_rad_params)
        self.enable_maximum_res_ledit(self._char_params.use_aimed_resolution)
        self.enable_aimed_mult_ledit(self._char_params.use_aimed_multiplicity)

        item = self.char_type_widget.charact_type_tbox.\
               widget(self._char_params.experiment_type)

        self.char_type_widget.charact_type_tbox.setCurrentWidget(item)
        self.char_type_widget.toggle_time_dose()
        crystal = self._char.reference_image_collection.crystal
        self.acq_widget.set_energies(crystal.energy_scan_result)

    def set_beamline_setup(self, bl_setup):
        """
        Descript. :
        """
        self.acq_widget.set_beamline_setup(bl_setup)
class AdvancedParametersWidget(QWidget):
    def __init__(self, parent = None, name = "advanced_parameters_widget"):
        QWidget.__init__(self, parent)

        # Hardware objects ----------------------------------------------------
        self._queue_model_hwobj = None
        self._beamline_setup_hwobj = None

        # Internal values -----------------------------------------------------
        self._data_collection = None
        self._tree_view_item = None

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        _dc_parameters_widget = QWidget(self)
        self._data_path_widget = DataPathWidget(_dc_parameters_widget)
        self._acq_widget = AcquisitionWidget(_dc_parameters_widget,
                                            layout = 'horizontal')

        # Layout --------------------------------------------------------------
        _dc_parameters_widget_layout = 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.setSpacing(2)
        _dc_parameters_widget_layout.addStretch(10)
        _dc_parameters_widget_layout.setContentsMargins(0, 0, 0, 0)

        _main_hlayout = QHBoxLayout(self)
        _main_hlayout.addWidget(_dc_parameters_widget)
        _main_hlayout.setSpacing(2)
        _main_hlayout.setContentsMargins(2, 2, 2, 2)
        _main_hlayout.addStretch(0)

        # Qt signal/slot connections ------------------------------------------
        #self._acq_widget.acqParametersChangedSignal.\
        #     connect(self.acq_parameters_changed)
        #self._data_path_widget.pathTemplateChangedSignal.\
        #     connect(self.acq_parameters_changed)
        self._acq_widget.madEnergySelectedSignal.connect(\
             self.mad_energy_selected)

        # Ohter ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.acq_widget_layout.mad_cbox.hide()
        self._acq_widget.acq_widget_layout.energies_combo.hide()
        self._acq_widget.acq_widget_layout.shutterless_cbx.hide()

    def set_beamline_setup(self, bl_setup):
        self._beamline_setup_hwobj = bl_setup
        self._acq_widget.set_beamline_setup(bl_setup)

    def mad_energy_selected(self, name, energy, state):
        path_template = self._data_collection.acquisitions[0].path_template

        if state:
            path_template.mad_prefix = name
        else:
            path_template.mad_prefix = ''

        run_number = self._beamline_setup_hwobj.queue_model_hwobj.\
          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_widget(self._tree_view_item)

    def populate_widget(self, tree_view_item, data_collection):
        self._tree_view_item = tree_view_item
        self._data_collection = data_collection

        #if isinstance(tree_view_item, Qt4_queue_item.XrayCenteringQueueItem):
        #    self._data_collection = tree_view_item.get_model().reference_image_collection
        #else:
        #    self._data_collection = tree_view_item.get_model()
        executed = self._data_collection.is_executed()

        self._acq_widget.setEnabled(not executed)
        self._data_path_widget.setEnabled(not executed)

        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 = self._data_collection.\
             acquisitions[0].path_template
        self._data_path_widget.update_data_model(self._data_collection.\
              acquisitions[0].path_template)

        self._acq_widget.update_data_model(\
             self._data_collection.acquisitions[0].acquisition_parameters,
             self._data_collection.acquisitions[0].path_template)
        #self._acq_widget.use_osc_start(False)

        self._acq_widget.acq_widget_layout.num_images_ledit.setDisabled(data_collection.is_mesh())
        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)
Esempio n. 42
0
    def __init__(self, parent=None, name=None, fl=0, acq_params=None,
                 path_template=None, layout='horizontal'):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None
        self._diffractometer_hwobj = None

        # Internal variables --------------------------------------------------
        self.previous_energy = 0

        # If the acq. widget is used with grids then total osc range is not
        # equal to num_images * osc_range, but num_images_per_line * osc_range
        # For grids the osc total range is updated when a grid is selected

        self.grid_mode = False

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.\
                                           AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)

        if layout == "horizontal":
            self.acq_widget_layout = loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_horizontal_layout.ui"))
            self.use_osc_start(False)
        else:
            self.acq_widget_layout = loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_vertical_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.osc_start_cbox.stateChanged.connect(\
             self.fix_osc_start)
        self.acq_widget_layout.exp_time_ledit.textChanged.connect(\
             self.exposure_time_ledit_changed)
        self.acq_widget_layout.first_image_ledit.textChanged.connect(\
             self.first_image_ledit_change)
        self.acq_widget_layout.num_images_ledit.textChanged.connect(\
             self.num_images_ledit_change)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(\
             self.detector_roi_mode_changed)
        self.acq_widget_layout.energies_combo.activated.connect(\
             self.energy_selected)
        self.acq_widget_layout.mad_cbox.toggled.connect(\
             self.use_mad)
        self.acq_widget_layout.osc_start_ledit.textEdited.connect(\
             self.osc_start_ledit_changed)
        self.acq_widget_layout.osc_range_ledit.textEdited.connect(\
             self.osc_range_per_frame_ledit_changed)
        self.acq_widget_layout.osc_total_range_ledit.textEdited.connect(\
             self.osc_total_range_ledit_changed)
        self.acq_widget_layout.energy_ledit.textEdited.connect(\
             self.energy_ledit_changed)
        self.acq_widget_layout.transmission_ledit.textEdited.connect(\
             self.transmission_ledit_changed)
        self.acq_widget_layout.resolution_ledit.textEdited.connect(\
             self.resolution_ledit_changed)
        self.acq_widget_layout.kappa_ledit.textEdited.connect(\
             self.kappa_ledit_changed)
        self.acq_widget_layout.kappa_phi_ledit.textEdited.connect(\
             self.kappa_phi_ledit_changed)
        
        if self.acq_widget_layout.findChild(QLineEdit, "overlap_ledit"):
            self.acq_widget_layout.overlap_ledit.textChanged.connect(\
                 self.overlap_changed)
        if self.acq_widget_layout.findChild(QCheckBox, "max_osc_range_cbx"):
            self.acq_widget_layout.max_osc_range_cbx.toggled.connect(\
                 self.max_osc_range_toggled)

        # Other --------------------------------------------------------------- 
        self.value_changed_list = []

        self.acq_widget_layout.energies_combo.setDisabled(True)
        self.acq_widget_layout.energies_combo.addItems(\
             ['ip: -', 'pk: -', 'rm1: -', 'rm2: -'])

        self.osc_start_validator = QDoubleValidator(\
             -10000, 10000, 4, self.acq_widget_layout.osc_start_ledit)
        self.osc_range_per_frame_validator = QDoubleValidator(\
             0, 10000, 4, self.acq_widget_layout.osc_range_ledit)
        self.osc_total_range_validator = QDoubleValidator(\
             0, 10000, 4, self.acq_widget_layout.osc_total_range_ledit)
        self.kappa_validator = QDoubleValidator(\
             0, 360, 4, self.acq_widget_layout.kappa_ledit)
        self.kappa_phi_validator = QDoubleValidator(\
             0, 360, 4, self.acq_widget_layout.kappa_phi_ledit)
        self.energy_validator = QDoubleValidator(\
             4, 25, 4, self.acq_widget_layout.energy_ledit)
        self.resolution_validator = QDoubleValidator(\
             0, 15, 3, self.acq_widget_layout.resolution_ledit)
        self.transmission_validator = QDoubleValidator(\
             0, 100, 3, self.acq_widget_layout.transmission_ledit)
        self.exp_time_validator = QDoubleValidator(\
             0.0001, 10000, 7, self.acq_widget_layout.exp_time_ledit)
        self.first_img_validator = QIntValidator(\
             0, 99999, self.acq_widget_layout.first_image_ledit)
        self.num_img_validator = QIntValidator(\
             1, 9999999, self.acq_widget_layout.num_images_ledit) 
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)
class AcquisitionStillWidget(QWidget):
  
    acqParametersChangedSignal = pyqtSignal(list)

    def __init__(self, parent=None, name=None, fl=0, acq_params=None,
                 path_template=None, layout='vertical'):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None
        self._diffractometer_hwobj = None

        # Internal variables --------------------------------------------------

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.\
                                           AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)

        self.acq_widget_layout = loadUi(os.path.join(\
             os.path.dirname(__file__),
             "ui_files/Qt4_acquisition_widget_vertical_still_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.num_triggers_ledit.textChanged.connect(\
             self.num_triggers_ledit_changed)
        self.acq_widget_layout.num_images_per_trigger_ledit.textChanged.connect(\
             self.num_images_per_trigger_ledit_changed)

        self.acq_widget_layout.exp_time_ledit.textChanged.connect(\
             self.exposure_time_ledit_changed)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(\
             self.detector_roi_mode_changed)
        self.acq_widget_layout.energy_ledit.textEdited.connect(\
             self.energy_ledit_changed)
        self.acq_widget_layout.transmission_ledit.textEdited.connect(\
             self.transmission_ledit_changed)
        self.acq_widget_layout.resolution_ledit.textEdited.connect(\
             self.resolution_ledit_changed)
        
        # Other --------------------------------------------------------------- 
        self.value_changed_list = []

        self.energy_validator = QDoubleValidator(\
             4, 25, 4, self.acq_widget_layout.energy_ledit)
        self.resolution_validator = QDoubleValidator(\
             0, 15, 3, self.acq_widget_layout.resolution_ledit)
        self.transmission_validator = QDoubleValidator(\
             0, 100, 3, self.acq_widget_layout.transmission_ledit)
        self.exp_time_validator = QDoubleValidator(\
             0.0001, 10000, 7, self.acq_widget_layout.exp_time_ledit)
        self.num_triggers_validator = QIntValidator(\
             1, 9999999, self.acq_widget_layout.num_triggers_ledit)
        self.num_images_per_trigger_validator = QIntValidator(\
             1, 9999999, self.acq_widget_layout.num_images_per_trigger_ledit)
        self.num_img_validator = QIntValidator(\
             1, 9999999, self.acq_widget_layout.num_images_ledit) 
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)

    def use_osc_start(self, status):
        pass

    def use_max_osc_range(self, status):
        pass

    def use_kappa(self, status):
        pass

    def set_beamline_setup(self, beamline_setup):
        self._beamline_setup_hwobj = beamline_setup
        limits_dict = self._beamline_setup_hwobj.get_acquisition_limit_values()
        self._diffractometer_hwobj = self._beamline_setup_hwobj.diffractometer_hwobj
 
        
        if 'exposure_time' in limits_dict:
            limits = tuple(map(float, limits_dict['exposure_time'].split(',')))
            (lower, upper) = limits
            self.exp_time_validator.setRange(lower, upper, 6)
        
        self._acquisition_mib.bind_value_update('exp_time', 
                                                self.acq_widget_layout.exp_time_ledit,
                                                float, 
                                                self.exp_time_validator)

        self._acquisition_mib.bind_value_update('num_triggers',
                                                self.acq_widget_layout.num_triggers_ledit,
                                                int,
                                                self.num_triggers_validator)

        self._acquisition_mib.bind_value_update('num_images_per_trigger',
                                                self.acq_widget_layout.num_images_per_trigger_ledit,
                                                int,
                                                self.num_images_per_trigger_validator)

        if 'number_of_images' in limits_dict:
            limits = tuple(map(float, limits_dict['number_of_images'].split(',')))
            (lower, upper) = limits
            self.num_img_validator.setRange(lower, upper)
        
        self._acquisition_mib.bind_value_update('num_images', 
                                                self.acq_widget_layout.num_images_ledit,
                                                int, 
                                                self.num_img_validator)

        self._acquisition_mib.\
             bind_value_update('energy',
                               self.acq_widget_layout.energy_ledit,
                               float,
                               self.energy_validator)
        self.update_energy_limits((self.energy_validator.bottom(),
                                   self.energy_validator.top()))

        self._acquisition_mib.\
             bind_value_update('transmission',
                               self.acq_widget_layout.transmission_ledit,
                               float,
                               self.transmission_validator)
        self.update_transmission_limits((self.transmission_validator.bottom(),
                                         self.transmission_validator.top()))

        self._acquisition_mib.\
             bind_value_update('resolution',
                               self.acq_widget_layout.resolution_ledit,
                               float,
                               self.resolution_validator)

        has_shutter_less = self._beamline_setup_hwobj.detector_has_shutterless()
        self.init_detector_roi_modes()

    def exposure_time_ledit_changed(self, new_values):
        self.emit_acq_parameters_changed()

    def energy_ledit_changed(self, new_value):
        if "energy" not in self.value_changed_list:
            self.value_changed_list.append("energy")
        self.emit_acq_parameters_changed()

    def update_energy(self, energy, wav=None):
        if "energy" not in self.value_changed_list and \
           not self.acq_widget_layout.energy_ledit.hasFocus():
            self.acq_widget_layout.energy_ledit.setText(str(energy))
        self.emit_acq_parameters_changed()

    def transmission_ledit_changed(self, transmission):
        if "transmission" not in self.value_changed_list:
            self.value_changed_list.append("transmission")
        self.emit_acq_parameters_changed()

    def update_transmission(self, transmission):
        if "transmission" not in self.value_changed_list:
            self.acq_widget_layout.transmission_ledit.setText(str(transmission))
        self.emit_acq_parameters_changed()
           
    def resolution_ledit_changed(self, resolution):
        if "resolution" not in self.value_changed_list:
            self.value_changed_list.append("resolution")
        self.emit_acq_parameters_changed()

    def update_resolution(self, resolution):
        if "resolution" not in self.value_changed_list and \
           not self.acq_widget_layout.resolution_ledit.hasFocus():
            self.acq_widget_layout.resolution_ledit.setText(str(resolution))
        self.emit_acq_parameters_changed()

    def update_energy_limits(self, limits):
        if limits:
            self.energy_validator.setBottom(limits[0])
            self.energy_validator.setTop(limits[1])
            self.acq_widget_layout.energy_ledit.setToolTip(\
               "Energy limits %0.4f : %0.4f keV\n" % \
               (limits[0], limits[1]) + \
               "4 digits precision.")
            self._acquisition_mib.validate_all()

    def update_transmission_limits(self, limits):
        if limits:
            self.transmission_validator.setBottom(limits[0])
            self.transmission_validator.setTop(limits[1])
            self.acq_widget_layout.transmission_ledit.setToolTip(\
               "Transmission limits %0.2f : %0.2f %%\n" % \
               (limits[0], limits[1]) + \
               "2 digits precision.")
            self._acquisition_mib.validate_all()

    def update_resolution_limits(self, limits):
        if limits:
            self.resolution_validator.setBottom(limits[0])
            self.resolution_validator.setTop(limits[1])
            self.acq_widget_layout.resolution_ledit.setToolTip(
               "Resolution limits %0.4f : %0.4f %s\n" % \
               (limits[0], limits[1], chr(197)) + 
               "4 digits precision.")
            self._acquisition_mib.validate_all()

    def update_detector_exp_time_limits(self, limits):
        if limits:
            self.exp_time_validator.setRange(limits[0], limits[1], 6)
            self.acq_widget_layout.exp_time_ledit.setToolTip(
               "Exposure time limits %0.6f s : %0.1f s\n" % \
               (limits[0], limits[1]) + \
               "6 digits precision.")
            self._acquisition_mib.validate_all()

    def init_detector_roi_modes(self):
        if self._beamline_setup_hwobj is not None:
            roi_modes = self._beamline_setup_hwobj.detector_hwobj.get_roi_modes()
            if (len(roi_modes) > 0 and
                self.acq_widget_layout.detector_roi_mode_combo.count() == 0):
                for roi_mode in roi_modes:
                    self.acq_widget_layout.detector_roi_mode_combo.\
                         addItem(roi_mode)
            self.acq_widget_layout.detector_roi_mode_label.setEnabled(len(roi_modes) > 1)
            self.acq_widget_layout.detector_roi_mode_combo.setEnabled(len(roi_modes) > 1)

    def update_detector_roi_mode(self, roi_mode_index):
        if roi_mode_index is not None and \
           self.acq_widget_layout.detector_roi_mode_combo.count() > 0:
            self.acq_widget_layout.detector_roi_mode_combo.\
                 setCurrentIndex(roi_mode_index)

    def detector_roi_mode_changed(self, roi_mode_index):
        if self._beamline_setup_hwobj is not None:
            self._beamline_setup_hwobj.detector_hwobj.set_roi_mode(roi_mode_index)

    def update_osc_range_per_frame_limits(self):
        pass

    def update_exp_time_limits(self):
        pass

    def update_osc_start(self, value):
        pass

    def update_kappa(self, value):
        pass

    def update_kappa_phi(self, value):
        pass

    def update_data_model(self, acquisition_parameters, path_template):
        self._acquisition_parameters = acquisition_parameters
        self._path_template = path_template        
        self._acquisition_mib.set_model(acquisition_parameters)
        self.emit_acq_parameters_changed()

    def check_parameter_conflict(self):
        return self._acquisition_mib.validate_all()

    def emit_acq_parameters_changed(self):
        self.acqParametersChangedSignal.emit(self._acquisition_mib.validate_all())

    def set_energies(self, energies):
        pass

    def num_triggers_ledit_changed(self, value):
        if "num_triggers" not in self.value_changed_list:
            self.value_changed_list.append("num_triggers")
        self.update_num_images()
        self.emit_acq_parameters_changed()

    def num_images_per_trigger_ledit_changed(self, values):
        if "num_images_per_trigger" not in self.value_changed_list:
            self.value_changed_list.append("num_images_per_trigger")
        self.update_num_images()   
        self.emit_acq_parameters_changed()

    def update_num_images(self):
        self.acq_widget_layout.num_images_ledit.setText(\
             str(self._acquisition_parameters.num_triggers * \
                 self._acquisition_parameters.num_images_per_trigger))
class AdvancedParametersWidget(QtGui.QWidget):
    def __init__(self, parent=None, name="advanced_parameters_widget"):
        QtGui.QWidget.__init__(self, parent)

        # Hardware objects ----------------------------------------------------
        self._queue_model_hwobj = None
        self._beamline_setup_hwobj = None

        # Internal values -----------------------------------------------------
        self._data_collection = None
        self._tree_view_item = None

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        _dc_parameters_widget = QtGui.QWidget(self)
        self._data_path_widget = DataPathWidget(_dc_parameters_widget)
        self._acq_widget = AcquisitionWidget(_dc_parameters_widget,
                                             layout='horizontal')
        #self._acq_widget.setFixedHeight(170)
        _snapshot_widget = QtGui.QWidget(self)
        self.position_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__),
                         'ui_files/Qt4_snapshot_widget_layout.ui'))

        # Layout --------------------------------------------------------------
        _dc_parameters_widget_layout = QtGui.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.setSpacing(2)
        _dc_parameters_widget_layout.addStretch(10)
        _dc_parameters_widget_layout.setContentsMargins(0, 0, 0, 0)

        _snapshots_vlayout = QtGui.QVBoxLayout(_snapshot_widget)
        _snapshots_vlayout.addWidget(self.position_widget)
        _snapshots_vlayout.setContentsMargins(0, 0, 0, 0)
        _snapshots_vlayout.setSpacing(2)
        _snapshots_vlayout.addStretch(10)

        _main_hlayout = QtGui.QHBoxLayout(self)
        _main_hlayout.addWidget(_dc_parameters_widget)
        _main_hlayout.addWidget(_snapshot_widget)
        _main_hlayout.setSpacing(2)
        _main_hlayout.setContentsMargins(2, 2, 2, 2)
        _main_hlayout.addStretch(0)

        # 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.handle_path_conflict)

        # Ohter ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.acq_widget_layout.mad_cbox.hide()
        self._acq_widget.acq_widget_layout.energies_combo.hide()
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        self._acq_widget.acq_widget_layout.inverse_beam_cbx.hide()
        self._acq_widget.acq_widget_layout.shutterless_cbx.hide()
        self._acq_widget.acq_widget_layout.subwedge_size_label.hide()
        self._acq_widget.acq_widget_layout.subwedge_size_ledit.hide()

    def set_beamline_setup(self, bl_setup):
        self._beamline_setup_hwobj = bl_setup
        self._acq_widget.set_beamline_setup(bl_setup)

    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 handle_path_conflict(self):
        if self._tree_view_item:
            dc_tree_widget = self._tree_view_item.listView().parent()
            dc_tree_widget.check_for_path_collisions()
            path_template = self._data_collection.acquisitions[0].path_template
            path_conflict = self.queue_model_hwobj.\
                        check_for_path_collisions(path_template)

            if path_conflict:
                logging.getLogger("user_level_log").\
                    error('The current path settings will overwrite data' +\
                          ' from another task. Correct the problem before collecting')
                Qt4_widget_colors.set_widget_color(widget,
                                                   Qt4_widget_colors.LIGHT_RED)
            else:
                Qt4_widget_colors.set_widget_color(
                    widget, Qt4_widget_colors.LIGHT_WHITE)

    def mad_energy_selected(self, name, energy, state):
        path_template = self._data_collection.acquisitions[0].path_template

        if state:
            path_template.mad_prefix = name
        else:
            path_template.mad_prefix = ''

        run_number = self._beamline_setup_hwobj.queue_model_hwobj.\
          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_widget(self._tree_view_item)

    def populate_widget(self, tree_view_item):
        self._tree_view_item = tree_view_item
        advanced_model = tree_view_item.get_model()
        self._data_collection = advanced_model.reference_image_collection
        executed = self._data_collection.is_executed()

        self._acq_widget.setEnabled(not executed)
        self._data_path_widget.setEnabled(not executed)

        image = advanced_model.grid_object.get_snapshot()
        try:
            image = image.scaled(427, 320, QtCore.Qt.KeepAspectRatio)
            self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))
        except:
            pass

        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 = self._data_collection.\
             acquisitions[0].path_template
        self._data_path_widget.update_data_model(self._data_collection.\
              acquisitions[0].path_template)

        self._acq_widget.update_data_model(\
             self._data_collection.acquisitions[0].acquisition_parameters,
             self._data_collection.acquisitions[0].path_template)
        #self._acq_widget.use_osc_start(False)
        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("user_level_log").\
                warning(msg)
class AdvancedParametersWidget(QWidget):
    def __init__(self, parent = None, name = "advanced_parameters_widget"):
        QWidget.__init__(self, parent)

        # Hardware objects ----------------------------------------------------
        self._queue_model_hwobj = None
        self._beamline_setup_hwobj = None

        # Internal values -----------------------------------------------------
        self._data_collection = None
        self._tree_view_item = None

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        _dc_parameters_widget = QWidget(self)
        self._data_path_widget = DataPathWidget(_dc_parameters_widget)
        self._acq_widget = AcquisitionWidget(_dc_parameters_widget,
                                            layout = 'horizontal')

        # Layout --------------------------------------------------------------
        _dc_parameters_widget_layout = 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.setSpacing(2)
        _dc_parameters_widget_layout.addStretch(10)
        _dc_parameters_widget_layout.setContentsMargins(0, 0, 0, 0)

        _main_hlayout = QHBoxLayout(self)
        _main_hlayout.addWidget(_dc_parameters_widget)
        _main_hlayout.setSpacing(2)
        _main_hlayout.setContentsMargins(2, 2, 2, 2)
        _main_hlayout.addStretch(0)

        # Qt signal/slot connections ------------------------------------------
        #self._acq_widget.acqParametersChangedSignal.\
        #     connect(self.acq_parameters_changed)
        #self._data_path_widget.pathTemplateChangedSignal.\
        #     connect(self.acq_parameters_changed)
        self._acq_widget.madEnergySelectedSignal.connect(\
             self.mad_energy_selected)

        # Ohter ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.acq_widget_layout.mad_cbox.hide()
        self._acq_widget.acq_widget_layout.energies_combo.hide()
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        self._acq_widget.acq_widget_layout.shutterless_cbx.hide()

    def set_beamline_setup(self, bl_setup):
        self._beamline_setup_hwobj = bl_setup
        self._acq_widget.set_beamline_setup(bl_setup)

    def mad_energy_selected(self, name, energy, state):
        path_template = self._data_collection.acquisitions[0].path_template

        if state:
            path_template.mad_prefix = name
        else:
            path_template.mad_prefix = ''

        run_number = self._beamline_setup_hwobj.queue_model_hwobj.\
          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_widget(self._tree_view_item)

    def populate_widget(self, tree_view_item):
        self._tree_view_item = tree_view_item

        if isinstance(tree_view_item, Qt4_queue_item.XrayCenteringQueueItem):
            self._data_collection = tree_view_item.get_model().reference_image_collection
        else:
            self._data_collection = tree_view_item.get_model()
        executed = self._data_collection.is_executed()

        self._acq_widget.setEnabled(not executed)
        self._data_path_widget.setEnabled(not executed)

        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 = self._data_collection.\
             acquisitions[0].path_template
        self._data_path_widget.update_data_model(self._data_collection.\
              acquisitions[0].path_template)

        self._acq_widget.update_data_model(\
             self._data_collection.acquisitions[0].acquisition_parameters,
             self._data_collection.acquisitions[0].path_template)
        #self._acq_widget.use_osc_start(False)
        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, fl=0, acq_params=None,
                 path_template=None, layout='vertical'):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None
        self._diffractometer_hwobj = None

        # Internal variables --------------------------------------------------

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.\
                                           AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)

        self.acq_widget_layout = loadUi(os.path.join(\
             os.path.dirname(__file__),
             "ui_files/Qt4_acquisition_widget_vertical_still_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.num_triggers_ledit.textChanged.connect(\
             self.num_triggers_ledit_changed)
        self.acq_widget_layout.num_images_per_trigger_ledit.textChanged.connect(\
             self.num_images_per_trigger_ledit_changed)

        self.acq_widget_layout.exp_time_ledit.textChanged.connect(\
             self.exposure_time_ledit_changed)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(\
             self.detector_roi_mode_changed)
        self.acq_widget_layout.energy_ledit.textEdited.connect(\
             self.energy_ledit_changed)
        self.acq_widget_layout.transmission_ledit.textEdited.connect(\
             self.transmission_ledit_changed)
        self.acq_widget_layout.resolution_ledit.textEdited.connect(\
             self.resolution_ledit_changed)
        
        # Other --------------------------------------------------------------- 
        self.value_changed_list = []

        self.energy_validator = QDoubleValidator(\
             4, 25, 4, self.acq_widget_layout.energy_ledit)
        self.resolution_validator = QDoubleValidator(\
             0, 15, 3, self.acq_widget_layout.resolution_ledit)
        self.transmission_validator = QDoubleValidator(\
             0, 100, 3, self.acq_widget_layout.transmission_ledit)
        self.exp_time_validator = QDoubleValidator(\
             0.0001, 10000, 7, self.acq_widget_layout.exp_time_ledit)
        self.num_triggers_validator = QIntValidator(\
             1, 9999999, self.acq_widget_layout.num_triggers_ledit)
        self.num_images_per_trigger_validator = QIntValidator(\
             1, 9999999, self.acq_widget_layout.num_images_per_trigger_ledit)
        self.num_img_validator = QIntValidator(\
             1, 9999999, self.acq_widget_layout.num_images_ledit) 
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)
class AcquisitionWidgetSimple(QtGui.QWidget):
    """
    Descript. :
    """
    acqParametersChangedSignal = QtCore.pyqtSignal()
    madEnergySelectedSignal = QtCore.pyqtSignal(str, float, bool)

    def __init__(self, parent = None, name = None, fl = 0, acq_params = None, 
                 path_template = None, layout = None):
        """
        Descript. :
        """ 

        QtGui.QWidget.__init__(self, parent, QtCore.Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params
        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)
        self.acq_widget_layout = uic.loadUi(os.path.join(os.path.dirname(\
            __file__), "ui_files/Qt4_acquisition_widget_vertical_simple_layout.ui"))

        # Layout --------------------------------------------------------------
        main_layout = QtGui.QVBoxLayout(self)
        main_layout.addWidget(self.acq_widget_layout)
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.osc_start_cbox.stateChanged.connect(\
             self.use_osc_start)
        self.acq_widget_layout.num_images_cbox.activated.connect(\
             self.update_num_images)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(\
             self.detector_roi_mode_changed)

        # Other ---------------------------------------------------------------
        self.osc_start_validator = QtGui.QDoubleValidator(-10000, 10000, 4, self)
        self.osc_range_validator = QtGui.QDoubleValidator(-10000, 10000, 4, self)
        self.kappa_validator = QtGui.QDoubleValidator(0, 360, 4, self)
        self.kappa_phi_validator = QtGui.QDoubleValidator(0, 360, 4, self)
        self.energy_validator = QtGui.QDoubleValidator(0, 25, 5, self)
        self.resolution_validator = QtGui.QDoubleValidator(0, 15, 3, self)
        self.transmission_validator = QtGui.QDoubleValidator(0, 100, 3, self)
        self.exp_time_validator = QtGui.QDoubleValidator(0, 10000, 5, self)
        self.acq_widget_layout.num_images_cbox.setCurrentIndex(1)

        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)

    def set_osc_start_limits(self, limits):
        if not None in limits:
            self.osc_start_validator.setRange(limits[0], limits[1], 4)

    def update_osc_start(self, new_value):
        """
        Descript. :
        """
        if not self.acq_widget_layout.osc_start_cbox.hasFocus():
            osc_start_value = 0
            try:
               osc_start_value = round(float(new_value), 2)
            except TypeError:
               pass
            self.acq_widget_layout.osc_start_ledit.setText(\
                 "%.2f" % osc_start_value)
            #self._acquisition_parameters.osc_start = osc_start_value

    def update_kappa(self, new_value):
        """
        Descript. :
        """
        if not self.acq_widget_layout.kappa_ledit.hasFocus():
            self.acq_widget_layout.kappa_ledit.setText(\
                 "%.2f" % float(new_value))

    def update_kappa_phi(self, new_value):
        """
        Descript. :
        """
        if not self.acq_widget_layout.kappa_phi_ledit.hasFocus():
            self.acq_widget_layout.kappa_phi_ledit.setText(\
                 "%.2f" % float(new_value))

    def use_kappa(self, state):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            if self._beamline_setup_hwobj.diffractometer_hwobj.in_plate_mode():
                state = False
        self.acq_widget_layout.kappa_label.setEnabled(state)
        self.acq_widget_layout.kappa_ledit.setEnabled(state)
        self.acq_widget_layout.kappa_phi_label.setEnabled(state)
        self.acq_widget_layout.kappa_phi_ledit.setEnabled(state)

    def update_num_images(self, index = None, num_images = None):
        """
        Descript. :
        """
        if index is not None:
            if index is 0:
                self._acquisition_parameters.num_images = 1
                self._path_template.num_files = 1
            elif index is 1:
                self._acquisition_parameters.num_images = 2
                self._path_template.num_files = 2
            elif index is 2:
                self._acquisition_parameters.num_images = 4
                self._path_template.num_files = 4

        if num_images:
            if self.acq_widget_layout.num_images_cbox.count() > 3:
                self.acq_widget_layout.num_images_cbox.removeItem(4)
        
            if num_images is 1:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(0)    
            elif num_images is 2:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(1)
            elif num_images is 4:
                self.acq_widget_layout.num_images_cbox.setCurrentIndex(2)
            else:
                self.acq_widget_layout.num_images_cbox.addItem(str(num_images))
                self.acq_widget_layout.num_images_cbox.setCurrenIndex(3)

            self._path_template.num_files = num_images

    def use_mad(self, state):
        """
        Descript. :
        """
        pass

    def get_mad_energy(self):
        """
        Descript. :
        """
        pass

    def set_energies(self, energy_scan_result):
        """
        Descript. :
        """
        pass

    def energy_selected(self, index):
        """
        Descript. :
        """
        pass

    def set_beamline_setup(self, beamline_setup):
        """
        Descript. :
        """
        self._beamline_setup_hwobj = beamline_setup
        limits_dict = self._beamline_setup_hwobj.get_acquisition_limit_values()

        if 'osc_range' in limits_dict:
            limits = tuple(map(float, limits_dict['osc_range'].split(',')))
            (lower, upper) = limits
            elf.osc_start_validator.setRange(lower, upper, 4)
            self.osc_range_validator.setRange(lower, upper, 4)

        self._acquisition_mib.bind_value_update('osc_start', 
                                                self.acq_widget_layout.osc_start_ledit,
                                                float, 
                                                self.osc_start_validator)

        self._acquisition_mib.bind_value_update('osc_range', 
                                                self.acq_widget_layout.osc_range_ledit,
                                                float, 
                                                self.osc_range_validator)

        if 'kappa' in limits_dict:
            limits = tuple(map(float, limits_dict['kappa'].split(',')))
            (lower, upper) = limits
            self.kappa_validator.setRange(lower, upper, 4)
        self._acquisition_mib.bind_value_update('kappa', 
                                                self.acq_widget_layout.kappa_ledit,
                                                float,
                                                self.kappa_validator)

        if 'kappa_phi' in limits_dict:
            limits = tuple(map(float, limits_dict['kappa_phi'].split(',')))
            (lower, upper) = limits
            self.kappa_phi_validator.setRange(lower, upper, 4)
        self._acquisition_mib.bind_value_update('kappa_phi',     
                                                self.acq_widget_layout.kappa_phi_ledit,
                                                float,
                                                self.kappa_phi_validator)

        if 'exposure_time' in limits_dict:
            limits = tuple(map(float, limits_dict['exposure_time'].split(',')))
            (lower, upper) = limits
            self.exp_time_validator.setRange(lower, upper, 5)

        self._acquisition_mib.bind_value_update('exp_time',
                              self.acq_widget_layout.exp_time_ledit,
                              float, 
                              self.exp_time_validator)

        self._acquisition_mib.\
             bind_value_update('energy',
                               self.acq_widget_layout.energy_ledit,
                               float,
                               self.energy_validator)
        self.acq_widget_layout.energy_ledit.setToolTip(\
             "Energy limits %0.3f : %0.3f" % \
             (self.energy_validator.bottom(), self.energy_validator.top()))

        self._acquisition_mib.\
             bind_value_update('transmission',
                            self.acq_widget_layout.transmission_ledit,
                            float,
                            self.transmission_validator)

        self._acquisition_mib.\
             bind_value_update('resolution',
                               self.acq_widget_layout.resolution_ledit,
                               float,
                               self.resolution_validator)
 
        self.set_tunable_energy(beamline_setup.tunable_wavelength())

    def set_energy(self, energy, wav):
        """
        Descript. :
        """
        if not self.acq_widget_layout.energy_ledit.hasFocus():
            self.acq_widget_layout.energy_ledit.setText(\
                 "%.4f" % float(energy))

    def update_transmission(self, transmission):
        """
        Descript. :
        """
        if self.acq_widget_layout.transmission_ledit.hasFocus():
            self.acq_widget_layout.transmission_ledit.setText(\
                 "%.2f" % float(transmission))

    def update_resolution(self, resolution):
        """
        Descript. :
        """
        if not self.acq_widget_layout.resolution_ledit.hasFocus():
            self.acq_widget_layout.resolution_ledit.setText(\
                 "%.3f" % float(resolution))

    def update_energy_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.energy_validator.setBottom(limits[0])
            self.energy_validator.setTop(limits[1])
            self.acq_widget_layout.energy_ledit.setToolTip(
               "Energy limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_transmission_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.transmission_validator.setBottom(limits[0])
            self.transmission_validator.setTop(limits[1])
            self.acq_widget_layout.transmission_ledit.setToolTip(
               "Transmission limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_resolution_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.resolution_validator.setBottom(limits[0])
            self.resolution_validator.setTop(limits[1])
            self.acq_widget_layout.resolution_ledit.setToolTip(
               "Resolution limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_detector_exp_time_limits(self, limits):
        """
        Descript. :
        """
        if limits:
            self.exp_time_validator.setBottom(limits[0])
            self.exp_time_validator.setTop(limits[1])
            self.acq_widget_layout.exp_time_ledit.setToolTip(
               "Exposure time limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def init_detector_roi_modes(self):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            roi_modes = self._beamline_setup_hwobj._get_roi_modes()
            if (len(roi_modes) > 0 and
                self.acq_widget_layout.detector_roi_mode_combo.count() == 0):
                for roi_mode in roi_modes: 
                    self.acq_widget_layout.detector_roi_mode_combo.\
                         addItem(roi_mode)
                self.acq_widget_layout.detector_roi_mode_label.setEnabled(True)
                self.acq_widget_layout.detector_roi_mode_combo.setEnabled(True)
                #self._acquisition_mib.bind_value_update('detector_roi_mode',
                #               self.acq_widget_layout.detector_roi_mode_combo,
                #               str,
                #               None)

    def update_detector_roi_mode(self, roi_mode_index):
        """
        Descript. :
        """
        if self.acq_widget_layout.detector_roi_mode_combo.count() > 0:
            self.acq_widget_layout.detector_roi_mode_combo.\
                 setCurrentIndex(roi_mode_index)

    def detector_roi_mode_changed(self, roi_mode_index):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            self._beamline_setup_hwobj.detector_hwobj.set_roi_mode(roi_mode_index)
 
    def update_data_model(self, acquisition_parameters, path_template):
        """
        Descript. :
        """
        self._acquisition_parameters = acquisition_parameters
        self._acquisition_mib.set_model(acquisition_parameters)
        self._path_template = path_template
        self.update_num_images(None, acquisition_parameters.num_images)

    def set_tunable_energy(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.energy_ledit.setEnabled(state)

    def use_osc_start(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.osc_start_ledit.setEnabled(state)

    def check_parameter_conflict(self):
        """
        Descript. :
        """
        return len(self._acquisition_mib.validate_all()) > 0
Esempio n. 48
0
class AcquisitionWidget(QtGui.QWidget):
    """
    Descript. :
    """
    def __init__(self,
                 parent=None,
                 name=None,
                 fl=0,
                 acq_params=None,
                 path_template=None,
                 layout='horizontal'):
        """
        Descript. :
        """
        QtGui.QWidget.__init__(self, parent, QtCore.Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------
        self.previous_energy = 0

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.\
                                           AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(
            self._acquisition_parameters)

        if layout == "horizontal":
            self.acq_widget = uic.loadUi(
                os.path.join(
                    os.path.dirname(__file__),
                    "ui_files/Qt4_acquisition_widget_horizontal_layout.ui"))
            self.acq_widget.inverse_beam_cbx.hide()
            self.acq_widget.subwedge_size_label.hide()
            self.acq_widget.subwedge_size_ledit.hide()
        else:
            self.acq_widget = uic.loadUi(
                os.path.join(
                    os.path.dirname(__file__),
                    "ui_files/Qt4_acquisition_widget_vertical_layout.ui"))
        # Layout --------------------------------------------------------------
        self.main_layout = QtGui.QVBoxLayout(self)
        self.main_layout.addWidget(self.acq_widget)
        self.main_layout.setSpacing(0)
        self.main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.main_layout)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget.energies_combo.activated.connect(self.energy_selected)
        self.acq_widget.mad_cbox.toggled.connect(self.use_mad)
        self.acq_widget.inverse_beam_cbx.toggled.connect(
            self.set_use_inverse_beam)
        self.acq_widget.first_image_ledit.textChanged.connect(
            self.first_image_ledit_change)
        self.acq_widget.num_images_ledit.textChanged.connect(
            self.num_images_ledit_change)

        overlap_ledit = self.acq_widget.findChild(QtGui.QLineEdit,
                                                  "overlap_ledit")
        if overlap_ledit is not None:
            overlap_ledit.textChanged.connect(self.overlap_changed)

        self.acq_widget.subwedge_size_ledit.textChanged.connect(
            self.subwedge_size_ledit_change)
        self.acq_widget.osc_start_cbox.toggled.connect(
            self.osc_start_cbox_click)

        # Other ---------------------------------------------------------------
        self.acq_widget.subwedge_size_ledit.setDisabled(True)
        self.acq_widget.energies_combo.setDisabled(True)
        self.acq_widget.energies_combo.addItems(
            ['ip: -', 'pk: -', 'rm1: -', 'rm2: -'])
        self.acq_widget.osc_start_ledit.setEnabled(False)

        self.osc_start_validator = QtGui.QDoubleValidator(
            -10000, 10000, 4, self)
        self.osc_range_validator = QtGui.QDoubleValidator(
            -10000, 10000, 4, self)
        self.kappa_validator = QtGui.QDoubleValidator(0, 360, 4, self)
        self.kappa_phi_validator = QtGui.QDoubleValidator(0, 360, 4, self)
        self.energy_validator = QtGui.QDoubleValidator(0, 25, 4, self)
        self.resolution_validator = QtGui.QDoubleValidator(0, 15, 3, self)
        self.transmission_validator = QtGui.QDoubleValidator(0, 100, 3, self)
        self.exp_time_validator = QtGui.QDoubleValidator(
            0.0001, 10000, 4, self)
        self.first_img_validator = QtGui.QIntValidator(0, 99999, self)
        self.num_img_validator = QtGui.QIntValidator(1, 99999, self)

    def osc_start_cbox_click(self, state):
        """
        Descript. :
        """
        self.update_osc_start(
            self._beamline_setup_hwobj._get_omega_axis_position())
        self.acq_widget.osc_start_ledit.setEnabled(state)

    def update_osc_start(self, new_value):
        """
        Descript. :
        """
        if not self.acq_widget.osc_start_cbox.isChecked():
            osc_start_value = 0
            try:
                osc_start_value = round(float(new_value), 2)
            except TypeError:
                pass
            self.acq_widget.osc_start_ledit.setText("%.2f" % osc_start_value)
            self._acquisition_parameters.osc_start = osc_start_value

    def update_kappa(self, new_value):
        self.acq_widget.kappa_ledit.setText("%.2f" % float(new_value))
        #self._acquisition_parameters.kappa = float(new_value)

    def update_kappa_phi(self, new_value):
        self.acq_widget.kappa_phi_ledit.setText("%.2f" % float(new_value))
        #self._acquisition_parameters.kappa_phi = float(new_value)

    def use_osc_start(self, state):
        """
        Descript. :
        """
        self.acq_widget.osc_start_cbox.setChecked(state)
        self.acq_widget.osc_start_cbox.setDisabled(state)

    def use_kappa(self, state):
        if self._beamline_setup.diffractometer_hwobj.get_head_type() == \
           self._beamline_setup.diffractometer_hwobj.PLATE:
            state = False
        self.acq_widget_layout.kappa_ledit.setEnabled(state)

    def use_kappa_phi(self, state):
        if self._beamline_setup.diffractometer_hwobj.get_head_type() == \
           self._beamline_setup.diffractometer_hwobj.PLATE:
            state = False
        self.acq_widget_layout.kappa_phi_ledit.setEnabled(state)

    def set_beamline_setup(self, beamline_setup):
        """
        Descript. :
        """
        self._beamline_setup_hwobj = beamline_setup
        limits_dict = self._beamline_setup_hwobj.get_acquisition_limit_values()

        if 'osc_range' in limits_dict:
            limits = tuple(map(float, limits_dict['osc_range'].split(',')))
            (lower, upper) = limits
            self.osc_start_validator.setRange(lower, upper, 4)
            self.osc_range_validator.setRange(lower, upper, 4)

        self._acquisition_mib.bind_value_update(
            'osc_start', self.acq_widget.osc_start_ledit, float,
            self.osc_start_validator)

        self._acquisition_mib.bind_value_update(
            'osc_range', self.acq_widget.osc_range_ledit, float,
            self.osc_range_validator)

        if self.acq_widget.findChild(QtGui.QLineEdit, "kappa_ledit"):
            if 'kappa' in limits_dict:
                limits = tuple(map(float, limits_dict['kappa'].split(',')))
                (lower, upper) = limits
                self.kappa_validator.setRange(lower, upper, 4)
            self._acquisition_mib.bind_value_update(
                'kappa', self.acq_widget.kappa_ledit, float,
                self.kappa_validator)

        if self.acq_widget.findChild(QtGui.QLineEdit, "kappa_phi_ledit"):
            if 'kappa_phi' in limits_dict:
                limits = tuple(map(float, limits_dict['kappa_phi'].split(',')))
                (lower, upper) = limits
                self.kappa_phi_validator.setRange(lower, upper, 4)
            self._acquisition_mib.bind_value_update(
                'kappa_phi', self.acq_widget.kappa_phi_ledit, float,
                self.kappa_phi_validator)

        if 'exposure_time' in limits_dict:
            limits = tuple(map(float, limits_dict['exposure_time'].split(',')))
            (lower, upper) = limits
            self.exp_time_valdidator.setRange(lower, upper, 5)

        self._acquisition_mib.bind_value_update('exp_time',
                                                self.acq_widget.exp_time_ledit,
                                                float, self.exp_time_validator)

        if 'number_of_images' in limits_dict:
            limits = tuple(map(int,
                               limits_dict['number_of_images'].split(',')))
            (lower, upper) = limits
            self.num_img_valdidator.setRange(lower, upper)
            self.first_img_valdidator.setRange(lower, upper)

        self._acquisition_mib.bind_value_update(
            'first_image', self.acq_widget.first_image_ledit, int,
            self.first_img_validator)

        self._acquisition_mib.bind_value_update(
            'num_images', self.acq_widget.num_images_ledit, int,
            self.num_img_validator)

        num_passes = self.acq_widget.findChild(QtGui.QLineEdit,
                                               "num_passes_ledit")

        if num_passes:
            self._acquisition_mib.\
                bind_value_update('num_passes', num_passes, int,
                                  QtGui.QIntValidator(1, 1000, self))

        overlap_ledit = self.acq_widget.findChild(QtGui.QLineEdit,
                                                  "overlap_ledit")

        if overlap_ledit:
            self._acquisition_mib.\
                bind_value_update('overlap', overlap_ledit, float,
                                  QtGui.QDoubleValidator(-1000, 1000, 2, self))

        self._acquisition_mib.\
             bind_value_update('energy',
                               self.acq_widget.energy_ledit,
                               float,
                               self.energy_validator)

        self._acquisition_mib.\
             bind_value_update('transmission',
                               self.acq_widget.transmission_ledit,
                               float,
                               self.transmission_validator)

        self._acquisition_mib.\
             bind_value_update('resolution',
                               self.acq_widget.resolution_ledit,
                               float,
                               self.resolution_validator)

        self._acquisition_mib.\
             bind_value_update('inverse_beam',
                               self.acq_widget.inverse_beam_cbx,
                               bool,
                               None)

        self._acquisition_mib.\
             bind_value_update('shutterless',
                               self.acq_widget.shutterless_cbx,
                               bool,
                               None)
        """self.acq_widget_layout.osc_start_ledit.setToolTip(\
               "Oscillation start limits %0.2f : %0.2f" %(\
               self.osc_start_validator.bottom(),
               self.osc_start_validator.top()))

        self.acq_widget_layout.osc_range_ledit.setToolTip(\
               "Oscillation range limits %0.2f : %0.2f" %(\
               self.osc_ra_validator.bottom(),
               self.osc_start_validator.top()))"""

        self.set_tunable_energy(beamline_setup.tunable_wavelength())

        has_shutter_less = self._beamline_setup_hwobj.detector_has_shutterless(
        )
        self.acq_widget.shutterless_cbx.setEnabled(has_shutter_less)
        self.acq_widget.shutterless_cbx.setChecked(has_shutter_less)

        if self._beamline_setup_hwobj.disable_num_passes():
            num_passes = self.acq_widget.findChild(QtGui.QLineEdit,
                                                   "num_passes_ledit")
            if num_passes:
                num_passes.setDisabled(True)

    def first_image_ledit_change(self, new_value):
        """
        Descript. :
        """
        if str(new_value).isdigit():
            self._path_template.start_num = int(new_value)
            widget = self.acq_widget.first_image_ledit
            self.emit(QtCore.SIGNAL('pathTemplateChanged'), widget, new_value)

    def num_images_ledit_change(self, new_value):
        """
        Descript. :
        """
        if str(new_value).isdigit():
            self._path_template.num_files = int(new_value)
            widget = self.acq_widget.num_images_ledit
            self.emit(QtCore.SIGNAL('pathTemplateChanged'), widget, new_value)

    def overlap_changed(self, new_value):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj:
            has_shutter_less = self._beamline_setup_hwobj.detector_has_shutterless(
            )
        else:
            has_shutter_less = True

        if has_shutter_less:
            try:
                new_value = float(new_value)
            except ValueError:
                pass

            if new_value != 0:
                self.acq_widget.shutterless_cbx.setEnabled(False)
                self.acq_widget.shutterless_cbx.setChecked(False)
                self._acquisition_parameters.shutterless = False
            else:
                self.acq_widget.shutterless_cbx.setEnabled(True)
                self.acq_widget.shutterless_cbx.setChecked(True)
                self._acquisition_parameters.shutterless = True

    def use_mad(self, state):
        """
        Descript. :
        """
        self.acq_widget.energies_combo.setEnabled(state)
        if state:
            (name, energy) = self.get_mad_energy()

            if energy != 0:
                self.set_energy(energy, 0)

            self.emit(QtCore.SIGNAL('mad_energy_selected'), name, energy,
                      state)
        else:
            self.set_energy(self.previous_energy, 0)
            energy = self._beamline_setup_hwobj.energy_hwobj.getCurrentEnergy()
            self.emit(QtCore.SIGNAL('mad_energy_selected'), '',
                      self.previous_energy, state)

    def set_use_inverse_beam(self, state):
        """
        Descript. :
        """
        if state:
            self.acq_widget.subwedge_size_ledit.setEnabled(True)
        else:
            self.acq_widget.subwedge_size_ledit.setDisabled(True)

    def use_inverse_beam(self):
        """
        Descript. :
        """
        return self.acq_widget.inverse_beam_cbx.checkState == QtCore.Qt.Checked

    def get_num_subwedges(self):
        """
        Descript. :
        """
        return int(self.acq_widget.subwedge_size_ledit.text())

    def subwedge_size_ledit_change(self, new_value):
        """
        Descript. :
        """
        if int(new_value) > self._acquisition_parameters.num_images:
            Qt4_widget_colors.set_widget_color(\
                 self.acq_widget.subwedge_size_ledit,
                 Qt4_widget_colors.LIGHT_RED)
        else:
            Qt4_widget_colors.set_widget_color(
                self.acq_widget.subwedge_size_ledit, Qt4_widget_colors.WHITE)

    def get_mad_energy(self):
        """
        Descript. :
        """
        energy_str = str(self.acq_widget.energies_combo.currentText())
        (name, value) = energy_str.split(':')

        name = name.strip()
        value = value.strip()
        value = 0 if (value == '-') else value

        return (name, value)

    def set_energies(self, energy_scan_result):
        """
        Descript. :
        """
        self.acq_widget.energies_combo.clear()

        inflection = ('ip: %.4f' % energy_scan_result.inflection) if \
                     energy_scan_result.inflection else 'ip: -'

        peak = ('pk: %.4f' % energy_scan_result.peak) if \
               energy_scan_result.peak else 'pk: -'

        first_remote = ('rm1: %.4f' % energy_scan_result.first_remote) if \
                       energy_scan_result.first_remote else 'rm1: -'

        second_remote = ('rm2: %.4f' % energy_scan_result.second_remote) if \
                        energy_scan_result.second_remote else 'rm2: -'

        self.acq_widget.energies_combo.\
             addItems([inflection, peak, first_remote, second_remote])

    def energy_selected(self, index):
        """
        Descript. :
        """
        if self.acq_widget.mad_cbox.isChecked():
            (name, energy) = self.get_mad_energy()
            if energy != 0:
                self.set_energy(energy, 0)

            self.emit(QtCore.SIGNAL('mad_energy_selected'), name, energy, True)

    def set_energy(self, energy, wav):
        """
        Descript. :
        """
        self.acq_widget.energy_ledit.setText("%.4f" % float(energy))

    def update_transmission(self, transmission):
        """
        Descript. :
        """
        self.acq_widget.transmission_ledit.setText("%.2f" %
                                                   float(transmission))

    def update_resolution(self, resolution):
        """
        Descript. :
        """
        self.acq_widget.resolution_ledit.setText("%.3f" % float(resolution))

    def update_energy_limits(self, limits):
        if limits:
            self.energy_validator.setBottom(limits[0])
            self.energy_validator.setTop(limits[1])
            self.acq_widget_layout.energy_ledit.setToolTip(\
               "Energy limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_transmission_limits(self, limits):
        if limits:
            self.transmission_validator.setBottom(limits[0])
            self.transmission_validator.setTop(limits[1])
            self.acq_widget_layout.transmission_ledit.setToolTip(\
               "Transmission limits %0.3f : %0.3f" %(limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_resolution_limits(self, limits):
        if limits:
            self.resolution_validator.setBottom(limits[0])
            self.resolution_validator.setTop(limits[1])
            self.acq_widget_layout.resolution_ledit.setToolTip(
                "Resolution limits %0.3f : %0.3f" % (limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_detector_exp_time_limits(self, limits):
        if limits:
            self.exp_time_validator.setRange(limits[0], limits[1], 4)
            self.acq_widget_layout.exp_time_ledit.setToolTip(
                "Exposure time limits %0.3f : %0.3f" % (limits[0], limits[1]))
            self._acquisition_mib.validate_all()

    def update_osc_range_limits(self, exp_time):
        osc_range = 40.0 * exp_time
        self.osc_range_validator.setRange(0, osc_range, 4)
        self.acq_widget_layout.osc_range_ledit.setToolTip(
            "Oscillation range limits %0.2f : %0.2f" % (0, osc_range))
        self._acquisition_mib.validate_all()

    def update_data_model(self, acquisition_parameters, path_template):
        """
        Descript. :
        """
        self._acquisition_parameters = acquisition_parameters
        self._path_template = path_template
        self._acquisition_mib.set_model(acquisition_parameters)

        #Update mad widgets
        mad = True if self._path_template.mad_prefix != '' else False

        if mad:
            mad_prefix = self._path_template.mad_prefix
            index = MAD_ENERGY_COMBO_NAMES[mad_prefix]
            self.acq_widget.energies_combo.setCurrentIndex(index)
            self.acq_widget.mad_cbox.setChecked(True)
            self.acq_widget.energies_combo.setEnabled(True)
        else:
            self.acq_widget.mad_cbox.setChecked(False)
            self.acq_widget.energies_combo.setEnabled(False)
            self.acq_widget.energies_combo.setCurrentIndex(0)

    def set_tunable_energy(self, state):
        """
        Descript. :
        """
        self.acq_widget.energy_ledit.setEnabled(state)
        self.acq_widget.mad_cbox.setEnabled(state)
        self.acq_widget.energies_combo.setEnabled(state)

    def disable_inverse_beam(self, state):
        """
        Descript. :
        """
        if state:
            self.acq_widget.inverse_beam_cbx.hide()
            self.acq_widget.subwedge_size_label.hide()
            self.acq_widget.subwedge_size_ledit.hide()
        else:
            self.acq_widget.inverse_beam_cbx.show()
            self.acq_widget.subwedge_size_label.show()
            self.acq_widget.subwedge_size_ledit.show()

    def hide_aperture(self, state):
        """
        Descript. :
        """
        pass
Esempio n. 49
0
class AcquisitionWidget(QWidget):
  
    acqParametersChangedSignal = pyqtSignal(list)
    madEnergySelectedSignal = pyqtSignal(str, float, bool)

    def __init__(self, parent=None, name=None, fl=0, acq_params=None,
                 path_template=None, layout='horizontal'):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        
        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None
        self._diffractometer_hwobj = None

        # Internal variables --------------------------------------------------
        self.previous_energy = 0

        # If the acq. widget is used with grids then total osc range is not
        # equal to num_images * osc_range, but num_images_per_line * osc_range
        # For grids the osc total range is updated when a grid is selected

        self.grid_mode = False

        # Properties ---------------------------------------------------------- 

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.\
                                           AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters)

        if layout == "horizontal":
            self.acq_widget_layout = loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_horizontal_layout.ui"))
            self.use_osc_start(False)
        else:
            self.acq_widget_layout = loadUi(os.path.join(\
                 os.path.dirname(__file__),
                 "ui_files/Qt4_acquisition_widget_vertical_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QVBoxLayout(self)
        __main_vlayout.addWidget(self.acq_widget_layout)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget_layout.osc_start_cbox.stateChanged.connect(\
             self.fix_osc_start)
        self.acq_widget_layout.exp_time_ledit.textChanged.connect(\
             self.exposure_time_ledit_changed)
        self.acq_widget_layout.first_image_ledit.textChanged.connect(\
             self.first_image_ledit_change)
        self.acq_widget_layout.num_images_ledit.textChanged.connect(\
             self.num_images_ledit_change)
        self.acq_widget_layout.detector_roi_mode_combo.activated.connect(\
             self.detector_roi_mode_changed)
        self.acq_widget_layout.energies_combo.activated.connect(\
             self.energy_selected)
        self.acq_widget_layout.mad_cbox.toggled.connect(\
             self.use_mad)
        self.acq_widget_layout.osc_start_ledit.textEdited.connect(\
             self.osc_start_ledit_changed)
        self.acq_widget_layout.osc_range_ledit.textEdited.connect(\
             self.osc_range_per_frame_ledit_changed)
        self.acq_widget_layout.osc_total_range_ledit.textEdited.connect(\
             self.osc_total_range_ledit_changed)
        self.acq_widget_layout.energy_ledit.textEdited.connect(\
             self.energy_ledit_changed)
        self.acq_widget_layout.transmission_ledit.textEdited.connect(\
             self.transmission_ledit_changed)
        self.acq_widget_layout.resolution_ledit.textEdited.connect(\
             self.resolution_ledit_changed)
        self.acq_widget_layout.kappa_ledit.textEdited.connect(\
             self.kappa_ledit_changed)
        self.acq_widget_layout.kappa_phi_ledit.textEdited.connect(\
             self.kappa_phi_ledit_changed)
        
        if self.acq_widget_layout.findChild(QLineEdit, "overlap_ledit"):
            self.acq_widget_layout.overlap_ledit.textChanged.connect(\
                 self.overlap_changed)
        if self.acq_widget_layout.findChild(QCheckBox, "max_osc_range_cbx"):
            self.acq_widget_layout.max_osc_range_cbx.toggled.connect(\
                 self.max_osc_range_toggled)

        # Other --------------------------------------------------------------- 
        self.value_changed_list = []

        self.acq_widget_layout.energies_combo.setDisabled(True)
        self.acq_widget_layout.energies_combo.addItems(\
             ['ip: -', 'pk: -', 'rm1: -', 'rm2: -'])

        self.osc_start_validator = QDoubleValidator(\
             -10000, 10000, 4, self.acq_widget_layout.osc_start_ledit)
        self.osc_range_per_frame_validator = QDoubleValidator(\
             0, 10000, 4, self.acq_widget_layout.osc_range_ledit)
        self.osc_total_range_validator = QDoubleValidator(\
             0, 10000, 4, self.acq_widget_layout.osc_total_range_ledit)
        self.kappa_validator = QDoubleValidator(\
             0, 360, 4, self.acq_widget_layout.kappa_ledit)
        self.kappa_phi_validator = QDoubleValidator(\
             0, 360, 4, self.acq_widget_layout.kappa_phi_ledit)
        self.energy_validator = QDoubleValidator(\
             4, 25, 4, self.acq_widget_layout.energy_ledit)
        self.resolution_validator = QDoubleValidator(\
             0, 15, 3, self.acq_widget_layout.resolution_ledit)
        self.transmission_validator = QDoubleValidator(\
             0, 100, 3, self.acq_widget_layout.transmission_ledit)
        self.exp_time_validator = QDoubleValidator(\
             0.0001, 10000, 7, self.acq_widget_layout.exp_time_ledit)
        self.first_img_validator = QIntValidator(\
             0, 99999, self.acq_widget_layout.first_image_ledit)
        self.num_img_validator = QIntValidator(\
             1, 9999999, self.acq_widget_layout.num_images_ledit) 
        self.acq_widget_layout.detector_roi_mode_label.setEnabled(False)
        self.acq_widget_layout.detector_roi_mode_combo.setEnabled(False)

    def use_max_osc_range(self, state):
        self.acq_widget_layout.max_osc_range_cbx.setEnabled(state)

    def fix_osc_start(self, state):
        """
        Fix osc start, so the lineEdit do not change when osc is changed
        """
        self.acq_widget_layout.osc_start_ledit.setEnabled(state)

    def update_osc_start(self, new_value):
        """
        Updates osc line edit
        """
        if "osc_start" not in self.value_changed_list and \
           not self.acq_widget_layout.osc_start_ledit.hasFocus() and \
           not self.acq_widget_layout.osc_start_cbox.isChecked():
            osc_start_value = 0
            try:
               osc_start_value = round(float(new_value), 2)
            except TypeError:
               pass

            self.acq_widget_layout.osc_start_ledit.setText(str(osc_start_value))
            self._acquisition_parameters.osc_start = osc_start_value

            #self.update_osc_total_range_limits()
            #self.update_num_images_limits()

    def osc_start_ledit_changed(self, osc_start):
        """Fixes osc start edit"""
        if "osc_start" not in self.value_changed_list:
            self.value_changed_list.append("osc_start")
        self.update_osc_total_range_limits()
        self.update_num_images_limits()
        self.emit_acq_parameters_changed()

    def update_osc_start_limits(self):
        """In the plate mode sets osc start limits"""
        self.update_osc_total_range_limits()
        self.update_num_images_limits()

    def osc_range_per_frame_ledit_changed(self, new_value):
        self.update_osc_total_range()
        self.update_num_images_limits()
        self.update_exp_time_limits()
        self.emit_acq_parameters_changed()

    def update_osc_range_per_frame_limits(self):
        try:
            max_osc_speed = self._diffractometer_hwobj.get_osc_max_speed()
            top_limit = max_osc_speed * float(self.acq_widget_layout.exp_time_ledit.text())

            self.osc_range_per_frame_validator.setTop(top_limit)
            tool_tip = "Oscillation range per frame limits 0 : " +\
                       "%0.4f\n4 digits precision." % top_limit

            self.acq_widget_layout.osc_range_ledit.setToolTip(tool_tip)
            self._acquisition_mib.validate_all()
        except:
            pass

    def update_osc_total_range(self):
        self.acq_widget_layout.osc_total_range_ledit.blockSignals(True)
        if not self.grid_mode:
            try:
                self.acq_widget_layout.osc_total_range_ledit.setText(str(\
                     float(self.acq_widget_layout.osc_range_ledit.text()) * \
                     float(self.acq_widget_layout.num_images_ledit.text())))
            except:
                pass
        self.acq_widget_layout.osc_total_range_ledit.blockSignals(False)

    def update_total_exp_time(self):
        try:
            self.acq_widget_layout.total_exp_time_ledit.setText("%.2f" % \
                 (float(self.acq_widget_layout.exp_time_ledit.text()) * \
                  float(self.acq_widget_layout.num_images_ledit.text())))
        except:
            pass

    def osc_total_range_ledit_changed(self, new_value):
        if not self.grid_mode:
            try:
                num_images = int(float(new_value) / \
                   float(self.acq_widget_layout.osc_range_ledit.text()))
                self.acq_widget_layout.num_images_ledit.blockSignals(True)
                self.acq_widget_layout.num_images_ledit.setText("%d" % num_images)
                self._acquisition_parameters.num_images = num_images
                self.acq_widget_layout.num_images_ledit.blockSignals(False)
            except:
                pass
            self.emit_acq_parameters_changed()

    def update_osc_total_range_limits(self, num_images=None):
        """Updates osc totol range. Limits are changed if a plate is used.
           - For simple oscillation osc_range is defined by osc_start and 
             osc_start top limit.
           - For mesh osc_range is defined by number of images per line
             and osc in the middle of mesh  
        """
        if self._diffractometer_hwobj.in_plate_mode():
            if hasattr(self.parent(), "set_osc_total_range"):
                self.parent().set_osc_total_range(num_images)
                self._acquisition_mib.validate_all()

    def update_exp_time_limits(self):
        try:
           exp_time_limits = self._beamline_setup_hwobj.detector_hwobj.get_exposure_time_limits()
           max_osc_speed = self._diffractometer_hwobj.get_osc_max_speed()
           top_limit = float(self.acq_widget_layout.osc_range_ledit.text()) / max_osc_speed
           limits = (max(exp_time_limits[0], top_limit), exp_time_limits[1]) 

           self.update_detector_exp_time_limits(limits)
        except:
           pass

    def update_kappa(self, new_value):
        """
        Updates kappa value
        """
        if not self.acq_widget_layout.kappa_ledit.hasFocus() and \
           new_value is not None:
            self.acq_widget_layout.kappa_ledit.setText(str(new_value))
            self.emit_acq_parameters_changed()

    def update_kappa_phi(self, new_value):
        """
        Descript. :
        """
        if not self.acq_widget_layout.kappa_phi_ledit.hasFocus() and \
           new_value:
            self.acq_widget_layout.kappa_phi_ledit.setText(str(new_value))
            self.emit_acq_parameters_changed()

    def use_osc_start(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.osc_start_cbox.setVisible(state)
        self.acq_widget_layout.osc_start_label.setVisible(not state)
        self.acq_widget_layout.osc_start_ledit.setEnabled(not state)

    def use_kappa(self, state):
        """
        Descript. :
        """
        if self._diffractometer_hwobj is not None:
            if self._diffractometer_hwobj.in_plate_mode():
                state = False
        self.acq_widget_layout.kappa_label.setEnabled(state)
        self.acq_widget_layout.kappa_ledit.setEnabled(state)
        self.acq_widget_layout.kappa_phi_label.setEnabled(state)
        self.acq_widget_layout.kappa_phi_ledit.setEnabled(state)

    def set_beamline_setup(self, beamline_setup):
        """
        Descript. :
        """
        self._beamline_setup_hwobj = beamline_setup
        limits_dict = self._beamline_setup_hwobj.get_acquisition_limit_values()
        self._diffractometer_hwobj = self._beamline_setup_hwobj.diffractometer_hwobj
 
        
        if 'osc_range' in limits_dict:
            limits = tuple(map(float, limits_dict['osc_range'].split(',')))
            (lower, upper) = limits
            self.osc_start_validator.setRange(lower, upper, 4)
            self.osc_range_per_frame_validator.setRange(lower, upper, 4)
            self.osc_total_range_validator.setRange(lower, upper, 4)

        self._acquisition_mib.bind_value_update('osc_start', 
                                                self.acq_widget_layout.osc_start_ledit,
                                                float, 
                                                self.osc_start_validator)

        self._acquisition_mib.bind_value_update('osc_range', 
                                                self.acq_widget_layout.osc_range_ledit,
                                                float, 
                                                self.osc_range_per_frame_validator)

        self._acquisition_mib.bind_value_update('osc_total_range',
                                                self.acq_widget_layout.osc_total_range_ledit,
                                                float,
                                                self.osc_total_range_validator)

        if 'kappa' in limits_dict:
            limits = tuple(map(float, limits_dict['kappa'].split(',')))
            (lower, upper) = limits
            self.kappa_validator.setRange(lower, upper, 4)
        self._acquisition_mib.bind_value_update('kappa', 
                                                self.acq_widget_layout.kappa_ledit,
                                                float,
                                                self.kappa_validator)

        if 'kappa_phi' in limits_dict:
            limits = tuple(map(float, limits_dict['kappa_phi'].split(',')))
            (lower, upper) = limits
            self.kappa_phi_validator.setRange(lower, upper, 4)
        self._acquisition_mib.bind_value_update('kappa_phi',     
                                                self.acq_widget_layout.kappa_phi_ledit,
                                                float,
                                                self.kappa_phi_validator)

        if 'exposure_time' in limits_dict:
            limits = tuple(map(float, limits_dict['exposure_time'].split(',')))
            (lower, upper) = limits
            self.exp_time_validator.setRange(lower, upper, 6)
        
        self._acquisition_mib.bind_value_update('exp_time', 
                                                self.acq_widget_layout.exp_time_ledit,
                                                float, 
                                                self.exp_time_validator)

        if 'number_of_images' in limits_dict:
            limits = tuple(map(float, limits_dict['number_of_images'].split(',')))
            (lower, upper) = limits
            self.num_img_validator.setRange(lower, upper)
            self.first_img_validator.setRange(lower, upper)
        
        self._acquisition_mib.bind_value_update('first_image', 
                                                self.acq_widget_layout.first_image_ledit,
                                                int, 
                                                self.first_img_validator)

        self._acquisition_mib.bind_value_update('num_images', 
                                                self.acq_widget_layout.num_images_ledit,
                                                int, 
                                                self.num_img_validator)

        num_passes = self.acq_widget_layout.findChild(QLineEdit, "num_passes_ledit")

        if num_passes:
            self._acquisition_mib.\
                bind_value_update('num_passes', num_passes, int,
                                  QIntValidator(1, 1000, self))

        overlap_ledit = self.acq_widget_layout.findChild(QLineEdit, "overlap_ledit")

        if overlap_ledit:
            self._acquisition_mib.\
                bind_value_update('overlap', overlap_ledit, float,
                                  QDoubleValidator(-1000, 1000, 2, self))

        self._acquisition_mib.\
             bind_value_update('energy',
                               self.acq_widget_layout.energy_ledit,
                               float,
                               self.energy_validator)
        self.update_energy_limits((self.energy_validator.bottom(),
                                   self.energy_validator.top()))

        self._acquisition_mib.\
             bind_value_update('transmission',
                               self.acq_widget_layout.transmission_ledit,
                               float,
                               self.transmission_validator)
        self.update_transmission_limits((self.transmission_validator.bottom(),
                                         self.transmission_validator.top()))

        self._acquisition_mib.\
             bind_value_update('resolution',
                               self.acq_widget_layout.resolution_ledit,
                               float,
                               self.resolution_validator)
        #self.update_resolution_limits((self.resolution_validator.bottom(),
        #                               self.resolution_validator.top()))

        self._acquisition_mib.\
             bind_value_update('shutterless',
                               self.acq_widget_layout.shutterless_cbx,
                               bool,
                               None)

        self.set_tunable_energy(beamline_setup.tunable_wavelength())

        has_shutter_less = self._beamline_setup_hwobj.detector_has_shutterless()
        self.acq_widget_layout.shutterless_cbx.setEnabled(has_shutter_less)
        self.acq_widget_layout.shutterless_cbx.setChecked(has_shutter_less)

        if self._beamline_setup_hwobj.disable_num_passes():
            num_passes = self.acq_widget_layout.findChild(QLineEdit, "num_passes_ledit")
            if num_passes:
                num_passes.setDisabled(True)

        self.init_detector_roi_modes()

    def first_image_ledit_change(self, new_value):
        """
        Descript. :
        """
        #if str(new_value).isdigit():
        #    #self._path_template.start_num = int(new_value)
        #    #widget = self.acq_widget_layout.first_image_ledit
        self.emit_acq_parameters_changed()

    def exposure_time_ledit_changed(self, new_values):
        """If the exposure time changes we have to check the osc speed
           and if necessary update osc range per frame
        """
        self.update_osc_range_per_frame_limits()
        self.update_osc_total_range_limits()
        self.update_total_exp_time()
        self.emit_acq_parameters_changed()

    def num_images_ledit_change(self, new_value):
        """
        Descript. :
        """
        if str(new_value).isdigit():
            #self._path_template.num_files = int(new_value)
            self.update_osc_range_per_frame_limits()
            self.update_osc_total_range_limits()
            self.update_osc_total_range()
            self.update_total_exp_time()
        self.emit_acq_parameters_changed()

    def overlap_changed(self, new_value):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj:
            has_shutter_less = self._beamline_setup_hwobj.detector_has_shutterless()
        else:
            has_shutter_less = True

        if has_shutter_less:
            try:
                new_value = float(new_value)
            except ValueError:
                pass

            if new_value != 0:
                self.acq_widget_layout.shutterless_cbx.setEnabled(False)
                self.acq_widget_layout.shutterless_cbx.setChecked(False)
                self._acquisition_parameters.shutterless = False
            else:
                self.acq_widget_layout.shutterless_cbx.setEnabled(True)
                self.acq_widget_layout.shutterless_cbx.setChecked(True)
                self._acquisition_parameters.shutterless = True

    def use_mad(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.energies_combo.setEnabled(state)
        if state:
            (name, energy) = self.get_mad_energy()

            if energy != 0:
                self.update_energy(energy)
            self.madEnergySelectedSignal.emit(name, energy, state)
        else:
            self.update_energy(self.previous_energy)
            energy = self._beamline_setup_hwobj.energy_hwobj.getCurrentEnergy()
            self.madEnergySelectedSignal.emit('', self.previous_energy, state)

    def max_osc_range_toggled(self, state):
        self.update_osc_total_range_limits()

    def get_mad_energy(self):
        """
        Descript. :
        """
        energy_str = str(self.acq_widget_layout.energies_combo.currentText())
        (name, value) = energy_str.split(':')
        
        name = name.strip()
        value = value.strip()
        value = 0 if (value == '-') else float(value)

        return (name, value)

    def set_energies(self, energy_scan_result):
        """
        Descript. :
        """
        self.acq_widget_layout.energies_combo.clear()

        inflection = ('ip: %.4f' % energy_scan_result.inflection) if \
                     energy_scan_result.inflection else 'ip: -'

        peak = ('pk: %.4f' % energy_scan_result.peak) if \
               energy_scan_result.peak else 'pk: -'

        first_remote = ('rm1: %.4f' % energy_scan_result.first_remote) if \
                       energy_scan_result.first_remote else 'rm1: -'

        second_remote = ('rm2: %.4f' % energy_scan_result.second_remote) if \
                        energy_scan_result.second_remote else 'rm2: -'

        self.acq_widget_layout.energies_combo.\
             addItems([inflection, peak, first_remote, second_remote])

    def energy_selected(self, index):
        """
        Descript. :
        """
        if self.acq_widget_layout.mad_cbox.isChecked():
            (name, energy) = self.get_mad_energy()
            if energy != 0:
                self.update_energy(energy)

            self.madEnergySelectedSignal.emit(name, energy, True)

    def energy_ledit_changed(self, new_value):
        if "energy" not in self.value_changed_list:
            self.value_changed_list.append("energy")
        self.emit_acq_parameters_changed()

    def update_energy(self, energy, wav=None):
        """
        Descript. :
        """
        if "energy" not in self.value_changed_list and \
           not self.acq_widget_layout.energy_ledit.hasFocus():
            self.acq_widget_layout.energy_ledit.setText(str(energy))
        self.emit_acq_parameters_changed()

    def transmission_ledit_changed(self, transmission):
        if "transmission" not in self.value_changed_list:
            self.value_changed_list.append("transmission")
        self.emit_acq_parameters_changed()

    def update_transmission(self, transmission):
        if "transmission" not in self.value_changed_list:
            self.acq_widget_layout.transmission_ledit.setText(str(transmission))
        self.emit_acq_parameters_changed()
           
    def resolution_ledit_changed(self, resolution):
        if "resolution" not in self.value_changed_list:
            self.value_changed_list.append("resolution")
        self.emit_acq_parameters_changed()

    def update_resolution(self, resolution):
        if "resolution" not in self.value_changed_list and \
           not self.acq_widget_layout.resolution_ledit.hasFocus():
            self.acq_widget_layout.resolution_ledit.setText(str(resolution))
        self.emit_acq_parameters_changed()

    def update_energy_limits(self, limits):
        if limits:
            self.energy_validator.setBottom(limits[0])
            self.energy_validator.setTop(limits[1])
            self.acq_widget_layout.energy_ledit.setToolTip(\
               "Energy limits %0.4f : %0.4f keV\n" % \
               (limits[0], limits[1]) + \
               "4 digits precision.")
            self._acquisition_mib.validate_all()

    def update_transmission_limits(self, limits):
        if limits:
            self.transmission_validator.setBottom(limits[0])
            self.transmission_validator.setTop(limits[1])
            self.acq_widget_layout.transmission_ledit.setToolTip(\
               "Transmission limits %0.2f : %0.2f %%\n" % \
               (limits[0], limits[1]) + \
               "2 digits precision.")
            self._acquisition_mib.validate_all()

    def update_resolution_limits(self, limits):
        if limits:
            self.resolution_validator.setBottom(limits[0])
            self.resolution_validator.setTop(limits[1])
            self.acq_widget_layout.resolution_ledit.setToolTip(
               "Resolution limits %0.4f : %0.4f %s\n" % \
               (limits[0], limits[1], chr(197)) + 
               "4 digits precision.")
            self._acquisition_mib.validate_all()

    def update_detector_exp_time_limits(self, limits):
        if limits:
            self.exp_time_validator.setRange(limits[0], limits[1], 6)
            self.acq_widget_layout.exp_time_ledit.setToolTip(
               "Exposure time limits %0.6f s : %0.1f s\n" % \
               (limits[0], limits[1]) + \
               "6 digits precision.")
            self._acquisition_mib.validate_all()

    def update_num_images_limits(self, num_images_limits=None):
        """Updates number of images limit. Method used if plate mode.
        """

        self._acquisition_mib.validate_all()

        return
        if self._diffractometer_hwobj.in_plate_mode():
           if num_images_limits is None:
               try:
                  osc_start = float(self.acq_widget_layout.osc_start_ledit.text())
                  osc_range = float(self.acq_widget_layout.osc_range_ledit.text())
               except ValueError:
                  return

               if osc_range == 0:
                   return

               num_images_limits = int((self.osc_start_validator.top() - \
                                        osc_start) / osc_range)

           self.num_img_validator.setTop(num_images_limits)
           self.acq_widget_layout.num_images_ledit.setToolTip(\
               "Number of images limits : %d" % num_images_limits)
           self._acquisition_mib.validate_all()

    def init_detector_roi_modes(self):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            roi_modes = self._beamline_setup_hwobj.detector_hwobj.get_roi_modes()
            if (len(roi_modes) > 0 and
                self.acq_widget_layout.detector_roi_mode_combo.count() == 0):
                for roi_mode in roi_modes:
                    self.acq_widget_layout.detector_roi_mode_combo.\
                         addItem(roi_mode)
                self.acq_widget_layout.detector_roi_mode_label.setEnabled(True)
                self.acq_widget_layout.detector_roi_mode_combo.setEnabled(True)
                #self._acquisition_mib.bind_value_update('detector_roi_mode',
                #               self.acq_widget_layout.detector_roi_mode_combo,
                ##               str,
                #               None)

    def update_detector_roi_mode(self, roi_mode_index):
        """
        Descript. :
        """
        if roi_mode_index is not None and \
           self.acq_widget_layout.detector_roi_mode_combo.count() > 0:
            self.acq_widget_layout.detector_roi_mode_combo.\
                 setCurrentIndex(roi_mode_index)

    def detector_roi_mode_changed(self, roi_mode_index):
        """
        Descript. :
        """
        if self._beamline_setup_hwobj is not None:
            self._beamline_setup_hwobj.detector_hwobj.set_roi_mode(roi_mode_index)

    def kappa_ledit_changed(self, new_value):
        if "kappa" not in self.value_changed_list:
            self.value_changed_list.append("kappa")
        self.emit_acq_parameters_changed()

    def kappa_phi_ledit_changed(self, new_value):
        if "kappa_phi" not in self.value_changed_list:
            self.value_changed_list.append("kappa_phi")
        self.emit_acq_parameters_changed()

    def update_data_model(self, acquisition_parameters, path_template):
        """
        Descript. :
        """
        self._acquisition_parameters = acquisition_parameters
        self._path_template = path_template        
        self._acquisition_mib.set_model(acquisition_parameters)
        
        #Update mad widgets
        mad = True if self._path_template.mad_prefix != '' else False

        if mad:
            mad_prefix = str(self._path_template.mad_prefix)
            index = MAD_ENERGY_COMBO_NAMES[str(mad_prefix)]
            self.acq_widget_layout.energies_combo.setCurrentIndex(index)
            self.acq_widget_layout.mad_cbox.setChecked(True)
            self.acq_widget_layout.energies_combo.setEnabled(True)
        else:
            self.acq_widget_layout.mad_cbox.setChecked(False)
            self.acq_widget_layout.energies_combo.setEnabled(False)
            self.acq_widget_layout.energies_combo.setCurrentIndex(0)

        #self.update_osc_start_limits()
        #self.update_osc_total_range()
        self.emit_acq_parameters_changed()

    def set_tunable_energy(self, state):
        """
        Descript. :
        """
        self.acq_widget_layout.energy_ledit.setEnabled(state)
        self.acq_widget_layout.mad_cbox.setEnabled(state)
        self.acq_widget_layout.energies_combo.setEnabled(state)
  
    def check_parameter_conflict(self):
        return self._acquisition_mib.validate_all()

    def emit_acq_parameters_changed(self):
        self.acqParametersChangedSignal.emit(self._acquisition_mib.validate_all())
Esempio n. 50
0
class CreateCharWidget(CreateTaskBase):
    """
    Descript. :
    """

    def __init__(self,parent = None,name = None, fl = 0):
        """
        Descript. :
        """

        CreateTaskBase.__init__(self, parent, name, fl, 'Characterisation')
        self.setObjectName("create_char_widget")

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._vertical_dimension_widget = None
        self._current_selected_item = None
        self.init_models()
        self._char_params_mib = DataModelInputBinder(self._char_params)
   
        # Graphic elements ----------------------------------------------------
        self._acq_widget = \
            AcquisitionWidgetSimple(self, acq_params = self._acquisition_parameters,
                                    path_template = self._path_template)

        self._data_path_widget = DataPathWidget(self, 
             data_model = self._path_template, layout = 'vertical')

        self._vertical_dimension_widget = loadUi(os.path.join(os.path.dirname(__file__),
             'ui_files/Qt4_vertical_crystal_dimension_widget_layout.ui'))

        self._char_widget = loadUi(os.path.join(os.path.dirname(__file__),
             'ui_files/Qt4_characterise_simple_widget_vertical_layout.ui')) 

        # Layout --------------------------------------------------------------
        _main_vlayout = QVBoxLayout(self) 
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._char_widget)
        _main_vlayout.addWidget(self._vertical_dimension_widget)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.setSpacing(6)
        _main_vlayout.addStretch(0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.path_template_changed)
        self._acq_widget.acqParametersChangedSignal.\
             connect(self.acq_parameters_changed)

        self._vertical_dimension_widget.space_group_ledit.activated.\
             connect(self._space_group_change)
        #self.connect(induced_burn_cbx, QtCore.SIGNAL("toggled(bool)"),
        #             self.use_induced_burn)

        self._char_widget.characterisation_gbox.toggled.connect(\
             self.characterisation_gbox_toggled)
        self._char_widget.wait_result_cbx.toggled.connect(\
             self.wait_results_cbx_toggled)
        self._char_widget.execute_plan_cbx.toggled.connect(\
             self.run_diffraction_plan_cbx_toggled)

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update(
             'opt_sad', self._char_widget.optimised_sad_cbx,
             bool, None)

        self._char_params_mib.bind_value_update(
             'account_rad_damage', self._char_widget.account_rad_dmg_cbx,
             bool, None)

        #self._char_params_mib.bind_value_update('determine_rad_params', 
        #                                        induced_burn_cbx,
        #                                        bool, None)

        self._char_params_mib.bind_value_update(
             'strategy_complexity', self._char_widget.start_comp_cbox,
             int, None)

        self._char_params_mib.\
            bind_value_update('max_crystal_vdim',
                              self._vertical_dimension_widget.max_vdim_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vdim',
                              self._vertical_dimension_widget.min_vdim_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vphi',
                              self._vertical_dimension_widget.min_vphi_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('max_crystal_vphi',
                              self._vertical_dimension_widget.max_vphi_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))
        
        self._vertical_dimension_widget.space_group_ledit.addItems(
            queue_model_enumerables.XTAL_SPACEGROUPS
        )

        self._data_path_widget.data_path_layout.compression_cbox.setVisible(False)

    def enable_compression(self, state):
        CreateTaskBase.enable_compression(self, False)

    def use_induced_burn(self, state):
        """
        Descript. :
        """
        self._acquisition_parameters.induce_burn = state

    def _space_group_change(self, index):
        """
        Descript. :
        """
        self._char_params.space_group = (
            queue_model_enumerables.XTAL_SPACEGROUPS[index]
        )

    def _set_space_group(self, space_group):
        """
        Descript. :
        """
        index  = 0
     
        if self._vertical_dimension_widget: 
            if space_group in queue_model_enumerables.XTAL_SPACEGROUPS:
                index = queue_model_enumerables.XTAL_SPACEGROUPS.index(space_group)

            self._space_group_change(index)
            self._vertical_dimension_widget.space_group_ledit.\
                 setCurrentIndex(index)

    def init_models(self):
        """
        Descript. :
        """
        CreateTaskBase.init_models(self)
        self._init_models()

    def _init_models(self):
        """
        Descript. :
        """
        self._char = queue_model_objects.Characterisation()
        self._char_params = self._char.characterisation_parameters
        self._processing_parameters = queue_model_objects.ProcessingParameters()
        self._set_space_group(self._processing_parameters.space_group)

        if self._beamline_setup_hwobj is not None:            
            self._acquisition_parameters = self._beamline_setup_hwobj.\
                get_default_char_acq_parameters()

            self._char_params = self._beamline_setup_hwobj.\
                                get_default_characterisation_parameters()
        else:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters()
        
        self._path_template.reference_image_prefix = 'ref'
        # The num images drop down default value is 1
        # we would like it to be 2
        self._acquisition_parameters.num_images = 2
        self._char.characterisation_software =\
            queue_model_enumerables.COLLECTION_ORIGIN.EDNA
        self._path_template.num_files = 2
        self._path_template.compression = False
        self._acquisition_parameters.shutterless = False

    def single_item_selection(self, tree_item):
        """
        Descript. :
        """
        CreateTaskBase.single_item_selection(self, tree_item)
        
        if isinstance(tree_item, Qt4_queue_item.SampleQueueItem):
            #self._init_models() 
            if self._char_params.space_group == "":
                sample_model = tree_item.get_model()
                self._set_space_group(sample_model.processing_parameters.space_group)
            #self._acq_widget.update_data_model(self._acquisition_parameters,
            #                                   self._path_template)
            #self._char_params_mib.set_model(self._char_params)
        elif isinstance(tree_item, Qt4_queue_item.BasketQueueItem):
            self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.CharacterisationQueueItem):
            if tree_item.get_model().is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

            self._char = tree_item.get_model()

            if self._char.get_path_template():
                self._path_template = self._char.get_path_template()

            self._data_path_widget.update_data_model(self._path_template)
            
            data_collection = self._char.reference_image_collection

            self._char_params = self._char.characterisation_parameters
            self._char_params_mib.set_model(self._char_params)

            self._acquisition_parameters = data_collection.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(data_collection.acquisitions) == 1:
                self.select_shape_with_cpos(self._acquisition_parameters.\
                                            centred_position)

            self._processing_parameters = data_collection.processing_parameters
        else:
            self.setDisabled(True)

    def update_processing_parameters(self, crystal):
        """
        Descript. :
        """
        self._processing_parameters.space_group = crystal.space_group
        self._char_params.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

    def approve_creation(self):
        """
        Descript. :
        """
        result = CreateTaskBase.approve_creation(self)
        selected_shapes = self._graphics_manager_hwobj.get_selected_shapes()

        for shape in selected_shapes:
            if isinstance(shape, GraphicsItemPoint):
                result = True
        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):
        """
        Descript. :
        """
        tasks = []

        if not shape or not isinstance(shape, GraphicsItemPoint):
            cpos = queue_model_objects.CentredPosition()
            cpos.snapshot_image = self._graphics_manager_hwobj.get_scene_snapshot()
        else:
            # Shapes selected and sample is mounted, get the
            # centred positions for the shapes
            snapshot = self._graphics_manager_hwobj.\
                        get_scene_snapshot(shape)
            cpos = copy.deepcopy(shape.get_centred_position())
            cpos.snapshot_image = snapshot 

        char_params = copy.deepcopy(self._char_params)
        acq = self._create_acq(sample)
        dc = queue_model_objects.\
                DataCollection([acq], sample.crystals[0],
                               self._processing_parameters)

        # Reference images for characterisations should be taken 90 deg apart
        # this is achived by setting overap to -89
        acq.acquisition_parameters.overlap = -89
        acq.acquisition_parameters.centred_position = cpos        
        
        dc.acquisitions[0] = acq
        dc.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.EDNA_REF
        dc.run_processing_parallel = False

        char = queue_model_objects.Characterisation(dc, 
                                                    char_params)
        char.set_name(dc.acquisitions[0].\
                      path_template.get_prefix())
        char.set_number(dc.acquisitions[0].\
                        path_template.run_number)
        char.run_characterisation = self._char_widget.characterisation_gbox.isChecked()
        char.wait_result = self._char_widget.wait_result_cbx.isChecked()
        char.run_diffraction_plan = self._char_widget.execute_plan_cbx.isChecked()
        char.diff_plan_compression = self._tree_brick.compression_state

        tasks.append(char)
        self._path_template.run_number += 1

        return tasks

    def characterisation_gbox_toggled(self, state):
        if self._char:
            self._char.run_characterisation = state

    def wait_results_cbx_toggled(self, state):
        if self._char:
            self._char.wait_result = state
 
    def run_diffraction_plan_cbx_toggled(self, state):
        if self._char:
            self._char.run_diffraction_plan = state
Esempio n. 51
0
    def __init__(self, *args):
        """
        Descript. :
        """
        BlissWidget.__init__(self, *args)

        # Internal variables ------------------------------------------------
        self.sample = queue_model_objects.Sample()
        self.crystal = self.sample.crystals[0]
        self.sample_mib = DataModelInputBinder(self.sample)
        self.crystal_mib = DataModelInputBinder(self.crystal)
       
        # Signals ------------------------------------------------------------ 

        # Slots --------------------------------------------------------------
        self.defineSlot("populate_sample_details", ({}))

        # Graphic elements ----------------------------------------------------
        _info_widget = QtGui.QWidget(self)
        self.crystal_widget = uic.loadUi(os.path.join(
                            os.path.dirname(__file__),
                            "widgets/ui_files/Qt4_crystal_widget_layout.ui"))
        self.sample_info_widget = uic.loadUi(
                                os.path.join(os.path.dirname(__file__),
                                "widgets/ui_files/Qt4_sample_info_widget_layout.ui"))

        # Layout --------------------------------------------------------------
        _info_widget_hlayout = QtGui.QHBoxLayout(_info_widget)
        _info_widget_hlayout.addWidget(self.sample_info_widget)
        _info_widget_hlayout.addWidget(self.crystal_widget)
        _info_widget_hlayout.addStretch(0)

        _main_hlayout = QtGui.QVBoxLayout(self)
        _main_hlayout.addWidget(_info_widget)
        _main_hlayout.addStretch(0)
        _main_hlayout.setSpacing(0)
        _main_hlayout.setContentsMargins(2, 2, 2, 2)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------

        # Other ---------------------------------------------------------------
        self.crystal_mib.bind_value_update('space_group',  
                                           self.crystal_widget.space_group_value_label,
                                           str, 
                                           None)

        self.crystal_mib.bind_value_update('protein_acronym',
                                           self.crystal_widget.protein_acronym_value_label,
                                           str,
                                           None)

        self.crystal_mib.bind_value_update('cell_a',
                                           self.crystal_widget.a_value_label,
                                           str,
                                           None)

        self.crystal_mib.bind_value_update('cell_alpha',
                                           self.crystal_widget.alpha_value_label,
                                           str,
                                           None)

        self.crystal_mib.bind_value_update('cell_b',
                                           self.crystal_widget.b_value_label,
                                           str,
                                           None)

        self.crystal_mib.bind_value_update('cell_beta',
                                           self.crystal_widget.beta_value_label,
                                           str,
                                           None)

        self.crystal_mib.bind_value_update('cell_c',
                                           self.crystal_widget.c_value_label,
                                           str,
                                           None)

        self.crystal_mib.bind_value_update('cell_gamma',
                                           self.crystal_widget.gamma_value_label,
                                           str,
                                           None)

        self.sample_mib.bind_value_update('name',
                                          self.sample_info_widget.name_value_label,
                                          str,
                                          None)
        

        self.sample_mib.bind_value_update('code',
                                          self.sample_info_widget.data_matrix_value_label,
                                          str,
                                          None)


        self.sample_mib.bind_value_update('holder_length',
                                          self.sample_info_widget.holder_length_value_label,
                                          str,
                                          None)


        self.sample_mib.bind_value_update('lims_sample_location',
                                          self.sample_info_widget.sample_location_value_label,
                                          str,
                                          None)


        self.sample_mib.bind_value_update('lims_container_location',
                                          self.sample_info_widget.basket_location_value_label,
                                          str,
                                          None)
class XrayImagingParametersWidget(QWidget):
    def __init__(self, parent=None, name=None, fl=0, xray_imaging_params=None):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if xray_imaging_params is None:
            self._xray_imaging_parameters = \
               queue_model_objects.XrayImagingParameters()
        else:
            self._xray_imaging_parameters = xray_imaging_params

        self._xray_imaging_mib = DataModelInputBinder(
            self._xray_imaging_parameters)

        self._parameters_widget = loadUi(os.path.join(\
             os.path.dirname(__file__),
             "ui_files/Qt4_xray_imaging_parameters_widget_layout.ui"))
        # Layout --------------------------------------------------------------
        __main_vlayout = QVBoxLayout(self)
        __main_vlayout.addWidget(self._parameters_widget)
        __main_vlayout.setSpacing(0)
        __main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------

        # Other ---------------------------------------------------------------

    def set_beamline_setup(self, beamline_setup):
        """Sets beamline setup and links qt gui with data model
        """
        self._beamline_setup_hwobj = beamline_setup

        self._xray_imaging_mib.\
             bind_value_update('camera_hw_binning',
                               self._parameters_widget.camera_hw_binning_combo,
                               int,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('camera_hw_roi',
                               self._parameters_widget.camera_hw_roi_combo,
                               int,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('store_data',
                               self._parameters_widget.store_data_cbox,
                               bool,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('live_display',
                               self._parameters_widget.live_display_cbox,
                               bool,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('pre_flat_field_frames',
                               self._parameters_widget.pre_flat_cbox,
                               bool,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('post_flat_field_frames',
                               self._parameters_widget.post_flat_cbox,
                               bool,
                               None)

        self._xray_imaging_mib.\
             bind_value_update('apply_pre_flat_field_frames',
                               self._parameters_widget.apply_flat_cbox,
                               bool,
                               None)

    def update_data_model(self, xray_imaging_parameters):
        """
        Descript. :
        """
        self._xray_imaging_parameters = xray_imaging_parameters
        self._xray_imaging_mib.set_model(xray_imaging_parameters)
Esempio n. 53
0
    def __init__(self, parent = None, name = "parameter_widget"):
        """
        Descript. :
        """

        QtGui.QWidget.__init__(self, parent)

        if name is not None: 
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._char = None
        self._char_params = queue_model_objects.CharacterisationParameters()
        self._char_params_mib = DataModelInputBinder(self._char_params)
        self._tree_view_item = None
        self.previous_energy = None
        
        self.add_dc_cb = None
        
        # Graphic elements ----------------------------------------------------
        rone_widget = QtGui.QWidget(self)
        self.reference_img_widget = ReferenceImageWidget(rone_widget)
        self.acq_widget = self.reference_img_widget.acq_widget
        self.path_widget = self.reference_img_widget.path_widget
        self.position_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
                                          'ui_files/Qt4_snapshot_widget_layout.ui'))
        self.position_widget.setMinimumSize(450, 340)

        rtwo_widget = QtGui.QWidget(self)
        self.char_type_widget = CharTypeWidget(rtwo_widget)
        self.routine_dc_widget = self.char_type_widget.routine_dc_page
        self.sad_widget = self.char_type_widget.sad_page
        self.rad_dmg_char_widget = self.char_type_widget.rad_damage_page
        self.opt_parameters_widget = OptimisationParametersWidgetLayout(self)
        
        rtree_widget = QtGui.QWidget(self)
        self.rad_dmg_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
             'ui_files/Qt4_radiation_damage_model_widget_layout.ui'))
        self.vertical_dimension_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
             'ui_files/Qt4_vertical_crystal_dimension_widget_layout.ui'))

        # Layout --------------------------------------------------------------
        rone_widget_layout = QtGui.QHBoxLayout(self)
        rone_widget_layout.addWidget(self.reference_img_widget)
        rone_widget_layout.addWidget(self.position_widget)
        #rone_widget_layout.addStretch(0)
        rone_widget_layout.setSpacing(2)
        rone_widget_layout.setContentsMargins(0, 0, 0, 0)
        rone_widget.setLayout(rone_widget_layout)

        rtwo_widget_layout = QtGui.QHBoxLayout(self)
        rtwo_widget_layout.addWidget(self.char_type_widget)
        rtwo_widget_layout.addWidget(self.opt_parameters_widget)
        rtwo_widget_layout.addStretch(0)
        rtwo_widget_layout.setSpacing(2)
        rtwo_widget_layout.setContentsMargins(0, 0, 0, 0)
        rtwo_widget.setLayout(rtwo_widget_layout)

        rtree_widget_layout = QtGui.QHBoxLayout(self)
        rtree_widget_layout.addWidget(self.rad_dmg_widget)
        rtree_widget_layout.addWidget(self.vertical_dimension_widget)
        rtree_widget_layout.addStretch(0)
        rtree_widget_layout.setSpacing(2)
        rtree_widget_layout.setContentsMargins(0, 0, 0, 0)
        rtree_widget.setLayout(rtree_widget_layout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(rone_widget)
        _main_vlayout.addWidget(rtwo_widget)
        _main_vlayout.addWidget(rtree_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(_main_vlayout)

        # SizePolicies -------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.toggle_permitted_range(self.opt_parameters_widget.\
             opt_param_widget.permitted_range_cbx.isChecked())

        self.opt_parameters_widget.opt_param_widget.permitted_range_cbx.\
             toggled.connect(self.toggle_permitted_range)

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update('min_dose',
                                                 self.routine_dc_widget.dose_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('min_time',
                                                 self.routine_dc_widget.time_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('use_min_dose',
                                                 self.routine_dc_widget.min_dose_radio,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('use_min_time',
                                                 self.routine_dc_widget.min_time_radio,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('account_rad_damage',
                                                 self.routine_dc_widget.radiation_damage_cbx,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('auto_res',
                                                 self.sad_widget.automatic_resolution_radio,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('sad_res',
                                                 self.sad_widget.sad_resolution_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.5, 20, 3, self))

        self._char_params_mib.bind_value_update('opt_sad',
                                                 self.sad_widget.optimised_sad_cbx,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('determine_rad_params',
                                                 self.rad_dmg_char_widget.rad_damage_cbx,
                                                 bool,
                                                 None)

        self._char_params_mib.bind_value_update('burn_osc_start',
                                                 self.rad_dmg_char_widget.burn_osc_start_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('burn_osc_interval',
                                                 self.rad_dmg_char_widget.burn_osc_interval_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
             'use_aimed_resolution',
             self.opt_parameters_widget.opt_param_widget.maximum_res_cbx,
             bool,
             None)

        self._char_params_mib.bind_value_update(
             'use_aimed_multiplicity',
             self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx,
             bool,
             None)

        self._char_params_mib.bind_value_update(
             'aimed_resolution',
             self.opt_parameters_widget.opt_param_widget.maximum_res_ledit,
             float,
             QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(\
             'aimed_multiplicity',
             self.opt_parameters_widget.opt_param_widget.aimed_mult_ledit,
             float,
             QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(
             'aimed_i_sigma',
             self.opt_parameters_widget.opt_param_widget.i_over_sigma_ledit,
             float,
             QtGui.QDoubleValidator(0.01, 1000, 2, self))

        self._char_params_mib.bind_value_update(
             'aimed_completness',
             self.opt_parameters_widget.opt_param_widget.aimed_comp_ledit,
             float,
             QtGui.QDoubleValidator(0.01, 1000, 2, self))
        
        self._char_params_mib.bind_value_update(
             'strategy_complexity',
             self.opt_parameters_widget.opt_param_widget.start_comp_cbox,
             int,
             None)

        self._char_params_mib.bind_value_update(
             'use_permitted_rotation',
             self.opt_parameters_widget.opt_param_widget.permitted_range_cbx,
             bool,
             None)

        self._char_params_mib.bind_value_update(
             'permitted_phi_start',
             self.opt_parameters_widget.opt_param_widget.phi_start_ledit,
             float,
             QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
             'permitted_phi_end',
             self.opt_parameters_widget.opt_param_widget.phi_end_ledit,
             float,
             QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update(
             'low_res_pass_strat',
             self.opt_parameters_widget.opt_param_widget.low_res_pass_cbx,
             bool,
             None)

        self._char_params_mib.bind_value_update('rad_suscept',
                                                 self.rad_dmg_widget.sensetivity_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('beta',
                                                 self.rad_dmg_widget.beta_over_gray_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('gamma',
                                                 self.rad_dmg_widget.gamma_over_gray_ledit,
                                                 float,
                                                 QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('max_crystal_vdim',
                                                self.vertical_dimension_widget.max_vdim_ledit,
                                                float,
                                                QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('min_crystal_vdim',
                                                self.vertical_dimension_widget.min_vdim_ledit,
                                                float,
                                                QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('min_crystal_vphi',
                                                self.vertical_dimension_widget.min_vphi_ledit,
                                                float,
                                                QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.bind_value_update('max_crystal_vphi',
                                                self.vertical_dimension_widget.max_vphi_ledit,
                                                float,
                                                QtGui.QDoubleValidator(0.0, 1000, 2, self))

        #self._char_params_mib.bind_value_update('space_group',
        #                                        self.vertical_dimension_widget.space_group_ledit,
        #                                        str,
        #                                        None)


        self.vertical_dimension_widget.space_group_ledit.\
             addItems(queue_model_enumerables.XTAL_SPACEGROUPS)

        self.char_type_widget.charact_type_tbox.currentChanged.connect(\
             self.update_char_type)
        self.rad_dmg_char_widget.rad_damage_cbx.toggled.connect(\
             self.enable_opt_parameters_widget)
        self.opt_parameters_widget.opt_param_widget.maximum_res_cbx.\
             toggled.connect(self.enable_maximum_res_ledit)
        self.opt_parameters_widget.opt_param_widget.aimed_mult_cbx.\
             toggled.connect(self.enable_aimed_mult_ledit)
        self.path_widget.data_path_layout.prefix_ledit.textChanged.\
             connect(self._prefix_ledit_change)
        self.path_widget.data_path_layout.run_number_ledit.textChanged.\
             connect(self._run_number_ledit_change)
        self.vertical_dimension_widget.space_group_ledit.activated.\
             connect(self._space_group_change)
Esempio n. 54
0
class CreateCharWidget(CreateTaskBase):
    """
    Descript. :
    """
    def __init__(self, parent=None, name=None, fl=0):
        """
        Descript. :
        """

        CreateTaskBase.__init__(self, parent, name, fl, 'Characterisation')

        if not name:
            self.setName("create_char_widget")

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._current_selected_item = None
        self.init_models()
        self._char_params_mib = DataModelInputBinder(self._char_params)

        # Graphic elements ----------------------------------------------------
        self._acq_widget = \
            AcquisitionWidgetSimple(self, acq_params = self._acquisition_parameters,
                                    path_template = self._path_template)

        self._data_path_gbox = QtGui.QGroupBox('Data location', self)
        self._data_path_widget = DataPathWidget(self._data_path_gbox,
                                                data_model=self._path_template,
                                                layout='vertical')

        self._vertical_dimension_widget = uic.loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_vertical_crystal_dimension_widget_layout.ui'))

        self._char_widget = uic.loadUi(
            os.path.join(
                os.path.dirname(__file__),
                'ui_files/Qt4_characterise_simple_widget_vertical_layout.ui'))

        gbox = self._char_widget.findChild(QtGui.QGroupBox,
                                           "characterisation_gbox")
        p = gbox.palette()
        p.setColor(QtGui.QPalette.Window, QtCore.Qt.red)
        p.setColor(QtGui.QPalette.Highlight, QtCore.Qt.red)
        gbox.setPalette(p)

        # Layout --------------------------------------------------------------
        _data_path_gbox_layout = QtGui.QVBoxLayout(self)
        _data_path_gbox_layout.addWidget(self._data_path_widget)
        _data_path_gbox_layout.setSpacing(0)
        _data_path_gbox_layout.setContentsMargins(0, 0, 0, 0)
        self._data_path_gbox.setLayout(_data_path_gbox_layout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_gbox)
        _main_vlayout.addWidget(self._char_widget)
        _main_vlayout.addWidget(self._vertical_dimension_widget)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(_main_vlayout)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update(
            'opt_sad', self._char_widget.optimised_sad_cbx, bool, None)

        self._char_params_mib.bind_value_update(
            'account_rad_damage', self._char_widget.account_rad_dmg_cbx, bool,
            None)

        #self._char_params_mib.bind_value_update('determine_rad_params',
        #                                        induced_burn_cbx,
        #                                        bool, None)

        self._char_params_mib.bind_value_update(
            'strategy_complexity', self._char_widget.start_comp_cbox, int,
            None)

        self._char_params_mib.\
            bind_value_update('max_crystal_vdim',
                              self._vertical_dimension_widget.max_vdim_ledit, float,
                              QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vdim',
                              self._vertical_dimension_widget.min_vdim_ledit, float,
                              QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vphi',
                              self._vertical_dimension_widget.min_vphi_ledit, float,
                              QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('max_crystal_vphi',
                              self._vertical_dimension_widget.max_vphi_ledit, float,
                              QtGui.QDoubleValidator(0.0, 1000, 2, self))

        self._vertical_dimension_widget.space_group_ledit.addItems(
            XTAL_SPACEGROUPS)

        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._vertical_dimension_widget.space_group_ledit.activated.\
             connect(self._space_group_change)

        self.connect(self._data_path_widget,
                     QtCore.SIGNAL("pathTemplateChanged"),
                     self.handle_path_conflict)

        #self.connect(induced_burn_cbx, QtCore.SIGNAL("toggled(bool)"),
        #             self.use_induced_burn)

    def use_induced_burn(self, state):
        """
        Descript. :
        """
        self._acquisition_parameters.induce_burn = state

    def _space_group_change(self, index):
        """
        Descript. :
        """
        self._char_params.space_group = queue_model_enumerables.\
                                        XTAL_SPACEGROUPS[index]

    def _set_space_group(self, space_group):
        """
        Descript. :
        """
        index = 0

        if space_group in XTAL_SPACEGROUPS:
            index = XTAL_SPACEGROUPS.index(space_group)

        self._space_group_change(index)
        self._vertical_dimension_widget.space_group_ledit.setCurrentIndex(
            index)

    def init_models(self):
        """
        Descript. :
        """
        CreateTaskBase.init_models(self)
        self._init_models()

    def _init_models(self):
        """
        Descript. :
        """
        self._char = queue_model_objects.Characterisation()
        self._char_params = self._char.characterisation_parameters
        self._processing_parameters = queue_model_objects.ProcessingParameters(
        )

        if self._beamline_setup_hwobj is not None:
            self._acquisition_parameters = self._beamline_setup_hwobj.\
                get_default_char_acq_parameters()

            self._char_params = self._beamline_setup_hwobj.\
                                get_default_characterisation_parameters()
            try:
                transmission = self._beamline_setup_hwobj.transmission_hwobj.getAttFactor(
                )
                transmission = round(float(transmission), 1)
            except AttributeError:
                transmission = 0

            try:
                resolution = self._beamline_setup_hwobj.resolution_hwobj.getPosition(
                )
                resolution = round(float(resolution), 3)
            except AttributeError:
                resolution = 0

            try:
                energy = self._beamline_setup_hwobj.energy_hwobj.getCurrentEnergy(
                )
                energy = round(float(energy), 4)
            except AttributeError:
                energy = 0

            self._acquisition_parameters.resolution = resolution
            self._acquisition_parameters.energy = energy
            self._acquisition_parameters.transmission = transmission
        else:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters(
            )

        return

        self._path_template.reference_image_prefix = 'ref'
        # The num images drop down default value is 1
        # we would like it to be 2
        self._acquisition_parameters.num_images = 2
        self._char.characterisation_software =\
            queue_model_enumerables.COLLECTION_ORIGIN.EDNA
        self._path_template.num_files = 2
        self._acquisition_parameters.shutterless = False

    def single_item_selection(self, tree_item):
        """
        Descript. :
        """
        CreateTaskBase.single_item_selection(self, tree_item)

        if isinstance(tree_item, Qt4_queue_item.SampleQueueItem):
            self._init_models()
            self._set_space_group(self._char_params.space_group)
            self._acq_widget.update_data_model(self._acquisition_parameters,
                                               self._path_template)
            self._char_params_mib.set_model(self._char_params)
            #self._char_params = copy.deepcopy(self._char_params)
            #self._acquisition_parameters = copy.deepcopy(self._acquisition_parameters)

        elif isinstance(tree_item, Qt4_queue_item.CharacterisationQueueItem):
            if tree_item.get_model().is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

            self._char = tree_item.get_model()

            if self._char.get_path_template():
                self._path_template = self._char.get_path_template()

            self._data_path_widget.update_data_model(self._path_template)

            data_collection = self._char.reference_image_collection

            self._char_params = self._char.characterisation_parameters
            self._char_params_mib.set_model(self._char_params)

            self._acquisition_parameters = data_collection.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(data_collection.acquisitions) == 1:
                self.select_shape_with_cpos(self._acquisition_parameters.\
                                            centred_position)

            self._processing_parameters = data_collection.processing_parameters
        else:
            self.setDisabled(True)

    def update_processing_parameters(self, crystal):
        """
        Descript. :
        """
        self._processing_parameters.space_group = crystal.space_group
        self._char_params.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

    def approve_creation(self):
        """
        Descript. :
        """
        result = CreateTaskBase.approve_creation(self)
        selected_shapes = self._graphics_manager_hwobj.get_selected_shapes()

        for shape in selected_shapes:
            if isinstance(shape, Qt4_GraphicsManager.GraphicsItemPoint):
                result = True
        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):
        """
        Descript. :
        """
        tasks = []

        if not shape:
            cpos = queue_model_objects.CentredPosition()
            cpos.snapshot_image = self._graphics_manager_hwobj.get_snapshot()
        else:
            # Shapes selected and sample is mounted, get the
            # centred positions for the shapes
            if isinstance(shape, Qt4_GraphicsManager.GraphicsItemPoint):
                snapshot = self._graphics_manager_hwobj.\
                           get_snapshot([shape])

                cpos = copy.deepcopy(shape.get_centred_positions()[0])
                cpos.snapshot_image = snapshot

        char_params = copy.deepcopy(self._char_params)
        acq = self._create_acq(sample)
        dc = queue_model_objects.\
                DataCollection([acq], sample.crystals[0],
                               self._processing_parameters)

        # Reference images for characterisations should be taken 90 deg apart
        # this is achived by setting overap to -89
        acq.acquisition_parameters.overlap = -89
        acq.acquisition_parameters.centred_position = cpos

        dc.acquisitions[0] = acq
        dc.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.EDNA_REF

        char = queue_model_objects.Characterisation(dc, char_params)
        char.set_name(dc.acquisitions[0].\
                      path_template.get_prefix())
        char.set_number(dc.acquisitions[0].\
                        path_template.run_number)

        tasks.append(char)
        self._path_template.run_number += 1

        return tasks
Esempio n. 55
0
    def __init__(self,
                 parent=None,
                 name=None,
                 fl=0,
                 acq_params=None,
                 path_template=None,
                 layout='horizontal'):
        """
        Descript. :
        """
        QtGui.QWidget.__init__(self, parent, QtCore.Qt.WindowFlags(fl))

        if name is not None:
            self.setObjectName(name)

        # Hardware objects ----------------------------------------------------
        self._beamline_setup_hwobj = None

        # Internal variables --------------------------------------------------
        self.previous_energy = 0

        # Properties ----------------------------------------------------------

        # Signals -------------------------------------------------------------

        # Slots ---------------------------------------------------------------

        # Graphic elements ----------------------------------------------------
        if acq_params is None:
            self._acquisition_parameters = queue_model_objects.\
                                           AcquisitionParameters()
        else:
            self._acquisition_parameters = acq_params

        if path_template is None:
            self._path_template = queue_model_objects.PathTemplate()
        else:
            self._path_template = path_template

        self._acquisition_mib = DataModelInputBinder(
            self._acquisition_parameters)

        if layout == "horizontal":
            self.acq_widget = uic.loadUi(
                os.path.join(
                    os.path.dirname(__file__),
                    "ui_files/Qt4_acquisition_widget_horizontal_layout.ui"))
            self.acq_widget.inverse_beam_cbx.hide()
            self.acq_widget.subwedge_size_label.hide()
            self.acq_widget.subwedge_size_ledit.hide()
        else:
            self.acq_widget = uic.loadUi(
                os.path.join(
                    os.path.dirname(__file__),
                    "ui_files/Qt4_acquisition_widget_vertical_layout.ui"))
        # Layout --------------------------------------------------------------
        self.main_layout = QtGui.QVBoxLayout(self)
        self.main_layout.addWidget(self.acq_widget)
        self.main_layout.setSpacing(0)
        self.main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.main_layout)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self.acq_widget.energies_combo.activated.connect(self.energy_selected)
        self.acq_widget.mad_cbox.toggled.connect(self.use_mad)
        self.acq_widget.inverse_beam_cbx.toggled.connect(
            self.set_use_inverse_beam)
        self.acq_widget.first_image_ledit.textChanged.connect(
            self.first_image_ledit_change)
        self.acq_widget.num_images_ledit.textChanged.connect(
            self.num_images_ledit_change)

        overlap_ledit = self.acq_widget.findChild(QtGui.QLineEdit,
                                                  "overlap_ledit")
        if overlap_ledit is not None:
            overlap_ledit.textChanged.connect(self.overlap_changed)

        self.acq_widget.subwedge_size_ledit.textChanged.connect(
            self.subwedge_size_ledit_change)
        self.acq_widget.osc_start_cbox.toggled.connect(
            self.osc_start_cbox_click)

        # Other ---------------------------------------------------------------
        self.acq_widget.subwedge_size_ledit.setDisabled(True)
        self.acq_widget.energies_combo.setDisabled(True)
        self.acq_widget.energies_combo.addItems(
            ['ip: -', 'pk: -', 'rm1: -', 'rm2: -'])
        self.acq_widget.osc_start_ledit.setEnabled(False)

        self.osc_start_validator = QtGui.QDoubleValidator(
            -10000, 10000, 4, self)
        self.osc_range_validator = QtGui.QDoubleValidator(
            -10000, 10000, 4, self)
        self.kappa_validator = QtGui.QDoubleValidator(0, 360, 4, self)
        self.kappa_phi_validator = QtGui.QDoubleValidator(0, 360, 4, self)
        self.energy_validator = QtGui.QDoubleValidator(0, 25, 4, self)
        self.resolution_validator = QtGui.QDoubleValidator(0, 15, 3, self)
        self.transmission_validator = QtGui.QDoubleValidator(0, 100, 3, self)
        self.exp_time_validator = QtGui.QDoubleValidator(
            0.0001, 10000, 4, self)
        self.first_img_validator = QtGui.QIntValidator(0, 99999, self)
        self.num_img_validator = QtGui.QIntValidator(1, 99999, self)
Esempio n. 56
0
    def __init__(self, parent=None, name=None, fl=0):
        """
        Descript. :
        """

        CreateTaskBase.__init__(self, parent, name, fl, "Characterisation")
        self.setObjectName("create_char_widget")

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._vertical_dimension_widget = None
        self._current_selected_item = None
        self.init_models()
        self._char_params_mib = DataModelInputBinder(self._char_params)

        # Graphic elements ----------------------------------------------------
        self._acq_widget = AcquisitionWidgetSimple(
            self, acq_params=self._acquisition_parameters, path_template=self._path_template
        )

        self._data_path_widget = DataPathWidget(self, data_model=self._path_template, layout="vertical")

        self._vertical_dimension_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__), "ui_files/Qt4_vertical_crystal_dimension_widget_layout.ui")
        )

        self._char_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__), "ui_files/Qt4_characterise_simple_widget_vertical_layout.ui")
        )

        # Layout --------------------------------------------------------------
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._char_widget)
        _main_vlayout.addWidget(self._vertical_dimension_widget)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
        _main_vlayout.setSpacing(2)
        _main_vlayout.addStretch(10)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.connect(self.acq_parameters_changed)
        self._acq_widget.acqParametersChangedSignal.connect(self.acq_parameters_changed)

        self._vertical_dimension_widget.space_group_ledit.activated.connect(self._space_group_change)
        # self.connect(induced_burn_cbx, QtCore.SIGNAL("toggled(bool)"),
        #             self.use_induced_burn)

        self._char_widget.characterisation_gbox.toggled.connect(self.characterisation_gbox_toggled)
        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update("opt_sad", self._char_widget.optimised_sad_cbx, bool, None)

        self._char_params_mib.bind_value_update("account_rad_damage", self._char_widget.account_rad_dmg_cbx, bool, None)

        # self._char_params_mib.bind_value_update('determine_rad_params',
        #                                        induced_burn_cbx,
        #                                        bool, None)

        self._char_params_mib.bind_value_update("strategy_complexity", self._char_widget.start_comp_cbox, int, None)

        self._char_params_mib.bind_value_update(
            "max_crystal_vdim",
            self._vertical_dimension_widget.max_vdim_ledit,
            float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "min_crystal_vdim",
            self._vertical_dimension_widget.min_vdim_ledit,
            float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "min_crystal_vphi",
            self._vertical_dimension_widget.min_vphi_ledit,
            float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._char_params_mib.bind_value_update(
            "max_crystal_vphi",
            self._vertical_dimension_widget.max_vphi_ledit,
            float,
            QtGui.QDoubleValidator(0.0, 1000, 2, self),
        )

        self._vertical_dimension_widget.space_group_ledit.addItems(XTAL_SPACEGROUPS)
Esempio n. 57
0
    def __init__(self,parent = None,name = None, fl = 0):
        """
        Descript. :
        """

        CreateTaskBase.__init__(self, parent, name, fl, 'Characterisation')
        self.setObjectName("create_char_widget")

        # Hardware objects ----------------------------------------------------

        # Internal variables --------------------------------------------------
        self._vertical_dimension_widget = None
        self._current_selected_item = None
        self.init_models()
        self._char_params_mib = DataModelInputBinder(self._char_params)
   
        # Graphic elements ----------------------------------------------------
        self._acq_widget = \
            AcquisitionWidgetSimple(self, acq_params = self._acquisition_parameters,
                                    path_template = self._path_template)

        self._data_path_widget = DataPathWidget(self, 
             data_model = self._path_template, layout = 'vertical')

        self._vertical_dimension_widget = loadUi(os.path.join(os.path.dirname(__file__),
             'ui_files/Qt4_vertical_crystal_dimension_widget_layout.ui'))

        self._char_widget = loadUi(os.path.join(os.path.dirname(__file__),
             'ui_files/Qt4_characterise_simple_widget_vertical_layout.ui')) 

        # Layout --------------------------------------------------------------
        _main_vlayout = QVBoxLayout(self) 
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._char_widget)
        _main_vlayout.addWidget(self._vertical_dimension_widget)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.setSpacing(6)
        _main_vlayout.addStretch(0)

        # SizePolicies --------------------------------------------------------

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.path_template_changed)
        self._acq_widget.acqParametersChangedSignal.\
             connect(self.acq_parameters_changed)

        self._vertical_dimension_widget.space_group_ledit.activated.\
             connect(self._space_group_change)
        #self.connect(induced_burn_cbx, QtCore.SIGNAL("toggled(bool)"),
        #             self.use_induced_burn)

        self._char_widget.characterisation_gbox.toggled.connect(\
             self.characterisation_gbox_toggled)
        self._char_widget.wait_result_cbx.toggled.connect(\
             self.wait_results_cbx_toggled)
        self._char_widget.execute_plan_cbx.toggled.connect(\
             self.run_diffraction_plan_cbx_toggled)

        # Other ---------------------------------------------------------------
        self._char_params_mib.bind_value_update(
             'opt_sad', self._char_widget.optimised_sad_cbx,
             bool, None)

        self._char_params_mib.bind_value_update(
             'account_rad_damage', self._char_widget.account_rad_dmg_cbx,
             bool, None)

        #self._char_params_mib.bind_value_update('determine_rad_params', 
        #                                        induced_burn_cbx,
        #                                        bool, None)

        self._char_params_mib.bind_value_update(
             'strategy_complexity', self._char_widget.start_comp_cbox,
             int, None)

        self._char_params_mib.\
            bind_value_update('max_crystal_vdim',
                              self._vertical_dimension_widget.max_vdim_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vdim',
                              self._vertical_dimension_widget.min_vdim_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('min_crystal_vphi',
                              self._vertical_dimension_widget.min_vphi_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))

        self._char_params_mib.\
            bind_value_update('max_crystal_vphi',
                              self._vertical_dimension_widget.max_vphi_ledit, float,
                              QDoubleValidator(0.0, 1000, 2, self))
        
        self._vertical_dimension_widget.space_group_ledit.addItems(
            queue_model_enumerables.XTAL_SPACEGROUPS
        )

        self._data_path_widget.data_path_layout.compression_cbox.setVisible(False)
Esempio n. 58
0
class ProcessingWidget(QWidget):

    enableProcessingSignal = pyqtSignal(bool, bool)

    def __init__(self, parent=None, name=None, fl=0, data_model=None):

        QWidget.__init__(self, parent, Qt.WindowFlags(fl))
        if name is not None:
            self.setObjectName(name)

        if data_model is None:
            self._model = queue_model_objects.ProcessingParameters()
        else:
            self._model = data_model

        self._model_mib = DataModelInputBinder(self._model)

        self.processing_widget = self.acq_widget_layout = loadUi(
            os.path.join(os.path.dirname(__file__),
                         "ui_files/Qt4_processing_widget_vertical_layout.ui"))

        self.main_layout = QVBoxLayout(self)
        self.main_layout.addWidget(self.processing_widget)
        self.main_layout.setSpacing(0)
        self.main_layout.setContentsMargins(0, 0, 0, 0)

        self.processing_widget.space_group_combo.\
            addItems(queue_model_enumerables.XTAL_SPACEGROUPS)

        self._model_mib.bind_value_update('cell_a',
                                          self.processing_widget.a_ledit,
                                          float, None)

        self._model_mib.bind_value_update('cell_alpha',
                                          self.processing_widget.alpha_ledit,
                                          float, None)

        self._model_mib.bind_value_update('cell_b',
                                          self.processing_widget.b_ledit,
                                          float, None)

        self._model_mib.bind_value_update('cell_beta',
                                          self.processing_widget.beta_ledit,
                                          float, None)

        self._model_mib.bind_value_update('cell_c',
                                          self.processing_widget.c_ledit,
                                          float, None)

        self._model_mib.bind_value_update('cell_gamma',
                                          self.processing_widget.gamma_ledit,
                                          float, None)

        self._model_mib.bind_value_update(
            'num_residues', self.processing_widget.num_residues_ledit, float,
            None)

        self.processing_widget.space_group_combo.activated.\
             connect(self._space_group_change)
        self.processing_widget.run_processing_after_cbox.stateChanged.\
             connect(self._run_processing_after_toggled)
        self.processing_widget.run_processing_parallel_cbox.stateChanged.\
             connect(self._run_processing_parallel_toggled)

    def _space_group_change(self, index):
        self._model.space_group = queue_model_enumerables.\
            XTAL_SPACEGROUPS[index]

    def _set_space_group(self, space_group):
        index = 0

        if space_group in queue_model_enumerables.XTAL_SPACEGROUPS:
            index = queue_model_enumerables.XTAL_SPACEGROUPS.index(space_group)

        self._space_group_change(index)
        self.processing_widget.space_group_combo.setCurrentIndex(index)

    def update_data_model(self, model):
        self._model = model
        self._model_mib.set_model(model)
        self._set_space_group(model.space_group)

    def _run_processing_after_toggled(self, state):
        self.enableProcessingSignal.emit(\
             self.processing_widget.run_processing_after_cbox.isChecked(),
             self.processing_widget.run_processing_parallel_cbox.isChecked())

    def _run_processing_parallel_toggled(self, state):
        self.enableProcessingSignal.emit(\
             self.processing_widget.run_processing_after_cbox.isChecked(),
             self.processing_widget.run_processing_parallel_cbox.isChecked())