Exemplo n.º 1
0
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, QtCore.Qt.WindowFlags(fl),
                                'XRF-scan')

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

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

        # Internal variables --------------------------------------------------
        self.count_time = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        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')

        _parameters_gbox = QtGui.QGroupBox('Parameters', self)
        _count_time_label = QtGui.QLabel("Count time (sec.):",
                                         _parameters_gbox)
        self.count_time_ledit = QtGui.QLineEdit("1", _parameters_gbox)
        self.count_time_ledit.setMaximumWidth(75)

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

        _parameters_gbox_hlayout = QtGui.QHBoxLayout(self)
        _parameters_gbox_hlayout.addWidget(_count_time_label)
        _parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _parameters_gbox_hlayout.addStretch(0)
        _parameters_gbox_hlayout.setSpacing(2)
        _parameters_gbox_hlayout.setContentsMargins(0, 0, 0, 0)
        _parameters_gbox.setLayout(_parameters_gbox_hlayout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._data_path_gbox)
        _main_vlayout.addWidget(_parameters_gbox)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)
        self.setLayout(_main_vlayout)

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

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.data_path_layout.run_number_ledit.textChanged.\
             connect(self._run_number_ledit_change)

        self.connect(self._data_path_widget,
                     QtCore.SIGNAL("pathTemplateChanged"),
                     self.handle_path_conflict)
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, QtCore.Qt.WindowFlags(fl),
                                'GphlWorkflow')

        if not name:
            self.setObjectName("Qt4_create_gphl_workflow_widget")

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

        # Internal variables --------------------------------------------------
        self.current_prefix = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._workflow_type_widget = QtGui.QGroupBox('Workflow type', self)

        self._workflow_cbox = QtGui.QComboBox(self._workflow_type_widget)
        self._gphl_acq_widget = QtGui.QGroupBox('Acquisition', self)
        self._gphl_acq_param_widget = GphlAcquisitionWidget(
            self._gphl_acq_widget, "gphl_acquisition_parameter_widget")
        self._gphl_diffractcal_widget = GphlDiffractcalWidget(
            self._gphl_acq_widget, "gphl_diffractcal_widget")

        self._data_path_widget = DataPathWidget(self,
                                                'create_dc_path_widget',
                                                layout='vertical')
        data_path_layout = self._data_path_widget.data_path_layout
        data_path_layout.file_name_label.hide()
        data_path_layout.file_name_value_label.hide()
        data_path_layout.run_number_label.hide()
        data_path_layout.run_number_ledit.hide()

        # Layout --------------------------------------------------------------
        _workflow_type_vlayout = QtGui.QVBoxLayout(self._workflow_type_widget)
        _workflow_type_vlayout.addWidget(self._workflow_cbox)
        _gphl_acq_vlayout = QtGui.QVBoxLayout(self._gphl_acq_widget)
        _gphl_acq_vlayout.addWidget(self._gphl_acq_param_widget)
        _gphl_acq_vlayout.addWidget(self._gphl_diffractcal_widget)
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._workflow_type_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._gphl_acq_widget)
        _main_vlayout.addStretch(0)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

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

        # Qt signal/slot connections ------------------------------------------
        self._workflow_cbox.currentIndexChanged[str].connect(
            self.workflow_selected)

        # set up popup data dialog
        self.gphl_data_dialog = GphlDataDialog(self, 'GPhL Workflow Data')
        self.gphl_data_dialog.setModal(True)
        self.gphl_data_dialog.continueClickedSignal.connect(self.data_acquired)
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, Qt.WindowFlags(fl),
                                'XRF spectrum')

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

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

        # Internal variables --------------------------------------------------
        self.count_time = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._data_path_widget = DataPathWidget(self,
                                                data_model=self._path_template,
                                                layout='vertical')

        _parameters_gbox = QGroupBox('Parameters', self)
        _count_time_label = QLabel("Count time (sec.):", _parameters_gbox)
        self.count_time_ledit = QLineEdit("1", _parameters_gbox)
        #self.count_time_ledit.setMaximumWidth(75)
        self.adjust_transmission_cbox = QCheckBox(\
             "Adjust transmission", _parameters_gbox)
        self.adjust_transmission_cbox.setChecked(True)

        # Layout --------------------------------------------------------------
        _parameters_gbox_hlayout = QHBoxLayout(_parameters_gbox)
        _parameters_gbox_hlayout.addWidget(_count_time_label)
        _parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _parameters_gbox_hlayout.addWidget(self.adjust_transmission_cbox)
        _parameters_gbox_hlayout.addStretch(0)
        _parameters_gbox_hlayout.setSpacing(2)
        _parameters_gbox_hlayout.setContentsMargins(0, 0, 0, 0)

        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(_parameters_gbox)
        _main_vlayout.setSpacing(6)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)

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

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.path_template_changed)
        self.adjust_transmission_cbox.stateChanged.connect(\
             self.adjust_transmission_state_changed)

        # Other ---------------------------------------------------------------
        self._data_path_widget.data_path_layout.compression_cbox.setVisible(
            False)
Exemplo n.º 4
0
    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')

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

        _main_hlayout = QtGui.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.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 __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)
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, Qt.WindowFlags(fl),
                                'XrayImaging')

        if not name:
            self.setObjectName("create_xray_imaging_widget")

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

        # Internal variables --------------------------------------------------
        self._xray_imaging_parameters = None
        self._processing_parameters = None
        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._xray_imaging_parameters_widget = XrayImagingParametersWidget(\
             self, 'xray_imaging_widget',
             xray_imaging_params=self._xray_imaging_parameters)

        self._acq_widget = AcquisitionWidget(
            self,
            "acquisition_widget",
            layout='vertical',
            acq_params=self._acquisition_parameters,
            path_template=self._path_template)
        self._acq_widget.grid_mode = False

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

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

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

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

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False)
    def __init__(self, parent = None, name = None, fl = 0):
        CreateTaskBase.__init__(self, parent, name, QtCore.Qt.WindowFlags(fl), 'XRF-scan')
 
        if name is not None:
            self.setObjectName(name)

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

        # Internal variables --------------------------------------------------
	self.count_time = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        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')

	_parameters_gbox = QtGui.QGroupBox('Parameters', self)
	_count_time_label = QtGui.QLabel("Count time (sec.):", _parameters_gbox)
	self.count_time_ledit = QtGui.QLineEdit("1", _parameters_gbox)
        self.count_time_ledit.setMaximumWidth(75)

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

        _parameters_gbox_hlayout = QtGui.QHBoxLayout(self)
        _parameters_gbox_hlayout.addWidget(_count_time_label)
        _parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _parameters_gbox_hlayout.addStretch(0)
        _parameters_gbox_hlayout.setSpacing(2)
        _parameters_gbox_hlayout.setContentsMargins(0, 0, 0, 0)
        _parameters_gbox.setLayout(_parameters_gbox_hlayout)

        _main_vlayout = QtGui.QVBoxLayout(self)
	_main_vlayout.addWidget(self._data_path_gbox)
	_main_vlayout.addWidget(_parameters_gbox)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)
        self.setLayout(_main_vlayout)

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

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.data_path_layout.run_number_ledit.textChanged.\
             connect(self._run_number_ledit_change)
        
        self.connect(self._data_path_widget,
                     QtCore.SIGNAL("pathTemplateChanged"),
                     self.handle_path_conflict)
    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._processing_widget = ProcessingWidget(_dc_parameters_widget)
        
        # 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(10)

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

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

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.data_path_layout.prefix_ledit.textChanged.\
             connect(self._prefix_ledit_change)
        self._data_path_widget.data_path_layout.run_number_ledit.textChanged.\
             connect(self._run_number_ledit_change)
        self._acq_widget.madEnergySelectedSignal.\
             connect(self.mad_energy_selected)
        self._acq_widget.acqParametersChangedSignal.\
             connect(self.acq_parameters_changed)
    def __init__(self, parent = None, name = None, fl = 0):
        CreateTaskBase.__init__(self, parent, name, 
            Qt.WindowFlags(fl), 'XRF spectrum')
 
        if name is not None:
            self.setObjectName(name)

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

        # Internal variables --------------------------------------------------
        self.count_time = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._data_path_widget = DataPathWidget(self, 
             data_model = self._path_template, layout = 'vertical')

        _parameters_gbox = QGroupBox('Parameters', self)
        _count_time_label = QLabel("Count time (sec.):", _parameters_gbox)
        self.count_time_ledit = QLineEdit("1", _parameters_gbox)
        #self.count_time_ledit.setMaximumWidth(75)
        self.adjust_transmission_cbox = QCheckBox(\
             "Adjust transmission", _parameters_gbox)
        self.adjust_transmission_cbox.setChecked(True)
        

        # Layout --------------------------------------------------------------
        _parameters_gbox_hlayout = QHBoxLayout(_parameters_gbox)
        _parameters_gbox_hlayout.addWidget(_count_time_label)
        _parameters_gbox_hlayout.addWidget(self.count_time_ledit) 
        _parameters_gbox_hlayout.addWidget(self.adjust_transmission_cbox)
        _parameters_gbox_hlayout.addStretch(0)
        _parameters_gbox_hlayout.setSpacing(2)
        _parameters_gbox_hlayout.setContentsMargins(0, 0, 0, 0)

        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(_parameters_gbox)
        _main_vlayout.setSpacing(6)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)

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

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.path_template_changed)
        self.adjust_transmission_cbox.stateChanged.connect(\
             self.adjust_transmission_state_changed)

        # Other ---------------------------------------------------------------
        self._data_path_widget.data_path_layout.compression_cbox.setVisible(False)
    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")

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

        _main_hlayout = QtGui.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.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()
Exemplo n.º 11
0
    def __init__(self,parent = None,name = None,fl = 0):
        QtGui.QWidget.__init__(self, parent, QtCore.Qt.WindowFlags(fl))

        if not name:
            self.setObjectName("ReferenceImageWidget")

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

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

        # Graphic elements ----------------------------------------------------
        self.group_box = QtGui.QGroupBox("Reference images", self)
        self.tool_box = QtGui.QToolBox(self.group_box)
        self.page_widget = QtGui.QWidget(self.tool_box)
        self.path_widget = DataPathWidget(self.page_widget)
        self.acq_groupbox = QtGui.QGroupBox("Acquisition", self.page_widget)
        self.acq_widget = AcquisitionWidget(self.acq_groupbox, 'horizontal')
        self.acq_widget.acq_widget.inverse_beam_cbx.hide()
        self.acq_widget.acq_widget.shutterless_cbx.hide()
        self.acq_widget.acq_widget.subwedge_size_label.hide()
        self.acq_widget.acq_widget.subwedge_size_ledit.hide()
        #self.acq_widget.acq_widget.setFixedHeight(130)
        self.tool_box.addItem(self.page_widget, "Acquisition parameters")

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

        _page_widget_layout = QtGui.QVBoxLayout(self)
        _page_widget_layout.addWidget(self.path_widget)
        _page_widget_layout.addWidget(self.acq_groupbox)
        _page_widget_layout.addStretch(0)
        _page_widget_layout.setSpacing(0)
        _page_widget_layout.setContentsMargins(0, 0, 0, 0)  
        self.page_widget.setLayout(_page_widget_layout)
        
        _group_box_vlayout = QtGui.QVBoxLayout(self)
        _group_box_vlayout.addWidget(self.tool_box)
        _group_box_vlayout.setSpacing(0)
        _group_box_vlayout.setContentsMargins(0, 0, 0, 0)
        self.group_box.setLayout(_group_box_vlayout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self.group_box)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(_main_vlayout)

        Qt4_widget_colors.set_widget_color(self, Qt4_widget_colors.GROUP_BOX_GRAY) 
    def __init__(self, parent = None, name = None, fl = 0):
        CreateTaskBase.__init__(self, parent, name, 
            Qt.WindowFlags(fl), 'XRF spectrum')
 
        if name is not None:
            self.setObjectName(name)

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

        # Internal variables --------------------------------------------------
        self.count_time = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._data_path_widget = DataPathWidget(self, 
             data_model = self._path_template, layout = 'vertical')

        self._parameters_widget = loadUi(os.path.join(os.path.dirname(__file__),
                        "ui_files/Qt4_xrf_parameters_widget_layout.ui"))
        
        self.adjust_transmission_cbox = self._parameters_widget.adjust_transmission_cbox
        self.excitation_energy_ledit = self._parameters_widget.excitation_energy_ledit
        self.excitation_energy_ledit.setText("15.00")
        self.count_time_ledit = self._parameters_widget.count_time_ledit
        self.count_time_ledit.setText("10")
        
        # Layout --------------------------------------------------------------
        
        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._parameters_widget)
        _main_vlayout.setSpacing(6)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)

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

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.path_template_changed)
        self.adjust_transmission_cbox.stateChanged.connect(\
             self.adjust_transmission_state_changed)
Exemplo n.º 13
0
    def __init__(self, parent=None, name=None, fl=0):
        QWidget.__init__(self, parent, Qt.WindowFlags(fl))

        if not name:
            self.setObjectName("ReferenceImageWidget")

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

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

        # Graphic elements ----------------------------------------------------
        self.group_box = QGroupBox("Reference images", self)
        self.tool_box = QToolBox(self.group_box)
        self.page_widget = QWidget(self.tool_box)
        self.path_widget = DataPathWidget(self.page_widget)
        self.acq_widget = AcquisitionWidget(self.page_widget, 'horizontal')
        self.acq_widget.acq_widget_layout.shutterless_cbx.hide()
        #self.acq_widget.acq_widget_layout.setFixedHeight(130)
        self.tool_box.addItem(self.page_widget, "Acquisition parameters")

        # Layout --------------------------------------------------------------
        _page_widget_layout = QVBoxLayout(self.page_widget)
        _page_widget_layout.addWidget(self.path_widget)
        _page_widget_layout.addWidget(self.acq_widget)
        _page_widget_layout.addStretch(0)
        _page_widget_layout.setSpacing(0)
        _page_widget_layout.setContentsMargins(0, 0, 0, 0)

        _group_box_vlayout = QVBoxLayout(self.group_box)
        _group_box_vlayout.addWidget(self.tool_box)
        _group_box_vlayout.setSpacing(0)
        _group_box_vlayout.setContentsMargins(0, 0, 0, 0)

        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self.group_box)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
Exemplo n.º 14
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)
Exemplo n.º 15
0
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, QtCore.Qt.WindowFlags(fl),
                                'Advanced')

        if not name:
            self.setObjectName("create_advanced_widget")

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

        # Internal variables --------------------------------------------------
        self.init_models()
        self._advanced_methods = None
        self._grid_map = {}

        # Graphic elements ----------------------------------------------------
        self._advanced_methods_widget = uic.loadUi(os.path.join(\
            os.path.dirname(__file__), "ui_files/Qt4_advanced_methods_layout.ui"))

        self._acq_widget = AcquisitionWidget(
            self,
            "acquisition_widget",
            layout='vertical',
            acq_params=self._acquisition_parameters,
            path_template=self._path_template)

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

        # Layout --------------------------------------------------------------
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._advanced_methods_widget)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addStretch(0)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)

        # 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._data_path_widget.pathTemplateChangedSignal.connect(\
             self.handle_path_conflict)

        self._acq_widget.acqParametersChangedSignal.connect(\
             self.handle_path_conflict)
        self._acq_widget.madEnergySelectedSignal.connect(\
             self.mad_energy_selected)

        self._advanced_methods_widget.grid_treewidget.itemSelectionChanged.\
             connect(self.grid_treewidget_item_selection_changed)
        self._advanced_methods_widget.draw_grid_button.clicked.\
             connect(self.draw_grid_button_clicked)
        self._advanced_methods_widget.remove_grid_button.clicked.\
             connect(self.remove_grid_button_clicked)
        self._advanced_methods_widget.hor_spacing_ledit.textChanged.\
             connect(self.spacing_changed)
        self._advanced_methods_widget.ver_spacing_ledit.textChanged.\
             connect(self.spacing_changed)

        self._advanced_methods_widget.move_right_button.clicked.\
             connect(lambda : self.move_grid("right"))
        self._advanced_methods_widget.move_left_button.clicked.\
             connect(lambda : self.move_grid("left"))
        self._advanced_methods_widget.move_up_button.clicked.\
             connect(lambda : self.move_grid("up"))
        self._advanced_methods_widget.move_down_button.clicked.\
             connect(lambda : self.move_grid("down"))

        self._advanced_methods_widget.overlay_cbox.toggled.\
             connect(self.overlay_toggled)
        self._advanced_methods_widget.overlay_slider.valueChanged.\
             connect(self.overlay_alpha_changed)
        self._advanced_methods_widget.move_to_grid_button.clicked.\
             connect(self.move_to_grid)

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False)
        self._acq_widget.use_kappa_phi(False)
        self._acq_widget.acq_widget_layout.num_images_label.setEnabled(False)
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        for col in range(self._advanced_methods_widget.\
                         grid_treewidget.columnCount()):
            self._advanced_methods_widget.grid_treewidget.\
                 resizeColumnToContents(col)
