Ejemplo n.º 1
0
    def do_plot(self, custom_data):
        x = custom_data[0, :]
        y = custom_data[-1, :]
        x.shape = -1
        y.shape = -1
        title = "top"
        xtitle = "X"
        ytitle = "Y"
        print(x, y)

        plot = PlotWindow(roi=True, control=True, position=True)
        plot.setDefaultPlotLines(False)
        plot.setActiveCurveColor(color='darkblue')
        plot.addCurve(x, y, title, symbol='o', color='blue')  #'+', '^',
        plot.setGraphXLabel(xtitle)
        plot.setGraphYLabel(ytitle)
        plot.setDrawModeEnabled(True, 'rectangle')
        plot.setZoomModeEnabled(True)

        if self.figure_canvas is not None:
            self.mainArea.layout().removeWidget(self.figure_canvas)

        self.figure_canvas = plot

        self.mainArea.layout().addWidget(self.figure_canvas)

        gui.rubber(self.mainArea)
def test():
    from silx.math.fit import fittheories
    from silx.math.fit import fitmanager
    from silx.math.fit import functions
    from silx.gui.plot.PlotWindow import PlotWindow
    import numpy

    a = qt.QApplication([])

    x = numpy.arange(1000)
    y1 = functions.sum_gauss(x, 100, 400, 100)

    fit = fitmanager.FitManager(x=x, y=y1)

    fitfuns = fittheories.FitTheories()
    fit.addtheory(name="Gaussian",
                  function=functions.sum_gauss,
                  parameters=("height", "peak center", "fwhm"),
                  estimate=fitfuns.estimate_height_position_fwhm)
    fit.settheory('Gaussian')
    fit.configure(
        PositiveFwhmFlag=True,
        PositiveHeightAreaFlag=True,
        AutoFwhm=True,
    )

    # Fit
    fit.estimate()
    fit.runfit()

    w = ParametersTab()
    w.show()
    w.fillFromFit(fit.fit_results, view='Gaussians')

    y2 = functions.sum_splitgauss(x, 100, 400, 100, 40, 10, 600, 50, 500, 80,
                                  850, 10, 50)
    fit.setdata(x=x, y=y2)

    # Define new theory
    fit.addtheory(name="Asymetric gaussian",
                  function=functions.sum_splitgauss,
                  parameters=("height", "peak center", "left fwhm",
                              "right fwhm"),
                  estimate=fitfuns.estimate_splitgauss)
    fit.settheory('Asymetric gaussian')

    # Fit
    fit.estimate()
    fit.runfit()

    w.fillFromFit(fit.fit_results, view='Asymetric gaussians')

    # Plot
    pw = PlotWindow(control=True)
    pw.addCurve(x, y1, "Gaussians")
    pw.addCurve(x, y2, "Asymetric gaussians")
    pw.show()

    a.exec_()
Ejemplo n.º 3
0
    def setUp(self):
        TestCaseQt.setUp(self)
        self.plot = PlotWindow()
        self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)

        self.colormap1 = Colormap(name='blue', vmin=0.0, vmax=1.0,
                                  normalization='linear')
        self.colormap2 = Colormap(name='red', vmin=10.0, vmax=100.0,
                                  normalization='log')
        self.defaultColormap = self.plot.getDefaultColormap()

        self.plot.getColormapAction()._actionTriggered(checked=True)
        self.colormapDialog = self.plot.getColormapAction()._dialog
        self.colormapDialog.setAttribute(qt.Qt.WA_DeleteOnClose)
