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.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):
        self.energy_scan_hwobj = energy_scan_hwobj
        if self.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()
Пример #2
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()
Пример #3
0
class Qt4_DCParametersBrick(BlissWidget):
    """
    Descript. :
    """
    def __init__(self, *args):
        """
        Descript. :
        """
        BlissWidget.__init__(self, *args)

        # Hardware objects ----------------------------------------------------
        self.beamline_setup_hwobj = None
        self.queue_model_hwobj = None
        self.session_hwobj = None

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

        # Properties ----------------------------------------------------------
        self.addProperty("queue-model", "string", "/queue-model")
        self.addProperty("beamline_setup", "string", "/beamline-setup")
        self.addProperty("useImageTracking", "boolean", True)

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

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

        # Graphic elements ----------------------------------------------------
        self.tool_box = QtGui.QToolBox(self)
        self.parameters_widget = DCParametersWidget(self, "parameters_widget")
        self.results_static_view = QtGui.QTextBrowser(self.tool_box)
        self.image_tracking_widget = ImageTrackingWidget(self.tool_box)
        self.advance_results_widget = AdvancedResultsWidget(self.tool_box)
        self.snapshot_widget = SnapshotWidget(self)

        self.tool_box.addItem(self.parameters_widget, "Parameters")
        self.tool_box.addItem(self.image_tracking_widget,
                              "Results - ADXV control")
        self.tool_box.addItem(self.results_static_view, "Results")
        self.tool_box.addItem(self.advance_results_widget,
                              "Results - Heat map")

        # Layout --------------------------------------------------------------
        _main_vlayout = QtGui.QHBoxLayout(self)
        _main_vlayout.addWidget(self.tool_box)
        _main_vlayout.addWidget(self.snapshot_widget)

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

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

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

    def populate_dc_parameter_widget(self, item):
        """
        Descript. :
        """
        self.parameters_widget._data_path_widget._base_image_dir = \
            self.session_hwobj.get_base_image_directory()
        self.parameters_widget._data_path_widget._base_process_dir = \
            self.session_hwobj.get_base_process_directory()

        data_collection = item.get_model()

        if data_collection.is_helical():
            self.advance_results_widget.show()
        else:
            self.advance_results_widget.hide()


        self.snapshot_widget.display_snapshot(data_collection.\
             acquisitions[0].acquisition_parameters.\
             centred_position.snapshot_image,
             width=800)

        if data_collection.is_collected():
            self.parameters_widget.setEnabled(False)
            self.results_static_view.reload()
            self.image_tracking_widget.set_data_collection(data_collection)
            self.image_tracking_widget.refresh()
        else:
            self.parameters_widget.setEnabled(True)
        self.parameters_widget.populate_widget(item)
        #TODO
        #self.advance_results_widget.populate_widget(item)
        self.advance_results_widget.heat_map_widget.clean_result()
        self.advance_results_widget.heat_map_widget.\
             set_associated_data_collection(data_collection)
        self.advance_results_widget.heat_map_widget._summary_gbox.hide()

    def populate_results(self, data_collection):
        """
        Descript. :
        """
        if data_collection.html_report[-4:] == 'html':
            if self.results_static_view.mimeSourceFactory().\
                   data(data_collection.html_report) == None:
                self.results_static_view.setText(\
                     html_template.html_report(data_collection))
            else:
                self.results_static_view.setSource(data_collection.html_report)
        else:
            self.results_static_view.setText(\
                 html_template.html_report(data_collection))

    def propertyChanged(self, property_name, old_value, new_value):
        """
        Descript. :
        """
        if property_name == 'beamline_setup':
            self.beamline_setup_hwobj = self.getHardwareObject(new_value)
            self.session_hwobj = self.beamline_setup_hwobj.session_hwobj
            self.parameters_widget.set_beamline_setup(
                self.beamline_setup_hwobj)
            self.advance_results_widget.set_beamline_setup(
                self.beamline_setup_hwobj)
            if hasattr(self.beamline_setup_hwobj, "image_tracking_hwobj"):
                self.image_tracking_widget.set_image_tracking_hwobj(\
                     self.beamline_setup_hwobj.image_tracking_hwobj)
        elif property_name == 'queue-model':
            self.parameters_widget.queue_model_hwobj = \
                 self.getHardwareObject(new_value)
        elif property_name == 'useImageTracking':
            if new_value:
                self.tool_box.removeItem(self.tool_box.indexOf(\
                     self.results_static_view))
                self.results_static_view.hide()
            else:
                self.tool_box.removeItem(self.tool_box.indexOf(\
                     self.image_tracking_widget))
                self.image_tracking_widget.hide()