Exemplo n.º 16
0
    def __init__(self, parent = None, name = "xrf_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.xrf_scan_model = queue_model_objects.XRFScan()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self)
        _parameters_widget = QtGui.QWidget(_top_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.other_parameters_gbox = QtGui.QGroupBox("Other parameters", _parameters_widget) 
        self.count_time_label = QtGui.QLabel("Count time:", 
                                             self.other_parameters_gbox)
	self.count_time_ledit = QtGui.QLineEdit(self.other_parameters_gbox)
	self.count_time_ledit.setFixedWidth(50)
        self.adjust_transmission_cbox = QtGui.QCheckBox("Adjust transmission", \
             self.other_parameters_gbox)
        self.adjust_transmission_cbox.hide()
        _snapshot_widget = QtGui.QWidget(self)
        self.position_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
                                          'ui_files/Qt4_snapshot_widget_layout.ui'))
        self.mca_spectrum_widget = McaSpectrumWidget(self)
 
        # Layout -------------------------------------------------------------
        _other_parameters_gbox_hlayout = QtGui.QHBoxLayout(self.other_parameters_gbox)
        _other_parameters_gbox_hlayout.addWidget(self.count_time_label)  
        _other_parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _other_parameters_gbox_hlayout.addWidget(self.adjust_transmission_cbox)
        _other_parameters_gbox_hlayout.addStretch(0)
        _other_parameters_gbox_hlayout.setSpacing(2)
        _other_parameters_gbox_hlayout.setContentsMargins(3, 3, 3, 3)

        _parameters_widget_layout = QtGui.QVBoxLayout(_parameters_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addWidget(self.other_parameters_gbox)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _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(0)

        _top_widget_layout = QtGui.QHBoxLayout(_top_widget)
        _top_widget_layout.addWidget(_parameters_widget)
        _top_widget_layout.addWidget(_snapshot_widget)
        _top_widget_layout.setSpacing(2)
        _top_widget_layout.setContentsMargins(0, 0, 0, 0)
        
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.mca_spectrum_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
       
        # SizePolicies -------------------------------------------------------
        self.position_widget.setFixedSize(457, 350)
        self.mca_spectrum_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                               QtGui.QSizePolicy.Expanding)
        _top_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Fixed)

        # 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.count_time_ledit.textChanged.connect(self._count_time_ledit_change)
        
        # Other ---------------------------------------------------------------
        Qt4_widget_colors.set_widget_color(self.other_parameters_gbox,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.data_path_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY) 
        Qt4_widget_colors.set_widget_color(self.position_widget, 
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
Exemplo n.º 17
0
class CreateAdvancedWidget(CreateTaskBase):
    """Widget used to create advanced collection methods
    """

    def __init__(self, parent=None,name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, 
            QtCore.Qt.WindowFlags(fl), 'Advanced')

        if not name:
            self.setObjectName("create_advanced_widget")

        # Hardware objects ----------------------------------------------------
 
        # Internal variables --------------------------------------------------
        self.init_models()
        self._advanced_methods = None
        self._grid_map = {}

        # Graphic elements ----------------------------------------------------
        self._advanced_methods_widget = uic.loadUi(os.path.join(\
            os.path.dirname(__file__), "ui_files/Qt4_advanced_methods_layout.ui"))

        self._acq_widget =  AcquisitionWidget(self, "acquisition_widget",
             layout='vertical', acq_params=self._acquisition_parameters,
             path_template=self._path_template)

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

        # Layout --------------------------------------------------------------
        _main_vlayout = QtGui.QVBoxLayout(self) 
        _main_vlayout.addWidget(self._advanced_methods_widget)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addStretch(0)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)

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

        # Qt signal/slot connections ------------------------------------------
        self._acq_widget.acqParametersChangedSignal.\
             connect(self.acq_parameters_changed)
        self._acq_widget.madEnergySelectedSignal.\
             connect(self.mad_energy_selected)
        self._acq_widget.acq_widget_layout.set_max_osc_range_button.clicked.\
             connect(self.set_max_osc_range_clicked)

        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.acq_parameters_changed)

        self._advanced_methods_widget.grid_treewidget.itemSelectionChanged.\
             connect(self.grid_treewidget_item_selection_changed)
        self._advanced_methods_widget.draw_grid_button.clicked.\
             connect(self.draw_grid_button_clicked)
        self._advanced_methods_widget.remove_grid_button.clicked.\
             connect(self.remove_grid_button_clicked)
        self._advanced_methods_widget.hor_spacing_ledit.textChanged.\
             connect(self.spacing_changed)
        self._advanced_methods_widget.ver_spacing_ledit.textChanged.\
             connect(self.spacing_changed)

        self._advanced_methods_widget.move_right_button.clicked.\
             connect(lambda : self.move_grid("right"))
        self._advanced_methods_widget.move_left_button.clicked.\
             connect(lambda : self.move_grid("left"))
        self._advanced_methods_widget.move_up_button.clicked.\
             connect(lambda : self.move_grid("up"))
        self._advanced_methods_widget.move_down_button.clicked.\
             connect(lambda : self.move_grid("down"))        
      
        self._advanced_methods_widget.overlay_cbox.toggled.\
             connect(self.overlay_toggled)
        self._advanced_methods_widget.overlay_slider.valueChanged.\
             connect(self.overlay_alpha_changed) 
        self._advanced_methods_widget.overlay_color_button.clicked.\
             connect(self.overlay_change_color)
        self._advanced_methods_widget.move_to_grid_button.clicked.\
             connect(self.move_to_grid)

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False) 
        self._acq_widget.acq_widget_layout.num_images_label.setEnabled(False)
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        for col in range(self._advanced_methods_widget.\
                         grid_treewidget.columnCount()):
            self._advanced_methods_widget.grid_treewidget.\
                 resizeColumnToContents(col)
        self._acq_widget.acq_widget_layout.\
             set_max_osc_range_button.setEnabled(False)

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

    def _init_models(self):
        """
        Descript. :
        """
        CreateTaskBase.init_models(self)
        self._processing_parameters = queue_model_objects.ProcessingParameters()

        if self._beamline_setup_hwobj is not None:
            has_shutter_less = self._beamline_setup_hwobj.\
                               detector_has_shutterless()
            self._acquisition_parameters.shutterless = has_shutter_less

            self._acquisition_parameters = self._beamline_setup_hwobj.\
                get_default_acquisition_parameters("default_advanced_values")

            if not self._advanced_methods:
                self._advanced_methods = self._beamline_setup_hwobj.get_advanced_methods()            
                if self._advanced_methods:
                   for method in self._advanced_methods:
                       self._advanced_methods_widget.method_combo.addItem(method)
                else:
                   self.setEnabled(False)    

            self.grid_treewidget_item_selection_changed()

    def set_beamline_setup(self, bl_setup_hwobj):
        """
        In plate mode osciallation is start is in the middle of grid
        """
        CreateTaskBase.set_beamline_setup(self, bl_setup_hwobj)

        self._acq_widget.acq_widget_layout.osc_start_label.\
             setText("Oscillation middle:")
        self._acq_widget.acq_widget_layout.set_max_osc_range_button.setVisible(\
             self._beamline_setup_hwobj.diffractometer_hwobj.in_plate_mode())

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

        if len(self._advanced_methods_widget.\
           grid_treewidget.selectedItems()) == 0:
            msg = "No grid selected. Continuing with automatic grid."
            logging.getLogger("GUI").info(msg)
        return result
            
    def update_processing_parameters(self, crystal):
        """
        Descript. :
        """
        return

    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._acq_widget.update_data_model(self._acquisition_parameters,
                                                self._path_template)            
        elif isinstance(tree_item, Qt4_queue_item.BasketQueueItem):
            self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.DataCollectionQueueItem):
            data_collection = tree_item.get_model()
            if tree_item.get_model().is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

            # sample_data_model = self.get_sample_item(tree_item).get_model()
            #self._acq_widget.disable_inverse_beam(True)
            #self._graphics_manager_hwobj.de_select_all()
            self._graphics_manager_hwobj.select_shape(data_collection.grid)

            self._path_template = data_collection.get_path_template()
            self._data_path_widget.update_data_model(self._path_template)

            self._acquisition_parameters = data_collection.acquisitions[0].\
                                           acquisition_parameters
            self._acq_widget.update_data_model(self._acquisition_parameters,
                                               self._path_template)
            self.get_acquisition_widget().use_osc_start(True)
        else:
            self.setDisabled(True)
        self.grid_treewidget_item_selection_changed()
  
    def _create_task(self,  sample, shape):
        """Creates tasks based on selected grids

        :param sample: selected sample object
        :type sample: SampleQueueItem
        :param shape: selected shape
        :type shape: Qt4_GraphicsLib.GraphicsItem
        """
        tasks = []
        selected_grids = self.get_selected_grids() 

        if len(selected_grids) == 0:
            selected_grids.append(self._graphics_manager_hwobj.\
                update_auto_grid()) 

        for grid in selected_grids:
            grid.set_snapshot(self._graphics_manager_hwobj.\
                  get_scene_snapshot(grid))

            grid_properties = grid.get_properties()

            acq = self._create_acq(sample)
            acq.acquisition_parameters.centred_position = \
                grid.get_centred_position()
            acq.acquisition_parameters.mesh_range = \
                [grid_properties["dx_mm"], grid_properties["dy_mm"]]
            acq.acquisition_parameters.num_lines = \
                grid_properties["num_lines"]
            acq.acquisition_parameters.num_images = \
                grid_properties["num_lines"] * \
                grid_properties["num_images_per_line"]
            grid.set_osc_range(acq.acquisition_parameters.osc_range)

            processing_parameters = deepcopy(self._processing_parameters)

            dc = queue_model_objects.DataCollection([acq],
                                     sample.crystals[0],
                                     processing_parameters)

            dc.set_name(acq.path_template.get_prefix())
            dc.set_number(acq.path_template.run_number)
            dc.set_experiment_type(EXPERIMENT_TYPE.MESH)
            dc.set_requires_centring(False)
            dc.grid = grid

            exp_type = str(self._advanced_methods_widget.\
                method_combo.currentText())
            if exp_type == "MeshScan":
                dc.run_processing_parallel = "MeshScan"
                tasks.append(dc)
            elif exp_type == "XrayCentering":
                xray_centering = queue_model_objects.XrayCentering(\
                   dc, sample.crystals[0])
                dc.run_processing_parallel = "XrayCentering"
                tasks.append(xray_centering)
            self._path_template.run_number += 1

            return tasks

    def shape_created(self, shape, shape_type):
        """If a grid is created then adds it to the treewidget.
           A binding between graphical grid and treewidget item is based
           on the self._grid_map

        :param shape: graphics object
        :type shape: Qt4_GraphicsLib.GraphicsItem
        :param shape_type: type of the object (point, line, grid)
        :type shape_type: str 
        """
        if shape_type == "Grid":
            self._advanced_methods_widget.grid_treewidget.clearSelection()
            grid_properties = shape.get_properties()
            info_str_list = []
            info_str_list.append(grid_properties["name"])
            info_str_list.append("%d" % (grid_properties["beam_x_mm"] * 1000.0))
            info_str_list.append("%d" % (grid_properties["beam_y_mm"] * 1000.0))
            info_str_list.append("%d" % grid_properties["num_lines"])
            info_str_list.append("%d" % grid_properties["num_images_per_line"])

            grid_treewidget_item = QtGui.QTreeWidgetItem(\
                self._advanced_methods_widget.grid_treewidget,
                info_str_list)
            grid_treewidget_item.setSelected(True)
            self._grid_map[shape] = grid_treewidget_item
            self.grid_treewidget_item_selection_changed()
            
    def shape_deleted(self, shape, shape_type):
        """Removes shape from QTreeWidget and self._grid_map

        :param shape: graphics object
        :type shape: QtGraphicsLib.GraphicsItem
        :param shape_type: type of the object (point, line, grid)
        :type shape_type: str 
        """
        if self._grid_map.get(shape):
            treewidget_item_modelindex = self._advanced_methods_widget.\
                 grid_treewidget.indexFromItem(self._grid_map[shape])
            self._advanced_methods_widget.grid_treewidget.takeTopLevelItem(\
                 treewidget_item_modelindex.row())
            self._grid_map.pop(shape) 

    def grid_treewidget_item_selection_changed(self):
        """Updates acquisition parameters based on the selected grid.
        """
        self.enable_grid_controls(False)
      
        osc_dynamic_limits = None
        if self._beamline_setup_hwobj.diffractometer_hwobj.in_plate_mode():
            osc_dynamic_limits = self._beamline_setup_hwobj.\
                diffractometer_hwobj.get_osc_dynamic_limits()
        self._acq_widget.acq_widget_layout.\
             set_max_osc_range_button.setEnabled(False)

        for item in self._grid_map.items():
            grid = item[0]
            treewidget_item = item[1]
  
            if treewidget_item.isSelected():
                grid_properties = grid.get_properties() 
                cell_count = grid_properties["num_lines"] * \
                             grid_properties["num_images_per_line"]
                self._acq_widget.acq_widget_layout.num_images_ledit.setText(\
                     "%d" % cell_count)
                self._acq_widget.acq_widget_layout.first_image_ledit.setText(\
                     "%d" % grid_properties["first_image_num"])
                centred_point = grid.get_centred_position()
                self._acq_widget.acq_widget_layout.osc_start_ledit.setText(\
                     "%.2f" % float(centred_point.phi))
                self._acq_widget.acq_widget_layout.kappa_ledit.setText(\
                     "%.2f" % float(centred_point.kappa))
                self._acq_widget.acq_widget_layout.kappa_phi_ledit.setText(\
                     "%.2f" % float(centred_point.kappa_phi))
                self._advanced_methods_widget.hor_spacing_ledit.setText(\
                     "%.2f" % (float(grid_properties["xOffset"]) * 1000))
                self._advanced_methods_widget.ver_spacing_ledit.setText(\
                     "%.2f" % (float(grid_properties["yOffset"]) * 1000))

             
                if osc_dynamic_limits:
                    osc_range_limits = \
                        (0, 
                         min(abs(centred_point.phi - osc_dynamic_limits[0]),
                             abs(osc_dynamic_limits[1] - centred_point.phi)) /\
                         float(grid_properties["num_images_per_line"]))

                    self._acq_widget.update_osc_range_limits(osc_range_limits)
                    self._acq_widget.update_num_images_limits(\
                         grid_properties["num_lines"] * \
                         grid_properties["num_images_per_line"])

                grid.setSelected(True) 
                self.enable_grid_controls(True)
                self._acq_widget.acq_widget_layout.\
                     set_max_osc_range_button.setEnabled(True)
            else:
                grid.setSelected(False)

    def get_selected_grids(self):
        """Returns selected grids
        
        :returns: list with grid objects
        """
        selected_grids = [] 
        for grid, grid_treewidget_item in self._grid_map.iteritems():
            if grid_treewidget_item.isSelected():
                selected_grids.append(grid)
        return selected_grids

    def draw_grid_button_clicked(self):
        """Starts grid drawing
        """
        self._graphics_manager_hwobj.create_grid(self.get_spacing())

    def remove_grid_button_clicked(self):
        """Removes selected grid
        """
        grid_to_delete = None 
        for grid, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_to_delete = grid
                break

        if grid_to_delete:
            self._graphics_manager_hwobj.delete_shape(grid_to_delete)
            self._advanced_methods_widget.move_to_grid_button.setEnabled(False)           

    def get_spacing(self):
        """Returns spacing in microns

        :returns: list of two floats
        """
        spacing = [0, 0]
        try:
           spacing[0] = float(self._advanced_methods_widget.\
               hor_spacing_ledit.text()) / 1000.0
        except:
           pass
        try:
           spacing[1] = float(self._advanced_methods_widget.\
               ver_spacing_ledit.text()) / 1000.0
        except:
           pass
        return spacing

    def spacing_changed(self, value):
        """Updates spacing of the selected grid
        """
        spacing = self.get_spacing()
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.set_spacing(spacing)
                #self._graphics_manager_hwobj.\
                #     update_grid_motor_positions(grid_object)
                break

    def move_to_grid(self):
        """Moves diffractometer to the center of the grid
        """
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                self._beamline_setup_hwobj.diffractometer_hwobj.\
                     move_to_centred_position(grid_object.get_centred_position())
                break

    def overlay_toggled(self, state):
        """Toggles (on/off) overlay
        """
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.set_display_overlay(state)
                break
           
    def overlay_alpha_changed(self, alpha_value):
        """Changes the transperency of the grid
        """
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.set_fill_alpha(alpha_value)
                break

    def overlay_change_color(self):
        """Changes the default color (blue) of overlay
        """
        color = QtGui.QColorDialog.getColor()
        if color.isValid():
            for grid_object, treewidget_item in self._grid_map.iteritems():
                if treewidget_item.isSelected():
                    grid_object.set_base_color(color)
                    break

    def move_grid(self, direction):
        """Moves grid by one pix in selected direction

        :param direction: direction to move (right, left, up, down)
        :type direction: str
        """
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.move_by_pix(direction)
                self._graphics_manager_hwobj.\
                     update_grid_motor_positions(grid_object)
                break

    def enable_grid_controls(self, state):
        """Enables grid controls if a grid is selectd
        """
        self._advanced_methods_widget.overlay_cbox.setEnabled(state)
        self._advanced_methods_widget.overlay_slider.setEnabled(state)
        self._advanced_methods_widget.overlay_color_button.setEnabled(state)
        self._advanced_methods_widget.move_to_grid_button.setEnabled(state)
        self._advanced_methods_widget.remove_grid_button.setEnabled(state)        

        self._advanced_methods_widget.move_right_button.setEnabled(state)
        self._advanced_methods_widget.move_left_button.setEnabled(state)
        self._advanced_methods_widget.move_up_button.setEnabled(state)
        self._advanced_methods_widget.move_down_button.setEnabled(state)

    def set_max_osc_range_clicked(self, state):
        """Sets the osc range based on grid (number of images per line
           and osc in the middle of the grid)        
        """
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_properties = grid_object.get_properties()
                self._acq_widget.acq_widget_layout.osc_range_ledit.setText(\
                     "%.4f" % (self._acq_widget.osc_range_validator.top() - 0.0001))
                self._acq_widget.update_num_images_limits(\
                     grid_properties["num_lines"] * \
                     grid_properties["num_images_per_line"])
                break
Exemplo n.º 18
0
    def __init__(self, parent=None,name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, 
            Qt.WindowFlags(fl), 'XrayImaging')

        if not name:
            self.setObjectName("create_xray_imaging_widget")

        # Hardware objects ----------------------------------------------------
 
        # Internal variables --------------------------------------------------
        self._xray_imaging_parameters = None
        self._processing_parameters = None
        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._xray_imaging_parameters_widget = XrayImagingParametersWidget(\
             self, 'xray_imaging_widget',
             xray_imaging_params=self._xray_imaging_parameters)

        self._acq_widget =  AcquisitionWidget(self, "acquisition_widget",
             layout='vertical', acq_params=self._acquisition_parameters,
             path_template=self._path_template)
        self._acq_widget.grid_mode = False

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

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

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

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

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False)
        self._acq_widget.acq_widget_layout.max_osc_range_cbx.setVisible(False)
        self._acq_widget.acq_widget_layout.first_image_label.setVisible(False)
        self._acq_widget.acq_widget_layout.first_image_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.detector_roi_mode_label.setVisible(False)
        self._acq_widget.acq_widget_layout.detector_roi_mode_combo.setVisible(False)
        self._acq_widget.acq_widget_layout.energies_combo.setVisible(False)
        self._acq_widget.acq_widget_layout.mad_cbox.setVisible(False)
        self._acq_widget.acq_widget_layout.energy_label.setVisible(False)
        self._acq_widget.acq_widget_layout.energy_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.transmission_label.setVisible(False)
        self._acq_widget.acq_widget_layout.transmission_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.resolution_label.setVisible(False)
        self._acq_widget.acq_widget_layout.resolution_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.kappa_label.setVisible(False)
        self._acq_widget.acq_widget_layout.kappa_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.kappa_phi_label.setVisible(False)
        self._acq_widget.acq_widget_layout.kappa_phi_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.shutterless_cbx.setVisible(False)
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)
Exemplo n.º 20
0
    def __init__(self, parent=None,name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, 
            Qt.WindowFlags(fl), 'Advanced')

        if not name:
            self.setObjectName("create_advanced_widget")

        # Hardware objects ----------------------------------------------------
 
        # Internal variables --------------------------------------------------
        self.init_models()
        self._advanced_methods = None
        self._grid_map = {}
        self.spacing = [0, 0]
        self.dc_selected = False

        # Graphic elements ----------------------------------------------------
        self._advanced_methods_widget = loadUi(os.path.join(\
            os.path.dirname(__file__), "ui_files/Qt4_advanced_methods_layout.ui"))

        self._acq_widget =  AcquisitionWidget(self, "acquisition_widget",
             layout='vertical', acq_params=self._acquisition_parameters,
             path_template=self._path_template)
        self._acq_widget.grid_mode = True

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

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

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

        # Qt signal/slot connections ------------------------------------------
        self._acq_widget.acqParametersChangedSignal.\
             connect(self.acq_parameters_changed)
        self._acq_widget.madEnergySelectedSignal.\
             connect(self.mad_energy_selected)

        self._acq_widget.acq_widget_layout.osc_range_ledit.textEdited.connect(\
             self.grid_osc_range_ledit_changed)
        self._acq_widget.acq_widget_layout.osc_total_range_ledit.textEdited.connect(\
             self.grid_osc_total_range_ledit_changed)

        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.path_template_changed)

        self._advanced_methods_widget.grid_treewidget.itemSelectionChanged.\
             connect(self.grid_treewidget_item_selection_changed)
        self._advanced_methods_widget.draw_grid_button.clicked.\
             connect(self.draw_grid_button_clicked)
        self._advanced_methods_widget.remove_grid_button.clicked.\
             connect(self.remove_grid_button_clicked)
        self._advanced_methods_widget.hor_spacing_ledit.textEdited.\
             connect(self.hor_spacing_changed)
        self._advanced_methods_widget.ver_spacing_ledit.textEdited.\
             connect(self.ver_spacing_changed)

        self._advanced_methods_widget.move_right_button.clicked.\
             connect(lambda : self.move_grid("right"))
        self._advanced_methods_widget.move_left_button.clicked.\
             connect(lambda : self.move_grid("left"))
        self._advanced_methods_widget.move_up_button.clicked.\
             connect(lambda : self.move_grid("up"))
        self._advanced_methods_widget.move_down_button.clicked.\
             connect(lambda : self.move_grid("down"))        
      
        self._advanced_methods_widget.overlay_cbox.toggled.\
             connect(self.overlay_toggled)
        self._advanced_methods_widget.overlay_slider.valueChanged.\
             connect(self.overlay_alpha_changed) 
        self._advanced_methods_widget.overlay_color_button.clicked.\
             connect(self.overlay_change_color)
        self._advanced_methods_widget.move_to_grid_button.clicked.\
             connect(self.move_to_grid)

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False) 
        self._acq_widget.acq_widget_layout.num_images_label.setEnabled(False)
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        for col in range(self._advanced_methods_widget.\
                         grid_treewidget.columnCount()):
            self._advanced_methods_widget.grid_treewidget.\
                 resizeColumnToContents(col)

        self._acq_widget.acq_widget_layout.osc_total_range_label.setText(\
            "Total osc. range per line")
