예제 #1
0
    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)
예제 #2
0
    def __init__(self, *args):
        BlissWidget.__init__(self, *args)

        self.defineSlot('set_data', ())

        if pymca_imported:
            self.mcafit_widget = McaAdvancedFit.McaAdvancedFit(self)
            self.mcafit_widget.dismissButton.hide()
        else:
            self.mcafit_widget = TwoAxisPlotWidget(self)

        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self.mcafit_widget)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    def __init__(self, *args):
        BlissWidget.__init__(self, *args)

        self.defineSlot('set_data',())

        if pymca_imported:    
            self.mcafit_widget = McaAdvancedFit.McaAdvancedFit(self)
            self.mcafit_widget.dismissButton.hide()
        else:
            self.mcafit_widget = TwoAxisPlotWidget(self)
       
        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self.mcafit_widget)  
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)
예제 #6
0
    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)
예제 #7
0
class McaSpectrumWidget(BlissWidget):
    def __init__(self, *args):
        BlissWidget.__init__(self, *args)

        self.defineSlot('set_data', ())

        if pymca_imported:
            self.mcafit_widget = McaAdvancedFit.McaAdvancedFit(self)
            self.mcafit_widget.dismissButton.hide()
        else:
            self.mcafit_widget = TwoAxisPlotWidget(self)

        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self.mcafit_widget)
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

    def set_data(self, data, calib, config):
        try:
            configured = False
            if os.path.exists(config.get("file", "")) and \
               pymca_imported:
                self._configure(config)
                configured = True
            data = np.array(data)
            x = np.array(data[:, 0]).astype(np.float)
            y = np.array(data[:, 1]).astype(np.float)
            xmin = float(config["min"])
            xmax = float(config["max"])
            #self.mcafit_widget.refreshWidgets()
            calib = np.ravel(calib).tolist()
            """kw = {}
            kw.update(config)
            kw['xmin'] = xmin
            kw['xmax'] = xmax
            kw['calibration'] = calib"""
            self.mcafit_widget.setdata(x, y)
            if pymca_imported:
                #elf.mcafit.setdata(x, y, **kw)# xmin=xmin, xmax=xmax, calibration=calib)
                self.mcafit_widget._energyAxis = False
                self.mcafit_widget.toggleEnergyAxis()
                self.mcafit_widget.setdata(x, y)
            #result = self._fit()
            #pyarch file name and directory
            pf = config["legend"].split(".")
            pd = pf[0].split("/")
            outfile = pd[-1]
            outdir = config['htmldir']
            sourcename = config['legend']

            if pymca_imported:
                result = self._fit()
                if configured:
                    report = McaAdvancedFit.QtMcaAdvancedFitReport.\
                         QtMcaAdvancedFitReport(None, outfile=outfile, outdir=outdir,
                         fitresult=result, sourcename=sourcename,
                         plotdict={'logy':False}, table=2)

                    text = report.getText()
                    report.writeReport(text=text)

        except:
            logging.getLogger().exception("McaSpectrumWidget: problem fitting %s %s %s" % \
                                          (str(data), str(calib), str(config)))

    def _fit(self):
        return self.mcafit_widget.fit()

    def _configure(self, config):
        d = ConfigDict.ConfigDict()
        d.read(config["file"])
        if not d.has_key('concentrations'):
            d['concentrations'] = {}
        if not d.has_key('attenuators'):
            d['attenuators'] = {}
            d['attenuators']['Matrix'] = [1, 'Water', 1.0, 0.01, 45.0, 45.0]
        if config.has_key('flux'):
            d['concentrations']['flux'] = float(config['flux'])
        if config.has_key('time'):
            d['concentrations']['time'] = float(config['time'])
        self.mcafit_widget.mcafit.configure(d)

    def clear(self):
        #TODO make with clear
        x = np.array([0]).astype(np.float)
        y = np.array([0]).astype(np.float)
        self.mcafit_widget.setdata(x, y)
