class EnergyScanParametersWidget(qt.QWidget):
    def __init__(self, parent = None, name = "energy_scan_tab_widget"):
        qt.QWidget.__init__(self, parent, name)

        # Data Attributes
        self.energy_scan = queue_model_objects.EnergyScan()
        self._tree_view_item = None

        # Layout
        h_layout = qt.QHBoxLayout(self, 0, 0, "main_v_layout")
        col_one_vlayout = qt.QVBoxLayout(h_layout, 0, "row_one")

        periodic_table_gbox = qt.QHGroupBox("Available Elements", self)
        self.periodic_table =  PeriodicTableBrick(periodic_table_gbox)
        #QPeriodicTable.QPeriodicTable(periodic_table_gbox)
        self.periodic_table.setFixedHeight(341)
        self.periodic_table.setFixedWidth(650)
        #font = periodic_table.font()
        #font.setPointSize(8)
        #periodic_table.setFont(font)
        #scan_plot_gbox = qt.QHGroupBox("Scan plot", self)
        #spec_scan_plot_brick = SpecScanPlotBrick(scan_plot_gbox)
        self.data_path_widget = DataPathWidget(self)
        self.data_path_widget.data_path_widget_layout.child('file_name_label').setText('')
        self.data_path_widget.data_path_widget_layout.child('file_name_value_label').hide()

        col_one_vlayout.add(periodic_table_gbox)
        col_one_vlayout.add(self.data_path_widget)
        col_one_vlayout.addStretch(10)

        qt.QObject.connect(self.periodic_table, qt.PYSIGNAL('edgeSelected'), 
                           self.element_clicked)

        qt.QObject.connect(self.data_path_widget.data_path_widget_layout.child('prefix_ledit'), 
                           qt.SIGNAL("textChanged(const QString &)"), 
                           self._prefix_ledit_change)


        qt.QObject.connect(self.data_path_widget.data_path_widget_layout.child('run_number_ledit'), 
                           qt.SIGNAL("textChanged(const QString &)"), 
                           self._run_number_ledit_change)
        
        qt.QObject.connect(qt.qApp, qt.PYSIGNAL('tab_changed'),
                           self.tab_changed)

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

    def _run_number_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.energy_scan.set_number(int(new_value))
            self._tree_view_item.setText(0, self.energy_scan.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 = item.get_model()
        executed = self.energy_scan.is_executed()

        self.data_path_widget.setEnabled(not executed)
        self.periodic_table.setEnabled(not executed)
        self.scan_plot.setEnabled(not executed)
        self.results_plot.setEnabled(not executed)

        if self.energy_scan.is_executed():
            self.data_path_widget.setEnabled(False)
            self.periodic_table.setEnabled(False)
        else:
            self.data_path_widget.setEnabled(True)
            self.periodic_table.setEnabled(True)
            self.data_path_widget.update_data_model(self.energy_scan.path_template)
            self.periodic_table.setTableElement(self.energy_scan.element_symbol, \
                                                    self.energy_scan.edge)

    def element_clicked(self, symbol, energy):
        self.energy_scan.element_symbol = symbol
        self.energy_scan.edge = energy
Пример #2
0
class XRFSpectrumParametersWidget(qt.QWidget):
    def __init__(self, parent=None, name="xrf_spectrum_tab_widget"):
        qt.QWidget.__init__(self, parent, name)

        # Data Attributes
        self.xrf_spectrum_hwobj = None
        self.xrf_spectrum = queue_model_objects.XRFSpectrum()
        self._tree_view_item = None

        self.data_path_widget = DataPathWidget(self)
        self.other_parameters_gbox = qt.QHGroupBox("Other parameters", self)
        self.count_time_label = qt.QLabel("Count time:", self.other_parameters_gbox)
        self.count_time_ledit = qt.QLineEdit(
            self.other_parameters_gbox, "count_time_ledit"
        )
        self.count_time_ledit.setFixedWidth(50)

        spacer = qt.QWidget(self.other_parameters_gbox)
        spacer.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed)

        widget_ui = os.path.join(
            os.path.dirname(__file__), "ui_files/snapshot_widget_layout.ui"
        )
        widget = qtui.QWidgetFactory.create(widget_ui)
        widget.reparent(self, qt.QPoint(0, 0))
        self.position_widget = widget
        self.position_widget.setFixedSize(457, 350)
        # self.position_widget.setSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Fixed)

        self.mca_spectrum = McaSpectrumBrick(self)
        self.mca_spectrum.setSizePolicy(
            qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding
        )
        self.mca_spectrum.setMinimumHeight(700)

        v_layout = qt.QVBoxLayout(self)
        rone_hlayout = qt.QHBoxLayout(v_layout)
        rone_vlayout = qt.QVBoxLayout(rone_hlayout)
        rone_sv_layout = qt.QVBoxLayout(rone_hlayout)

        rone_vlayout.addWidget(self.data_path_widget)
        rone_vlayout.addWidget(self.other_parameters_gbox)
        rone_vlayout.addStretch()

        rone_sv_layout.addWidget(self.position_widget)
        rone_sv_layout.addStretch()

        v_layout.addWidget(self.mca_spectrum)
        v_layout.addStretch()

        qt.QObject.connect(
            self.data_path_widget.data_path_widget_layout.child("prefix_ledit"),
            qt.SIGNAL("textChanged(const QString &)"),
            self._prefix_ledit_change,
        )

        qt.QObject.connect(
            self.data_path_widget.data_path_widget_layout.child("run_number_ledit"),
            qt.SIGNAL("textChanged(const QString &)"),
            self._run_number_ledit_change,
        )

        qt.QObject.connect(
            self.count_time_ledit,
            qt.SIGNAL("textChanged(const QString &)"),
            self._count_time_ledit_change,
        )

        qt.QObject.connect(qt.qApp, qt.PYSIGNAL("tab_changed"), self.tab_changed)

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

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

    def _count_time_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.xrf_spectrum.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 = item.get_model()
        self.data_path_widget.update_data_model(self.xrf_spectrum.path_template)
        self.count_time_ledit.setText(str(self.xrf_spectrum.count_time))

        executed = self.xrf_spectrum.is_executed()

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

        image = self.xrf_spectrum.centred_position.snapshot_image
        if image:
            try:
                w = image.width()
                h = image.height()
                ratio = w / float(h)
                h2 = (
                    self.data_path_widget.height() + self.other_parameters_gbox.height()
                )
                w2 = h2 * ratio
                image = image.scale(w2, h2)
                self.position_widget.child("svideo").setPixmap(qt.QPixmap(image))
            except BaseException:
                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, mcaData, mcaCalib, mcaConfig):
        self.mca_spectrum.setData(mcaData, mcaCalib, mcaConfig)