Exemplo n.º 21
0
class CreateAdvancedWidget(CreateTaskBase):
    """Widget used to create advanced collection methods
    """

    def __init__(self, parent=None,name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, 
            Qt.WindowFlags(fl), 'Advanced')

        if not name:
            self.setObjectName("create_advanced_widget")

        # Hardware objects ----------------------------------------------------
 
        # Internal variables --------------------------------------------------
        self.init_models()
        self._advanced_methods = None
        self._grid_map = {}
        self.spacing = [0, 0]
        self.dc_selected = False

        # Graphic elements ----------------------------------------------------
        self._advanced_methods_widget = loadUi(os.path.join(\
            os.path.dirname(__file__), "ui_files/Qt4_advanced_methods_layout.ui"))

        self._acq_widget =  AcquisitionWidget(self, "acquisition_widget",
             layout='vertical', acq_params=self._acquisition_parameters,
             path_template=self._path_template)
        self._acq_widget.grid_mode = True

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

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

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

        # Qt signal/slot connections ------------------------------------------
        self._acq_widget.acqParametersChangedSignal.\
             connect(self.acq_parameters_changed)
        self._acq_widget.madEnergySelectedSignal.\
             connect(self.mad_energy_selected)

        self._acq_widget.acq_widget_layout.osc_range_ledit.textEdited.connect(\
             self.grid_osc_range_ledit_changed)
        self._acq_widget.acq_widget_layout.osc_total_range_ledit.textEdited.connect(\
             self.grid_osc_total_range_ledit_changed)

        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.path_template_changed)

        self._advanced_methods_widget.grid_treewidget.itemSelectionChanged.\
             connect(self.grid_treewidget_item_selection_changed)
        self._advanced_methods_widget.draw_grid_button.clicked.\
             connect(self.draw_grid_button_clicked)
        self._advanced_methods_widget.remove_grid_button.clicked.\
             connect(self.remove_grid_button_clicked)
        self._advanced_methods_widget.hor_spacing_ledit.textEdited.\
             connect(self.hor_spacing_changed)
        self._advanced_methods_widget.ver_spacing_ledit.textEdited.\
             connect(self.ver_spacing_changed)

        self._advanced_methods_widget.move_right_button.clicked.\
             connect(lambda : self.move_grid("right"))
        self._advanced_methods_widget.move_left_button.clicked.\
             connect(lambda : self.move_grid("left"))
        self._advanced_methods_widget.move_up_button.clicked.\
             connect(lambda : self.move_grid("up"))
        self._advanced_methods_widget.move_down_button.clicked.\
             connect(lambda : self.move_grid("down"))        
      
        self._advanced_methods_widget.overlay_cbox.toggled.\
             connect(self.overlay_toggled)
        self._advanced_methods_widget.overlay_slider.valueChanged.\
             connect(self.overlay_alpha_changed) 
        self._advanced_methods_widget.overlay_color_button.clicked.\
             connect(self.overlay_change_color)
        self._advanced_methods_widget.move_to_grid_button.clicked.\
             connect(self.move_to_grid)

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False) 
        self._acq_widget.acq_widget_layout.num_images_label.setEnabled(False)
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        for col in range(self._advanced_methods_widget.\
                         grid_treewidget.columnCount()):
            self._advanced_methods_widget.grid_treewidget.\
                 resizeColumnToContents(col)

        self._acq_widget.acq_widget_layout.osc_total_range_label.setText(\
            "Total osc. range per line")
        #self.enable_widgets(False)

    def enable_widgets(self, state):
        return
        self._acq_widget.setEnabled(state)
        self._data_path_widget.setEnabled(state)

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

    def _init_models(self):
        """
        Descript. :
        """
        CreateTaskBase.init_models(self)
        self._processing_parameters = queue_model_objects.ProcessingParameters()

        if self._beamline_setup_hwobj is not None:
            has_shutter_less = self._beamline_setup_hwobj.\
                               detector_has_shutterless()
            self._acquisition_parameters.shutterless = has_shutter_less

            self._acquisition_parameters = self._beamline_setup_hwobj.\
                get_default_acquisition_parameters("default_advanced_values")

            if not self._advanced_methods:
                self._advanced_methods = self._beamline_setup_hwobj.get_advanced_methods()            
                if self._advanced_methods:
                   for method in self._advanced_methods:
                       self._advanced_methods_widget.method_combo.addItem(method)
                else:
                   self.setEnabled(False)    

            self.grid_treewidget_item_selection_changed()

    def set_beamline_setup(self, bl_setup_hwobj):
        """
        In plate mode oscillation start is in the middle of the grid
        """
        CreateTaskBase.set_beamline_setup(self, bl_setup_hwobj)

        self._acq_widget.acq_widget_layout.osc_start_label.\
             setText("Oscillation middle:")

        hor_size, ver_size = bl_setup_hwobj.beam_info_hwobj.get_beam_size()
        self.spacing[0] = hor_size
        self.spacing[1] = ver_size
        self._advanced_methods_widget.hor_spacing_ledit.setText(\
             "%.1f" % (hor_size * 1000))
        self._advanced_methods_widget.ver_spacing_ledit.setText(\
             "%.1f" % (ver_size * 1000))

    def set_beam_info(self, beam_info):
        self.spacing[0] = beam_info["size_x"]
        self.spacing[1] = beam_info["size_y"]
        self._advanced_methods_widget.hor_spacing_ledit.setText(\
             "%.1f" % (beam_info["size_x"] * 1000))
        self._advanced_methods_widget.ver_spacing_ledit.setText(\
             "%.1f" % (beam_info["size_x"] * 1000))

    def approve_creation(self):
        """
        Descript. :
        """
        result = CreateTaskBase.approve_creation(self)
        selected_grid = self.get_selected_shapes()[0]

        if not selected_grid:
            msg = "No grid selected. Please select a grid to continue!"
            logging.getLogger("GUI").warning(msg)
            result = False
            #selected_grid = self._graphics_manager_hwobj.get_auto_grid()
        else:
            grid_properties = selected_grid.get_properties()
            exp_time = float(self._acq_widget.acq_widget_layout.exp_time_ledit.text())
            speed = grid_properties["yOffset"] / exp_time
            if speed >= 2.25:
                logging.getLogger("GUI").error("Translation speed %.3f is above the limit 2.25" % speed)
                return False
            osc_range_per_frame = float(self._acq_widget.acq_widget_layout.osc_range_ledit.text())
            speed = osc_range_per_frame / exp_time
            if speed >= 300:
                logging.getLogger("GUI").error("Rotation speed per frame %.3f is above the limit 300" % speed)
                return False
        return result
            
    def update_processing_parameters(self, crystal):
        """
        Descript. :
        """
        return

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

        if isinstance(tree_item, Qt4_queue_item.SampleQueueItem):
            pass
        elif isinstance(tree_item, Qt4_queue_item.BasketQueueItem):
            pass
            #self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.DataCollectionQueueItem) or \
             isinstance(tree_item, Qt4_queue_item.XrayCenteringQueueItem):

            if isinstance(tree_item, Qt4_queue_item.XrayCenteringQueueItem):
                data_collection = tree_item.get_model().reference_image_collection                 
            else:
                data_collection = tree_item.get_model()

            if tree_item.get_model().is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

            if data_collection.is_mesh():
                # sample_data_model = self.get_sample_item(tree_item).get_model()
                #self._acq_widget.disable_inverse_beam(True)
                #self._graphics_manager_hwobj.de_select_all()
                self._graphics_manager_hwobj.select_shape(data_collection.grid)
                self._advanced_methods_widget.grid_treewidget.setCurrentItem(\
                     self._grid_map[data_collection.grid])

                self._path_template = data_collection.get_path_template()
                self._data_path_widget.update_data_model(self._path_template)

                self._acquisition_parameters = data_collection.acquisitions[0].\
                                              acquisition_parameters
                self._acq_widget.update_data_model(self._acquisition_parameters,
                                                   self._path_template)
                #self.get_acquisition_widget().use_osc_start(True)
            self.dc_selected = True
        else:
            self.setDisabled(True)
        self.grid_treewidget_item_selection_changed()
  
    def _create_task(self,  sample, shape):
        """Creates tasks based on selected grids

        :param sample: selected sample object
        :type sample: SampleQueueItem
        :param shape: selected shape
        :type shape: Qt4_GraphicsLib.GraphicsItem
        """
        tasks = []
        selected_grid = self.get_selected_shapes()[0]
        mesh_dc = self._create_dc_from_grid(sample, selected_grid)

        exp_type = str(self._advanced_methods_widget.method_combo.currentText())
        if exp_type == "MeshScan":
            tasks.append(mesh_dc)
        elif exp_type == "XrayCentering":
            xray_centering = queue_model_objects.XrayCentering(mesh_dc)
            tasks.append(xray_centering)
        else:
            logging.getLogger("GUI").\
                warning("Method %s does not exist in queue_model_objects" % exp_type)
        mesh_dc.run_processing_parallel = exp_type

        return tasks

    def shape_created(self, shape, shape_type):
        """If a grid is created then adds it to the treewidget.
           A binding between graphical grid and treewidget item is based
           on the self._grid_map

        :param shape: graphics object
        :type shape: Qt4_GraphicsLib.GraphicsItem
        :param shape_type: type of the object (point, line, grid)
        :type shape_type: str 
        """
        if shape_type == "Grid":
            self._advanced_methods_widget.grid_treewidget.clearSelection()
            grid_properties = shape.get_properties()
            info_str_list = []
            info_str_list.append(grid_properties["name"])
            info_str_list.append("%d" % grid_properties["num_lines"])
            info_str_list.append("%d" % grid_properties["num_images_per_line"])

            if not self.dc_selected:
                exp_time = max(float(grid_properties["yOffset"] / 2.245),
                      self._acq_widget.exp_time_validator.bottom()+0.00001)
                self._acq_widget.acq_widget_layout.exp_time_ledit.setText("%.6f" % exp_time)
 
            grid_treewidget_item = QTreeWidgetItem(\
                self._advanced_methods_widget.grid_treewidget,
                info_str_list)
            self._grid_map[shape] = grid_treewidget_item

            if not self.dc_selected:
                grid_treewidget_item.setSelected(True)
                self.grid_treewidget_item_selection_changed()
                if self._acq_widget.acq_widget_layout.max_osc_range_cbx.isChecked():
                    self._acq_widget.update_osc_total_range_limits(grid_properties["num_images_per_line"])
                else:
                    self.update_grid_osc_total_range()
            
    def shape_deleted(self, shape, shape_type):
        """Removes shape from QTreeWidget and self._grid_map

        :param shape: graphics object
        :type shape: QtGraphicsLib.GraphicsItem
        :param shape_type: type of the object (point, line, grid)
        :type shape_type: str 
        """
        if self._grid_map.get(shape):
            treewidget_item_modelindex = self._advanced_methods_widget.\
                 grid_treewidget.indexFromItem(self._grid_map[shape])
            self._advanced_methods_widget.grid_treewidget.takeTopLevelItem(\
                 treewidget_item_modelindex.row())
            self._grid_map.pop(shape) 

    def grid_treewidget_item_selection_changed(self):
        """Updates acquisition parameters based on the selected grid.
        """
        self.enable_grid_controls(False)
      
        for item in self._grid_map.items():
            grid = item[0]
            treewidget_item = item[1]
  
            if treewidget_item.isSelected():
                grid_properties = grid.get_properties() 
                cell_count = grid_properties["num_lines"] * \
                             grid_properties["num_images_per_line"]
                self._acq_widget.acq_widget_layout.num_images_ledit.setText(\
                     "%d" % cell_count)
                self._acq_widget.acq_widget_layout.first_image_ledit.setText(\
                     "%d" % grid_properties["first_image_num"])
                centred_point = grid.get_centred_position()
                self._acq_widget.acq_widget_layout.kappa_ledit.setText(\
                     "%.2f" % float(centred_point.kappa))
                self._acq_widget.acq_widget_layout.kappa_phi_ledit.setText(\
                     "%.2f" % float(centred_point.kappa_phi))
                self._advanced_methods_widget.hor_spacing_ledit.setText(\
                     "%.2f" % (float(grid_properties["xOffset"]) * 1000))
                self._advanced_methods_widget.ver_spacing_ledit.setText(\
                     "%.2f" % (float(grid_properties["yOffset"]) * 1000))

                treewidget_item.setText(3, str(grid_properties["num_lines"]))
                treewidget_item.setText(4, str(grid_properties["num_images_per_line"]))
            
                grid.setSelected(True) 
                self.enable_grid_controls(True)
            else:
                grid.setSelected(False)

    def get_selected_shapes(self):
        """Returns selected grids
        
        :returns: selected grid objects
        """
        shapes = []
        for grid, grid_treewidget_item in self._grid_map.iteritems():
            if grid_treewidget_item.isSelected():
                shapes.append(grid)
        return shapes

    def get_selected_grid_properties(self):
        """Returns properties of the selected grid

        :returns: dict with properties
        """

        for grid, grid_treewidget_item in self._grid_map.iteritems():
            if grid_treewidget_item.isSelected():
                return grid.get_properties()

    def draw_grid_button_clicked(self):
        """Starts grid drawing
        """
        self._graphics_manager_hwobj.create_grid(self.spacing)

    def remove_grid_button_clicked(self):
        """Removes selected grid
        """
        grid_to_delete = self.get_selected_shapes()[0]

        if grid_to_delete:
            self._graphics_manager_hwobj.delete_shape(grid_to_delete)
            self._advanced_methods_widget.move_to_grid_button.setEnabled(False)           

    def hor_spacing_changed(self, value):
        """Updates spacing of the selected grid
        """
        try:
            self.spacing[0] = float(self._advanced_methods_widget.hor_spacing_ledit.text()) / 1000
            self.set_spacing()
        except:
            pass

    def ver_spacing_changed(self, value):
        """Updates spacing of the selected grid
        """
        try:
            self.spacing[1] = float(self._advanced_methods_widget.ver_spacing_ledit.text()) / 1000
            self.set_spacing()
        except:
            pass

    def set_spacing(self):
        if 0 in self.spacing:
            return

        for grid, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid.set_spacing(self.spacing, adjust_size=\
                   self._advanced_methods_widget.adjust_size_cbox.isChecked())
                grid_properties = grid.get_properties()

                
                treewidget_item.setText(1, str(grid_properties["num_lines"]))
                treewidget_item.setText(2, str(grid_properties["num_images_per_line"]))
                cell_count = grid_properties["num_lines"] * \
                             grid_properties["num_images_per_line"]
                self._acq_widget.acq_widget_layout.num_images_ledit.setText(\
                     str(grid_properties["num_lines"] * \
                         grid_properties["num_images_per_line"]))

    def move_to_grid(self):
        """Moves diffractometer to the center of the grid
        """
        grid = self.get_selected_shapes()[0]

        if grid:
            self._beamline_setup_hwobj.diffractometer_hwobj.\
                move_to_centred_position(grid.get_centred_position())

    def overlay_toggled(self, state):
        """Toggles (on/off) overlay
        """
        grid = self.get_selected_shapes()[0]

        if grid:
            grid.set_display_overlay(state)
           
    def overlay_alpha_changed(self, alpha_value):
        """Changes the transperency of the grid
        """
        grid = self.get_selected_shapes()[0]

        if grid:
            grid.set_fill_alpha(alpha_value)

    def overlay_change_color(self):
        """Changes the default color (blue) of overlay
        """
        color = QColorDialog.getColor()
        grid = self.get_selected_shapes()[0]

        if color.isValid() and grid:
            grid.set_base_color(color)

    def move_grid(self, direction):
        """Moves grid by one pix in selected direction

        :param direction: direction to move (right, left, up, down)
        :type direction: str
        """
        grid = self.get_selected_shapes()[0]

        if grid:
            grid.move_by_pix(direction)
            self._graphics_manager_hwobj.\
                 update_grid_motor_positions(grid)

    def enable_grid_controls(self, state):
        """Enables grid controls if a grid is selectd
        """
        self._advanced_methods_widget.overlay_cbox.setEnabled(state)
        self._advanced_methods_widget.overlay_slider.setEnabled(state)
        self._advanced_methods_widget.overlay_color_button.setEnabled(state)
        self._advanced_methods_widget.move_to_grid_button.setEnabled(state)
        self._advanced_methods_widget.remove_grid_button.setEnabled(state)        

        self._advanced_methods_widget.move_right_button.setEnabled(state)
        self._advanced_methods_widget.move_left_button.setEnabled(state)
        self._advanced_methods_widget.move_up_button.setEnabled(state)
        self._advanced_methods_widget.move_down_button.setEnabled(state)

        self._acq_widget.acq_widget_layout.max_osc_range_cbx.setEnabled(\
             state and self._in_plate_mode)

        self.enable_widgets(state)
        self._acq_widget.emit_acq_parameters_changed()

    def grid_osc_range_ledit_changed(self, new_value):
        """Osc range per frame changed

        :param new_value: new value
        :type new_value: str
        """
        
        self.update_grid_osc_total_range() 

    def grid_osc_total_range_ledit_changed(self, new_value):
        """Updates osc range per frame


        :param new_value: new value
        :type new_value: str
        """

        grid_properties = self.get_selected_grid_properties()
        if grid_properties:
            try:
                self._acq_widget.acq_widget_layout.osc_range_ledit.setText(\
                     "%.4f" % (float(new_value) / grid_properties["num_images_per_line"] - 1e-5))
                self._acq_widget.emit_acq_parameters_changed()
            except:
                pass

    def update_grid_osc_total_range(self):
        """Updates osc range per line
        """

        grid_properties = self.get_selected_grid_properties()
        if grid_properties:
            self._acq_widget.acq_widget_layout.osc_total_range_ledit.setText(str(\
                float(self._acq_widget.acq_widget_layout.osc_range_ledit.text()) * \
                grid_properties["num_images_per_line"]))

    def set_osc_total_range(self, num_images=None, mesh=False):
        grid_properties = self.get_selected_grid_properties()
        if grid_properties:
            CreateTaskBase.set_osc_total_range(self, grid_properties["num_images_per_line"], mesh=True)    
Exemplo n.º 22
0
    def __init__(self, parent = None, name = "xrf_spectrum_parameters_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.xrf_spectrum_model = queue_model_objects.XRFSpectrum()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self)
        _parameters_widget = QtGui.QWidget(_top_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.other_parameters_gbox = QtGui.QGroupBox("Other parameters", _parameters_widget) 
        self.count_time_label = QtGui.QLabel("Count time:", 
                                             self.other_parameters_gbox)
        self.count_time_ledit = QtGui.QLineEdit(self.other_parameters_gbox)
        self.count_time_ledit.setFixedWidth(50)
        self.adjust_transmission_cbox = QtGui.QCheckBox("Adjust transmission", \
             self.other_parameters_gbox)
        self.adjust_transmission_cbox.hide()
        self.mca_spectrum_widget = McaSpectrumWidget(self)
        self.snapshot_widget = SnapshotWidget(self)
 
        # Layout -------------------------------------------------------------
        _other_parameters_gbox_hlayout = QtGui.QHBoxLayout(self.other_parameters_gbox)
        _other_parameters_gbox_hlayout.addWidget(self.count_time_label)  
        _other_parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _other_parameters_gbox_hlayout.addWidget(self.adjust_transmission_cbox)
        _other_parameters_gbox_hlayout.addStretch(0)
        _other_parameters_gbox_hlayout.setSpacing(2)
        _other_parameters_gbox_hlayout.setContentsMargins(0, 0, 0, 0)

        _parameters_widget_layout = QtGui.QVBoxLayout(_parameters_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addWidget(self.other_parameters_gbox)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _parameters_widget_layout.setContentsMargins(0, 0, 0, 0)

        _top_widget_layout = QtGui.QHBoxLayout(_top_widget)
        _top_widget_layout.addWidget(_parameters_widget)
        _top_widget_layout.addWidget(self.snapshot_widget)
        _top_widget_layout.setSpacing(2)
        _top_widget_layout.addStretch(0)
        _top_widget_layout.setContentsMargins(0, 0, 0, 0)
        
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.mca_spectrum_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
       
        # SizePolicies -------------------------------------------------------
        self.mca_spectrum_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                               QtGui.QSizePolicy.Expanding)
        _top_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Fixed)

        # 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.count_time_ledit.textChanged.connect(\
             self._count_time_ledit_change)
