Ejemplo n.º 1
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()
Ejemplo n.º 2
0
class CustomInfoWidget(QWidget):
    """Custom information widget"""

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

        self.value_plot = None

        self.title_label = QLabel(self)
        self.value_widget = QWidget(self)
        self.value_label = QLabel(self.value_widget)
        self.value_label.setAlignment(Qt.AlignCenter)
        self.history_button = QPushButton(\
             Qt4_Icons.load_icon("LineGraph"), "", self.value_widget)
        self.history_button.hide()
        self.history_button.setFixedWidth(22)
        self.history_button.setFixedHeight(22)

        _value_widget_hlayout = QHBoxLayout(self.value_widget)
        _value_widget_hlayout.addWidget(self.value_label)
        _value_widget_hlayout.addWidget(self.history_button) 
        _value_widget_hlayout.setSpacing(2)
        _value_widget_hlayout.setContentsMargins(0, 0, 0, 0)

        self.main_vlayout = QVBoxLayout(self)
        self.main_vlayout.addWidget(self.title_label)
        self.main_vlayout.addWidget(self.value_widget)
        self.main_vlayout.setSpacing(1)
        self.main_vlayout.setContentsMargins(0, 0, 0, 0)

        self.history_button.clicked.connect(self.open_history_view)

    def init_info(self, info_dict, max_plot_points=None):
        self.title_label.setText(info_dict.get("title", "???"))
        self.history_button.setVisible(info_dict.get("history", False))
        font = self.value_label.font()
        if info_dict.get("font"): 
            font.setPointSize(info_dict.get("font"))
        if info_dict.get("bold"): 
            font.setBold(True)
        self.value_label.setFont(font)

        if info_dict.get("align") == "left":
            self.value_label.setAlignment(Qt.AlignLeft)
        elif info_dict.get("align") == "right":
            self.value_label.setAlignment(Qt.AlignRight)
        elif info_dict.get("align") == "center":
            self.value_label.setAlignment(Qt.AlignHCenter)
        elif info_dict.get("align") == "justify":
            self.value_label.setAlignment(Qt.AlignJustify)

        if info_dict.get("history"):
            self.history_button.show() 
            self.value_plot = TwoAxisPlotWidget(self, realtime_plot=True)
            self.value_plot.hide()
            self.main_vlayout.addWidget(self.value_plot)
            self.value_plot.set_tight_layout()
            self.value_plot.clear()
            self.value_plot.set_max_plot_point(max_plot_points)
            #self.value_plot.set_y_axis_limits([0, None])
        self.update_info(info_dict)

    def update_info(self, info_dict):
        if info_dict.get("value_str"): 
            self.value_label.setText(info_dict.get("value_str"))
        else:
            self.value_label.setText(str(info_dict.get("value"))) 

        if info_dict.get('in_range') is None:
            Qt4_widget_colors.set_widget_color(self.value_label,
                                               Qt4_widget_colors.GRAY)
        elif info_dict.get('in_range') == True:
            Qt4_widget_colors.set_widget_color(self.value_label,
                                               Qt4_widget_colors.LIGHT_BLUE)
        else:
            Qt4_widget_colors.set_widget_color(self.value_label,
                                               Qt4_widget_colors.LIGHT_RED)
        value = info_dict.get('value')
        if type(value) in (int, float) and self.value_plot:
            self.value_plot.add_new_plot_value(value)

    def open_history_view(self):
        self.value_plot.setVisible(not self.value_plot.isVisible())
class EnergyScanParametersWidget(QtGui.QWidget):
    def __init__(self, parent=None, name="energy_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

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

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

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

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

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

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

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

        self.setLayout(_main_vlayout)

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

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

        self.data_path_widget.data_path_layout.prefix_ledit.textChanged.connect(self._prefix_ledit_change)

        self.data_path_widget.data_path_layout.run_number_ledit.textChanged.connect(self._run_number_ledit_change)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    def chooch_finished(
        self, pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title
    ):
        self.result_plot_widget.plot_results(
            pk, fppPeak, fpPeak, ip, fppInfl, fpInfl, rm, chooch_graph_x, chooch_graph_y1, chooch_graph_y2, title
        )
        self.scan_plot_widget.plot_finished()
Ejemplo n.º 4
0
class CustomInfoWidget(QtGui.QWidget):
    def __init__(self, *args):
        """
        Descript. :
        """
        QtGui.QWidget.__init__(self, *args)

        self.value_plot = None

        self.title_label = QtGui.QLabel(self)
        self.value_widget = QtGui.QWidget(self)
        self.value_label = QtGui.QLabel(self.value_widget)
        self.value_label.setAlignment(QtCore.Qt.AlignCenter)
        self.history_button = QtGui.QPushButton(\
             Qt4_Icons.load_icon("LineGraph"), "", self.value_widget)
        self.history_button.hide()
        self.history_button.setFixedWidth(22)
        self.history_button.setFixedHeight(22)

        _value_widget_hlayout = QtGui.QHBoxLayout(self.value_widget)
        _value_widget_hlayout.addWidget(self.value_label)
        _value_widget_hlayout.addWidget(self.history_button)
        _value_widget_hlayout.setSpacing(2)
        _value_widget_hlayout.setContentsMargins(0, 0, 0, 0)

        self.main_vlayout = QtGui.QVBoxLayout(self)
        self.main_vlayout.addWidget(self.title_label)
        self.main_vlayout.addWidget(self.value_widget)
        self.main_vlayout.setSpacing(1)
        self.main_vlayout.setContentsMargins(0, 0, 0, 0)

        self.history_button.clicked.connect(self.open_history_view)

    def init_info(self, info_dict, max_plot_points=None):
        self.title_label.setText(info_dict.get("title", "???"))
        self.history_button.setVisible(info_dict.get("history", False))
        font = self.value_label.font()
        if info_dict.get("font"):
            font.setPointSize(info_dict.get("font"))
        if info_dict.get("bold"):
            font.setBold(True)
        self.value_label.setFont(font)

        if info_dict.get("history"):
            self.history_button.show()
            self.value_plot = TwoAxisPlotWidget(self, realtime_plot=True)
            self.value_plot.hide()
            self.main_vlayout.addWidget(self.value_plot)
            self.value_plot.set_tight_layout()
            self.value_plot.clear()
            self.value_plot.set_max_plot_point(max_plot_points)
        self.update_info(info_dict)

    def update_info(self, info_dict):
        if info_dict.get("value_str"):
            self.value_label.setText(info_dict.get("value_str"))
        else:
            self.value_label.setText(str(info_dict.get("value")))

        if info_dict.get('in_range') is None:
            Qt4_widget_colors.set_widget_color(self.value_label,
                                               Qt4_widget_colors.GRAY)
        elif info_dict.get('in_range') == True:
            Qt4_widget_colors.set_widget_color(self.value_label,
                                               Qt4_widget_colors.LIGHT_BLUE)
        else:
            Qt4_widget_colors.set_widget_color(self.value_label,
                                               Qt4_widget_colors.LIGHT_RED)
        value = info_dict.get('value')
        if type(value) in (int, float) and self.value_plot:
            self.value_plot.add_new_plot_value(value)

    def open_history_view(self):
        self.value_plot.setVisible(not self.value_plot.isVisible())