Ejemplo n.º 4
0
def test():
    from .functions import sum_gauss
    from . import fittheories
    from . import bgtheories

    # Create synthetic data with a sum of gaussian functions
    x = numpy.arange(1000).astype(numpy.float)

    p = [1000, 100., 250, 255, 690., 45, 1500, 800.5, 95]
    y = 0.5 * x + 13 + sum_gauss(x, *p)

    # Fitting
    fit = FitManager()
    # more sensitivity necessary to resolve
    # overlapping peaks at x=690 and x=800.5
    fit.setdata(x=x, y=y)
    fit.loadtheories(fittheories)
    fit.settheory('Gaussians')
    fit.loadbgtheories(bgtheories)
    fit.setbackground('Linear')
    fit.estimate()
    fit.runfit()

    print("Searched parameters = ", p)
    print("Obtained parameters : ")
    dummy_list = []
    for param in fit.fit_results:
        print(param['name'], ' = ', param['fitresult'])
        dummy_list.append(param['fitresult'])
    print("chisq = ", fit.chisq)

    # Plot
    constant, slope = dummy_list[:2]
    p1 = dummy_list[2:]
    print(p1)
    y2 = slope * x + constant + sum_gauss(x, *p1)

    try:
        from silx.gui import qt
        from silx.gui.plot.PlotWindow import PlotWindow
        app = qt.QApplication([])
        pw = PlotWindow(control=True)
        pw.addCurve(x, y, "Original")
        pw.addCurve(x, y2, "Fit result")
        pw.legendsDockWidget.show()
        pw.show()
        app.exec_()
    except ImportError:
        _logger.warning("Could not import qt to display fit result as curve")
Ejemplo n.º 5
0
    def remove_all(self):
        if ConfirmDialog.confirmed(
                parent=self,
                message="Confirm Removal of ALL diffraction Pattern?"):
            self.diffraction_pattern_tabs.clear()
            self.diffraction_pattern_box_array = []

            diffraction_pattern_box = DiffractionPatternBox(
                widget=self,
                parent=gui.createTabPage(
                    self.diffraction_pattern_tabs,
                    DiffractionPattern.get_default_name(0)),
                index=0)

            self.diffraction_pattern_box_array.append(diffraction_pattern_box)

            self.tabs.clear()
            self.tab_diff = []
            self.tabs_data_plot = []
            self.tab_data = []
            self.tab_plot = []
            self.plot = []
            self.table_data = []

            self.tab_diff.append(
                gui.createTabPage(self.tabs,
                                  DiffractionPattern.get_default_name(0)))
            self.tabs_data_plot.append(gui.tabWidget(self.tab_diff[0]))
            self.tab_data.append(
                gui.createTabPage(self.tabs_data_plot[0], "Data"))
            self.tab_plot.append(
                gui.createTabPage(self.tabs_data_plot[0], "Plot"))

            self.plot.append(PlotWindow())
            self.plot[0].setDefaultPlotLines(True)
            self.plot[0].setActiveCurveColor(color="#00008B")
            self.plot[0].setGraphXLabel(r"2$\theta$")
            self.plot[0].setGraphYLabel("Intensity")

            self.tab_plot[0].layout().addWidget(self.plot[0])

            table_widget = self.create_table_widget()

            self.table_data.append(table_widget)

            self.tab_data[0].layout().addWidget(table_widget,
                                                alignment=Qt.AlignHCenter)

            self.dumpSettings()
Ejemplo n.º 6
0
def plotWindow(parent=None, backend=None,
               resetzoom=True, autoScale=True, logScale=True, grid=True,
               curveStyle=True, colormap=True,
               aspectRatio=True, yInverted=True,
               copy=True, save=True, print_=True,
               control=False, position=False,
               roi=True, mask=True, fit=False):
    if backend is None:
        backend = OasysBackendMatplotlibQt

    return PlotWindow(parent=parent, backend=backend,
                      resetzoom=resetzoom, autoScale=autoScale, logScale=logScale, grid=grid,
                      curveStyle=curveStyle, colormap=colormap,
                      aspectRatio=aspectRatio, yInverted=yInverted,
                      copy=copy, save=save, print_=print_,
                      control=control, position=position,
                      roi=roi, mask=mask, fit=fit)