Exemplo n.º 23
0
    def __init__(self, parent=None, name="energy_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.energy_scan_model = queue_model_objects.EnergyScan()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self)
        _parameters_widget = QtGui.QWidget(_top_widget)
        self.periodic_table_widget = PeriodicTableWidget(_parameters_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.data_path_widget.data_path_layout.file_name_label.setText('')
        self.data_path_widget.data_path_layout.file_name_value_label.hide()
        self.position_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__),
                         'ui_files/Qt4_snapshot_widget_layout.ui'))
        self.position_widget.setFixedSize(450, 340)

        self.scan_plot_widget = TwoAxisPlotWidget(self)
        self.scan_plot_widget.set_real_time_plot(True)
        self.result_plot_widget = TwoAxisPlotWidget(self)
        """self.scan_plot_widget = ScanPlotWidget(self)
        self.scan_plot_widget.setRealTimePlot(True)
        self.result_plot_widget = ScanPlotWidget(self)
        self.result_plot_widget.setRealTimePlot(False)
        self.scan_plot_widget.setFixedHeight(200)
        self.result_plot_widget.setFixedHeight(200)"""

        # Layout -------------------------------------------------------------
        _parameters_widget_layout = QtGui.QVBoxLayout()
        _parameters_widget_layout.addWidget(self.periodic_table_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _parameters_widget_layout.setContentsMargins(0, 0, 0, 0)
        _parameters_widget.setLayout(_parameters_widget_layout)

        _top_widget_hlayout = QtGui.QHBoxLayout(self)
        _top_widget_hlayout.addWidget(_parameters_widget)
        _top_widget_hlayout.addWidget(self.position_widget)
        _top_widget_hlayout.addStretch(0)
        _top_widget_hlayout.setSpacing(2)
        _top_widget_hlayout.setContentsMargins(0, 0, 0, 0)
        _top_widget.setLayout(_top_widget_hlayout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.scan_plot_widget)
        _main_vlayout.addWidget(self.result_plot_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)

        self.setLayout(_main_vlayout)

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

        # Qt signal/slot connections ------------------------------------------
        #qt.QObject.connect(self.periodic_table_widget, qt.PYSIGNAL('edgeSelected'),
        #                   self.element_clicked)

        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)

        #qt.QObject.connect(qt.qApp, qt.PYSIGNAL('tab_changed'),
        #                   self.tab_changed)

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

        Qt4_widget_colors.set_widget_color(self.periodic_table_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.position_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.data_path_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
class CreateXrayImagingWidget(CreateTaskBase):
    """Widget used to create xray imaging method
    """
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, Qt.WindowFlags(fl),
                                'XrayImaging')

        if not name:
            self.setObjectName("create_xray_imaging_widget")

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

        # Internal variables --------------------------------------------------
        self._xray_imaging_parameters = None
        self._processing_parameters = None
        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._xray_imaging_parameters_widget = XrayImagingParametersWidget(\
             self, 'xray_imaging_widget',
             xray_imaging_params=self._xray_imaging_parameters)

        self._acq_widget = AcquisitionWidget(
            self,
            "acquisition_widget",
            layout='vertical',
            acq_params=self._acquisition_parameters,
            path_template=self._path_template)
        self._acq_widget.grid_mode = False

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

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

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

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

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False)

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

        self._xray_imaging_parameters = queue_model_objects.XrayImagingParameters(
        )

        if self._beamline_setup_hwobj is not None:
            self._acquisition_parameters = self._beamline_setup_hwobj.\
                get_default_acquisition_parameters("default_imaging_values")

    def set_beamline_setup(self, bl_setup_hwobj):
        """
        In plate mode osciallation is start is in the middle of grid
        """
        CreateTaskBase.set_beamline_setup(self, bl_setup_hwobj)
        self._xray_imaging_parameters_widget.set_beamline_setup(bl_setup_hwobj)

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

        if isinstance(tree_item, Qt4_queue_item.SampleQueueItem):
            self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.BasketQueueItem):
            self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.XrayImagingQueueItem):
            data_model = tree_item.get_model()

            self._path_template = data_model.get_path_template()
            self._data_path_widget.update_data_model(self._path_template)

            self._acquisition_parameters = data_model.acquisitions[
                0].acquisition_parameters
            self._acq_widget.update_data_model(self._acquisition_parameters,
                                               self._path_template)

            self._xray_imaging_parameters = data_model.xray_imaging_parameters
            self._xray_imaging_parameters_widget.update_data_model(
                self._xray_imaging_parameters)

            self.setDisabled(False)

    # 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. :
        """
        if isinstance(shape, GraphicsItemPoint):
            snapshot = self._graphics_manager_hwobj.get_scene_snapshot(shape)
            cpos = copy.deepcopy(shape.get_centred_position())
            cpos.snapshot_image = snapshot
        else:
            cpos = queue_model_objects.CentredPosition()
            cpos.snapshot_image = self._graphics_manager_hwobj.get_scene_snapshot(
            )

        self._path_template.run_number += 1

        acq = self._create_acq(sample)
        acq.acquisition_parameters.centred_position = cpos
        dc = queue_model_objects.XrayImaging(
            self._xray_imaging_parameters.copy(), [acq], sample.crystals[0])
        dc.set_name(acq.path_template.get_prefix())
        dc.set_number(acq.path_template.run_number)
        dc.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.NATIVE

        return [dc]
Exemplo n.º 25
0
    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()
Exemplo n.º 26
0
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 CreateAdvancedWidget(CreateTaskBase):
    """Widget used to create advanced collection methods
    """

    def __init__(self, parent=None,name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, 
            Qt.WindowFlags(fl), 'Advanced')

        if not name:
            self.setObjectName("create_advanced_widget")

        # Hardware objects ----------------------------------------------------
 
        # Internal variables --------------------------------------------------
        self.init_models()
        self._advanced_methods = None
        self._grid_map = {}
        self.spacing = [0, 0]
        self.dc_selected = False

        # Graphic elements ----------------------------------------------------
        self._advanced_methods_widget = loadUi(os.path.join(\
            os.path.dirname(__file__), "ui_files/Qt4_advanced_methods_layout.ui"))

        self._acq_widget =  AcquisitionWidget(self, "acquisition_widget",
             layout='vertical', acq_params=self._acquisition_parameters,
             path_template=self._path_template)
        self._acq_widget.grid_mode = True

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

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

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

        # Qt signal/slot connections ------------------------------------------
        self._acq_widget.acqParametersChangedSignal.\
             connect(self.acq_parameters_changed)
        self._acq_widget.madEnergySelectedSignal.\
             connect(self.mad_energy_selected)

        self._acq_widget.acq_widget_layout.osc_range_ledit.textEdited.connect(\
             self.grid_osc_range_ledit_changed)
        self._acq_widget.acq_widget_layout.osc_total_range_ledit.textEdited.connect(\
             self.grid_osc_total_range_ledit_changed)
        self._acq_widget.acq_widget_layout.set_max_osc_range_button.clicked.\
             connect(self.set_max_osc_total_range_clicked)

        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.path_template_changed)

        self._advanced_methods_widget.grid_treewidget.itemSelectionChanged.\
             connect(self.grid_treewidget_item_selection_changed)
        self._advanced_methods_widget.draw_grid_button.clicked.\
             connect(self.draw_grid_button_clicked)
        self._advanced_methods_widget.remove_grid_button.clicked.\
             connect(self.remove_grid_button_clicked)
        self._advanced_methods_widget.hor_spacing_ledit.textEdited.\
             connect(self.hor_spacing_changed)
        self._advanced_methods_widget.ver_spacing_ledit.textEdited.\
             connect(self.ver_spacing_changed)

        self._advanced_methods_widget.move_right_button.clicked.\
             connect(lambda : self.move_grid("right"))
        self._advanced_methods_widget.move_left_button.clicked.\
             connect(lambda : self.move_grid("left"))
        self._advanced_methods_widget.move_up_button.clicked.\
             connect(lambda : self.move_grid("up"))
        self._advanced_methods_widget.move_down_button.clicked.\
             connect(lambda : self.move_grid("down"))        
      
        self._advanced_methods_widget.overlay_cbox.toggled.\
             connect(self.overlay_toggled)
        self._advanced_methods_widget.overlay_slider.valueChanged.\
             connect(self.overlay_alpha_changed) 
        self._advanced_methods_widget.overlay_color_button.clicked.\
             connect(self.overlay_change_color)
        self._advanced_methods_widget.move_to_grid_button.clicked.\
             connect(self.move_to_grid)

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False) 
        self._acq_widget.acq_widget_layout.num_images_label.setEnabled(False)
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        for col in range(self._advanced_methods_widget.\
                         grid_treewidget.columnCount()):
            self._advanced_methods_widget.grid_treewidget.\
                 resizeColumnToContents(col)

        self._acq_widget.acq_widget_layout.osc_total_range_label.setText(\
            "Total osc. range per line")

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

    def _init_models(self):
        """
        Descript. :
        """
        CreateTaskBase.init_models(self)
        self._processing_parameters = queue_model_objects.ProcessingParameters()

        if self._beamline_setup_hwobj is not None:
            has_shutter_less = self._beamline_setup_hwobj.\
                               detector_has_shutterless()
            self._acquisition_parameters.shutterless = has_shutter_less

            self._acquisition_parameters = self._beamline_setup_hwobj.\
                get_default_acquisition_parameters("default_advanced_values")

            if not self._advanced_methods:
                self._advanced_methods = self._beamline_setup_hwobj.get_advanced_methods()            
                if self._advanced_methods:
                   for method in self._advanced_methods:
                       self._advanced_methods_widget.method_combo.addItem(method)
                else:
                   self.setEnabled(False)    

            self.grid_treewidget_item_selection_changed()

    def set_beamline_setup(self, bl_setup_hwobj):
        """
        In plate mode osciallation is start is in the middle of grid
        """
        CreateTaskBase.set_beamline_setup(self, bl_setup_hwobj)

        self._acq_widget.acq_widget_layout.osc_start_label.\
             setText("Oscillation middle:")

        hor_size, ver_size = bl_setup_hwobj.beam_info_hwobj.get_beam_size()
        self.spacing = [hor_size, ver_size] 
        self._advanced_methods_widget.hor_spacing_ledit.setText(\
             "%.1f" % (hor_size * 1000))
        self._advanced_methods_widget.ver_spacing_ledit.setText(\
             "%.1f" % (ver_size * 1000))

    def approve_creation(self):
        """
        Descript. :
        """
        result = CreateTaskBase.approve_creation(self)
        selected_grid = self.get_selected_grid()

        if not selected_grid:
            msg = "No grid selected. Please select a grid to continue!"
            logging.getLogger("GUI").warning(msg)
            result = False
        else:
            grid_properties = selected_grid.get_properties()
            exp_time = float(self._acq_widget.\
                acq_widget_layout.exp_time_ledit.text())
            speed = grid_properties["yOffset"] / exp_time
            if speed >= 0.8:
                logging.getLogger("GUI").error(\
                    "Translation speed " + \
                    "%.3f is above the limit 0.8" % speed)
                return False
            osc_range_per_frame = float(self._acq_widget.\
                acq_widget_layout.osc_range_ledit.text())
            speed = osc_range_per_frame / exp_time
            if speed >= 166:
                logging.getLogger("GUI").error(\
                    "Rotation speed per frame " + \
                    "%.3f is above the limit 166" % speed)
                return False
            result = True

        return result
            
    def update_processing_parameters(self, crystal):
        """
        Descript. :
        """
        return

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

        if isinstance(tree_item, Qt4_queue_item.SampleQueueItem):
            pass
        elif isinstance(tree_item, Qt4_queue_item.BasketQueueItem):
            pass
            #self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.DataCollectionQueueItem) or \
             isinstance(tree_item, Qt4_queue_item.XrayCenteringQueueItem):

            if isinstance(tree_item, Qt4_queue_item.XrayCenteringQueueItem):
                data_collection = tree_item.get_model().reference_image_collection                 
            else:
                data_collection = tree_item.get_model()

            if tree_item.get_model().is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

            if data_collection.is_mesh():
                # sample_data_model = self.get_sample_item(tree_item).get_model()
                #self._acq_widget.disable_inverse_beam(True)
                #self._graphics_manager_hwobj.de_select_all()
                self._graphics_manager_hwobj.select_shape(data_collection.grid)
                self._advanced_methods_widget.grid_treewidget.setCurrentItem(\
                     self._grid_map[data_collection.grid])

                self._path_template = data_collection.get_path_template()
                self._data_path_widget.update_data_model(self._path_template)

                self._acquisition_parameters = data_collection.acquisitions[0].\
                                              acquisition_parameters
                self._acq_widget.update_data_model(self._acquisition_parameters,
                                                   self._path_template)
                self.get_acquisition_widget().use_osc_start(True)
            self.dc_selected = True
        else:
            self.setDisabled(True)
        self.grid_treewidget_item_selection_changed()
  
    def _create_task(self,  sample, shape):
        """Creates tasks based on selected grids

        :param sample: selected sample object
        :type sample: SampleQueueItem
        :param shape: selected shape
        :type shape: Qt4_GraphicsLib.GraphicsItem
        """
        tasks = []
        selected_grid = self.get_selected_grid()

        mesh_dc = self._create_dc_from_grid(sample, selected_grid)

        exp_type = str(self._advanced_methods_widget.method_combo.currentText())
        if exp_type == "MeshScan":
            tasks.append(mesh_dc)
        elif exp_type == "XrayCentering":
            xray_centering = queue_model_objects.XrayCentering(mesh_dc)
            tasks.append(xray_centering)
        else:
            logging.getLogger("GUI").\
                warning("Method %s does not exist in queue_model_objects" % exp_type)
        mesh_dc.run_processing_parallel = exp_type

        return tasks

    def shape_created(self, shape, shape_type):
        """If a grid is created then adds it to the treewidget.
           A binding between graphical grid and treewidget item is based
           on the self._grid_map

        :param shape: graphics object
        :type shape: Qt4_GraphicsLib.GraphicsItem
        :param shape_type: type of the object (point, line, grid)
        :type shape_type: str 
        """
        if shape_type == "Grid":
            self._advanced_methods_widget.grid_treewidget.clearSelection()
            grid_properties = shape.get_properties()
            info_str_list = []
            info_str_list.append(grid_properties["name"])
            info_str_list.append("%d" % grid_properties["num_lines"])
            info_str_list.append("%d" % grid_properties["num_images_per_line"])

            if not self.dc_selected:
                exp_time = max(float(grid_properties["yOffset"] / 0.795),
                      self._acq_widget.exp_time_validator.bottom()+0.00001)
                self._acq_widget.acq_widget_layout.exp_time_ledit.setText("%.6f" % exp_time)
 
            grid_treewidget_item = QTreeWidgetItem(\
                self._advanced_methods_widget.grid_treewidget,
                info_str_list)
            self._grid_map[shape] = grid_treewidget_item

            if not self.dc_selected:
                grid_treewidget_item.setSelected(True)
                self.grid_treewidget_item_selection_changed()
                self.update_grid_osc_total_range()
            
    def shape_deleted(self, shape, shape_type):
        """Removes shape from QTreeWidget and self._grid_map

        :param shape: graphics object
        :type shape: QtGraphicsLib.GraphicsItem
        :param shape_type: type of the object (point, line, grid)
        :type shape_type: str 
        """
        if self._grid_map.get(shape):
            treewidget_item_modelindex = self._advanced_methods_widget.\
                 grid_treewidget.indexFromItem(self._grid_map[shape])
            self._advanced_methods_widget.grid_treewidget.takeTopLevelItem(\
                 treewidget_item_modelindex.row())
            self._grid_map.pop(shape) 

    def grid_treewidget_item_selection_changed(self):
        """Updates acquisition parameters based on the selected grid.
        """
        self.enable_grid_controls(False)
      
        for item in self._grid_map.items():
            grid = item[0]
            treewidget_item = item[1]
  
            if treewidget_item.isSelected():
                grid_properties = grid.get_properties() 
                cell_count = grid_properties["num_lines"] * \
                             grid_properties["num_images_per_line"]
                self._acq_widget.acq_widget_layout.num_images_ledit.setText(\
                     "%d" % cell_count)
                self._acq_widget.acq_widget_layout.first_image_ledit.setText(\
                     "%d" % grid_properties["first_image_num"])
                centred_point = grid.get_centred_position()
                self._acq_widget.acq_widget_layout.kappa_ledit.setText(\
                     "%.2f" % float(centred_point.kappa))
                self._acq_widget.acq_widget_layout.kappa_phi_ledit.setText(\
                     "%.2f" % float(centred_point.kappa_phi))
                self._advanced_methods_widget.hor_spacing_ledit.setText(\
                     "%.2f" % (float(grid_properties["xOffset"]) * 1000))
                self._advanced_methods_widget.ver_spacing_ledit.setText(\
                     "%.2f" % (float(grid_properties["yOffset"]) * 1000))

                treewidget_item.setText(3, str(grid_properties["num_lines"]))
                treewidget_item.setText(4, str(grid_properties["num_images_per_line"]))
            
                grid.setSelected(True) 
                self.enable_grid_controls(True)
            else:
                grid.setSelected(False)

    def get_selected_grid(self):
        """Returns selected grids
        
        :returns: selected grid objects
        """
        for grid, grid_treewidget_item in self._grid_map.iteritems():
            if grid_treewidget_item.isSelected():
                return grid

    def get_selected_grid_properties(self):
        """Returns properties of the selected grid

        :returns: dict with properties
        """

        for grid, grid_treewidget_item in self._grid_map.iteritems():
            if grid_treewidget_item.isSelected():
                return grid.get_properties()

    def draw_grid_button_clicked(self):
        """Starts grid drawing
        """
        self._graphics_manager_hwobj.create_grid(self.spacing)

    def remove_grid_button_clicked(self):
        """Removes selected grid
        """
        grid_to_delete = self.get_selected_grid()

        if grid_to_delete:
            self._graphics_manager_hwobj.delete_shape(grid_to_delete)
            self._advanced_methods_widget.move_to_grid_button.setEnabled(False)           

    def hor_spacing_changed(self, value):
        """Updates spacing of the selected grid
        """
        try:
            self.spacing[0] = float(self._advanced_methods_widget.hor_spacing_ledit.text()) / 1000
            self.set_spacing()
        except:
            pass

    def ver_spacing_changed(self, value):
        """Updates spacing of the selected grid
        """
        try:
            self.spacing[1] = float(self._advanced_methods_widget.ver_spacing_ledit.text()) / 1000
            self.set_spacing()
        except:
            pass

    def set_spacing(self):
        if 0 in self.spacing:
            return

        for grid, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid.set_spacing(self.spacing, adjust_size=\
                   self._advanced_methods_widget.adjust_size_cbox.isChecked())
                grid_properties = grid.get_properties()

                
                treewidget_item.setText(1, str(grid_properties["num_lines"]))
                treewidget_item.setText(2, str(grid_properties["num_images_per_line"]))
                cell_count = grid_properties["num_lines"] * \
                             grid_properties["num_images_per_line"]
                self._acq_widget.acq_widget_layout.num_images_ledit.setText(\
                     str(grid_properties["num_lines"] * \
                         grid_properties["num_images_per_line"]))

    def move_to_grid(self):
        """Moves diffractometer to the center of the grid
        """
        grid = self.get_selected_grid()

        if grid:
            self._beamline_setup_hwobj.diffractometer_hwobj.\
                move_to_centred_position(grid.get_centred_position())

    def overlay_toggled(self, state):
        """Toggles (on/off) overlay
        """
        grid = self.get_selected_grid()

        if grid:
            grid.set_display_overlay(state)
           
    def overlay_alpha_changed(self, alpha_value):
        """Changes the transperency of the grid
        """
        grid = self.get_selected_grid()

        if grid:
            grid.set_fill_alpha(alpha_value)

    def overlay_change_color(self):
        """Changes the default color (blue) of overlay
        """
        color = QColorDialog.getColor()
        grid = self.get_selected_grid()

        if color.isValid() and grid:
            grid.set_base_color(color)

    def move_grid(self, direction):
        """Moves grid by one pix in selected direction

        :param direction: direction to move (right, left, up, down)
        :type direction: str
        """
        grid = self.get_selected_grid()

        if grid:
            grid.move_by_pix(direction)
            self._graphics_manager_hwobj.\
                 update_grid_motor_positions(grid)

    def enable_grid_controls(self, state):
        """Enables grid controls if a grid is selectd
        """
        self._advanced_methods_widget.overlay_cbox.setEnabled(state)
        self._advanced_methods_widget.overlay_slider.setEnabled(state)
        self._advanced_methods_widget.overlay_color_button.setEnabled(state)
        self._advanced_methods_widget.move_to_grid_button.setEnabled(state)
        self._advanced_methods_widget.remove_grid_button.setEnabled(state)        

        self._advanced_methods_widget.move_right_button.setEnabled(state)
        self._advanced_methods_widget.move_left_button.setEnabled(state)
        self._advanced_methods_widget.move_up_button.setEnabled(state)
        self._advanced_methods_widget.move_down_button.setEnabled(state)

        self._acq_widget.acq_widget_layout.set_max_osc_range_button.setEnabled(\
             state and self._in_plate_mode)

    def grid_osc_range_ledit_changed(self, new_value):
        """Osc range per frame changed

        :param new_value: new value
        :type new_value: str
        """
        
        self.update_grid_osc_total_range() 

    def grid_osc_total_range_ledit_changed(self, new_value):
        """Updates osc range per frame


        :param new_value: new value
        :type new_value: str
        """

        grid_properties = self.get_selected_grid_properties()
        if grid_properties:
            try:
                self._acq_widget.acq_widget_layout.osc_range_ledit.setText(\
                     "%.4f" % (float(new_value) / grid_properties["num_images_per_line"] - 1e-5))
            except:
                pass

    def update_grid_osc_total_range(self):
        """Updates osc range per line
        """

        grid_properties = self.get_selected_grid_properties()
        if grid_properties:
            self._acq_widget.acq_widget_layout.osc_total_range_ledit.setText(str(\
                float(self._acq_widget.acq_widget_layout.osc_range_ledit.text()) * \
                grid_properties["num_images_per_line"]))

    def set_max_osc_total_range_clicked(self, state):
        """Sets the osc range based on grid (number of images per line
           and osc in the middle of the grid)        
        """
        grid_properties = self.get_selected_grid_properties()
        if grid_properties:
            exposure_time = float(self._acq_widget.acq_widget_layout.exp_time_ledit.text())
            (lower, upper), result_exp_time = self._acq_widget.update_osc_total_range_limits(\
                 calc_by_speed=False,
                 num_images=grid_properties["num_images_per_line"],
                 exp_time=exposure_time)
            self._acq_widget.acq_widget_layout.osc_start_ledit.setText(\
                 "%.4f" % ((lower + upper) / 2))
            self._acq_widget.acq_widget_layout.osc_total_range_ledit.setText(\
                 "%.4f" % (abs(upper - lower) - 1e-4))
            self._acq_widget.acq_widget_layout.osc_range_ledit.setText(\
                 "%.4f" % (abs(lower - upper) / grid_properties["num_images_per_line"]))
            self._acq_widget.acq_widget_layout.exp_time_ledit.setText(\
                 "%.5f" % (result_exp_time))
Exemplo n.º 28
0
    def __init__(self, parent = None, name = "energy_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.energy_scan_model = queue_model_objects.EnergyScan()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self) 
        _parameters_widget = QtGui.QWidget(_top_widget)  
        self.periodic_table_widget =  PeriodicTableWidget(_parameters_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.data_path_widget.data_path_layout.file_name_label.setText('')
        self.data_path_widget.data_path_layout.file_name_value_label.hide()
        self.snapshot_widget = SnapshotWidget(self)

        self.scan_actual_plot_widget = PymcaPlotWidget(self, True)
        self.scan_result_plot_widget = PymcaPlotWidget(self, False)
        self.chooch_plot_widget = PymcaPlotWidget(self, False)
        #self.scan_actual_plot_widget = TwoAxisPlotWidget(self, True)
        #self.chooch_plot_widget = TwoAxisPlotWidget(self, False)
 
        # Layout -------------------------------------------------------------
        _parameters_widget_layout = QtGui.QVBoxLayout()
        _parameters_widget_layout.addWidget(self.periodic_table_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _parameters_widget_layout.setContentsMargins(0, 0, 0, 0)
        _parameters_widget.setLayout(_parameters_widget_layout)

        _top_widget_hlayout = QtGui.QHBoxLayout(self)
        _top_widget_hlayout.addWidget(_parameters_widget)
        _top_widget_hlayout.addWidget(self.snapshot_widget)
        _top_widget_hlayout.addStretch(0)
        _top_widget_hlayout.setSpacing(2)
        _top_widget_hlayout.setContentsMargins(0, 0, 0, 0)
        _top_widget.setLayout(_top_widget_hlayout) 

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.scan_actual_plot_widget)
        _main_vlayout.addWidget(self.scan_result_plot_widget)
        _main_vlayout.addWidget(self.chooch_plot_widget)
        _main_vlayout.setSpacing(5)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        #_main_vlayout.addStretch(0)

        self.setLayout(_main_vlayout)
      
        # SizePolicies --------------------------------------------------------
        self.scan_actual_plot_widget.setSizePolicy(QtGui.QSizePolicy.Fixed,
                                            QtGui.QSizePolicy.Expanding)
        self.chooch_plot_widget.setSizePolicy(QtGui.QSizePolicy.Fixed,
                                              QtGui.QSizePolicy.Expanding)

        # Qt signal/slot connections ------------------------------------------
        #qt.QObject.connect(self.periodic_table_widget, qt.PYSIGNAL('edgeSelected'), 
        #                   self.element_clicked)

        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)
        
        # Other ---------------------------------------------------------------
        self.scan_actual_plot_widget.hide()
        self.scan_result_plot_widget.hide()
    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()
class XRFSpectrumParametersWidget(QtGui.QWidget):
    def __init__(self, parent=None, name="xrf_spectrum_parameters_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.xrf_spectrum_model = queue_model_objects.XRFSpectrum()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self)
        _parameters_widget = QtGui.QWidget(_top_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.other_parameters_gbox = QtGui.QGroupBox("Other parameters",
                                                     _parameters_widget)
        self.count_time_label = QtGui.QLabel("Count time:",
                                             self.other_parameters_gbox)
        self.count_time_ledit = QtGui.QLineEdit(self.other_parameters_gbox)
        self.count_time_ledit.setFixedWidth(50)
        self.adjust_transmission_cbox = QtGui.QCheckBox("Adjust transmission", \
             self.other_parameters_gbox)
        self.adjust_transmission_cbox.hide()
        _snapshot_widget = QtGui.QWidget(self)
        self.position_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__),
                         'ui_files/Qt4_snapshot_widget_layout.ui'))
        self.mca_spectrum_widget = McaSpectrumWidget(self)

        # Layout -------------------------------------------------------------
        _other_parameters_gbox_hlayout = QtGui.QHBoxLayout(
            self.other_parameters_gbox)
        _other_parameters_gbox_hlayout.addWidget(self.count_time_label)
        _other_parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _other_parameters_gbox_hlayout.addWidget(self.adjust_transmission_cbox)
        _other_parameters_gbox_hlayout.addStretch(0)
        _other_parameters_gbox_hlayout.setSpacing(2)
        _other_parameters_gbox_hlayout.setContentsMargins(3, 3, 3, 3)

        _parameters_widget_layout = QtGui.QVBoxLayout(_parameters_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addWidget(self.other_parameters_gbox)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _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(0)

        _top_widget_layout = QtGui.QHBoxLayout(_top_widget)
        _top_widget_layout.addWidget(_parameters_widget)
        _top_widget_layout.addWidget(_snapshot_widget)
        _top_widget_layout.setSpacing(2)
        _top_widget_layout.addStretch(0)
        _top_widget_layout.setContentsMargins(0, 0, 0, 0)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.mca_spectrum_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies -------------------------------------------------------
        self.position_widget.setFixedSize(457, 350)
        self.mca_spectrum_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                               QtGui.QSizePolicy.Expanding)
        _top_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Fixed)

        # 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.count_time_ledit.textChanged.connect(
            self._count_time_ledit_change)

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

    def _prefix_ledit_change(self, new_value):
        self.xrf_spectrum_model.set_name(str(new_value))
        self._tree_view_item.setText(
            0, self.xrf_spectrum_model.get_display_name())

    def _run_number_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.xrf_spectrum_model.set_number(int(new_value))
            self._tree_view_item.setText(
                0, self.xrf_spectrum_model.get_display_name())

    def _count_time_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.xrf_spectrum_model.set_count_time(float(new_value))

    def tab_changed(self):
        if self._tree_view_item:
            self.populate_widget(self._tree_view_item)

    def populate_widget(self, item):
        self._tree_view_item = item
        self.xrf_spectrum_model = item.get_model()
        executed = self.xrf_spectrum_model.is_executed()

        self.data_path_widget.setEnabled(not executed)
        self.other_parameters_gbox.setEnabled(not executed)
        self.mca_spectrum_widget.setEnabled(executed)

        if executed:
            result = self.xrf_spectrum_model.get_scan_result()
            self.mca_spectrum_widget.setData(result.mca_data, result.mca_calib,
                                             result.mca_config)
        else:
            self.mca_spectrum_widget.clear()

        self.data_path_widget.update_data_model(
            self.xrf_spectrum_model.path_template)
        self.count_time_ledit.setText(str(self.xrf_spectrum_model.count_time))

        image = self.xrf_spectrum_model.centred_position.snapshot_image
        if image is not None:
            try:
                image = image.scaled(427, 320, QtCore.Qt.KeepAspectRatio)
                self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))
            except:
                pass

    def set_xrf_spectrum_hwobj(self, xrf_spectrum_hwobj):
        self.xrf_spectrum_hwobj = xrf_spectrum_hwobj
        if self.xrf_spectrum_hwobj:
            self.xrf_spectrum_hwobj.connect("xrfSpectrumFinished",
                                            self.spectrum_finished)

    def spectrum_finished(self, mca_data, mca_calib, mca_config):
        self.mca_spectrum_widget.set_data(mca_data, mca_calib, mca_config)
class EnergyScanParametersWidget(QtGui.QWidget):
    def __init__(self, parent=None, name="energy_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.energy_scan_model = queue_model_objects.EnergyScan()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self)
        _parameters_widget = QtGui.QWidget(_top_widget)
        self.periodic_table_widget = PeriodicTableWidget(_parameters_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.data_path_widget.data_path_layout.file_name_label.setText("")
        self.data_path_widget.data_path_layout.file_name_value_label.hide()
        self.position_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__), "ui_files/Qt4_snapshot_widget_layout.ui")
        )
        self.position_widget.setFixedSize(450, 340)

        self.scan_plot_widget = TwoAxisPlotWidget(self)
        self.scan_plot_widget.set_real_time_plot(True)
        self.result_plot_widget = TwoAxisPlotWidget(self)

        """self.scan_plot_widget = ScanPlotWidget(self)
        self.scan_plot_widget.setRealTimePlot(True)
        self.result_plot_widget = ScanPlotWidget(self)
        self.result_plot_widget.setRealTimePlot(False)
        self.scan_plot_widget.setFixedHeight(200)
        self.result_plot_widget.setFixedHeight(200)"""

        # Layout -------------------------------------------------------------
        _parameters_widget_layout = QtGui.QVBoxLayout()
        _parameters_widget_layout.addWidget(self.periodic_table_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _parameters_widget_layout.setContentsMargins(0, 0, 0, 0)
        _parameters_widget.setLayout(_parameters_widget_layout)

        _top_widget_hlayout = QtGui.QHBoxLayout(self)
        _top_widget_hlayout.addWidget(_parameters_widget)
        _top_widget_hlayout.addWidget(self.position_widget)
        _top_widget_hlayout.addStretch(0)
        _top_widget_hlayout.setSpacing(2)
        _top_widget_hlayout.setContentsMargins(0, 0, 0, 0)
        _top_widget.setLayout(_top_widget_hlayout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.scan_plot_widget)
        _main_vlayout.addWidget(self.result_plot_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)

        self.setLayout(_main_vlayout)

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

        # Qt signal/slot connections ------------------------------------------
        # qt.QObject.connect(self.periodic_table_widget, qt.PYSIGNAL('edgeSelected'),
        #                   self.element_clicked)

        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)

        # qt.QObject.connect(qt.qApp, qt.PYSIGNAL('tab_changed'),
        #                   self.tab_changed)

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

        Qt4_widget_colors.set_widget_color(self.periodic_table_widget, Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.position_widget, Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.data_path_widget, Qt4_widget_colors.GROUP_BOX_GRAY)

    def _prefix_ledit_change(self, new_value):
        self.energy_scan_model.set_name(str(new_value))
        self._tree_view_item.setText(0, self.energy_scan_model.get_name())

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

    def tab_changed(self):
        if self._tree_view_item:
            self.populate_widget(self._tree_view_item)

    def populate_widget(self, item):
        self._tree_view_item = item
        self.energy_scan_model = item.get_model()
        executed = self.energy_scan_model.is_executed()

        self.data_path_widget.setEnabled(not executed)
        self.periodic_table_widget.setEnabled(not executed)
        self.scan_plot_widget.setEnabled(not executed)
        self.result_plot_widget.setEnabled(not executed)

        if executed:
            result = self.energy_scan_model.get_scan_result()
            self.scan_plot_widget.plot_scan_curve(result.data)
            self.result_plot_widget.plot_results(
                result.pk,
                result.fppPeak,
                result.fpPeak,
                result.ip,
                result.fppInfl,
                result.fpInfl,
                result.rm,
                result.chooch_graph_x,
                result.chooch_graph_y1,
                result.chooch_graph_y2,
                result.title,
            )
        else:
            self.scan_plot_widget.clear()
            self.result_plot_widget.clear()

        self.data_path_widget.update_data_model(self.energy_scan_model.path_template)
        self.periodic_table_widget.set_current_element_edge(
            self.energy_scan_model.element_symbol, self.energy_scan_model.edge
        )

        image = self.energy_scan_model.centred_position.snapshot_image
        if image is not None:
            try:
                image = image.scaled(427, 320, QtCore.Qt.KeepAspectRatio)
                self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))
            except:
                pass

    def element_clicked(self, symbol, energy):
        self.energy_scan_model.element_symbol = symbol
        self.energy_scan_model.edge = energy

    def set_enegy_scan_hwobj(self, energy_scan_hwobj):
        self.energy_scan_hwobj = energy_scan_hwobj
        if self.energy_scan_hwobj:
            self.energy_scan_hwobj.connect("scanStart", self.scan_started)
            self.energy_scan_hwobj.connect("scanNewPoint", self.scan_new_point)
            self.energy_scan_hwobj.connect("choochFinished", self.chooch_finished)

    def scan_started(self, scan_parameters):
        self.scan_plot_widget.start_new_scan(scan_parameters)
        self.data_path_widget.setEnabled(False)
        self.periodic_table_widget.setEnabled(False)

    def scan_new_point(self, x, y):
        self.scan_plot_widget.add_new_plot_value(x, y)

    def chooch_finished(
        self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title
    ):
        self.result_plot_widget.plot_results(
            pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title
        )
        self.scan_plot_widget.plot_finished()
Exemplo n.º 32
0
class CreateGphlWorkflowWidget(CreateTaskBase):
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name,
                                QtCore.Qt.WindowFlags(fl), 'GphlWorkflow')

        if not name:
            self.setObjectName("Qt4_create_gphl_workflow_widget")

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

        # Internal variables --------------------------------------------------
        self.current_prefix = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._workflow_type_widget = QtGui.QGroupBox('Workflow type', self)

        self._workflow_cbox = QtGui.QComboBox(self._workflow_type_widget)
        self._gphl_acq_widget = QtGui.QGroupBox('Acquisition', self)
        self._gphl_acq_param_widget =  GphlAcquisitionWidget(
            self._gphl_acq_widget, "gphl_acquisition_parameter_widget"
        )
        self._gphl_diffractcal_widget =  GphlDiffractcalWidget(
            self._gphl_acq_widget, "gphl_diffractcal_widget"
        )

        self._data_path_widget = DataPathWidget(self, 'create_dc_path_widget',
                                                layout='vertical')
        data_path_layout = self._data_path_widget.data_path_layout
        data_path_layout.file_name_label.hide()
        data_path_layout.file_name_value_label.hide()
        data_path_layout.run_number_label.hide()
        data_path_layout.run_number_ledit.hide()

        # Layout --------------------------------------------------------------
        _workflow_type_vlayout = QtGui.QVBoxLayout(self._workflow_type_widget)
        _workflow_type_vlayout.addWidget(self._workflow_cbox)
        _gphl_acq_vlayout = QtGui.QVBoxLayout(self._gphl_acq_widget)
        _gphl_acq_vlayout.addWidget(self._gphl_acq_param_widget)
        _gphl_acq_vlayout.addWidget(self._gphl_diffractcal_widget)
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._workflow_type_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._gphl_acq_widget)
        _main_vlayout.addStretch(0)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0,0,0,0)

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

        # Qt signal/slot connections ------------------------------------------
        self._workflow_cbox.currentIndexChanged[str].connect(
            self.workflow_selected
        )


        # set up popup data dialog
        self.gphl_data_dialog = GphlDataDialog(self, 'GPhL Workflow Data')
        self.gphl_data_dialog.setModal(True)
        self.gphl_data_dialog.continueClickedSignal.connect(self.data_acquired)
        # self.connect(self.gphl_data_dialog, qt.PYSIGNAL("continue_clicked"),
        #              self.data_acquired)

    def initialise_workflows(self, workflow_hwobj):
        self._workflow_hwobj = workflow_hwobj
        self._workflow_cbox.clear()
        # self._gphl_parameters_widget.set_workflow(workflow_hwobj)

        if self._workflow_hwobj is not None:
            workflow_names = list(workflow_hwobj.get_available_workflows())
            for workflow_name in workflow_names:
                self._workflow_cbox.addItem(workflow_name)
            self.workflow_selected(workflow_names[0])

            workflow_hwobj.connect('gphlParametersNeeded',
                                   self.gphl_data_dialog.open_dialog)

    def workflow_selected(self, name):
        # necessary as this comes in as a QString object
        name = str(name)
        # if reset or name != self._previous_workflow:
        xx = self._workflow_cbox
        xx.setCurrentIndex(xx.findText(name))

        parameters = self._workflow_hwobj.get_available_workflows()[name]
        beam_energies = parameters.get('beam_energies', {})
        strategy_type = parameters.get('strategy_type')
        if strategy_type == 'transcal':
            self._gphl_acq_widget.hide()
        elif strategy_type == 'diffractcal':
            # TODO update this
            self._gphl_diffractcal_widget.populate_widget()
            self._gphl_acq_widget.show()
            self._gphl_diffractcal_widget.show()
            self._gphl_acq_param_widget.hide()
        else:
            # acquisition type strategy
            self._gphl_acq_param_widget.populate_widget(
                beam_energies=beam_energies,
            )
            self._gphl_acq_widget.show()
            self._gphl_diffractcal_widget.hide()
            self._gphl_acq_param_widget.show()

        prefix = parameters.get('prefix')
        if prefix is not None:
            self.current_prefix = prefix

    def data_acquired(self):
        """Data gathered from popup, continue execution"""
        pass

    def single_item_selection(self, tree_item):
        CreateTaskBase.single_item_selection(self, tree_item)
        wf_model = tree_item.get_model()

        if not isinstance(tree_item, queue_item.SampleQueueItem):

            if isinstance(tree_item, queue_item.GphlWorkflowQueueItem):
                if tree_item.get_model().is_executed():
                    self.setDisabled(True)
                else:
                    self.setDisabled(False)

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

                self._data_path_widget.update_data_model(self._path_template)

            elif isinstance(tree_item, queue_item.BasketQueueItem):
                self.setDisabled(False)
            elif not isinstance(tree_item, queue_item.DataCollectionGroupQueueItem):
                self.setDisabled(True)

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

    def _init_models(self):
        pass

    def continue_button_click(self, sample_items, checked_items):
        """Intercepts the datacollection continue_button click for parameter setting"""
        tree_brick = self._tree_brick
        if tree_brick:
            for item in checked_items:
                model = item.get_model()
                if isinstance(model, queue_model_objects.GphlWorkflow):
                    dialog = tree_brick.dc_tree_widget.confirm_dialog
                    ss = dialog.conf_dialog_layout.take_snapshots_combo.currentText()
                    model.set_snapshot_count(int(ss) if ss else 0)

    # Called by the owning widget (task_toolbox_widget) to create
    # a collection. When a data collection group is selected.
    def _create_task(self, sample, shape):
        tasks = []

        path_template = self._create_path_template(sample, self._path_template)
        path_template.num_files = 0

        ho = self._workflow_hwobj
        if ho.get_state() == States.OFF:
            # We will be setting up the connection now - time to connect to quit
            QtGui.QApplication.instance().aboutToQuit.connect(ho.shutdown)

            tree_brick = self._tree_brick
            if tree_brick:
                tree_brick.dc_tree_widget.confirm_dialog.continueClickedSignal\
                    .connect(self.continue_button_click)


        wf = queue_model_objects.GphlWorkflow(self._workflow_hwobj)
        wf_type = str(self._workflow_cbox.currentText())
        wf.set_type(wf_type)

        if self.current_prefix:
            path_template.base_prefix = self.current_prefix
        wf.path_template = path_template
        wf.set_name(wf.path_template.get_prefix())
        wf.set_number(wf.path_template.run_number)

        wf_parameters = ho.get_available_workflows()[wf_type]
        strategy_type = wf_parameters.get('strategy_type')
        wf.set_interleave_order(wf_parameters.get('interleaveOrder', ''))
        if strategy_type == 'acquisition':
            expected_resolution = self._gphl_acq_param_widget.get_parameter_value(
                'expected_resolution'
            )

            dd = self._gphl_acq_param_widget.get_energy_dict()
            wf.set_beam_energies(dd)

            wf.set_space_group(
                self._gphl_acq_param_widget.get_parameter_value('space_group')
            )
            tag = self._gphl_acq_param_widget.get_parameter_value('crystal_system')
            crystal_system, point_group = None, None
            if tag:
                data = self._gphl_acq_param_widget._CRYSTAL_SYSTEM_DATA[tag]
                crystal_system = data.crystal_system
                point_groups = data.point_groups
                if len(point_groups) == 1 or point_groups[0] == '32':
                    # '32' is a special case; '312' and '321' are also returned as '32'
                    point_group = point_groups[0]
            wf.set_point_group(point_group)
            wf.set_crystal_system(crystal_system)

        elif strategy_type == 'diffractcal':
            expected_resolution = self._gphl_diffractcal_widget.get_parameter_value(
                'expected_resolution'
            )
            ss = self._gphl_diffractcal_widget.get_parameter_value('test_crystal')
            crystal_data = self._gphl_diffractcal_widget.test_crystals.get(ss)
            wf.set_space_group(crystal_data.space_group)
            wf.set_cell_parameters(
                tuple(getattr(crystal_data, tag)
                      for tag in ('a', 'b', 'c', 'alpha', 'beta', 'gamma'))
            )
        else:
            expected_resolution = None
        wf.set_expected_resolution(expected_resolution)
        
        tasks.append(wf)

        return tasks
    def __init__(self, parent = None, name = "xrf_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.xrf_scan_model = queue_model_objects.XRFScan()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self)
        _parameters_widget = QtGui.QWidget(_top_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.other_parameters_gbox = QtGui.QGroupBox("Other parameters", _parameters_widget) 
        self.count_time_label = QtGui.QLabel("Count time:", 
                                             self.other_parameters_gbox)
	self.count_time_ledit = QtGui.QLineEdit(self.other_parameters_gbox)
	self.count_time_ledit.setFixedWidth(50)
        self.position_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
                                          'ui_files/Qt4_snapshot_widget_layout.ui'))
        self.mca_spectrum_widget = McaSpectrumWidget(self)
 
        # Layout -------------------------------------------------------------
        self.other_parameters_gbox_layout = QtGui.QHBoxLayout(self)
        self.other_parameters_gbox_layout.addWidget(self.count_time_label)  
        self.other_parameters_gbox_layout.addWidget(self.count_time_ledit)
        self.other_parameters_gbox_layout.addStretch(0)
        self.other_parameters_gbox_layout.setSpacing(2)
        self.other_parameters_gbox_layout.setContentsMargins(3, 3, 3, 3)
        self.other_parameters_gbox.setLayout(self.other_parameters_gbox_layout)

        _parameters_widget_layout = QtGui.QVBoxLayout()
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addWidget(self.other_parameters_gbox)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _parameters_widget_layout.setContentsMargins(0, 0, 0, 0)
        _parameters_widget.setLayout(_parameters_widget_layout)

        _top_widget_layout = QtGui.QHBoxLayout(_top_widget)
        _top_widget_layout.addWidget(_parameters_widget)
        _top_widget_layout.addWidget(self.position_widget)
        _top_widget_layout.setSpacing(2)
        _top_widget_layout.setContentsMargins(0, 0, 0, 0)
        
        _top_widget.setLayout(_top_widget_layout) 

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.mca_spectrum_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(_main_vlayout)
       
        # SizePolicies -------------------------------------------------------
        self.position_widget.setFixedSize(457, 350)
        self.mca_spectrum_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                               QtGui.QSizePolicy.Expanding)
        _top_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Fixed)
        #self.mca_spectrum_widget.setMinimumHeight(800)
        #self.setSizePolicy(QtGui.QSizePolicy.Expanding,
        #                   QtGui.QSizePolicy.Fixed)

        # Qt signal/slot connections ------------------------------------------ 
        QtCore.QObject.connect(self.data_path_widget.data_path_layout.\
                               findChild(QtGui.QLineEdit, 'prefix_ledit'), 
                               QtCore.SIGNAL("textChanged(const QString &)"), 
                               self._prefix_ledit_change)

        QtCore.QObject.connect(self.data_path_widget.data_path_layout.\
                               findChild(QtGui.QLineEdit, 'run_number_ledit'), 
                               QtCore.SIGNAL("textChanged(const QString &)"), 
                               self._run_number_ledit_change)

        QtCore.QObject.connect(self.count_time_ledit,
                               QtCore.SIGNAL("textChanged(const QString &)"),
                               self._count_time_ledit_change)
        
        #QtCore.QObject.connect(.qApp, qt.PYSIGNAL('tab_changed'),
        #                   self.tab_changed)

        # Other ---------------------------------------------------------------
        Qt4_widget_colors.set_widget_color(self.other_parameters_gbox,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.data_path_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY) 
        Qt4_widget_colors.set_widget_color(self.position_widget, 
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
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)
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name,
                                QtCore.Qt.WindowFlags(fl), 'GphlWorkflow')

        if not name:
            self.setObjectName("Qt4_create_gphl_workflow_widget")

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

        # Internal variables --------------------------------------------------
        self.current_prefix = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._workflow_type_widget = QtGui.QGroupBox('Workflow type', self)

        self._workflow_cbox = QtGui.QComboBox(self._workflow_type_widget)
        self._gphl_acq_widget = QtGui.QGroupBox('Acquisition', self)
        self._gphl_acq_param_widget =  GphlAcquisitionWidget(
            self._gphl_acq_widget, "gphl_acquisition_parameter_widget"
        )
        self._gphl_diffractcal_widget =  GphlDiffractcalWidget(
            self._gphl_acq_widget, "gphl_diffractcal_widget"
        )

        self._data_path_widget = DataPathWidget(self, 'create_dc_path_widget',
                                                layout='vertical')
        data_path_layout = self._data_path_widget.data_path_layout
        data_path_layout.file_name_label.hide()
        data_path_layout.file_name_value_label.hide()
        data_path_layout.run_number_label.hide()
        data_path_layout.run_number_ledit.hide()

        # Layout --------------------------------------------------------------
        _workflow_type_vlayout = QtGui.QVBoxLayout(self._workflow_type_widget)
        _workflow_type_vlayout.addWidget(self._workflow_cbox)
        _gphl_acq_vlayout = QtGui.QVBoxLayout(self._gphl_acq_widget)
        _gphl_acq_vlayout.addWidget(self._gphl_acq_param_widget)
        _gphl_acq_vlayout.addWidget(self._gphl_diffractcal_widget)
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._workflow_type_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._gphl_acq_widget)
        _main_vlayout.addStretch(0)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0,0,0,0)

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

        # Qt signal/slot connections ------------------------------------------
        self._workflow_cbox.currentIndexChanged[str].connect(
            self.workflow_selected
        )


        # set up popup data dialog
        self.gphl_data_dialog = GphlDataDialog(self, 'GPhL Workflow Data')
        self.gphl_data_dialog.setModal(True)
        self.gphl_data_dialog.continueClickedSignal.connect(self.data_acquired)
Exemplo n.º 36
0
class CreateXRFScanWidget(CreateTaskBase):
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, QtCore.Qt.WindowFlags(fl), "XRF-scan")

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

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

        # Internal variables --------------------------------------------------
        self.count_time = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        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")

        _parameters_gbox = QtGui.QGroupBox("Parameters", self)
        _count_time_label = QtGui.QLabel("Count time (sec.):", _parameters_gbox)
        self.count_time_ledit = QtGui.QLineEdit("1", _parameters_gbox)
        self.count_time_ledit.setMaximumWidth(75)

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

        _parameters_gbox_hlayout = QtGui.QHBoxLayout(self)
        _parameters_gbox_hlayout.addWidget(_count_time_label)
        _parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _parameters_gbox_hlayout.addStretch(0)
        _parameters_gbox_hlayout.setSpacing(2)
        _parameters_gbox_hlayout.setContentsMargins(0, 0, 0, 0)
        _parameters_gbox.setLayout(_parameters_gbox_hlayout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._data_path_gbox)
        _main_vlayout.addWidget(_parameters_gbox)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)
        self.setLayout(_main_vlayout)

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

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.data_path_layout.run_number_ledit.textChanged.connect(self._run_number_ledit_change)

        self.connect(self._data_path_widget, QtCore.SIGNAL("pathTemplateChanged"), self.handle_path_conflict)

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

    def init_models(self):
        CreateTaskBase.init_models(self)
        self.enery_scan = queue_model_objects.XRFScan()
        self._path_template.start_num = 1
        self._path_template.num_files = 1
        self._path_template.suffix = "raw"

    def single_item_selection(self, tree_item):
        CreateTaskBase.single_item_selection(self, tree_item)
        escan_model = tree_item.get_model()

        if isinstance(tree_item, Qt4_queue_item.XRFScanQueueItem):
            if tree_item.get_model().is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

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

            self._data_path_widget.update_data_model(self._path_template)
        elif not (
            isinstance(tree_item, Qt4_queue_item.SampleQueueItem)
            or isinstance(tree_item, Qt4_queue_item.DataCollectionGroupQueueItem)
        ):
            self.setDisabled(True)

    def approve_creation(self):
        base_result = CreateTaskBase.approve_creation(self)

        self.count_time = None

        try:
            self.count_time = float(str(self.count_time_ledit.text()))
        except:
            logging.getLogger("user_level_log").info("Incorrect count time value.")

        return base_result and self.count_time

    # 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):
        data_collections = []

        if self.count_time is not None:
            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

            path_template = self._create_path_template(sample, self._path_template)

            xrf_scan = queue_model_objects.XRFScan(sample, path_template, cpos)
            xrf_scan.set_name(path_template.get_prefix())
            xrf_scan.set_number(path_template.run_number)
            xrf_scan.count_time = self.count_time

            data_collections.append(xrf_scan)
        else:
            logging.getLogger("user_level_log").info("No count time specified.")

        return data_collections
Exemplo n.º 37
0
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)
    def __init__(self, parent=None, name="energy_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.energy_scan_model = queue_model_objects.EnergyScan()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self)
        _parameters_widget = QtGui.QWidget(_top_widget)
        self.periodic_table_widget = PeriodicTableWidget(_parameters_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.data_path_widget.data_path_layout.file_name_label.setText("")
        self.data_path_widget.data_path_layout.file_name_value_label.hide()
        self.position_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__), "ui_files/Qt4_snapshot_widget_layout.ui")
        )
        self.position_widget.setFixedSize(450, 340)

        self.scan_plot_widget = TwoAxisPlotWidget(self)
        self.scan_plot_widget.set_real_time_plot(True)
        self.result_plot_widget = TwoAxisPlotWidget(self)

        """self.scan_plot_widget = ScanPlotWidget(self)
        self.scan_plot_widget.setRealTimePlot(True)
        self.result_plot_widget = ScanPlotWidget(self)
        self.result_plot_widget.setRealTimePlot(False)
        self.scan_plot_widget.setFixedHeight(200)
        self.result_plot_widget.setFixedHeight(200)"""

        # Layout -------------------------------------------------------------
        _parameters_widget_layout = QtGui.QVBoxLayout()
        _parameters_widget_layout.addWidget(self.periodic_table_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _parameters_widget_layout.setContentsMargins(0, 0, 0, 0)
        _parameters_widget.setLayout(_parameters_widget_layout)

        _top_widget_hlayout = QtGui.QHBoxLayout(self)
        _top_widget_hlayout.addWidget(_parameters_widget)
        _top_widget_hlayout.addWidget(self.position_widget)
        _top_widget_hlayout.addStretch(0)
        _top_widget_hlayout.setSpacing(2)
        _top_widget_hlayout.setContentsMargins(0, 0, 0, 0)
        _top_widget.setLayout(_top_widget_hlayout)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.scan_plot_widget)
        _main_vlayout.addWidget(self.result_plot_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)

        self.setLayout(_main_vlayout)

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

        # Qt signal/slot connections ------------------------------------------
        # qt.QObject.connect(self.periodic_table_widget, qt.PYSIGNAL('edgeSelected'),
        #                   self.element_clicked)

        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)

        # qt.QObject.connect(qt.qApp, qt.PYSIGNAL('tab_changed'),
        #                   self.tab_changed)

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

        Qt4_widget_colors.set_widget_color(self.periodic_table_widget, Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.position_widget, Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.data_path_widget, Qt4_widget_colors.GROUP_BOX_GRAY)
class XRFSpectrumParametersWidget(QWidget):
    def __init__(self, parent=None, name="xrf_spectrum_parameters_widget"):
        QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.xrf_spectrum_model = queue_model_objects.XRFSpectrum()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QWidget(self)
        _parameters_widget = QWidget(_top_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.other_parameters_gbox = QGroupBox("Other parameters",
                                               _parameters_widget)
        self.count_time_label = QLabel("Count time:",
                                       self.other_parameters_gbox)
        self.count_time_ledit = QLineEdit(self.other_parameters_gbox)
        self.count_time_ledit.setFixedWidth(50)
        self.adjust_transmission_cbox = QCheckBox("Adjust transmission", \
             self.other_parameters_gbox)
        self.adjust_transmission_cbox.hide()
        self.mca_spectrum_widget = McaSpectrumWidget(self)
        self.snapshot_widget = SnapshotWidget(self)

        # Layout -------------------------------------------------------------
        _other_parameters_gbox_hlayout = QHBoxLayout(
            self.other_parameters_gbox)
        _other_parameters_gbox_hlayout.addWidget(self.count_time_label)
        _other_parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _other_parameters_gbox_hlayout.addWidget(self.adjust_transmission_cbox)
        _other_parameters_gbox_hlayout.addStretch(0)
        _other_parameters_gbox_hlayout.setSpacing(2)
        _other_parameters_gbox_hlayout.setContentsMargins(0, 0, 0, 0)

        _parameters_widget_layout = QVBoxLayout(_parameters_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addWidget(self.other_parameters_gbox)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _parameters_widget_layout.setContentsMargins(0, 0, 0, 0)

        _top_widget_layout = QHBoxLayout(_top_widget)
        _top_widget_layout.addWidget(_parameters_widget)
        _top_widget_layout.addWidget(self.snapshot_widget)
        _top_widget_layout.setSpacing(2)
        _top_widget_layout.addStretch(0)
        _top_widget_layout.setContentsMargins(0, 0, 0, 0)

        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.mca_spectrum_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies -------------------------------------------------------
        self.mca_spectrum_widget.setSizePolicy(QSizePolicy.Expanding,
                                               QSizePolicy.Expanding)
        _top_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)

        # 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.count_time_ledit.textChanged.connect(\
             self._count_time_ledit_change)

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

    def _prefix_ledit_change(self, new_value):
        self.xrf_spectrum_model.set_name(str(new_value))
        self._tree_view_item.setText(\
             0, self.xrf_spectrum_model.get_display_name())

    def _run_number_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.xrf_spectrum_model.set_number(int(new_value))
            self._tree_view_item.setText(\
                 0, self.xrf_spectrum_model.get_display_name())

    def _count_time_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.xrf_spectrum_model.set_count_time(float(new_value))

    def tab_changed(self):
        if self._tree_view_item:
            self.populate_widget(self._tree_view_item)

    def populate_widget(self, item):
        self._tree_view_item = item
        self.xrf_spectrum_model = item.get_model()
        executed = self.xrf_spectrum_model.is_executed()

        self.data_path_widget.setEnabled(not executed)
        self.other_parameters_gbox.setEnabled(not executed)
        #self.mca_spectrum_widget.setEnabled(executed)

        if executed:
            result = self.xrf_spectrum_model.get_spectrum_result()
            self.mca_spectrum_widget.set_data(result.mca_data,
                                              result.mca_calib,
                                              result.mca_config)
        else:
            self.mca_spectrum_widget.clear()

        self.data_path_widget.update_data_model(\
             self.xrf_spectrum_model.path_template)
        self.count_time_ledit.setText(\
             str(self.xrf_spectrum_model.count_time))

        image = self.xrf_spectrum_model.centred_position.snapshot_image
        self.snapshot_widget.display_snapshot(image, width=400)

    def set_xrf_spectrum_hwobj(self, xrf_spectrum_hwobj):
        if self.xrf_spectrum_hwobj is None:
            self.xrf_spectrum_hwobj = xrf_spectrum_hwobj
            self.xrf_spectrum_hwobj.connect("xrfSpectrumFinished",
                                            self.spectrum_finished)

    def spectrum_finished(self, mca_data, mca_calib, mca_config):
        self.mca_spectrum_widget.set_data(mca_data, mca_calib, mca_config)
Exemplo n.º 40
0
class CreateXrayImagingWidget(CreateTaskBase):
    """Widget used to create xray imaging method
    """

    def __init__(self, parent=None,name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, 
            Qt.WindowFlags(fl), 'XrayImaging')

        if not name:
            self.setObjectName("create_xray_imaging_widget")

        # Hardware objects ----------------------------------------------------
 
        # Internal variables --------------------------------------------------
        self._xray_imaging_parameters = None
        self._processing_parameters = None
        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._xray_imaging_parameters_widget = XrayImagingParametersWidget(\
             self, 'xray_imaging_widget',
             xray_imaging_params=self._xray_imaging_parameters)

        self._acq_widget =  AcquisitionWidget(self, "acquisition_widget",
             layout='vertical', acq_params=self._acquisition_parameters,
             path_template=self._path_template)
        self._acq_widget.grid_mode = False

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

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

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

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

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False)
        self._acq_widget.acq_widget_layout.max_osc_range_cbx.setVisible(False)
        self._acq_widget.acq_widget_layout.first_image_label.setVisible(False)
        self._acq_widget.acq_widget_layout.first_image_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.detector_roi_mode_label.setVisible(False)
        self._acq_widget.acq_widget_layout.detector_roi_mode_combo.setVisible(False)
        self._acq_widget.acq_widget_layout.energies_combo.setVisible(False)
        self._acq_widget.acq_widget_layout.mad_cbox.setVisible(False)
        self._acq_widget.acq_widget_layout.energy_label.setVisible(False)
        self._acq_widget.acq_widget_layout.energy_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.transmission_label.setVisible(False)
        self._acq_widget.acq_widget_layout.transmission_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.resolution_label.setVisible(False)
        self._acq_widget.acq_widget_layout.resolution_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.kappa_label.setVisible(False)
        self._acq_widget.acq_widget_layout.kappa_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.kappa_phi_label.setVisible(False)
        self._acq_widget.acq_widget_layout.kappa_phi_ledit.setVisible(False)
        self._acq_widget.acq_widget_layout.shutterless_cbx.setVisible(False)

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

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

        self._xray_imaging_parameters = queue_model_objects.XrayImagingParameters()

        if self._beamline_setup_hwobj is not None:
            self._acquisition_parameters = self._beamline_setup_hwobj.\
                get_default_acquisition_parameters("default_imaging_values")
            self._path_template.suffix = 'tiff'

    def set_beamline_setup(self, bl_setup_hwobj):
        """
        In plate mode osciallation is start is in the middle of grid
        """
        CreateTaskBase.set_beamline_setup(self, bl_setup_hwobj)
        #self._xray_imaging_parameters_widget.set_beamline_setup(bl_setup_hwobj)

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

        if isinstance(tree_item, Qt4_queue_item.SampleQueueItem):
            self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.BasketQueueItem):
            self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.XrayImagingQueueItem):
            data_model= tree_item.get_model()

            self._path_template = data_model.get_path_template()
            self._data_path_widget.update_data_model(self._path_template)

            self._acquisition_parameters = data_model.acquisition.acquisition_parameters
            self._acq_widget.update_data_model(self._acquisition_parameters,
                                               self._path_template)

            self._xray_imaging_parameters = data_model.xray_imaging_parameters
            self._xray_imaging_parameters_widget.update_data_model(data_model)
    

            self.setDisabled(False)

    # 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. :
        """
        if isinstance(shape, GraphicsItemPoint):
            snapshot = self._graphics_manager_hwobj.get_scene_snapshot(shape)
            cpos = copy.deepcopy(shape.get_centred_position())
            cpos.snapshot_image = snapshot
        else:
            cpos = queue_model_objects.CentredPosition()
            cpos.snapshot_image = self._graphics_manager_hwobj.get_scene_snapshot()

        #self._path_template.run_number += 1

        acq = self._create_acq(sample)
        acq.acquisition_parameters.centred_position = cpos
        dc = queue_model_objects.XrayImaging(self._xray_imaging_parameters.copy(),
                                             acq,
                                             sample.crystals[0])
        dc.set_name(acq.path_template.get_prefix())
        dc.set_number(acq.path_template.run_number)
        dc.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.IMAGING

        return [dc]