예제 #8
0
    def __init__(self, parent=None, name="energy_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

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

        # Graphic elements ----------------------------------------------------
        _top_widget = QtGui.QWidget(self)
        _parameters_widget = QtGui.QWidget(_top_widget)

        self.periodic_table_widget = PeriodicTableWidget(_parameters_widget)

        self.data_path_widget = DataPathWidget(_parameters_widget)
        # 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)
예제 #9
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()
    def __init__(self, parent=None, name="energy_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

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

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

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

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

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

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

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

        self.setLayout(_main_vlayout)

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

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

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

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

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

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

        Qt4_widget_colors.set_widget_color(self.periodic_table_widget, Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.position_widget, Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.data_path_widget, Qt4_widget_colors.GROUP_BOX_GRAY)
class 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()
예제 #12
0
class McaSpectrumWidget(BlissWidget):
    def __init__(self, *args):
        BlissWidget.__init__(self, *args)

        self.defineSlot('set_data',())

        if pymca_imported:    
            self.mcafit_widget = McaAdvancedFit.McaAdvancedFit(self)
            self.mcafit_widget.dismissButton.hide()
        else:
            self.mcafit_widget = TwoAxisPlotWidget(self)
       
        _main_vlayout = QVBoxLayout(self)
        _main_vlayout.addWidget(self.mcafit_widget)  
        _main_vlayout.setSpacing(0)
        _main_vlayout.setContentsMargins(0, 0, 0, 0)

    def set_data(self, data, calib, config):
        logging.getLogger().info('McaSpectrumWidget set_data calib %s, config %s' % (str(calib), str(config)))
        
        try:
            configured = False
            if os.path.exists(config.get("file", "")) and \
               pymca_imported:
                self._configure(config)
                configured = True
            data = np.array(data)
            x = np.array(data[:,0]).astype(np.float)
            y = np.array(data[:,1]).astype(np.float)
            xmin = float(config["min"])
            xmax = float(config["max"])
            #self.mcafit_widget.refreshWidgets()
            calib = np.ravel(calib).tolist()
            """kw = {}
            kw.update(config)
            kw['xmin'] = xmin
            kw['xmax'] = xmax
            kw['calibration'] = calib"""
            self.mcafit_widget.setdata(x, y)
            if pymca_imported:
                #elf.mcafit.setdata(x, y, **kw)# xmin=xmin, xmax=xmax, calibration=calib)
                self.mcafit_widget._energyAxis = False
                self.mcafit_widget.toggleEnergyAxis()
                self.mcafit_widget.setdata(x, y)
            #result = self._fit()
            #pyarch file name and directory
            pf = config["legend"].split(".")
            pd = pf[0].split("/")
            outfile = pd[-1]
            outdir = config['htmldir']
            sourcename = config['legend']

            if pymca_imported:
                result = self._fit()
                if configured:
                    report = McaAdvancedFit.QtMcaAdvancedFitReport.\
                         QtMcaAdvancedFitReport(None, outfile=outfile, outdir=outdir,
                         fitresult=result, sourcename=sourcename, 
                         plotdict={'logy':False}, table=2)

                    text = report.getText()
                    report.writeReport(text=text)
  
        except:
            logging.getLogger().info('traceback %s' % traceback.format_exc())
            logging.getLogger().exception("McaSpectrumWidget: problem fitting %s %s %s" % \
                                          (str(data), str(calib), str(config)))

    def _fit(self):
        return self.mcafit_widget.fit()

    def _configure(self, config):
        d = ConfigDict.ConfigDict()
        d.read(config["file"])
        if not d.has_key('concentrations'):
            d['concentrations']= {}
        if not d.has_key('attenuators'):
            d['attenuators']= {}
            d['attenuators']['Matrix'] = [1, 'Water', 1.0, 0.01, 45.0, 45.0]
        if config.has_key('flux'):
            d['concentrations']['flux'] = float(config['flux'])
        if config.has_key('time'):
            d['concentrations']['time'] = float(config['time'])
        self.mcafit_widget.mcafit.configure(d)

    def clear(self):
        #TODO make with clear
        x = np.array([0]).astype(np.float)
        y = np.array([0]).astype(np.float)
        self.mcafit_widget.setdata(x, y)
예제 #13
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())
예제 #14
0
    def __init__(self, parent=None, name="energy_scan_tab_widget"):
        QtGui.QWidget.__init__(self, parent)

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

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

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

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

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

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

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

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

        self.setLayout(_main_vlayout)

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

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

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

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

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

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

        Qt4_widget_colors.set_widget_color(self.periodic_table_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.position_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
        Qt4_widget_colors.set_widget_color(self.data_path_widget,
                                           Qt4_widget_colors.GROUP_BOX_GRAY)
    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)
예제 #16
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())