Ejemplo n.º 7
0
    def build_plot_fit(self):
        fit_global_parameter = self.fit_global_parameters if self.fitted_fit_global_parameters is None else self.fitted_fit_global_parameters

        self.plot_fit = []
        self.tabs_plot_fit_data.clear()

        for index in range(1 if fit_global_parameter is None else len(fit_global_parameter.fit_initialization.diffraction_patterns)):
            tab_plot_fit_data = gui.createTabPage(self.tabs_plot_fit_data, "Diff. Patt. " + str(index+1))

            plot_fit = PlotWindow()
            plot_fit.setDefaultPlotLines(True)
            plot_fit.setActiveCurveColor(color="#00008B")
            plot_fit.setGraphXLabel(r"2$\theta$ (deg)")
            plot_fit.setGraphYLabel("Intensity")

            self.plot_fit.append(plot_fit)
            tab_plot_fit_data.layout().addWidget(plot_fit)
Ejemplo n.º 8
0
    def __init__(self):
        super().__init__(show_automatic_box=True)

        main_box = gui.widgetBox(self.controlArea, "Fitter Setting", orientation="vertical", width=self.CONTROL_AREA_WIDTH)

        button_box = gui.widgetBox(main_box, "", orientation="vertical", width=self.CONTROL_AREA_WIDTH-15, height=70)

        button_box_1 = gui.widgetBox(button_box, "", orientation="horizontal")

        self.fit_button = gui.button(button_box_1,  self, "Fit", height=40, callback=self.do_fit)
        self.fit_button.setStyleSheet("color: #252468")
        font = QFont(self.fit_button.font())
        font.setBold(True)
        font.setPixelSize(18)
        self.fit_button.setFont(font)

        self.stop_fit_button = gui.button(button_box_1,  self, "STOP", height=40, callback=self.stop_fit)
        self.stop_fit_button.setStyleSheet("color: red")
        font = QFont(self.stop_fit_button.font())
        font.setBold(True)
        font.setItalic(True)
        self.stop_fit_button.setFont(font)

        button_box_2 = gui.widgetBox(button_box, "", orientation="horizontal")

        gui.button(button_box_2,  self, "Send Current Fit", height=40, callback=self.send_current_fit)
        gui.button(button_box_2,  self, "Save Data", height=40, callback=self.save_data)

        orangegui.separator(main_box)

        self.cb_fitter = orangegui.comboBox(main_box, self, "fitter_name", label="Fit algorithm", items=FitterName.tuple(), orientation="horizontal")


        iteration_box = gui.widgetBox(main_box, "", orientation="horizontal", width=250)

        gui.lineEdit(iteration_box, self, "n_iterations", "Nr. Iterations", labelWidth=80, valueType=int, validator=QIntValidator())
        orangegui.checkBox(iteration_box, self, "is_incremental", "Incremental")

        iteration_box = gui.widgetBox(main_box, "", orientation="vertical", width=250)

        self.le_current_iteration = gui.lineEdit(iteration_box, self, "current_iteration", "Current Iteration", labelWidth=120, valueType=int, orientation="horizontal")
        self.le_current_iteration.setReadOnly(True)
        self.le_current_iteration.setStyleSheet("background-color: #FAFAB0; color: #252468")
        font = QFont(self.le_current_iteration.font())
        font.setBold(True)
        self.le_current_iteration.setFont(font)

        orangegui.separator(main_box)

        self.plot_box = gui.widgetBox(main_box, "Plotting Options", orientation="vertical", width=self.CONTROL_AREA_WIDTH-20)

        self.cb_interactive = orangegui.checkBox(self.plot_box, self, "is_interactive", "Refresh Plots while fitting", callback=self.set_interactive)
        orangegui.separator(self.plot_box, height=8)

        self.cb_show_wss_gof = orangegui.checkBox(self.plot_box, self, "show_wss_gof", "Refresh W.S.S. and G.o.F. plots" )
        orangegui.separator(self.plot_box)
        self.cb_show_ipf     = orangegui.checkBox(self.plot_box, self, "show_ipf", "Refresh Instrumental Profile plots")
        orangegui.separator(self.plot_box)
        self.cb_show_shift     = orangegui.checkBox(self.plot_box, self, "show_shift", "Refresh Calibration Shift plots")
        orangegui.separator(self.plot_box)
        self.cb_show_size    = orangegui.checkBox(self.plot_box, self, "show_size", "Refresh Size Distribution plot")
        orangegui.separator(self.plot_box)
        self.cb_show_warren  = orangegui.checkBox(self.plot_box, self, "show_warren", "Refresh Warren's plot")

        self.set_interactive()

        tab_free_out = gui.widgetBox(main_box, "Free Output Parameters", orientation="vertical")

        self.scrollarea_free_out = QScrollArea(tab_free_out)
        self.scrollarea_free_out.setMinimumWidth(self.CONTROL_AREA_WIDTH-55)
        self.scrollarea_free_out.setMaximumHeight(170)

        def write_text():
            self.free_output_parameters_text = self.text_area_free_out.toPlainText()

        self.text_area_free_out = gui.textArea(height=1000, width=1000, readOnly=False)
        self.text_area_free_out.setText(self.free_output_parameters_text)
        self.text_area_free_out.textChanged.connect(write_text)

        self.scrollarea_free_out.setWidget(self.text_area_free_out)
        self.scrollarea_free_out.setWidgetResizable(1)

        tab_free_out.layout().addWidget(self.scrollarea_free_out, alignment=Qt.AlignHCenter)

        self.tabs = gui.tabWidget(self.mainArea)

        self.tab_fit_in  = gui.createTabPage(self.tabs, "Fit Input Parameters")
        self.tab_plot    = gui.createTabPage(self.tabs, "Plots")
        self.tab_fit_out = gui.createTabPage(self.tabs, "Fit Output Parameters")

        self.tabs_plot = gui.tabWidget(self.tab_plot)

        self.tab_plot_fit_data = gui.createTabPage(self.tabs_plot, "Fit")
        self.tab_plot_fit_wss  = gui.createTabPage(self.tabs_plot, "W.S.S.")
        self.tab_plot_fit_gof  = gui.createTabPage(self.tabs_plot, "G.o.F.")
        self.tab_plot_ipf   = gui.createTabPage(self.tabs_plot, "Instrumental Profile")
        self.tab_plot_size   = gui.createTabPage(self.tabs_plot, "Size Distribution")
        self.tab_plot_strain = gui.createTabPage(self.tabs_plot, "Warren's Plot")

        self.std_output = gui.textArea(height=100, width=800)
        self.std_output.setStyleSheet("font-family: Courier, monospace;")

        out_box = gui.widgetBox(self.mainArea, "System Output", addSpace=False, orientation="horizontal")
        out_box.layout().addWidget(self.std_output)

        self.tabs_plot_fit_data = gui.tabWidget(self.tab_plot_fit_data)
        self.tabs_plot_ipf = gui.tabWidget(self.tab_plot_ipf)
        self.tab_plot_fwhm = gui.createTabPage(self.tabs_plot_ipf, "Caglioti's FWHM")
        self.tab_plot_eta  = gui.createTabPage(self.tabs_plot_ipf, "Caglioti's \u03b7")
        self.tab_plot_lab6 = gui.createTabPage(self.tabs_plot_ipf, "LaB6 Tan Correction")

        self.build_plot_fit()

        self.plot_fit_wss = PlotWindow()
        self.plot_fit_wss.setDefaultPlotLines(True)
        self.plot_fit_wss.setActiveCurveColor(color="#00008B")
        self.plot_fit_wss.setGraphXLabel("Iteration")
        self.plot_fit_wss.setGraphYLabel("WSS")

        self.tab_plot_fit_wss.layout().addWidget(self.plot_fit_wss)

        self.plot_fit_gof = PlotWindow()
        self.plot_fit_gof.setDefaultPlotLines(True)
        self.plot_fit_gof.setActiveCurveColor(color="#00008B")
        self.plot_fit_gof.setGraphXLabel("Iteration")
        self.plot_fit_gof.setGraphYLabel("GOF")

        self.tab_plot_fit_gof.layout().addWidget(self.plot_fit_gof)

        self.plot_size = PlotWindow()
        self.plot_size.setDefaultPlotLines(True)
        self.plot_size.setActiveCurveColor(color="#00008B")
        self.plot_size.setGraphTitle("Crystalline Domains Size Distribution")
        self.plot_size.setGraphXLabel(r"D [nm]")
        self.plot_size.setGraphYLabel("Frequency")

        self.tab_plot_size.layout().addWidget(self.plot_size)

        self.plot_strain = PlotWindow(control=True)
        legendsDockWidget = LegendsDockWidget(plot=self.plot_strain)
        self.plot_strain._legendsDockWidget = legendsDockWidget
        self.plot_strain._dockWidgets.append(legendsDockWidget)
        self.plot_strain.addDockWidget(qt.Qt.RightDockWidgetArea, legendsDockWidget)
        self.plot_strain._legendsDockWidget.setFixedWidth(120)
        self.plot_strain.getLegendsDockWidget().show()

        self.plot_strain.setDefaultPlotLines(True)
        self.plot_strain.setActiveCurveColor(color="#00008B")
        self.plot_strain.setGraphTitle("Warren's plot")
        self.plot_strain.setGraphXLabel(r"L [nm]")
        self.plot_strain.setGraphYLabel("$\sqrt{<{\Delta}L^{2}>}$ [nm]")

        self.tab_plot_strain.layout().addWidget(self.plot_strain)

        box = gui.widgetBox(self.tab_plot_fwhm, "", orientation="horizontal")

        boxl = gui.widgetBox(box, "", orientation="vertical")
        boxr = gui.widgetBox(box, "", orientation="vertical", width=150)

        def set_fwhm_autoscale():
            self.le_fwhm_xmin.setEnabled(self.fwhm_autoscale==0)
            self.le_fwhm_xmax.setEnabled(self.fwhm_autoscale==0)
            self.le_fwhm_ymin.setEnabled(self.fwhm_autoscale==0)
            self.le_fwhm_ymax.setEnabled(self.fwhm_autoscale==0)

        orangegui.checkBox(boxr, self, "fwhm_autoscale", "Autoscale", callback=set_fwhm_autoscale)

        self.le_fwhm_xmin = gui.lineEdit(boxr, self, "fwhm_xmin", "2\u03b8 min", labelWidth=70, valueType=float)
        self.le_fwhm_xmax = gui.lineEdit(boxr, self, "fwhm_xmax", "2\u03b8 max", labelWidth=70, valueType=float)
        self.le_fwhm_ymin = gui.lineEdit(boxr, self, "fwhm_ymin", "FWHM min", labelWidth=70, valueType=float)
        self.le_fwhm_ymax = gui.lineEdit(boxr, self, "fwhm_ymax", "FWHM max", labelWidth=70, valueType=float)
        gui.button(boxr, self, "Refresh", height=40, callback=self.refresh_caglioti_fwhm)

        set_fwhm_autoscale()

        self.plot_ipf_fwhm = PlotWindow()
        self.plot_ipf_fwhm.setDefaultPlotLines(True)
        self.plot_ipf_fwhm.setActiveCurveColor(color="#00008B")
        self.plot_ipf_fwhm.setGraphXLabel("2\u03b8 (deg)")
        self.plot_ipf_fwhm.setGraphYLabel("FWHM (deg)")

        boxl.layout().addWidget(self.plot_ipf_fwhm)


        box = gui.widgetBox(self.tab_plot_eta, "", orientation="horizontal")

        boxl = gui.widgetBox(box, "", orientation="vertical")
        boxr = gui.widgetBox(box, "", orientation="vertical", width=150)

        def set_eta_autoscale():
            self.le_eta_xmin.setEnabled(self.eta_autoscale==0)
            self.le_eta_xmax.setEnabled(self.eta_autoscale==0)
            self.le_eta_ymin.setEnabled(self.eta_autoscale==0)
            self.le_eta_ymax.setEnabled(self.eta_autoscale==0)

        orangegui.checkBox(boxr, self, "eta_autoscale", "Autoscale", callback=set_eta_autoscale)

        self.le_eta_xmin = gui.lineEdit(boxr, self, "eta_xmin", "2\u03b8 min", labelWidth=70, valueType=float)
        self.le_eta_xmax = gui.lineEdit(boxr, self, "eta_xmax", "2\u03b8 max", labelWidth=70, valueType=float)
        self.le_eta_ymin = gui.lineEdit(boxr, self, "eta_ymin", "\u03b7 min", labelWidth=70, valueType=float)
        self.le_eta_ymax = gui.lineEdit(boxr, self, "eta_ymax", "\u03b7 max", labelWidth=70, valueType=float)
        gui.button(boxr, self, "Refresh", height=40, callback=self.refresh_caglioti_eta)

        set_eta_autoscale()

        self.plot_ipf_eta = PlotWindow()
        self.plot_ipf_eta.setDefaultPlotLines(True)
        self.plot_ipf_eta.setActiveCurveColor(color="#00008B")
        self.plot_ipf_eta.setGraphXLabel("2\u03b8 (deg)")
        self.plot_ipf_eta.setGraphYLabel("\u03b7")

        boxl.layout().addWidget(self.plot_ipf_eta)

        box = gui.widgetBox(self.tab_plot_lab6, "", orientation="horizontal")

        boxl = gui.widgetBox(box, "", orientation="vertical")
        boxr = gui.widgetBox(box, "", orientation="vertical", width=150)

        def set_lab6_autoscale():
            self.le_lab6_xmin.setEnabled(self.lab6_autoscale==0)
            self.le_lab6_xmax.setEnabled(self.lab6_autoscale==0)
            self.le_lab6_ymin.setEnabled(self.lab6_autoscale==0)
            self.le_lab6_ymax.setEnabled(self.lab6_autoscale==0)

        orangegui.checkBox(boxr, self, "lab6_autoscale", "Autoscale", callback=set_lab6_autoscale)

        self.le_lab6_xmin = gui.lineEdit(boxr, self, "lab6_xmin", "2\u03b8 min", labelWidth=70, valueType=float)
        self.le_lab6_xmax = gui.lineEdit(boxr, self, "lab6_xmax", "2\u03b8 max", labelWidth=70, valueType=float)
        self.le_lab6_ymin = gui.lineEdit(boxr, self, "lab6_ymin", "\u0394(2\u03b8) min", labelWidth=70, valueType=float)
        self.le_lab6_ymax = gui.lineEdit(boxr, self, "lab6_ymax", "\u0394(2\u03b8) max", labelWidth=70, valueType=float)
        gui.button(boxr, self, "Refresh", height=40, callback=self.refresh_lab6)

        set_lab6_autoscale()

        self.plot_ipf_lab6 = PlotWindow()
        self.plot_ipf_lab6.setDefaultPlotLines(True)
        self.plot_ipf_lab6.setActiveCurveColor(color="#00008B")
        self.plot_ipf_lab6.setGraphXLabel("2\u03b8 (deg)")
        self.plot_ipf_lab6.setGraphYLabel("\u0394(2\u03b8) (deg)")

        boxl.layout().addWidget(self.plot_ipf_lab6)

        # -------------------

        self.table_fit_in = self.create_table_widget(is_output=False)
        self.tab_fit_in.layout().addWidget(self.table_fit_in, alignment=Qt.AlignHCenter)

        # -------------------

        self.table_fit_out = self.create_table_widget()
        self.tab_fit_out.layout().addWidget(self.table_fit_out, alignment=Qt.AlignHCenter)