Exemplo n.º 41
0
    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)
Exemplo n.º 42
0
class CreateAdvancedWidget(CreateTaskBase):
    """
    Descript. :
    """
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, QtCore.Qt.WindowFlags(fl),
                                'Advanced')

        if not name:
            self.setObjectName("create_advanced_widget")

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

        # Internal variables --------------------------------------------------
        self.init_models()
        self._advanced_methods = None
        self._grid_map = {}

        # Graphic elements ----------------------------------------------------
        self._advanced_methods_widget = uic.loadUi(os.path.join(\
            os.path.dirname(__file__), "ui_files/Qt4_advanced_methods_layout.ui"))

        self._acq_widget = AcquisitionWidget(
            self,
            "acquisition_widget",
            layout='vertical',
            acq_params=self._acquisition_parameters,
            path_template=self._path_template)

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

        # Layout --------------------------------------------------------------
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._advanced_methods_widget)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addStretch(0)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)

        # 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._data_path_widget.pathTemplateChangedSignal.connect(\
             self.handle_path_conflict)

        self._acq_widget.acqParametersChangedSignal.connect(\
             self.handle_path_conflict)
        self._acq_widget.madEnergySelectedSignal.connect(\
             self.mad_energy_selected)

        self._advanced_methods_widget.grid_treewidget.itemSelectionChanged.\
             connect(self.grid_treewidget_item_selection_changed)
        self._advanced_methods_widget.draw_grid_button.clicked.\
             connect(self.draw_grid_button_clicked)
        self._advanced_methods_widget.remove_grid_button.clicked.\
             connect(self.remove_grid_button_clicked)
        self._advanced_methods_widget.hor_spacing_ledit.textChanged.\
             connect(self.spacing_changed)
        self._advanced_methods_widget.ver_spacing_ledit.textChanged.\
             connect(self.spacing_changed)

        self._advanced_methods_widget.move_right_button.clicked.\
             connect(lambda : self.move_grid("right"))
        self._advanced_methods_widget.move_left_button.clicked.\
             connect(lambda : self.move_grid("left"))
        self._advanced_methods_widget.move_up_button.clicked.\
             connect(lambda : self.move_grid("up"))
        self._advanced_methods_widget.move_down_button.clicked.\
             connect(lambda : self.move_grid("down"))

        self._advanced_methods_widget.overlay_cbox.toggled.\
             connect(self.overlay_toggled)
        self._advanced_methods_widget.overlay_slider.valueChanged.\
             connect(self.overlay_alpha_changed)
        self._advanced_methods_widget.move_to_grid_button.clicked.\
             connect(self.move_to_grid)

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False)
        self._acq_widget.use_kappa_phi(False)
        self._acq_widget.acq_widget_layout.num_images_label.setEnabled(False)
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        for col in range(self._advanced_methods_widget.\
                         grid_treewidget.columnCount()):
            self._advanced_methods_widget.grid_treewidget.\
                 resizeColumnToContents(col)

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

    def _init_models(self):
        """
        Descript. :
        """
        self._advanced = queue_model_objects.Advanced()
        self._processing_parameters = queue_model_objects.ProcessingParameters(
        )

        if self._beamline_setup_hwobj is not None:
            has_shutter_less = self._beamline_setup_hwobj.\
                               detector_has_shutterless()
            self._acquisition_parameters.shutterless = has_shutter_less

            self._acquisition_parameters = self._beamline_setup_hwobj.\
                get_default_acquisition_parameters("default_advanced_values")

            if not self._advanced_methods:
                self._advanced_methods = self._beamline_setup_hwobj.get_advanced_methods(
                )
                if self._advanced_methods:
                    for method in self._advanced_methods:
                        self._advanced_methods_widget.method_combo.addItem(
                            method)
                else:
                    self.setEnabled(False)
            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

            self.grid_treewidget_item_selection_changed()
        else:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters(
            )

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

        if len(self._advanced_methods_widget.grid_treewidget.\
            selectedItems()) == 0:
            msg = "No grid selected. Automatic grid will be used."
            logging.getLogger("user_level_log").info(msg)
        return result

    def update_processing_parameters(self, crystal):
        """
        Descript. :
        """
        return

    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._acq_widget.update_data_model(self._acquisition_parameters,
                                               self._path_template)
        elif isinstance(tree_item, Qt4_queue_item.BasketQueueItem):
            self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.AdvancedQueueItem):
            advanced = tree_item.get_model()
            if tree_item.get_model().is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

            # sample_data_model = self.get_sample_item(tree_item).get_model()
            #self._acq_widget.disable_inverse_beam(True)

            self._path_template = advanced.get_path_template()
            self._data_path_widget.update_data_model(self._path_template)

            data_collection = advanced.reference_image_collection

            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)
        else:
            self.setDisabled(True)
        #if self._advanced_methods_widget.grid_treewidget.count() > 0:
        #    self._advanced_methods_widget.grid_treewidget.clearSelection()

    def _create_task(self, sample, shape):
        """
        Descript. :
        """
        data_collections = []
        selected_grids = self.get_selected_grids()

        if len(selected_grids) == 0:
            selected_grids.append(self._graphics_manager_hwobj.\
                create_automatic_grid())

        for shape in selected_grids:
            shape.set_snapshot(self._graphics_manager_hwobj.\
                  get_scene_snapshot(shape))

            grid_properties = shape.get_properties()

            acq = self._create_acq(sample)
            acq.acquisition_parameters.centred_position = \
                shape.get_centred_position()
            acq.acquisition_parameters.mesh_range = \
                [grid_properties["dx_mm"], grid_properties["dy_mm"]]
            acq.acquisition_parameters.num_lines = \
                grid_properties["num_lines"]
            acq.acquisition_parameters.num_images = \
                grid_properties["num_lines"] * \
                grid_properties["num_images_per_line"]

            processing_parameters = deepcopy(self._processing_parameters)

            dc = queue_model_objects.DataCollection([acq], sample.crystals[0],
                                                    processing_parameters)

            dc.set_name(acq.path_template.get_prefix())
            dc.set_number(acq.path_template.run_number)
            dc.set_experiment_type(EXPERIMENT_TYPE.MESH)

            exp_type = str(self._advanced_methods_widget.method_combo.\
                currentText())
            advanced = queue_model_objects.Advanced(exp_type, dc, shape,
                                                    sample.crystals[0])

            data_collections.append(advanced)
            self._path_template.run_number += 1

            return data_collections

    def shape_created(self, shape, shape_type):
        if shape_type == "Grid":
            self._advanced_methods_widget.grid_treewidget.clearSelection()
            grid_properties = shape.get_properties()
            info_str_list = QtCore.QStringList()
            info_str_list.append(grid_properties["name"])
            info_str_list.append("%d" % grid_properties["beam_x"])
            info_str_list.append("%d" % grid_properties["beam_y"])
            info_str_list.append("%d" % grid_properties["num_lines"])
            info_str_list.append("%d" % grid_properties["num_images_per_line"])

            grid_treewidget_item = QtGui.QTreeWidgetItem(\
                self._advanced_methods_widget.grid_treewidget,
                info_str_list)
            grid_treewidget_item.setSelected(True)
            self._grid_map[shape] = grid_treewidget_item
            self.grid_treewidget_item_selection_changed()

    def shape_deleted(self, shape, shape_type):
        if self._grid_map.get(shape):
            treewidget_item_modelindex = self._advanced_methods_widget.\
                 grid_treewidget.indexFromItem(self._grid_map[shape])
            self._advanced_methods_widget.grid_treewidget.takeTopLevelItem(\
                 treewidget_item_modelindex.row())
            self._grid_map.pop(shape)

    def grid_treewidget_item_selection_changed(self):
        self._advanced_methods_widget.remove_grid_button.setEnabled(False)
        for grid_object, treewidget_item in self._grid_map.items():
            if treewidget_item.isSelected():
                grid_properties = grid_object.get_properties()
                cell_count = grid_properties["num_lines"] * \
                             grid_properties["num_images_per_line"]
                self._acq_widget.acq_widget_layout.num_images_ledit.setText(\
                     "%d" % cell_count)
                self._acq_widget.acq_widget_layout.first_image_ledit.setText(\
                     "%d" % grid_properties["first_image_num"])
                centred_point = grid_object.get_centred_position()
                self._acq_widget.acq_widget_layout.osc_start_ledit.setText(\
                     "%.2f" % float(centred_point.phi))
                self._acq_widget.acq_widget_layout.kappa_ledit.setText(\
                     "%.2f" % float(centred_point.kappa))
                self._acq_widget.acq_widget_layout.kappa_phi_ledit.setText(\
                     "%.2f" % float(centred_point.kappa_phi))
                self._advanced_methods_widget.hor_spacing_ledit.setText(\
                     "%.2f" % float(grid_properties["xOffset"]))
                self._advanced_methods_widget.ver_spacing_ledit.setText(\
                     "%.2f" % float(grid_properties["yOffset"]))
                grid_object.setSelected(True)
                self._advanced_methods_widget.remove_grid_button.setEnabled(
                    True)
            else:
                grid_object.setSelected(False)
        self._advanced_methods_widget.move_to_grid_button.setEnabled(True)

    def get_selected_grids(self):
        selected_grids = []
        for grid, grid_treewidget_item in self._grid_map.items():
            if grid_treewidget_item.isSelected():
                selected_grids.append(grid)
        return selected_grids

    def draw_grid_button_clicked(self):
        self._graphics_manager_hwobj.create_grid(self.get_spacing())

    def remove_grid_button_clicked(self):
        grid_to_delete = None
        for grid, treewidget_item in self._grid_map.items():
            if treewidget_item.isSelected():
                grid_to_delete = grid
                break
        if grid_to_delete:
            self._graphics_manager_hwobj.delete_shape(grid_to_delete)
            self._advanced_methods_widget.move_to_grid_button.setEnabled(False)

    def get_spacing(self):
        spacing = [0, 0]
        try:
            spacing[0] = float(self._advanced_methods_widget.\
                hor_spacing_ledit.text())
        except:
            pass
        try:
            spacing[1] = float(self._advanced_methods_widget.\
                ver_spacing_ledit.text())
        except:
            pass
        return spacing

    def spacing_changed(self, value):
        spacing = self.get_spacing()
        for grid_object, treewidget_item in self._grid_map.items():
            if treewidget_item.isSelected():
                grid_object.set_spacing(spacing)
                #self._graphics_manager_hwobj.\
                #     update_grid_motor_positions(grid_object)

    def move_to_grid(self):
        for grid_object, treewidget_item in self._grid_map.items():
            if treewidget_item.isSelected():
                self._beamline_setup_hwobj.diffractometer_hwobj.\
                     move_to_centred_position(grid_object.get_centred_position())

    def overlay_toggled(self, state):
        for grid_object, treewidget_item in self._grid_map.items():
            if treewidget_item.isSelected():
                grid_object.set_display_overlay(state)

    def overlay_alpha_changed(self, alpha_value):
        for grid_object, treewidget_item in self._grid_map.items():
            if treewidget_item.isSelected():
                grid_object.set_fill_alpha(alpha_value)

    def move_grid(self, direction):
        for grid_object, treewidget_item in self._grid_map.items():
            if treewidget_item.isSelected():
                grid_object.move_by_pix(direction)
                self._graphics_manager_hwobj.\
                     update_grid_motor_positions(grid_object)