Пример #4
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)
Пример #5
0
class Qt4_AdvancedBrick(BlissWidget):

    def __init__(self, *args):
        BlissWidget.__init__(self, *args)

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

        # Internal values -----------------------------------------------------

        # Properties ----------------------------------------------------------
        self.addProperty("beamline_setup", "string", "/beamline-setup")

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

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

        # Graphic elements ----------------------------------------------------
        self.tool_box = QToolBox(self)
        self.parameters_widget = AdvancedParametersWidget(self) 
        self.results_widget = AdvancedResultsWidget(self)
        self.snapshot_widget = SnapshotWidget(self)

        self.tool_box.addItem(self.parameters_widget, "Parameters")
        self.tool_box.addItem(self.results_widget, "Results - Heat map")

        # Layout --------------------------------------------------------------
        _main_vlayout = QHBoxLayout(self)
        _main_vlayout.addWidget(self.tool_box)
        _main_vlayout.addWidget(self.snapshot_widget)

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

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

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

    def populate_advanced_widget(self, item):
        self.parameters_widget._data_path_widget._base_image_dir = \
            self.session_hwobj.get_base_image_directory()
        self.parameters_widget._data_path_widget._base_process_dir = \
            self.session_hwobj.get_base_process_directory()

        self.parameters_widget.populate_widget(item)
        self.results_widget.populate_widget(item)

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

        self.snapshot_widget.display_snapshot(\
             data_collection.grid.get_snapshot())

        self.tool_box.setCurrentWidget(self.results_widget)

    def propertyChanged(self, property_name, old_value, new_value):
        """
        Overriding BaseComponents.BlissWidget (propertyChanged object) 
        run method.
        """
        if property_name == 'beamline_setup':
            bl_setup = self.getHardwareObject(new_value)
            self.session_hwobj = bl_setup.session_hwobj
            self.parameters_widget.set_beamline_setup(bl_setup)
            self.results_widget.set_beamline_setup(bl_setup)
Пример #6
0
class Qt4_AdvancedBrick(BlissWidget):

    def __init__(self, *args):
        BlissWidget.__init__(self, *args)

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

        # Internal values -----------------------------------------------------

        # Properties ----------------------------------------------------------
        self.addProperty("beamline_setup", "string", "/beamline-setup")

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

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

        # Graphic elements ----------------------------------------------------
        self.tool_box = QToolBox(self)
        self.parameters_widget = AdvancedParametersWidget(self) 
        self.results_widget = AdvancedResultsWidget(self)

        self.line_parameters_widget = AdvancedParametersWidget(self)
        self.line_results_widget = AdvancedResultsWidget(self)
        self.snapshot_widget = SnapshotWidget(self)

        self.tool_box.addItem(self.parameters_widget, "2D Heat map: Parameters")
        self.tool_box.addItem(self.results_widget, "2D Heat map: Results")
        self.tool_box.addItem(self.line_parameters_widget, "Line scan: Parameters")
        self.tool_box.addItem(self.line_results_widget, "Line scan: Results")

        # Layout --------------------------------------------------------------
        _main_vlayout = QHBoxLayout(self)
        _main_vlayout.addWidget(self.tool_box)
        _main_vlayout.addWidget(self.snapshot_widget)

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

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

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

    def populate_advanced_widget(self, item):
        self.parameters_widget._data_path_widget._base_image_dir = \
            self.session_hwobj.get_base_image_directory()
        self.parameters_widget._data_path_widget._base_process_dir = \
            self.session_hwobj.get_base_process_directory()

        self.line_parameters_widget._data_path_widget._base_image_dir = \
            self.session_hwobj.get_base_image_directory()
        self.line_parameters_widget._data_path_widget._base_process_dir = \
            self.session_hwobj.get_base_process_directory()

        #self.parameters_widget.populate_widget(item)
        #self.results_widget.populate_widget(item)

        if isinstance(item, Qt4_queue_item.XrayCenteringQueueItem):
            data_collection = item.get_model().reference_image_collection
            self.parameters_widget.populate_widget(item, data_collection)
            self.results_widget.populate_widget(item, data_collection)   

            self.line_parameters_widget.populate_widget(item, item.get_model().line_collection)
            self.line_results_widget.populate_widget(item, item.get_model().line_collection) 
        else:
            data_collection = item.get_model()
            self.parameters_widget.populate_widget(item, data_collection)
            self.results_widget.populate_widget(item, data_collection) 

        self.line_parameters_widget.setEnabled(isinstance(item, Qt4_queue_item.XrayCenteringQueueItem))
        self.line_results_widget.setEnabled(isinstance(item, Qt4_queue_item.XrayCenteringQueueItem))

        try:
            self.snapshot_widget.display_snapshot(\
                 data_collection.grid.get_snapshot())
        except:
            pass

        self.tool_box.setCurrentWidget(self.results_widget)

    def propertyChanged(self, property_name, old_value, new_value):
        """
        Overriding BaseComponents.BlissWidget (propertyChanged object) 
        run method.
        """
        if property_name == 'beamline_setup':
            bl_setup = self.getHardwareObject(new_value)
            self.session_hwobj = bl_setup.session_hwobj
            self.parameters_widget.set_beamline_setup(bl_setup)
            self.results_widget.set_beamline_setup(bl_setup)

            self.line_parameters_widget.set_beamline_setup(bl_setup)
            self.line_results_widget.set_beamline_setup(bl_setup)