Пример #3
0
class DCParametersWidget(qt.QWidget):
    def __init__(self, parent=None, name="parameter_widget"):
        qt.QWidget.__init__(self, parent, name)
        self._data_collection = None
        self.add_dc_cb = None
        self._tree_view_item = None
        self.queue_model = None
        self._beamline_setup_hwobj = None

        self.caution_pixmap = Icons.load("Caution2.png")
        self.path_widget = DataPathWidget(self, "dc_params_path_widget")
        self.acq_gbox = qt.QVGroupBox("Acquisition", self)
        self.acq_gbox.setInsideMargin(2)
        self.acq_widget = AcquisitionWidget(self.acq_gbox, layout="horizontal")

        self.acq_widget.setFixedHeight(170)

        widget_ui = os.path.join(
            os.path.dirname(__file__), "ui_files/snapshot_widget_layout.ui"
        )
        widget = qtui.QWidgetFactory.create(widget_ui)
        widget.reparent(self, qt.QPoint(0, 0))
        self.position_widget = widget
        self._processing_gbox = qt.QVGroupBox("Processing", self, "processing_gbox")

        self.processing_widget = ProcessingWidget(self._processing_gbox)

        v_layout = qt.QVBoxLayout(self, 11, 10, "main_layout")
        rone_hlayout = qt.QHBoxLayout(v_layout, 10, "rone")
        rone_vlayout = qt.QVBoxLayout(rone_hlayout)
        rone_sv_layout = qt.QVBoxLayout(rone_hlayout)

        rone_vlayout.addWidget(self.path_widget)
        rone_vlayout.addWidget(self.acq_gbox)
        rtwo_hlayout = qt.QHBoxLayout(rone_vlayout, 10, "rtwo")
        rone_vlayout.addStretch(10)

        rone_sv_layout.addWidget(self.position_widget)
        rone_sv_layout.addStretch(10)
        rone_hlayout.addStretch()

        rtwo_hlayout.addWidget(self._processing_gbox)
        rtwo_hlayout.addStretch(10)
        v_layout.addStretch()

        self.connect(
            self.acq_widget,
            qt.PYSIGNAL("mad_energy_selected"),
            self.mad_energy_selected,
        )

        self.connect(
            self.path_widget.data_path_widget_layout.child("prefix_ledit"),
            qt.SIGNAL("textChanged(const QString &)"),
            self._prefix_ledit_change,
        )

        self.connect(
            self.path_widget.data_path_widget_layout.child("run_number_ledit"),
            qt.SIGNAL("textChanged(const QString &)"),
            self._run_number_ledit_change,
        )

        self.connect(
            self.acq_widget,
            qt.PYSIGNAL("path_template_changed"),
            self.handle_path_conflict,
        )

        self.connect(
            self.path_widget,
            qt.PYSIGNAL("path_template_changed"),
            self.handle_path_conflict,
        )

        qt.QObject.connect(qt.qApp, qt.PYSIGNAL("tab_changed"), self.tab_changed)

    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):
        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_gbox.setEnabled(state)
        self.path_widget.setEnabled(state)
        self._processing_gbox.setEnabled(state)

    def populate_parameter_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

            image = image.scale(427, 320)
            self.position_widget.child("svideo").setPixmap(qt.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)