class CreateAdvancedWidget(CreateTaskBase):
    """
    Descript. :
    """

    def __init__(self, parent = None,name = None, fl = 0):
        CreateTaskBase.__init__(self, parent, name, QtCore.Qt.WindowFlags(fl), 'Advanced')

        if not name:
            self.setObjectName("create_advanced_widget")

        # Hardware objects ----------------------------------------------------
 
        # Internal variables --------------------------------------------------
        self.init_models()
        self._advanced_methods = None
        self._grid_map = {}

        # Graphic elements ----------------------------------------------------
        self._advanced_methods_widget = uic.loadUi(os.path.join(\
            os.path.dirname(__file__), "ui_files/Qt4_advanced_methods_layout.ui"))

        self._acq_widget =  AcquisitionWidget(self, "acquisition_widget",
             layout='vertical', acq_params=self._acquisition_parameters,
             path_template=self._path_template)

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

        # Layout --------------------------------------------------------------
        _main_vlayout = QtGui.QVBoxLayout(self) 
        _main_vlayout.addWidget(self._advanced_methods_widget)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addStretch(0)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)

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

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

        self._advanced_methods_widget.grid_treewidget.itemSelectionChanged.\
             connect(self.grid_treewidget_item_selection_changed)
        self._advanced_methods_widget.draw_grid_button.clicked.\
             connect(self.draw_grid_button_clicked)
        self._advanced_methods_widget.remove_grid_button.clicked.\
             connect(self.remove_grid_button_clicked)
        self._advanced_methods_widget.hor_spacing_ledit.textChanged.\
             connect(self.spacing_changed)
        self._advanced_methods_widget.ver_spacing_ledit.textChanged.\
             connect(self.spacing_changed)

        self._advanced_methods_widget.move_right_button.clicked.\
             connect(lambda : self.move_grid("right"))
        self._advanced_methods_widget.move_left_button.clicked.\
             connect(lambda : self.move_grid("left"))
        self._advanced_methods_widget.move_up_button.clicked.\
             connect(lambda : self.move_grid("up"))
        self._advanced_methods_widget.move_down_button.clicked.\
             connect(lambda : self.move_grid("down"))        
      
        self._advanced_methods_widget.overlay_cbox.toggled.\
             connect(self.overlay_toggled)
        self._advanced_methods_widget.overlay_slider.valueChanged.\
             connect(self.overlay_alpha_changed) 
        self._advanced_methods_widget.overlay_color_button.clicked.\
             connect(self.overlay_change_color)
        self._advanced_methods_widget.move_to_grid_button.clicked.\
             connect(self.move_to_grid)

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False) 
        self._acq_widget.acq_widget_layout.num_images_label.setEnabled(False)
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        for col in range(self._advanced_methods_widget.\
                         grid_treewidget.columnCount()):
            self._advanced_methods_widget.grid_treewidget.\
                 resizeColumnToContents(col)

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

    def _init_models(self):
        """
        Descript. :
        """
        self._processing_parameters = queue_model_objects.ProcessingParameters()

        if self._beamline_setup_hwobj is not None:
            has_shutter_less = self._beamline_setup_hwobj.\
                               detector_has_shutterless()
            self._acquisition_parameters.shutterless = has_shutter_less

            self._acquisition_parameters = self._beamline_setup_hwobj.\
                get_default_acquisition_parameters("default_advanced_values")

            if not self._advanced_methods:
                self._advanced_methods = self._beamline_setup_hwobj.get_advanced_methods()            
                if self._advanced_methods:
                   for method in self._advanced_methods:
                       self._advanced_methods_widget.method_combo.addItem(method)
                else:
                   self.setEnabled(False)    
            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

            self.grid_treewidget_item_selection_changed()
        else:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters()

    def set_beamline_setup(self, bl_setup_hwobj):
        """
        In plate mode osciallation is start is in the middle of grid
        """
        CreateTaskBase.set_beamline_setup(self, bl_setup_hwobj)

        if bl_setup_hwobj.diffractometer_hwobj.in_plate_mode():
            self._acq_widget.acq_widget_layout.osc_start_label.\
                 setText("Oscillation middle:")

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

        if len(self._advanced_methods_widget.\
           grid_treewidget.selectedItems()) == 0:
            msg = "No grid selected. Continuing with automatic grid."
            logging.getLogger("GUI").info(msg)
        return result
            
    def update_processing_parameters(self, crystal):
        """
        Descript. :
        """
        return

    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._acq_widget.update_data_model(self._acquisition_parameters,
                                                self._path_template)            
        elif isinstance(tree_item, Qt4_queue_item.BasketQueueItem):
            self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.DataCollectionQueueItem):
            data_collection = tree_item.get_model()
            if tree_item.get_model().is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

            # sample_data_model = self.get_sample_item(tree_item).get_model()
            #self._acq_widget.disable_inverse_beam(True)
            #self._graphics_manager_hwobj.de_select_all()
            self._graphics_manager_hwobj.select_shape(data_collection.grid)

            self._path_template = data_collection.get_path_template()
            self._data_path_widget.update_data_model(self._path_template)

            self._acquisition_parameters = data_collection.acquisitions[0].\
                                           acquisition_parameters
            self._acq_widget.update_data_model(self._acquisition_parameters,
                                               self._path_template)
            self.get_acquisition_widget().use_osc_start(True)
        else:
            self.setDisabled(True)
  
    def _create_task(self,  sample, shape):
        """
        Descript. :
        """
        tasks = []
        selected_grids = self.get_selected_grids() 

        if len(selected_grids) == 0:
            selected_grids.append(self._graphics_manager_hwobj.\
                update_auto_grid()) 

        for grid in selected_grids:
            grid.set_snapshot(self._graphics_manager_hwobj.\
                  get_scene_snapshot(grid))

            grid_properties = grid.get_properties()

            acq = self._create_acq(sample)
            acq.acquisition_parameters.centred_position = \
                grid.get_centred_position()
            acq.acquisition_parameters.mesh_range = \
                [grid_properties["dx_mm"], grid_properties["dy_mm"]]
            acq.acquisition_parameters.num_lines = \
                grid_properties["num_lines"]
            acq.acquisition_parameters.num_images = \
                grid_properties["num_lines"] * \
                grid_properties["num_images_per_line"]
            grid.set_osc_range(acq.acquisition_parameters.osc_range)

            processing_parameters = deepcopy(self._processing_parameters)

            dc = queue_model_objects.DataCollection([acq],
                                     sample.crystals[0],
                                     processing_parameters)

            dc.set_name(acq.path_template.get_prefix())
            dc.set_number(acq.path_template.run_number)
            dc.set_experiment_type(EXPERIMENT_TYPE.MESH)
            dc.set_requires_centring(False)
            dc.grid = grid

            exp_type = str(self._advanced_methods_widget.\
                method_combo.currentText())
            if exp_type == "Mesh":
                dc.run_processing_parallel = "MeshScan"
                tasks.append(dc)
            elif exp_type == "XrayCentering":
                xray_centering = queue_model_objects.XrayCentering(\
                   dc, sample.crystals[0])
                dc.run_processing_parallel = "XrayCentering"
                tasks.append(xray_centering)
            self._path_template.run_number += 1

            return tasks

    def shape_created(self, shape, shape_type):
        if shape_type == "Grid":
            self._advanced_methods_widget.grid_treewidget.clearSelection()
            grid_properties = shape.get_properties()
            info_str_list = []
            info_str_list.append(grid_properties["name"])
            info_str_list.append("%d" % (grid_properties["beam_x_mm"] * 1000.0))
            info_str_list.append("%d" % (grid_properties["beam_y_mm"] * 1000.0))
            info_str_list.append("%d" % grid_properties["num_lines"])
            info_str_list.append("%d" % grid_properties["num_images_per_line"])

            grid_treewidget_item = QtGui.QTreeWidgetItem(\
                self._advanced_methods_widget.grid_treewidget,
                info_str_list)
            grid_treewidget_item.setSelected(True)
            self._grid_map[shape] = grid_treewidget_item
            self.grid_treewidget_item_selection_changed()
            
    def shape_deleted(self, shape, shape_type):
        if self._grid_map.get(shape):
            treewidget_item_modelindex = self._advanced_methods_widget.\
                 grid_treewidget.indexFromItem(self._grid_map[shape])
            self._advanced_methods_widget.grid_treewidget.takeTopLevelItem(\
                 treewidget_item_modelindex.row())
            self._grid_map.pop(shape) 

    def grid_treewidget_item_selection_changed(self):
        self.enable_grid_controls(False)
      
        osc_dynamic_limits = None
        if self._beamline_setup_hwobj.diffractometer_hwobj.in_plate_mode():
            osc_dynamic_limits = self._beamline_setup_hwobj.\
                diffractometer_hwobj.get_osc_dynamic_limits()

        for item in self._grid_map.items():
            grid = item[0]
            treewidget_item = item[1]
  
            if treewidget_item.isSelected():
                grid_properties = grid.get_properties() 
                cell_count = grid_properties["num_lines"] * \
                             grid_properties["num_images_per_line"]
                self._acq_widget.acq_widget_layout.num_images_ledit.setText(\
                     "%d" % cell_count)
                self._acq_widget.acq_widget_layout.first_image_ledit.setText(\
                     "%d" % grid_properties["first_image_num"])
                centred_point = grid.get_centred_position()
                self._acq_widget.acq_widget_layout.osc_start_ledit.setText(\
                     "%.2f" % float(centred_point.phi))
                self._acq_widget.acq_widget_layout.kappa_ledit.setText(\
                     "%.2f" % float(centred_point.kappa))
                self._acq_widget.acq_widget_layout.kappa_phi_ledit.setText(\
                     "%.2f" % float(centred_point.kappa_phi))
                self._advanced_methods_widget.hor_spacing_ledit.setText(\
                     "%.2f" % (float(grid_properties["xOffset"]) * 1000))
                self._advanced_methods_widget.ver_spacing_ledit.setText(\
                     "%.2f" % (float(grid_properties["yOffset"]) * 1000))

             
                if osc_dynamic_limits:
                    osc_range_limits = \
                        (0, 
                         abs(osc_dynamic_limits[1] - osc_dynamic_limits[0]) /\
                         float(grid_properties["num_images_per_line"]))
                    self._acq_widget.update_osc_range_limits(osc_range_limits)
                    self._acq_widget.acq_widget_layout.osc_range_ledit.\
                         setText("%.2f" % (abs(osc_range_limits[1] -\
                                               osc_range_limits[0]))) 

                grid.setSelected(True) 
                self.enable_grid_controls(True)
            else:
                grid.setSelected(False)

    def get_selected_grids(self):
        selected_grids = [] 
        for grid, grid_treewidget_item in self._grid_map.iteritems():
            if grid_treewidget_item.isSelected():
                selected_grids.append(grid)
        return selected_grids

    def draw_grid_button_clicked(self):
        self._graphics_manager_hwobj.create_grid(self.get_spacing())

    def remove_grid_button_clicked(self):
        grid_to_delete = None 
        for grid, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_to_delete = grid
                break
        if grid_to_delete:
            self._graphics_manager_hwobj.delete_shape(grid_to_delete)
            self._advanced_methods_widget.move_to_grid_button.setEnabled(False)           

    def get_spacing(self):
        spacing = [0, 0]
        try:
           spacing[0] = float(self._advanced_methods_widget.\
               hor_spacing_ledit.text()) / 1000.0
        except:
           pass
        try:
           spacing[1] = float(self._advanced_methods_widget.\
               ver_spacing_ledit.text()) / 1000.0
        except:
           pass
        return spacing

    def spacing_changed(self, value):
        spacing = self.get_spacing()
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.set_spacing(spacing)
                #self._graphics_manager_hwobj.\
                #     update_grid_motor_positions(grid_object)

    def move_to_grid(self):
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                self._beamline_setup_hwobj.diffractometer_hwobj.\
                     move_to_centred_position(grid_object.get_centred_position())

    def overlay_toggled(self, state):
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.set_display_overlay(state)
           
    def overlay_alpha_changed(self, alpha_value):
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.set_fill_alpha(alpha_value)

    def overlay_change_color(self):
        color = QtGui.QColorDialog.getColor()
        if color.isValid():
            for grid_object, treewidget_item in self._grid_map.iteritems():
                if treewidget_item.isSelected():
                    grid_object.set_base_color(color)

    def move_grid(self, direction):
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.move_by_pix(direction)
                self._graphics_manager_hwobj.\
                     update_grid_motor_positions(grid_object)

    def enable_grid_controls(self, state):
        self._advanced_methods_widget.overlay_cbox.setEnabled(state)
        self._advanced_methods_widget.overlay_slider.setEnabled(state)
        self._advanced_methods_widget.overlay_color_button.setEnabled(state)
        self._advanced_methods_widget.move_to_grid_button.setEnabled(state)
        self._advanced_methods_widget.remove_grid_button.setEnabled(state)        

        self._advanced_methods_widget.move_right_button.setEnabled(state)
        self._advanced_methods_widget.move_left_button.setEnabled(state)
        self._advanced_methods_widget.move_up_button.setEnabled(state)
        self._advanced_methods_widget.move_down_button.setEnabled(state)
