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 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)
        # LNLS
        # self.data_path_widget.data_path_layout.file_name_label.setText('')
        # self.data_path_widget.data_path_layout.file_name_label.hide()
        # self.data_path_widget.data_path_layout.file_name_value_label.hide()

        # ---------------------------------------------------------------------
        # LNLS
        self.data_path_widget.setFixedHeight(140)
        # ---------------------------------------------------------------------

        _snapshot_widget = QtGui.QWidget(self)

        # Snapshot of current position
        self.position_widget = uic.loadUi(
            os.path.join(os.path.dirname(__file__),
                         'ui_files/Qt4_snapshot_widget_layout.ui'))
        # LNLS
        self.position_widget.setFixedSize(450, 340)

        # Graphics
        self.scan_plot_widget = TwoAxisPlotWidget(self, True)
        self.result_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)

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

        _top_widget_hlayout = QtGui.QHBoxLayout(self)
        _top_widget_hlayout.addWidget(_parameters_widget)
        _top_widget_hlayout.addWidget(_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_plot_widget)
        _main_vlayout.addWidget(self.result_plot_widget)
        _main_vlayout.setSpacing(5)
        _main_vlayout.setContentsMargins(2, 2, 2, 2)
        _main_vlayout.addStretch(0)

        self.setLayout(_main_vlayout)

        # SizePolicies --------------------------------------------------------
        self.scan_plot_widget.setSizePolicy(QtGui.QSizePolicy.Fixed,
                                            QtGui.QSizePolicy.Expanding)
        self.result_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 ---------------------------------------------------------------

    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()
        # LNLS
        #self.data_path_widget.setEnabled(not executed)
        self.data_path_widget.setEnabled(False)
        self.periodic_table_widget.setEnabled(not executed)
        self.scan_plot_widget.setEnabled(not executed)
        self.result_plot_widget.setEnabled(not executed)

        width = self.data_path_widget.width() + \
                self.position_widget.width()
        self.scan_plot_widget.setFixedWidth(width)
        self.result_plot_widget.setFixedWidth(width)

        # ---------------------------------------------------------------------
        # LNLS
        height = 185
        self.scan_plot_widget.setFixedHeight(height)
        self.result_plot_widget.setFixedHeight(height)
        # ---------------------------------------------------------------------

        if executed:
            result = self.energy_scan_model.get_scan_result()
            self.scan_plot_widget.plot_energy_scan_curve(result.data)
            self.result_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)
        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(450, 360, 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("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):
        self.scan_plot_widget.start_new_scan()
        self.data_path_widget.setEnabled(False)
        self.periodic_table_widget.setEnabled(False)
        # LNLS
        self.result_plot_widget.clear()

    def energy_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_energy_scan_results(
            pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x,
            chooch_graph_y1, chooch_graph_y2, title)
        self.scan_plot_widget.plot_finished()
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()
        _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.position_widget.setFixedSize(450, 340)        

        self.scan_plot_widget = TwoAxisPlotWidget(self, True)
        self.result_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)

        _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_hlayout = QtGui.QHBoxLayout(self)
        _top_widget_hlayout.addWidget(_parameters_widget)
        _top_widget_hlayout.addWidget(_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_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 --------------------------------------------------------
        self.scan_plot_widget.setSizePolicy(QtGui.QSizePolicy.Fixed,
                                            QtGui.QSizePolicy.Expanding)
        self.result_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 ---------------------------------------------------------------

    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)
 
        width = self.data_path_widget.width() + \
                self.position_widget.width()
        self.scan_plot_widget.setFixedWidth(width)
        self.result_plot_widget.setFixedWidth(width)

        if executed:
            result = self.energy_scan_model.get_scan_result()
            self.scan_plot_widget.plot_energy_scan_curve(result.data)
            self.result_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)
        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("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):
        self.scan_plot_widget.start_new_scan()
        self.data_path_widget.setEnabled(False)
        self.periodic_table_widget.setEnabled(False)

    def energy_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_energy_scan_results(pk, fppPeak, fpPeak, 
              ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, 
              chooch_graph_y2, title)
        self.scan_plot_widget.plot_finished()