Пример #4
0
class DCParametersWidget(qt.QWidget):
    def __init__(self, parent=None, name="parameter_widget"):
        qt.QWidget.__init__(self, parent, name)
        self._data_collection = None
        self.add_dc_cb = None
        self._tree_view_item = None
        self.queue_model = None
        self._beamline_setup_hwobj = None

        self.caution_pixmap = Icons.load("Caution2.png")
        self.path_widget = DataPathWidget(self, 'dc_params_path_widget')
        self.acq_gbox = qt.QVGroupBox("Acquisition", self)
        self.acq_gbox.setInsideMargin(2)
        self.acq_widget = AcquisitionWidget(self.acq_gbox, layout='horizontal')

        self.acq_widget.setFixedHeight(170)

        widget_ui = os.path.join(os.path.dirname(__file__),
                                 'ui_files/snapshot_widget_layout.ui')
        widget = qtui.QWidgetFactory.create(widget_ui)
        widget.reparent(self, qt.QPoint(0, 0))
        self.position_widget = widget
        self._processing_gbox = qt.QVGroupBox('Processing', self,
                                              'processing_gbox')

        self.processing_widget = ProcessingWidget(self._processing_gbox)

        v_layout = qt.QVBoxLayout(self, 11, 10, "main_layout")
        rone_hlayout = qt.QHBoxLayout(v_layout, 10, "rone")
        rone_vlayout = qt.QVBoxLayout(rone_hlayout)
        rone_sv_layout = qt.QVBoxLayout(rone_hlayout)

        rone_vlayout.addWidget(self.path_widget)
        rone_vlayout.addWidget(self.acq_gbox)
        rtwo_hlayout = qt.QHBoxLayout(rone_vlayout, 10, "rtwo")
        rone_vlayout.addStretch(10)

        rone_sv_layout.addWidget(self.position_widget)
        rone_sv_layout.addStretch(10)
        rone_hlayout.addStretch()

        rtwo_hlayout.addWidget(self._processing_gbox)
        rtwo_hlayout.addStretch(10)
        v_layout.addStretch()

        self.connect(self.acq_widget, qt.PYSIGNAL('mad_energy_selected'),
                     self.mad_energy_selected)

        self.connect(
            self.path_widget.data_path_widget_layout.child('prefix_ledit'),
            qt.SIGNAL("textChanged(const QString &)"),
            self._prefix_ledit_change)

        self.connect(
            self.path_widget.data_path_widget_layout.child('run_number_ledit'),
            qt.SIGNAL("textChanged(const QString &)"),
            self._run_number_ledit_change)

        self.connect(self.acq_widget, qt.PYSIGNAL("path_template_changed"),
                     self.handle_path_conflict)

        self.connect(self.path_widget, qt.PYSIGNAL("path_template_changed"),
                     self.handle_path_conflict)

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

    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):
        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_gbox.setEnabled(state)
        self.path_widget.setEnabled(state)
        self._processing_gbox.setEnabled(state)

    def populate_parameter_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

            image = image.scale(427, 320)
            self.position_widget.child("svideo").setPixmap(qt.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 EnergyScanParametersWidget(qt.QWidget):
    def __init__(self, parent=None, name="energy_scan_tab_widget"):
        qt.QWidget.__init__(self, parent, name)

        # Data Attributes
        self.energy_scan = queue_model_objects.EnergyScan()
        self._tree_view_item = None

        # Layout
        h_layout = qt.QHBoxLayout(self, 0, 0, "main_v_layout")
        col_one_vlayout = qt.QVBoxLayout(h_layout, 0, "row_one")

        periodic_table_gbox = qt.QHGroupBox("Available Elements", self)
        self.periodic_table = PeriodicTableBrick(periodic_table_gbox)
        #QPeriodicTable.QPeriodicTable(periodic_table_gbox)
        self.periodic_table.setFixedHeight(341)
        self.periodic_table.setFixedWidth(650)
        #font = periodic_table.font()
        #font.setPointSize(8)
        #periodic_table.setFont(font)
        #scan_plot_gbox = qt.QHGroupBox("Scan plot", self)
        #spec_scan_plot_brick = SpecScanPlotBrick(scan_plot_gbox)
        self.data_path_widget = DataPathWidget(self)
        self.data_path_widget.data_path_widget_layout.child(
            'file_name_label').setText('')
        self.data_path_widget.data_path_widget_layout.child(
            'file_name_value_label').hide()

        col_one_vlayout.add(periodic_table_gbox)
        col_one_vlayout.add(self.data_path_widget)
        col_one_vlayout.addStretch(10)

        qt.QObject.connect(self.periodic_table, qt.PYSIGNAL('edgeSelected'),
                           self.element_clicked)

        qt.QObject.connect(
            self.data_path_widget.data_path_widget_layout.child(
                'prefix_ledit'), qt.SIGNAL("textChanged(const QString &)"),
            self._prefix_ledit_change)

        qt.QObject.connect(
            self.data_path_widget.data_path_widget_layout.child(
                'run_number_ledit'), qt.SIGNAL("textChanged(const QString &)"),
            self._run_number_ledit_change)

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

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

    def _run_number_ledit_change(self, new_value):
        if str(new_value).isdigit():
            self.energy_scan.set_number(int(new_value))
            self._tree_view_item.setText(0, self.energy_scan.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 = item.get_model()

        if self.energy_scan.is_executed():
            self.data_path_widget.setEnabled(False)
            self.periodic_table.setEnabled(False)
        else:
            self.data_path_widget.setEnabled(True)
            self.periodic_table.setEnabled(True)
            self.data_path_widget.update_data_model(
                self.energy_scan.path_template)
            self.periodic_table.periodicTable.\
                tableElementChanged(self.energy_scan.element_symbol)

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