Exemplo n.º 44
0
class XRFScanParametersWidget(QtGui.QWidget):
    def __init__(self, parent = None, name = "xrf_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.xrf_scan_model = queue_model_objects.XRFScan()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self)
        _parameters_widget = QtGui.QWidget(_top_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.other_parameters_gbox = QtGui.QGroupBox("Other parameters", _parameters_widget) 
        self.count_time_label = QtGui.QLabel("Count time:", 
                                             self.other_parameters_gbox)
	self.count_time_ledit = QtGui.QLineEdit(self.other_parameters_gbox)
	self.count_time_ledit.setFixedWidth(50)
        self.adjust_transmission_cbox = QtGui.QCheckBox("Adjust transmission", \
             self.other_parameters_gbox)
        self.adjust_transmission_cbox.hide()
        _snapshot_widget = QtGui.QWidget(self)
        self.position_widget = uic.loadUi(os.path.join(os.path.dirname(__file__),
                                          'ui_files/Qt4_snapshot_widget_layout.ui'))
        self.mca_spectrum_widget = McaSpectrumWidget(self)
 
        # Layout -------------------------------------------------------------
        _other_parameters_gbox_hlayout = QtGui.QHBoxLayout(self.other_parameters_gbox)
        _other_parameters_gbox_hlayout.addWidget(self.count_time_label)  
        _other_parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _other_parameters_gbox_hlayout.addWidget(self.adjust_transmission_cbox)
        _other_parameters_gbox_hlayout.addStretch(0)
        _other_parameters_gbox_hlayout.setSpacing(2)
        _other_parameters_gbox_hlayout.setContentsMargins(3, 3, 3, 3)

        _parameters_widget_layout = QtGui.QVBoxLayout(_parameters_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addWidget(self.other_parameters_gbox)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _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(0)

        _top_widget_layout = QtGui.QHBoxLayout(_top_widget)
        _top_widget_layout.addWidget(_parameters_widget)
        _top_widget_layout.addWidget(_snapshot_widget)
        _top_widget_layout.setSpacing(2)
        _top_widget_layout.setContentsMargins(0, 0, 0, 0)
        
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.mca_spectrum_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
       
        # SizePolicies -------------------------------------------------------
        self.position_widget.setFixedSize(457, 350)
        self.mca_spectrum_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                               QtGui.QSizePolicy.Expanding)
        _top_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Fixed)

        # 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.count_time_ledit.textChanged.connect(self._count_time_ledit_change)
        
        # Other ---------------------------------------------------------------
        Qt4_widget_colors.set_widget_color(self.other_parameters_gbox,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.data_path_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY) 
        Qt4_widget_colors.set_widget_color(self.position_widget, 
                                           Qt4_widget_colors.GROUP_BOX_GRAY)

    def _prefix_ledit_change(self, new_value):
        self.xrf_scan_model.set_name(str(new_value))
        self._tree_view_item.setText(0, self.xrf_scan_model.get_display_name())

    def _run_number_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.xrf_scan_model.set_number(int(new_value))
            self._tree_view_item.setText(0, self.xrf_scan_model.get_display_name())

    def _count_time_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.xrf_scan_model.set_count_time(float(new_value))
        
    def tab_changed(self):
        if self._tree_view_item:
            self.populate_widget(self._tree_view_item)

    def populate_widget(self, item):
        self._tree_view_item = item
        self.xrf_scan_model = item.get_model()
        executed = self.xrf_scan_model.is_executed()

        self.data_path_widget.setEnabled(not executed)
        self.other_parameters_gbox.setEnabled(not executed)    
        self.mca_spectrum_widget.setEnabled(executed)        
 
        if executed:
            result = self.xrf_scan_model.get_scan_result()
            self.mca_spectrum_widget.setData(result.mca_data, result.mca_calib, result.mca_config) 
        else:
            self.mca_spectrum_widget.clear()
        
        self.data_path_widget.update_data_model(self.xrf_scan_model.path_template)  
        self.count_time_ledit.setText(str(self.xrf_scan_model.count_time)) 

        image = self.xrf_scan_model.centred_position.snapshot_image
        if image is not None:
            try:
               image = image.scaled(427, 320, QtCore.Qt.KeepAspectRatio)
               self.position_widget.svideo.setPixmap(QtGui.QPixmap(image))
            except:
               pass

    def set_xrf_scan_hwobj(self, xrf_scan_hwobj):
        self.xrf_scan_hwobj = xrf_scan_hwobj
        if self.xrf_scan_hwobj:
            self.xrf_scan_hwobj.connect("xrfScanFinished", self.scan_finished)

    def scan_finished(self, mcaData, mcaCalib, mcaConfig):
        self.mca_spectrum_widget.setData(mcaData, mcaCalib, mcaConfig)
Exemplo n.º 45
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)
class CreateXRFSpectrumWidget(CreateTaskBase):
    def __init__(self, parent = None, name = None, fl = 0):
        CreateTaskBase.__init__(self, parent, name, 
            QtCore.Qt.WindowFlags(fl), 'XRF spectrum')
 
        if name is not None:
            self.setObjectName(name)

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

        # Internal variables --------------------------------------------------
        self.count_time = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._data_path_widget = DataPathWidget(self, 
             data_model = self._path_template, layout = 'vertical')

        _parameters_gbox = QtGui.QGroupBox('Parameters', self)
        _count_time_label = QtGui.QLabel("Count time (sec.):", _parameters_gbox)
        self.count_time_ledit = QtGui.QLineEdit("1", _parameters_gbox)
        #self.count_time_ledit.setMaximumWidth(75)
        self.adjust_transmission_cbox = QtGui.QCheckBox(\
             "Adjust transmission", _parameters_gbox)
        self.adjust_transmission_cbox.setChecked(True)
        

        # Layout --------------------------------------------------------------
        _parameters_gbox_hlayout = QtGui.QHBoxLayout(_parameters_gbox)
        _parameters_gbox_hlayout.addWidget(_count_time_label)
        _parameters_gbox_hlayout.addWidget(self.count_time_ledit) 
        _parameters_gbox_hlayout.addWidget(self.adjust_transmission_cbox)
        _parameters_gbox_hlayout.addStretch(0)
        _parameters_gbox_hlayout.setSpacing(2)
        _parameters_gbox_hlayout.setContentsMargins(0, 0, 0, 0)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(_parameters_gbox)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)

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

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.acq_parameters_changed)
        self.adjust_transmission_cbox.stateChanged.connect(\
             self.adjust_transmission_state_changed)

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

    def init_models(self):
        CreateTaskBase.init_models(self)
        self.xrf_spectrum_model = queue_model_objects.XRFSpectrum()
        self._path_template.start_num = 1
        self._path_template.num_files = 1
        self._path_template.suffix = 'raw'

    def single_item_selection(self, tree_item):
        CreateTaskBase.single_item_selection(self, tree_item)
        self.xrf_spectrum_model = tree_item.get_model()

        if isinstance(tree_item, Qt4_queue_item.XRFSpectrumQueueItem):
            if self.xrf_spectrum_model.is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)    

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

            self._data_path_widget.update_data_model(self._path_template)
        elif not(isinstance(tree_item, Qt4_queue_item.SampleQueueItem) or \
                 isinstance(tree_item, Qt4_queue_item.DataCollectionGroupQueueItem)):
            self.setDisabled(True)

    def approve_creation(self):
        base_result = CreateTaskBase.approve_creation(self)

        self.count_time = None

        try:
           self.count_time = float(str(self.count_time_ledit.text()))
        except:
           logging.getLogger("GUI").\
                error("Incorrect count time value.")

        return base_result and self.count_time


    # 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):
        data_collections = []

        if self.count_time is not None:
            if not shape:
                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
                if isinstance(shape, GraphicsItemPoint):
                    snapshot = self._graphics_manager_hwobj.get_scene_snapshot(shape)

                    cpos = copy.deepcopy(shape.get_centred_position())
                    cpos.snapshot_image = snapshot

            path_template = self._create_path_template(sample, self._path_template)
           
            xrf_spectrum = queue_model_objects.XRFSpectrum(sample, path_template, cpos)
            xrf_spectrum.set_name(path_template.get_prefix())
            xrf_spectrum.set_number(path_template.run_number)
            xrf_spectrum.count_time = self.count_time  
            xrf_spectrum.adjust_transmission = self.adjust_transmission_cbox.isChecked()
            
            data_collections.append(xrf_spectrum)
        else:
            logging.getLogger("GUI").\
                error("No count time specified.") 

        return data_collections

    def adjust_transmission_state_changed(self, state):
        self.xrf_spectrum_model.adjust_transmission = state > 0
class CreateAdvancedWidget(CreateTaskBase):
    """
    Descript. :
    """

    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, QtCore.Qt.WindowFlags(fl), "Advanced")

        if not name:
            self.setObjectName("create_advanced_widget")

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

        # Internal variables --------------------------------------------------
        self.init_models()
        self._advanced_methods = None
        self._grid_map = {}

        # Graphic elements ----------------------------------------------------
        self._advanced_methods_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__), "ui_files/Qt4_advanced_methods_layout.ui")
        )

        self._acq_widget = AcquisitionWidget(
            self,
            "acquisition_widget",
            layout="vertical",
            acq_params=self._acquisition_parameters,
            path_template=self._path_template,
        )

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

        # Layout --------------------------------------------------------------
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._advanced_methods_widget)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addStretch(0)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)

        # 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._data_path_widget.pathTemplateChangedSignal.connect(self.handle_path_conflict)

        self._acq_widget.acqParametersChangedSignal.connect(self.handle_path_conflict)
        self._acq_widget.madEnergySelectedSignal.connect(self.mad_energy_selected)

        self._advanced_methods_widget.grid_treewidget.itemSelectionChanged.connect(
            self.grid_treewidget_item_selection_changed
        )
        self._advanced_methods_widget.draw_grid_button.clicked.connect(self.draw_grid_button_clicked)
        self._advanced_methods_widget.remove_grid_button.clicked.connect(self.remove_grid_button_clicked)
        self._advanced_methods_widget.hor_spacing_ledit.textChanged.connect(self.spacing_changed)
        self._advanced_methods_widget.ver_spacing_ledit.textChanged.connect(self.spacing_changed)

        self._advanced_methods_widget.move_right_button.clicked.connect(lambda: self.move_grid("right"))
        self._advanced_methods_widget.move_left_button.clicked.connect(lambda: self.move_grid("left"))
        self._advanced_methods_widget.move_up_button.clicked.connect(lambda: self.move_grid("up"))
        self._advanced_methods_widget.move_down_button.clicked.connect(lambda: self.move_grid("down"))

        self._advanced_methods_widget.overlay_cbox.toggled.connect(self.overlay_cbox_toggled)
        self._advanced_methods_widget.overlay_alpha_progressbar.valueChanged.connect(self.overlay_alpha_changed)
        self._advanced_methods_widget.move_to_grid_button.clicked.connect(self.move_to_grid)

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False)
        self._acq_widget.use_kappa_phi(False)
        self._acq_widget.acq_widget_layout.num_images_label.setEnabled(False)
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        for col in range(self._advanced_methods_widget.grid_treewidget.columnCount()):
            self._advanced_methods_widget.grid_treewidget.resizeColumnToContents(col)

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

    def _init_models(self):
        """
        Descript. :
        """
        self._advanced = queue_model_objects.Advanced()
        self._processing_parameters = queue_model_objects.ProcessingParameters()

        if self._beamline_setup_hwobj is not None:
            has_shutter_less = self._beamline_setup_hwobj.detector_has_shutterless()
            self._acquisition_parameters.shutterless = has_shutter_less

            self._acquisition_parameters = self._beamline_setup_hwobj.get_default_acquisition_parameters(
                "default_advanced_values"
            )

            if not self._advanced_methods:
                self._advanced_methods = self._beamline_setup_hwobj.get_advanced_methods()
                if self._advanced_methods:
                    for method in self._advanced_methods:
                        self._advanced_methods_widget.method_combo.addItem(method)
                else:
                    self.setEnabled(False)
            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

            self.grid_treewidget_item_selection_changed()
        else:
            self._acquisition_parameters = queue_model_objects.AcquisitionParameters()

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

        if len(self._advanced_methods_widget.grid_treewidget.selectedItems()) == 0:
            msg = "No grid selected. Automatic grid will be used."
            logging.getLogger("user_level_log").info(msg)
        return result

    def update_processing_parameters(self, crystal):
        """
        Descript. :
        """
        return

    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._acq_widget.update_data_model(self._acquisition_parameters, self._path_template)
        elif isinstance(tree_item, Qt4_queue_item.BasketQueueItem):
            self.setDisabled(False)
        elif isinstance(tree_item, Qt4_queue_item.AdvancedQueueItem):
            advanced = tree_item.get_model()
            if tree_item.get_model().is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

            # sample_data_model = self.get_sample_item(tree_item).get_model()
            # self._acq_widget.disable_inverse_beam(True)

            self._path_template = advanced.get_path_template()
            self._data_path_widget.update_data_model(self._path_template)

            data_collection = advanced.reference_image_collection

            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)
        else:
            self.setDisabled(True)
        # if self._advanced_methods_widget.grid_treewidget.count() > 0:
        #    self._advanced_methods_widget.grid_treewidget.clearSelection()

    def _create_task(self, sample, shape):
        """
        Descript. :
        """
        data_collections = []
        selected_grids = self.get_selected_grids()

        if len(selected_grids) == 0:
            selected_grids.append(self._graphics_manager_hwobj.create_automatic_grid())

        for shape in selected_grids:
            shape.set_snapshot(self._graphics_manager_hwobj.get_snapshot(shape))

            grid_properties = shape.get_properties()

            acq = self._create_acq(sample)
            acq.acquisition_parameters.centred_position = shape.get_centred_position()
            acq.acquisition_parameters.mesh_range = [grid_properties["dx_mm"], grid_properties["dy_mm"]]
            acq.acquisition_parameters.num_lines = grid_properties["num_lines"]
            acq.acquisition_parameters.num_images = (
                grid_properties["num_lines"] * grid_properties["num_images_per_line"]
            )

            processing_parameters = deepcopy(self._processing_parameters)

            dc = queue_model_objects.DataCollection([acq], sample.crystals[0], processing_parameters)

            dc.set_name(acq.path_template.get_prefix())
            dc.set_number(acq.path_template.run_number)
            dc.set_experiment_type(EXPERIMENT_TYPE.MESH)

            exp_type = str(self._advanced_methods_widget.method_combo.currentText()).title().replace(" ", "")
            advanced = queue_model_objects.Advanced(exp_type, dc, shape, sample.crystals[0])

            data_collections.append(advanced)
            self._path_template.run_number += 1

            return data_collections

    def shape_created(self, shape, shape_type):
        if shape_type == "Grid":
            self._advanced_methods_widget.grid_treewidget.clearSelection()
            grid_properties = shape.get_properties()
            info_str_list = QtCore.QStringList()
            info_str_list.append(grid_properties["name"])
            info_str_list.append("%d" % grid_properties["beam_x"])
            info_str_list.append("%d" % grid_properties["beam_y"])
            info_str_list.append("%d" % grid_properties["num_lines"])
            info_str_list.append("%d" % grid_properties["num_images_per_line"])

            grid_treewidget_item = QtGui.QTreeWidgetItem(self._advanced_methods_widget.grid_treewidget, info_str_list)
            grid_treewidget_item.setSelected(True)
            self._grid_map[shape] = grid_treewidget_item
            self.grid_treewidget_item_selection_changed()

    def shape_deleted(self, shape, shape_type):
        if self._grid_map.get(shape):
            treewidget_item_modelindex = self._advanced_methods_widget.grid_treewidget.indexFromItem(
                self._grid_map[shape]
            )
            self._advanced_methods_widget.grid_treewidget.takeTopLevelItem(treewidget_item_modelindex.row())
            self._grid_map.pop(shape)

    def grid_treewidget_item_selection_changed(self):
        self._advanced_methods_widget.remove_grid_button.setEnabled(False)
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_properties = grid_object.get_properties()
                cell_count = grid_properties["num_lines"] * grid_properties["num_images_per_line"]
                self._acq_widget.acq_widget_layout.num_images_ledit.setText("%d" % cell_count)
                self._acq_widget.acq_widget_layout.first_image_ledit.setText("%d" % grid_properties["first_image_num"])
                centred_point = grid_object.get_centred_position()
                self._acq_widget.acq_widget_layout.osc_start_ledit.setText("%.2f" % float(centred_point.phi))
                self._acq_widget.acq_widget_layout.kappa_ledit.setText("%.2f" % float(centred_point.kappa))
                self._acq_widget.acq_widget_layout.kappa_phi_ledit.setText("%.2f" % float(centred_point.kappa_phi))
                self._advanced_methods_widget.hor_spacing_ledit.setText("%.2f" % float(grid_properties["xOffset"]))
                self._advanced_methods_widget.ver_spacing_ledit.setText("%.2f" % float(grid_properties["yOffset"]))
                grid_object.setSelected(True)
                self._advanced_methods_widget.remove_grid_button.setEnabled(True)
            else:
                grid_object.setSelected(False)
        self._advanced_methods_widget.move_to_grid_button.setEnabled(True)

    def get_selected_grids(self):
        selected_grids = []
        for grid, grid_treewidget_item in self._grid_map.iteritems():
            if grid_treewidget_item.isSelected():
                selected_grids.append(grid)
        return selected_grids

    def draw_grid_button_clicked(self):
        self._graphics_manager_hwobj.create_grid(self.get_spacing())

    def remove_grid_button_clicked(self):
        grid_to_delete = None
        for grid, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_to_delete = grid
                break
        if grid_to_delete:
            self._graphics_manager_hwobj.delete_shape(grid_to_delete)
            self._advanced_methods_widget.move_to_grid_button.setEnabled(False)

    def get_spacing(self):
        spacing = [0, 0]
        try:
            spacing[0] = float(self._advanced_methods_widget.hor_spacing_ledit.text())
        except:
            pass
        try:
            spacing[1] = float(self._advanced_methods_widget.ver_spacing_ledit.text())
        except:
            pass
        return spacing

    def spacing_changed(self, value):
        spacing = self.get_spacing()
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.set_spacing(spacing)

    def move_to_grid(self):
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                self._beamline_setup_hwobj.diffractometer_hwobj.move_to_centred_position(
                    grid_object.get_centred_position()
                )

    def overlay_cbox_toggled(self, state):
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.set_display_overlay(state)

    def overlay_alpha_changed(self, alpha_value):
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.set_fill_alpha(alpha_value)

    def move_grid(self, direction):
        for grid_object, treewidget_item in self._grid_map.iteritems():
            if treewidget_item.isSelected():
                grid_object.move_by_pix(direction)
                self._graphics_manager_hwobj.update_grid_motor_positions(grid_object)