Ejemplo n.º 9
0
def plot(qapp):
    plot = PlotWindow()
    plot.setAttribute(qt.Qt.WA_DeleteOnClose)
    yield weakref.proxy(plot)
    plot.close()
    qapp.processEvents()
Ejemplo n.º 10
0
    def __init__(self):
        super().__init__(show_automatic_box=False)

        main_box = gui.widgetBox(self.controlArea,
                                 "Load Diffraction Pattern",
                                 orientation="vertical",
                                 width=self.CONTROL_AREA_WIDTH - 5,
                                 height=600)

        button_box = gui.widgetBox(main_box,
                                   "",
                                   orientation="horizontal",
                                   width=self.CONTROL_AREA_WIDTH - 25)

        gui.button(button_box,
                   self,
                   "Load Data",
                   height=50,
                   callback=self.load_diffraction_patterns)

        tabs_button_box = gui.widgetBox(main_box,
                                        "",
                                        addSpace=False,
                                        orientation="horizontal")

        btns = [
            gui.button(tabs_button_box,
                       self,
                       "Insert Before",
                       callback=self.insert_before),
            gui.button(tabs_button_box,
                       self,
                       "Insert After",
                       callback=self.insert_after),
            gui.button(tabs_button_box, self, "Remove", callback=self.remove),
            gui.button(tabs_button_box,
                       self,
                       "Remove All",
                       callback=self.remove_all)
        ]

        for btn in btns:
            btn.setFixedHeight(40)

        btns[3].setStyleSheet("color: red")
        font = QFont(btns[3].font())
        font.setItalic(True)
        btns[3].setFont(font)

        self.diffraction_pattern_tabs = gui.tabWidget(main_box)
        self.diffraction_pattern_box_array = []

        for index in range(len(self.filename)):
            diffraction_pattern_tab = gui.createTabPage(
                self.diffraction_pattern_tabs,
                DiffractionPattern.get_default_name(index))

            diffraction_pattern_box = DiffractionPatternBox(
                widget=self,
                parent=diffraction_pattern_tab,
                index=index,
                filename=self.filename[index],
                twotheta_min=self.twotheta_min[index],
                twotheta_has_min=self.twotheta_has_min[index],
                twotheta_max=self.twotheta_max[index],
                twotheta_has_max=self.twotheta_has_max[index],
                diffraction_pattern_name=self.diffraction_pattern_name[index])

            self.diffraction_pattern_box_array.append(diffraction_pattern_box)

        self.tabs = gui.tabWidget(self.mainArea)
        self.tab_diff = []
        self.tabs_data_plot = []
        self.tab_data = []
        self.tab_plot = []
        self.plot = []
        self.table_data = []

        for index in range(len(self.filename)):
            self.tab_diff.append(
                gui.createTabPage(self.tabs,
                                  DiffractionPattern.get_default_name(index)))
            self.tabs_data_plot.append(gui.tabWidget(self.tab_diff[index]))
            self.tab_data.append(
                gui.createTabPage(self.tabs_data_plot[index], "Data"))
            self.tab_plot.append(
                gui.createTabPage(self.tabs_data_plot[index], "Plot"))

            self.plot.append(PlotWindow())
            self.plot[index].setDefaultPlotLines(True)
            self.plot[index].setActiveCurveColor(color="#00008B")
            self.plot[index].setGraphXLabel(r"2$\theta$")
            self.plot[index].setGraphYLabel("Intensity")

            self.tab_plot[index].layout().addWidget(self.plot[index])

            table_widget = self.create_table_widget()

            self.table_data.append(table_widget)

            self.tab_data[index].layout().addWidget(table_widget,
                                                    alignment=Qt.AlignHCenter)

        runaction = OWAction("Load Diffraction Patterns", self)
        runaction.triggered.connect(self.load_diffraction_patterns)
        self.addAction(runaction)