Пример #7
0
class Qt4_DCParametersBrick(BlissWidget):
    """
    Descript. :
    """
    def __init__(self, *args):
        """
        Descript. :
        """
        BlissWidget.__init__(self, *args)

        # Hardware objects ----------------------------------------------------
        self.beamline_setup_hwobj = None
        self.queue_model_hwobj = None
        self.session_hwobj = None

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

        # Properties ----------------------------------------------------------
        self.addProperty("queue-model", "string", "/queue-model")
        self.addProperty("beamline_setup", "string", "/beamline-setup")
        self.addProperty("useImageTracking", "boolean", True)

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

        # Slots ---------------------------------------------------------------
        self.defineSlot("populate_dc_parameter_widget",({}))
       
        # Graphic elements ---------------------------------------------------- 
        self.tool_box = QtGui.QToolBox(self)
        self.parameters_widget = DCParametersWidget(self, "parameters_widget")
        self.results_static_view = QtGui.QTextBrowser(self.tool_box)
        self.image_tracking_widget = ImageTrackingWidget(self.tool_box) 
        self.advance_results_widget = AdvancedResultsWidget(self.tool_box)
        self.snapshot_widget = SnapshotWidget(self)

        self.tool_box.addItem(self.parameters_widget, "Parameters")
        self.tool_box.addItem(self.image_tracking_widget, "Results - ADXV control")
        self.tool_box.addItem(self.results_static_view, "Results")
        self.tool_box.addItem(self.advance_results_widget, "Results - Heat map")

        # Layout -------------------------------------------------------------- 
        _main_vlayout = QtGui.QHBoxLayout(self)
        _main_vlayout.addWidget(self.tool_box)
        _main_vlayout.addWidget(self.snapshot_widget)

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

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

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

    def populate_dc_parameter_widget(self, item):
        """
        Descript. :
        """
        self.parameters_widget._data_path_widget._base_image_dir = \
            self.session_hwobj.get_base_image_directory()
        self.parameters_widget._data_path_widget._base_process_dir = \
            self.session_hwobj.get_base_process_directory()

        data_collection = item.get_model()

        if data_collection.is_helical():
            self.advance_results_widget.show()
        else:
            self.advance_results_widget.hide()

              
        self.snapshot_widget.display_snapshot(data_collection.\
             acquisitions[0].acquisition_parameters.\
             centred_position.snapshot_image,
             width=800) 
        
        if data_collection.is_collected():
            self.parameters_widget.setEnabled(False)
            self.results_static_view.reload()
            self.image_tracking_widget.set_data_collection(data_collection)
            self.image_tracking_widget.refresh()
        else:
            self.parameters_widget.setEnabled(True)
        self.parameters_widget.populate_widget(item)
        #TODO 
        #self.advance_results_widget.populate_widget(item)
        self.advance_results_widget.heat_map_widget.clean_result()
        self.advance_results_widget.heat_map_widget.\
             set_associated_data_collection(data_collection) 
        self.advance_results_widget.heat_map_widget._summary_gbox.hide()

    def populate_results(self, data_collection):
        """
        Descript. :
        """
        if data_collection.html_report[-4:] == 'html':
            if self.results_static_view.mimeSourceFactory().\
                   data(data_collection.html_report) == None:
                self.results_static_view.setText(\
                     html_template.html_report(data_collection))
            else:
                self.results_static_view.setSource(data_collection.html_report)
        else:
            self.results_static_view.setText(\
                 html_template.html_report(data_collection))
        
    def propertyChanged(self, property_name, old_value, new_value):
        """
        Descript. :
        """
        if property_name == 'beamline_setup':            
            self.beamline_setup_hwobj = self.getHardwareObject(new_value)
            self.session_hwobj = self.beamline_setup_hwobj.session_hwobj
            self.parameters_widget.set_beamline_setup(self.beamline_setup_hwobj)
            self.advance_results_widget.set_beamline_setup(self.beamline_setup_hwobj)
            if hasattr(self.beamline_setup_hwobj, "image_tracking_hwobj"):
                self.image_tracking_widget.set_image_tracking_hwobj(\
                     self.beamline_setup_hwobj.image_tracking_hwobj)
        elif property_name == 'queue-model':            
            self.parameters_widget.queue_model_hwobj = \
                 self.getHardwareObject(new_value)
        elif property_name == 'useImageTracking':
            if new_value:
                self.tool_box.removeItem(self.tool_box.indexOf(\
                     self.results_static_view))
                self.results_static_view.hide()
            else:
                self.tool_box.removeItem(self.tool_box.indexOf(\
                     self.image_tracking_widget))
                self.image_tracking_widget.hide()
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)