Exemplo n.º 48
0
class EnergyScanParametersWidget(QtGui.QWidget):
    def __init__(self, parent = None, name = "energy_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.energy_scan_model = queue_model_objects.EnergyScan()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self) 
        _parameters_widget = QtGui.QWidget(_top_widget)  
        self.periodic_table_widget =  PeriodicTableWidget(_parameters_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.data_path_widget.data_path_layout.file_name_label.setText('')
        self.data_path_widget.data_path_layout.file_name_value_label.hide()
        self.snapshot_widget = SnapshotWidget(self)

        self.scan_actual_plot_widget = PymcaPlotWidget(self, True)
        self.scan_result_plot_widget = PymcaPlotWidget(self, False)
        self.chooch_plot_widget = PymcaPlotWidget(self, False)
        #self.scan_actual_plot_widget = TwoAxisPlotWidget(self, True)
        #self.chooch_plot_widget = TwoAxisPlotWidget(self, False)
 
        # Layout -------------------------------------------------------------
        _parameters_widget_layout = QtGui.QVBoxLayout()
        _parameters_widget_layout.addWidget(self.periodic_table_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _parameters_widget_layout.setContentsMargins(0, 0, 0, 0)
        _parameters_widget.setLayout(_parameters_widget_layout)

        _top_widget_hlayout = QtGui.QHBoxLayout(self)
        _top_widget_hlayout.addWidget(_parameters_widget)
        _top_widget_hlayout.addWidget(self.snapshot_widget)
        _top_widget_hlayout.addStretch(0)
        _top_widget_hlayout.setSpacing(2)
        _top_widget_hlayout.setContentsMargins(0, 0, 0, 0)
        _top_widget.setLayout(_top_widget_hlayout) 

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.scan_actual_plot_widget)
        _main_vlayout.addWidget(self.scan_result_plot_widget)
        _main_vlayout.addWidget(self.chooch_plot_widget)
        _main_vlayout.setSpacing(5)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        #_main_vlayout.addStretch(0)

        self.setLayout(_main_vlayout)
      
        # SizePolicies --------------------------------------------------------
        self.scan_actual_plot_widget.setSizePolicy(QtGui.QSizePolicy.Fixed,
                                            QtGui.QSizePolicy.Expanding)
        self.chooch_plot_widget.setSizePolicy(QtGui.QSizePolicy.Fixed,
                                              QtGui.QSizePolicy.Expanding)

        # Qt signal/slot connections ------------------------------------------
        #qt.QObject.connect(self.periodic_table_widget, qt.PYSIGNAL('edgeSelected'), 
        #                   self.element_clicked)

        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)
        
        # Other ---------------------------------------------------------------
        self.scan_actual_plot_widget.hide()
        self.scan_result_plot_widget.hide()

    def _prefix_ledit_change(self, new_value):
        self.energy_scan_model.set_name(str(new_value))
        self._tree_view_item.setText(0, self.energy_scan_model.get_name())

    def _run_number_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.energy_scan_model.set_number(int(new_value))
            self._tree_view_item.setText(0, self.energy_scan_model.get_name())
        
    def tab_changed(self):
        if self._tree_view_item:
            self.populate_widget(self._tree_view_item)

    def populate_widget(self, item):
        self._tree_view_item = item
        self.energy_scan_model = item.get_model()
        executed = self.energy_scan_model.is_executed()
        is_running = self.energy_scan_model.is_running() 

        self.data_path_widget.setDisabled(executed or is_running)
        self.periodic_table_widget.setDisabled(executed or is_running)
        #self.scan_actual_plot_widget.setEnabled()
        #self.scan_actual_plot_widget.setEnabled(not executed)
        #self.chooch_plot_widget.setEnabled(not executed)
 
        width = self.data_path_widget.width() + \
                self.snapshot_widget.width()
        self.scan_actual_plot_widget.setFixedWidth(width)
        self.scan_result_plot_widget.setFixedWidth(width)
        self.chooch_plot_widget.setFixedWidth(width)

        self.chooch_plot_widget.clear()
        title = "Element: %s, Edge: %s" % (\
                self.energy_scan_model.element_symbol,
                self.energy_scan_model.edge)

        if executed:
            self.scan_actual_plot_widget.hide()
            self.scan_result_plot_widget.show()

            result = self.energy_scan_model.get_scan_result()
            self.scan_result_plot_widget.plot_energy_scan_curve(result.data,
                                                         title)

            self.chooch_plot_widget.plot_energy_scan_results(\
              result.pk, result.fppPeak, result.fpPeak, result.ip, 
              result.fppInfl, result.fpInfl, result.rm, 
              result.chooch_graph_x, result.chooch_graph_y1, 
              result.chooch_graph_y2, result.title)
        elif is_running:
            self.scan_actual_plot_widget.show()
            self.scan_result_plot_widget.hide()
        else:
            self.scan_actual_plot_widget.hide()
            self.scan_result_plot_widget.show()
            self.scan_result_plot_widget.clear()

        self.data_path_widget.update_data_model(self.energy_scan_model.path_template)
        self.periodic_table_widget.set_current_element_edge(\
             self.energy_scan_model.element_symbol,
             self.energy_scan_model.edge)

        image = self.energy_scan_model.centred_position.snapshot_image
        self.snapshot_widget.display_snapshot(image, width=400)

    def element_clicked(self, symbol, energy):
        self.energy_scan_model.element_symbol = symbol
        self.energy_scan_model.edge = energy

    def set_enegy_scan_hwobj(self, energy_scan_hwobj):
        if self.energy_scan_hwobj is None:
            self.energy_scan_hwobj = energy_scan_hwobj
            self.energy_scan_hwobj.connect("energyScanStarted", self.energy_scan_started)
            self.energy_scan_hwobj.connect("scanNewPoint", self.energy_scan_new_point) 
            self.energy_scan_hwobj.connect("choochFinished", self.chooch_finished)

    def energy_scan_started(self, scan_info):
        self.scan_actual_plot_widget.clear()
        self.scan_actual_plot_widget.show()
        self.scan_result_plot_widget.clear()
        self.scan_result_plot_widget.hide()
        self.chooch_plot_widget.clear()
        self.scan_actual_plot_widget.start_new_scan(scan_info)
        self.data_path_widget.setEnabled(False)
        self.periodic_table_widget.setEnabled(False)

    def energy_scan_new_point(self, x, y):
        self.scan_actual_plot_widget.add_new_plot_value(x, y)

    def chooch_finished(self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, \
              chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title):
        self.chooch_plot_widget.plot_energy_scan_results(pk, fppPeak, fpPeak, 
              ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, 
              chooch_graph_y2, title)
        self.scan_actual_plot_widget.plot_finished()
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, QtCore.Qt.WindowFlags(fl), "Advanced")

        if not name:
            self.setObjectName("create_advanced_widget")

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

        # Internal variables --------------------------------------------------
        self.init_models()
        self._advanced_methods = None
        self._grid_map = {}

        # Graphic elements ----------------------------------------------------
        self._advanced_methods_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__), "ui_files/Qt4_advanced_methods_layout.ui")
        )

        self._acq_widget = AcquisitionWidget(
            self,
            "acquisition_widget",
            layout="vertical",
            acq_params=self._acquisition_parameters,
            path_template=self._path_template,
        )

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

        # Layout --------------------------------------------------------------
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._advanced_methods_widget)
        _main_vlayout.addWidget(self._acq_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addStretch(0)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)

        # 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._data_path_widget.pathTemplateChangedSignal.connect(self.handle_path_conflict)

        self._acq_widget.acqParametersChangedSignal.connect(self.handle_path_conflict)
        self._acq_widget.madEnergySelectedSignal.connect(self.mad_energy_selected)

        self._advanced_methods_widget.grid_treewidget.itemSelectionChanged.connect(
            self.grid_treewidget_item_selection_changed
        )
        self._advanced_methods_widget.draw_grid_button.clicked.connect(self.draw_grid_button_clicked)
        self._advanced_methods_widget.remove_grid_button.clicked.connect(self.remove_grid_button_clicked)
        self._advanced_methods_widget.hor_spacing_ledit.textChanged.connect(self.spacing_changed)
        self._advanced_methods_widget.ver_spacing_ledit.textChanged.connect(self.spacing_changed)

        self._advanced_methods_widget.move_right_button.clicked.connect(lambda: self.move_grid("right"))
        self._advanced_methods_widget.move_left_button.clicked.connect(lambda: self.move_grid("left"))
        self._advanced_methods_widget.move_up_button.clicked.connect(lambda: self.move_grid("up"))
        self._advanced_methods_widget.move_down_button.clicked.connect(lambda: self.move_grid("down"))

        self._advanced_methods_widget.overlay_cbox.toggled.connect(self.overlay_cbox_toggled)
        self._advanced_methods_widget.overlay_alpha_progressbar.valueChanged.connect(self.overlay_alpha_changed)
        self._advanced_methods_widget.move_to_grid_button.clicked.connect(self.move_to_grid)

        # Other ---------------------------------------------------------------
        self._acq_widget.use_osc_start(False)
        self._acq_widget.use_kappa(False)
        self._acq_widget.use_kappa_phi(False)
        self._acq_widget.acq_widget_layout.num_images_label.setEnabled(False)
        self._acq_widget.acq_widget_layout.num_images_ledit.setEnabled(False)
        for col in range(self._advanced_methods_widget.grid_treewidget.columnCount()):
            self._advanced_methods_widget.grid_treewidget.resizeColumnToContents(col)
Exemplo n.º 50
0
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)
Exemplo n.º 51
0
    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 __init__(self, parent=None, name="xrf_spectrum_parameters_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.xrf_spectrum_model = queue_model_objects.XRFSpectrum()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self)
        _parameters_widget = QtGui.QWidget(_top_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.other_parameters_gbox = QtGui.QGroupBox("Other parameters",
                                                     _parameters_widget)
        self.count_time_label = QtGui.QLabel("Count time:",
                                             self.other_parameters_gbox)
        self.count_time_ledit = QtGui.QLineEdit(self.other_parameters_gbox)
        self.count_time_ledit.setFixedWidth(50)
        self.adjust_transmission_cbox = QtGui.QCheckBox("Adjust transmission", \
             self.other_parameters_gbox)
        self.adjust_transmission_cbox.hide()
        _snapshot_widget = QtGui.QWidget(self)
        self.position_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__),
                         'ui_files/Qt4_snapshot_widget_layout.ui'))
        self.mca_spectrum_widget = McaSpectrumWidget(self)

        # Layout -------------------------------------------------------------
        _other_parameters_gbox_hlayout = QtGui.QHBoxLayout(
            self.other_parameters_gbox)
        _other_parameters_gbox_hlayout.addWidget(self.count_time_label)
        _other_parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _other_parameters_gbox_hlayout.addWidget(self.adjust_transmission_cbox)
        _other_parameters_gbox_hlayout.addStretch(0)
        _other_parameters_gbox_hlayout.setSpacing(2)
        _other_parameters_gbox_hlayout.setContentsMargins(3, 3, 3, 3)

        _parameters_widget_layout = QtGui.QVBoxLayout(_parameters_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addWidget(self.other_parameters_gbox)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _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(0)

        _top_widget_layout = QtGui.QHBoxLayout(_top_widget)
        _top_widget_layout.addWidget(_parameters_widget)
        _top_widget_layout.addWidget(_snapshot_widget)
        _top_widget_layout.setSpacing(2)
        _top_widget_layout.addStretch(0)
        _top_widget_layout.setContentsMargins(0, 0, 0, 0)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.mca_spectrum_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

        # SizePolicies -------------------------------------------------------
        self.position_widget.setFixedSize(457, 350)
        self.mca_spectrum_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                               QtGui.QSizePolicy.Expanding)
        _top_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Fixed)

        # 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.count_time_ledit.textChanged.connect(
            self._count_time_ledit_change)
Exemplo n.º 53
0
class XRFSpectrumParametersWidget(QtGui.QWidget):
    def __init__(self, parent = None, name = "xrf_spectrum_parameters_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

        # Internal variables --------------------------------------------------
        self.xrf_spectrum_model = queue_model_objects.XRFSpectrum()
        self._tree_view_item = None

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self)
        _parameters_widget = QtGui.QWidget(_top_widget)
        self.data_path_widget = DataPathWidget(_parameters_widget)
        self.other_parameters_gbox = QtGui.QGroupBox("Other parameters", _parameters_widget) 
        self.count_time_label = QtGui.QLabel("Count time:", 
                                             self.other_parameters_gbox)
        self.count_time_ledit = QtGui.QLineEdit(self.other_parameters_gbox)
        self.count_time_ledit.setFixedWidth(50)
        self.adjust_transmission_cbox = QtGui.QCheckBox("Adjust transmission", \
             self.other_parameters_gbox)
        self.adjust_transmission_cbox.hide()
        self.mca_spectrum_widget = McaSpectrumWidget(self)
        self.snapshot_widget = SnapshotWidget(self)
 
        # Layout -------------------------------------------------------------
        _other_parameters_gbox_hlayout = QtGui.QHBoxLayout(self.other_parameters_gbox)
        _other_parameters_gbox_hlayout.addWidget(self.count_time_label)  
        _other_parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _other_parameters_gbox_hlayout.addWidget(self.adjust_transmission_cbox)
        _other_parameters_gbox_hlayout.addStretch(0)
        _other_parameters_gbox_hlayout.setSpacing(2)
        _other_parameters_gbox_hlayout.setContentsMargins(0, 0, 0, 0)

        _parameters_widget_layout = QtGui.QVBoxLayout(_parameters_widget)
        _parameters_widget_layout.addWidget(self.data_path_widget)
        _parameters_widget_layout.addWidget(self.other_parameters_gbox)
        _parameters_widget_layout.addStretch(0)
        _parameters_widget_layout.setSpacing(2)
        _parameters_widget_layout.setContentsMargins(0, 0, 0, 0)

        _top_widget_layout = QtGui.QHBoxLayout(_top_widget)
        _top_widget_layout.addWidget(_parameters_widget)
        _top_widget_layout.addWidget(self.snapshot_widget)
        _top_widget_layout.setSpacing(2)
        _top_widget_layout.addStretch(0)
        _top_widget_layout.setContentsMargins(0, 0, 0, 0)
        
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(_top_widget)
        _main_vlayout.addWidget(self.mca_spectrum_widget)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
       
        # SizePolicies -------------------------------------------------------
        self.mca_spectrum_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                               QtGui.QSizePolicy.Expanding)
        _top_widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Fixed)

        # 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.count_time_ledit.textChanged.connect(\
             self._count_time_ledit_change)
        
        # Other ---------------------------------------------------------------


    def _prefix_ledit_change(self, new_value):
        self.xrf_spectrum_model.set_name(str(new_value))
        self._tree_view_item.setText(\
             0, self.xrf_spectrum_model.get_display_name())

    def _run_number_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.xrf_spectrum_model.set_number(int(new_value))
            self._tree_view_item.setText(\
                 0, self.xrf_spectrum_model.get_display_name())

    def _count_time_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.xrf_spectrum_model.set_count_time(float(new_value))
        
    def tab_changed(self):
        if self._tree_view_item:
            self.populate_widget(self._tree_view_item)

    def populate_widget(self, item):
        self._tree_view_item = item
        self.xrf_spectrum_model = item.get_model()
        executed = self.xrf_spectrum_model.is_executed()

        self.data_path_widget.setEnabled(not executed)
        self.other_parameters_gbox.setEnabled(not executed)    
        #self.mca_spectrum_widget.setEnabled(executed)        
 
        if executed:
            result = self.xrf_spectrum_model.get_spectrum_result()
            self.mca_spectrum_widget.set_data(result.mca_data, 
                 result.mca_calib, result.mca_config) 
        else:
            self.mca_spectrum_widget.clear()
        
        self.data_path_widget.update_data_model(\
             self.xrf_spectrum_model.path_template)  
        self.count_time_ledit.setText(\
             str(self.xrf_spectrum_model.count_time)) 

        image = self.xrf_spectrum_model.centred_position.snapshot_image
        self.snapshot_widget.display_snapshot(image, width=400)

    def set_xrf_spectrum_hwobj(self, xrf_spectrum_hwobj):
        if self.xrf_spectrum_hwobj is None:
            self.xrf_spectrum_hwobj = xrf_spectrum_hwobj
            self.xrf_spectrum_hwobj.connect("xrfSpectrumFinished",
                                            self.spectrum_finished)

    def spectrum_finished(self, mca_data, mca_calib, mca_config):
        self.mca_spectrum_widget.set_data(mca_data, mca_calib, mca_config)
Exemplo n.º 54
0
class CreateXRFSpectrumWidget(CreateTaskBase):
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, QtCore.Qt.WindowFlags(fl),
                                'XRF spectrum')

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

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

        # Internal variables --------------------------------------------------
        self.count_time = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._data_path_widget = DataPathWidget(self,
                                                data_model=self._path_template,
                                                layout='vertical')

        _parameters_gbox = QtGui.QGroupBox('Parameters', self)
        _count_time_label = QtGui.QLabel("Count time (sec.):",
                                         _parameters_gbox)
        self.count_time_ledit = QtGui.QLineEdit("1", _parameters_gbox)
        #self.count_time_ledit.setMaximumWidth(75)
        self.adjust_transmission_cbox = QtGui.QCheckBox(\
             "Adjust transmission", _parameters_gbox)
        self.adjust_transmission_cbox.setChecked(True)

        # Layout --------------------------------------------------------------
        _parameters_gbox_hlayout = QtGui.QHBoxLayout(_parameters_gbox)
        _parameters_gbox_hlayout.addWidget(_count_time_label)
        _parameters_gbox_hlayout.addWidget(self.count_time_ledit)
        _parameters_gbox_hlayout.addWidget(self.adjust_transmission_cbox)
        _parameters_gbox_hlayout.addStretch(0)
        _parameters_gbox_hlayout.setSpacing(2)
        _parameters_gbox_hlayout.setContentsMargins(0, 0, 0, 0)

        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(_parameters_gbox)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)

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

        # Qt signal/slot connections ------------------------------------------
        self._data_path_widget.pathTemplateChangedSignal.\
             connect(self.acq_parameters_changed)
        self.adjust_transmission_cbox.stateChanged.connect(\
             self.adjust_transmission_state_changed)

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

    def init_models(self):
        CreateTaskBase.init_models(self)
        self.xrf_spectrum_model = queue_model_objects.XRFSpectrum()
        self._path_template.start_num = 1
        self._path_template.num_files = 1
        self._path_template.suffix = 'raw'

    def single_item_selection(self, tree_item):
        CreateTaskBase.single_item_selection(self, tree_item)
        self.xrf_spectrum_model = tree_item.get_model()

        if isinstance(tree_item, Qt4_queue_item.XRFSpectrumQueueItem):
            if self.xrf_spectrum_model.is_executed():
                self.setDisabled(True)
            else:
                self.setDisabled(False)

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

            self._data_path_widget.update_data_model(self._path_template)
        elif not(isinstance(tree_item, Qt4_queue_item.SampleQueueItem) or \
                 isinstance(tree_item, Qt4_queue_item.DataCollectionGroupQueueItem)):
            self.setDisabled(True)

    def approve_creation(self):
        base_result = CreateTaskBase.approve_creation(self)

        self.count_time = None

        try:
            self.count_time = float(str(self.count_time_ledit.text()))
        except:
            logging.getLogger("GUI").\
                 error("Incorrect count time value.")

        return base_result and self.count_time

    # 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):
        data_collections = []

        if self.count_time is not None:
            if not shape:
                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
                if isinstance(shape, GraphicsItemPoint):
                    snapshot = self._graphics_manager_hwobj.get_scene_snapshot(
                        shape)

                    cpos = copy.deepcopy(shape.get_centred_position())
                    cpos.snapshot_image = snapshot

            path_template = self._create_path_template(sample,
                                                       self._path_template)

            xrf_spectrum = queue_model_objects.XRFSpectrum(
                sample, path_template, cpos)
            xrf_spectrum.set_name(path_template.get_prefix())
            xrf_spectrum.set_number(path_template.run_number)
            xrf_spectrum.count_time = self.count_time
            xrf_spectrum.adjust_transmission = self.adjust_transmission_cbox.isChecked(
            )

            data_collections.append(xrf_spectrum)
        else:
            logging.getLogger("GUI").\
                error("No count time specified.")

        return data_collections

    def adjust_transmission_state_changed(self, state):
        self.xrf_spectrum_model.adjust_transmission = state > 0
class CreateGphlWorkflowWidget(CreateTaskBase):
    def __init__(self, parent=None, name=None, fl=0):
        CreateTaskBase.__init__(self, parent, name, QtCore.Qt.WindowFlags(fl),
                                'GphlWorkflow')

        if not name:
            self.setObjectName("Qt4_create_gphl_workflow_widget")

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

        # Internal variables --------------------------------------------------
        self.current_prefix = None

        self.init_models()

        # Graphic elements ----------------------------------------------------
        self._workflow_type_widget = QtGui.QGroupBox('Workflow type', self)

        self._workflow_cbox = QtGui.QComboBox(self._workflow_type_widget)
        self._gphl_acq_widget = QtGui.QGroupBox('Acquisition', self)
        self._gphl_acq_param_widget = GphlAcquisitionWidget(
            self._gphl_acq_widget, "gphl_acquisition_parameter_widget")

        self._data_path_widget = DataPathWidget(self,
                                                'create_dc_path_widget',
                                                layout='vertical')
        data_path_layout = self._data_path_widget.data_path_layout
        data_path_layout.file_name_label.hide()
        data_path_layout.file_name_value_label.hide()
        data_path_layout.run_number_label.hide()
        data_path_layout.run_number_ledit.hide()

        self._processing_widget = ProcessingWidget(self)
        processing_layout = self._processing_widget.processing_widget
        processing_layout.num_residues_label.hide()
        processing_layout.num_residues_ledit.hide()
        processing_layout.run_processing_after_cbox.hide()

        # Layout --------------------------------------------------------------
        _workflow_type_vlayout = QtGui.QVBoxLayout(self._workflow_type_widget)
        _workflow_type_vlayout.addWidget(self._workflow_cbox)
        _gphl_acq_vlayout = QtGui.QVBoxLayout(self._gphl_acq_widget)
        _gphl_acq_vlayout.addWidget(self._gphl_acq_param_widget)
        _main_vlayout = QtGui.QVBoxLayout(self)
        _main_vlayout.addWidget(self._workflow_type_widget)
        _main_vlayout.addWidget(self._data_path_widget)
        _main_vlayout.addWidget(self._gphl_acq_widget)
        _main_vlayout.addWidget(self._processing_widget)
        _main_vlayout.addStretch(0)
        _main_vlayout.setSpacing(2)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

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

        # Qt signal/slot connections ------------------------------------------
        # TODO check if this is needed
        # self._data_path_widget.data_path_layout.prefix_ledit.textChanged.connect(
        #              self._prefix_ledit_change)
        # Removed in porting to master branch
        # self._data_path_widget.data_path_layout.run_number_ledit.textChanged.connect(
        #              self._run_number_ledit_change)
        self._workflow_cbox.currentIndexChanged[str].connect(
            self.workflow_selected)

        # set up popup data dialog
        self.gphl_data_dialog = GphlDataDialog(self, 'GPhL Workflow Data')
        self.gphl_data_dialog.setModal(True)
        self.gphl_data_dialog.continueClickedSignal.connect(self.data_acquired)
        # self.connect(self.gphl_data_dialog, qt.PYSIGNAL("continue_clicked"),
        #              self.data_acquired)

    def initialise_workflows(self, workflow_hwobj):
        self._workflow_hwobj = workflow_hwobj
        self._workflow_cbox.clear()
        # self._gphl_parameters_widget.set_workflow(workflow_hwobj)

        if self._workflow_hwobj is not None:
            workflow_names = list(workflow_hwobj.get_available_workflows())
            for workflow_name in workflow_names:
                self._workflow_cbox.addItem(workflow_name)
            self.workflow_selected(workflow_names[0])

            workflow_hwobj.connect('gphlParametersNeeded',
                                   self.gphl_data_dialog.open_dialog)

        # # Set hardwired and default values
        # self._gphl_acquisition_widget.set_param_value('char_energy',
        #     workflow_hwobj.getProperty('characterisation_energy')
        # )
        # # Placeholder. Must be set to match hardwired detector distance
        # self._gphl_acquisition_widget.set_param_value('detector_resolution', -1)

    def workflow_selected(self, name):
        # necessary as this comes in as a QString object
        name = str(name)
        # if reset or name != self._previous_workflow:
        xx = self._workflow_cbox
        xx.setCurrentIndex(xx.findText(name))
        # self._previous_workflow = name

        parameters = self._workflow_hwobj.get_available_workflows()[name]
        beam_energies = parameters.get('beam_energies', {})
        strategy_type = parameters.get('strategy_type')
        if strategy_type == 'transcal':
            self._processing_widget.hide()
            self._gphl_acq_widget.hide()
        else:
            # diffractcal or acquisition type strategy
            self._processing_widget.show()
            self._gphl_acq_param_widget.populate_widget(
                beam_energies=beam_energies)
            self._gphl_acq_widget.show()

        prefix = parameters.get('prefix')
        if prefix is not None:
            self.current_prefix = prefix

    def data_acquired(self):
        """Data gathered from popup, continue execution"""
        pass

    # def set_beam_energies(self, beam_energy_dict):
    #     parameter_dict = self._gphl_acquisition_widget.get_parameter_dict()
    #     for tag, energy in beam_energy_dict.items():
    #         if tag in parameter_dict:
    #             self._gphl_acquisition_widget.set_param_value(tag, energy)
    #         else:
    #             raise ValueError("GPhL: No active beam energy named %s"
    #                              % tag)

    def single_item_selection(self, tree_item):
        CreateTaskBase.single_item_selection(self, tree_item)
        wf_model = tree_item.get_model()

        if isinstance(tree_item, queue_item.SampleQueueItem):
            sample_model = tree_item.get_model()
            self._processing_parameters = sample_model.processing_parameters
        else:

            if isinstance(tree_item, queue_item.GphlWorkflowQueueItem):
                if tree_item.get_model().is_executed():
                    self.setDisabled(True)
                else:
                    self.setDisabled(False)

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

                self._data_path_widget.update_data_model(self._path_template)

            elif isinstance(tree_item, queue_item.BasketQueueItem):
                self.setDisabled(False)
            elif not isinstance(tree_item,
                                queue_item.DataCollectionGroupQueueItem):
                self.setDisabled(True)

        self._processing_widget.update_data_model(self._processing_parameters)

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

    def _init_models(self):
        self._processing_parameters = queue_model_objects.ProcessingParameters(
        )
        self._processing_parameters.num_residues = 0
        self._processing_parameters.process_data = False
        # self.workflow_selected(self._workflow_cbox.currentText())

    def continue_button_click(self, sample_items, checked_items):
        """Intercepts the datacollection continue_button click for parameter setting"""
        tree_brick = self._tree_brick
        if tree_brick:
            for item in checked_items:
                model = item.get_model()
                if isinstance(model, queue_model_objects.GphlWorkflow):
                    dialog = tree_brick.dc_tree_widget.confirm_dialog
                    ss = dialog.conf_dialog_layout.take_snapshots_combo.currentText(
                    )
                    model.set_snapshot_count(int(ss) if ss else 0)

    # Called by the owning widget (task_toolbox_widget) to create
    # a collection. When a data collection group is selected.
    def _create_task(self, sample, shape):
        tasks = []

        path_template = self._create_path_template(sample, self._path_template)
        path_template.num_files = 0

        ho = self._workflow_hwobj
        if ho.get_state() == States.OFF:
            # We will be setting up the connection now - time to connect to quit
            QtGui.QApplication.instance().aboutToQuit.connect(ho.shutdown)

            tree_brick = self._tree_brick
            if tree_brick:
                tree_brick.dc_tree_widget.confirm_dialog.continueClickedSignal\
                    .connect(self.continue_button_click)

        wf = queue_model_objects.GphlWorkflow(self._workflow_hwobj)
        wf_type = str(self._workflow_cbox.currentText())
        wf.set_type(wf_type)
        interleave_order = ho.get_available_workflows()[wf_type].get(
            'interleaveOrder', '')
        wf.set_interleave_order(interleave_order)

        if self.current_prefix:
            path_template.base_prefix = self.current_prefix
        wf.path_template = path_template
        wf.processing_parameters = self._processing_parameters
        wf.set_name(wf.path_template.get_prefix())
        wf.set_number(wf.path_template.run_number)

        expected_resolution = self._gphl_acq_param_widget.get_parameter_value(
            'expected_resolution')
        wf.set_expected_resolution(expected_resolution)

        dd = self._gphl_acq_param_widget.get_energy_dict()
        wf.set_beam_energies(dd)

        tasks.append(wf)

        return tasks