Ejemplo n.º 11
0
    def insert_after(self):
        current_index = self.diffraction_pattern_tabs.currentIndex()

        if ConfirmDialog.confirmed(
                parent=self,
                message="Confirm Insertion of a new element after " +
                self.diffraction_pattern_tabs.tabText(current_index) + "?"):
            diffraction_pattern_tab = gui.widgetBox(
                self.diffraction_pattern_tabs, addToLayout=0, margin=4)
            diffraction_pattern_box = DiffractionPatternBox(
                widget=self,
                parent=diffraction_pattern_tab,
                index=current_index + 1)
            diffraction_pattern_box.after_change_workspace_units()

            diffraction_pattern_pd_tab = gui.widgetBox(self.tabs,
                                                       addToLayout=0,
                                                       margin=4)

            if current_index == self.diffraction_pattern_tabs.count(
            ) - 1:  # LAST
                self.diffraction_pattern_tabs.addTab(diffraction_pattern_tab,
                                                     "TEMP")
                self.diffraction_pattern_box_array.append(
                    diffraction_pattern_box)

                self.tabs.addTab(diffraction_pattern_pd_tab, "TEMP")
                self.tab_diff.append(diffraction_pattern_pd_tab)

                self.tabs_data_plot.append(
                    gui.tabWidget(self.tab_diff[current_index + 1]))
                self.tab_data.append(
                    gui.createTabPage(self.tabs_data_plot[current_index + 1],
                                      "Data"))
                self.tab_plot.append(
                    gui.createTabPage(self.tabs_data_plot[current_index + 1],
                                      "Plot"))

                self.plot.append(PlotWindow())
                self.plot[current_index + 1].setDefaultPlotLines(True)
                self.plot[current_index +
                          1].setActiveCurveColor(color="#00008B")
                self.plot[current_index + 1].setGraphXLabel(r"2$\theta$")
                self.plot[current_index + 1].setGraphYLabel("Intensity")

                self.tab_plot[current_index + 1].layout().addWidget(
                    self.plot[current_index + 1])

                scrollarea = QScrollArea(self.tab_data[current_index])
                scrollarea.setMinimumWidth(805)
                scrollarea.setMinimumHeight(605)

                self.table_data.append(self.create_table_widget())

                scrollarea.setWidget(self.table_data[current_index + 1])
                scrollarea.setWidgetResizable(1)

                self.tab_data[current_index + 1].layout().addWidget(
                    scrollarea, alignment=Qt.AlignHCenter)
            else:
                self.diffraction_pattern_tabs.insertTab(
                    current_index + 1, diffraction_pattern_tab, "TEMP")
                self.diffraction_pattern_box_array.insert(
                    current_index + 1, diffraction_pattern_box)

                self.tabs.insertTab(current_index + 1,
                                    diffraction_pattern_pd_tab, "TEMP")
                self.tab_diff.insert(current_index + 1,
                                     diffraction_pattern_pd_tab)

                self.tabs_data_plot.insert(
                    current_index + 1,
                    gui.tabWidget(self.tab_diff[current_index + 1]))
                self.tab_data.insert(
                    current_index + 1,
                    gui.createTabPage(self.tabs_data_plot[current_index + 1],
                                      "Data"))
                self.tab_plot.insert(
                    current_index + 1,
                    gui.createTabPage(self.tabs_data_plot[current_index + 1],
                                      "Plot"))

                self.plot.insert(current_index + 1, PlotWindow())
                self.plot[current_index + 1].setDefaultPlotLines(True)
                self.plot[current_index +
                          1].setActiveCurveColor(color="#00008B")
                self.plot[current_index + 1].setGraphXLabel(r"2$\theta$")
                self.plot[current_index + 1].setGraphYLabel("Intensity")

                self.tab_plot[current_index + 1].layout().addWidget(
                    self.plot[current_index + 1])

                scrollarea = QScrollArea(self.tab_data[current_index + 1])
                scrollarea.setMinimumWidth(805)
                scrollarea.setMinimumHeight(605)

                self.table_data.insert(current_index + 1,
                                       self.create_table_widget())

                scrollarea.setWidget(self.table_data[current_index + 1])
                scrollarea.setWidgetResizable(1)

                self.tab_data[current_index + 1].layout().addWidget(
                    scrollarea, alignment=Qt.AlignHCenter)

            for index in range(current_index,
                               self.diffraction_pattern_tabs.count()):
                self.diffraction_pattern_tabs.setTabText(
                    index, DiffractionPattern.get_default_name(index))
                self.diffraction_pattern_box_array[index].index = index
                self.tabs.setTabText(
                    index, DiffractionPattern.get_default_name(index))

            self.dumpSettings()
            self.diffraction_pattern_tabs.setCurrentIndex(current_index + 1)
            self.tabs.setCurrentIndex(current_index + 1)