Exemple #1
0
class Plot(QtWidgets.QWidget):
    def __init__(self,
                 main,
                 title,
                 ylabel,
                 xlabel,
                 yunit,
                 xunit,
                 itemlist=False,
                 toolbar=False):
        super(Plot, self).__init__()

        self._plot = CurveDialog(toolbar=toolbar,
                                 wintitle=title,
                                 options=dict(ylabel=ylabel,
                                              yunit=yunit,
                                              xlabel=xlabel,
                                              xunit=xunit))

        if itemlist:
            self._plot.get_itemlist_panel().show()

        set_size_policy(self, QSizePolicy.Expanding, QSizePolicy.Expanding)
        set_size_policy(self._plot, QSizePolicy.Expanding,
                        QSizePolicy.Expanding)

        QtCore.QMetaObject.connectSlotsByName(self)
        self.setObjectName("Plot")

        main.addWidget(self._plot)

    def add(self, item):
        self._plot.get_plot().add_item(item)
Exemple #2
0
class PlotWidget():
    '''GuiQwt Plot'''
    def __init__(self, title, x_axis='lin', x_label='x', y_label='y'):
        '''Init plot and curves'''
        self.plot_dlg = CurveDialog(edit=False,
                                    toolbar=False,
                                    wintitle=title,
                                    options=dict(xlabel=x_label,
                                                 ylabel=y_label))
        self.curves = []
        self._x_axis = x_axis
        self._init_plot(x_label, y_label)

    def _init_plot(self, xlabel, ylabel):
        '''Init plot'''
        self.plot_dlg.get_itemlist_panel().show()
        _plot = self.plot_dlg.get_plot()
        #_label = '{0} = %.2f<br>{1} = %.2f'.format(xlabel, ylabel)
        #_xcursor = make.xcursor(0, 0, _label)
        #_plot.add_item(_xcursor)
        _plot.set_antialiasing(True)

    def add_curve(self, x, y, title, color):
        '''Add curves'''
        self.curves.append(make.curve(x, y, title=title, color=color))

    def update_curve(self, curve_item, x, y):
        '''Update curve values'''
        curve_item.set_data(x, y)
        curve_item.plot().replot()

    def del_curves(self):
        '''Delete curves'''
        _plot = self.plot_dlg.get_plot()
        for curve_item in self.curves:
            _plot.del_item(curve_item)
        self.curves = []

    def _plot_items(self):
        '''Plot curve items'''
        _plot = self.plot_dlg.get_plot()
        for curve_item in self.curves:
            _plot.add_item(curve_item)
            _plot.set_axis_scale(curve_item.xAxis(), self._x_axis)
        self.refresh()

    def refresh(self):
        '''Refersh plots'''
        _plot = self.plot_dlg.get_plot()
        _plot.do_autoscale()
        self.plot_dlg.adjustSize()

    def show(self):
        '''Show Plot'''
        self._plot_items()
        self.plot_dlg.show()
Exemple #3
0
def plot(*items):
    win = CurveDialog(edit=False, toolbar=True, wintitle="CurveDialog test",
                      options=dict(title="Title", xlabel="xlabel",
                                   ylabel="ylabel"))
    plot = win.get_plot()
    for item in items:
        plot.add_item(item)
    plot.set_axis_font("left", QFont("Courier"))
    win.get_itemlist_panel().show()
    plot.set_items_readonly(False)
    win.show()
    win.exec_()
Exemple #4
0
def plot(*items):
    win = CurveDialog(edit=False, toolbar=True, wintitle="CurveDialog test",
                      options=dict(title="Temperaturverlauf", xlabel="Zeit [s]",
                                   ylabel="Temperatur [\xb0C]"))
    win.add_tool(HRangeTool)
    plot = win.get_plot()
    for item in items:
        plot.add_item(item)
    #plot.set_axis_font("left", QFont("Courier"))
    win.get_itemlist_panel().show()
    plot.set_items_readonly(False)
    win.show()
    win.exec_()
Exemple #5
0
def taurusCurveMain():
    from taurus.qt.qtgui.extra_guiqwt.builder import make
    from taurus.qt.qtgui.application import TaurusApplication
    from guiqwt.plot import CurveDialog
    from guiqwt.tools import HRangeTool
    from taurus.qt.qtgui.extra_guiqwt.tools import TaurusCurveChooserTool, TimeAxisTool
    import taurus.core.util.argparse
    import sys

    parser = taurus.core.util.argparse.get_taurus_parser()
    parser.set_usage("%prog [options] [<model1> [<model2>] ...]")
    parser.set_description("a taurus application for plotting 1D data sets")
    app = TaurusApplication(cmd_line_parser=parser,
                            app_name="taurusplot2",
                            app_version=taurus.Release.version)
    args = app.get_command_line_args()

    win = CurveDialog(edit=False,
                      toolbar=True,
                      wintitle="TaurusPlot2",
                      options=dict(title="", xlabel="xlabel", ylabel="ylabel"))
    win.add_tool(HRangeTool)
    win.add_tool(TaurusCurveChooserTool)
    win.add_tool(TimeAxisTool)

    plot = win.get_plot()

    for a in args:
        mx_my = a.split('|')
        n = len(mx_my)
        if n == 1:
            mx, my = None, mx_my[0]
        elif n == 2:
            mx, my = mx_my
        else:
            print "Invalid model: %s\n" % mx_my
            parser.print_help(sys.stderr)
            sys.exit(1)
        # cycle colors
        style = make.style.next()
        color = style[0]
        linestyle = style[1:]
        plot.add_item(
            make.curve(mx, my, color=color, linestyle=linestyle, linewidth=2))

    win.get_itemlist_panel().show()
    plot.set_items_readonly(False)
    win.show()
    win.exec_()
Exemple #6
0
def plot(*items):
    win = CurveDialog(
        edit=False,
        toolbar=True,
        wintitle="CurveDialog test",
        options=dict(title="Title", xlabel="xlabel", ylabel="ylabel"),
    )
    plot = win.get_plot()
    for item in items:
        plot.add_item(item)
    # plot.set_axis_font("left", QFont("Courier"))
    win.get_itemlist_panel().show()
    plot.set_items_readonly(False)
    win.show()
    win.exec_()
Exemple #7
0
def taurusCurveMain():
    from taurus.qt.qtgui.extra_guiqwt.builder import make
    from taurus.qt.qtgui.application import TaurusApplication
    from guiqwt.plot import CurveDialog
    from guiqwt.tools import HRangeTool
    from taurus.qt.qtgui.extra_guiqwt.tools import TaurusCurveChooserTool, TimeAxisTool
    import taurus.core.util.argparse
    import sys

    parser = taurus.core.util.argparse.get_taurus_parser()
    parser.set_usage("%prog [options] [<model1> [<model2>] ...]")
    parser.set_description("a taurus application for plotting 1D data sets")
    app = TaurusApplication(
        cmd_line_parser=parser, app_name="taurusplot2", app_version=taurus.Release.version)
    args = app.get_command_line_args()

    win = CurveDialog(edit=False, toolbar=True, wintitle="TaurusPlot2",
                      options=dict(title="", xlabel="xlabel", ylabel="ylabel"))
    win.add_tool(HRangeTool)
    win.add_tool(TaurusCurveChooserTool)
    win.add_tool(TimeAxisTool)

    plot = win.get_plot()

    for a in args:
        mx_my = a.split('|')
        n = len(mx_my)
        if n == 1:
            mx, my = None, mx_my[0]
        elif n == 2:
            mx, my = mx_my
        else:
            print "Invalid model: %s\n" % mx_my
            parser.print_help(sys.stderr)
            sys.exit(1)
        # cycle colors
        style = make.style.next()
        color = style[0]
        linestyle = style[1:]
        plot.add_item(make.curve(mx, my, color=color,
                                 linestyle=linestyle, linewidth=2))

    win.get_itemlist_panel().show()
    plot.set_items_readonly(False)
    win.show()
    win.exec_()
class CentralWidget(QSplitter):
    def __init__(self, parent, toolbar):
        QSplitter.__init__(self, parent)
        # Define csvModel 提供csv處理的Model
        self.csvmodel = CsvFileModel()
        self.selectedRow = -1

        #connect error message
        self.connect(self.csvmodel, SIGNAL("ERROR_NOT_NONAME_ARRAY"),
                     partial(self.showErrorMessage, "NOT_NONAME_ARRAY"))

        # 連接csvlist與製造ImageListWithProperties
        imagelistwithproperties = ImageListWithProperties(self)

        self.addWidget(imagelistwithproperties)
        self.csvlist = imagelistwithproperties.csvlist
        self.connect(imagelistwithproperties, SIGNAL("PLOT"),
                     partial(self.csvmodel.plotCSV, self.csvlist))
        self.connect(imagelistwithproperties, SIGNAL("REMOVE"),
                     partial(self.csvmodel.removeCSV, self.csvlist))
        self.connect(imagelistwithproperties, SIGNAL("EXTRACT_ARRAY"),
                     partial(self.csvmodel.extractArray, self.csvlist))

        # View signal connect
        self.connect(self.csvlist,
                     SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
                     partial(self.csvmodel.plotCSV, self.csvlist))
        self.connect(self.csvlist, SIGNAL("currentRowChanged(int)"),
                     self.current_item_changed)
        self.connect(self.csvlist, SIGNAL("itemSelectionChanged()"),
                     self.selection_changed)

        self.properties = imagelistwithproperties.properties
        self.connect(self.properties, SIGNAL("apply_button_clicked()"),
                     self.properties_changed)

        # CsvModel signal connect
        self.connect(self.csvmodel, SIGNAL("CSV_UPDATED"), self.refresh_list)
        self.connect(self.csvmodel, SIGNAL("ARRAY_UPDATED"),
                     self.refresh_array_list)

        # 製造ArrayListWithProperties
        self.arraylistwithproperties = ArrayListWithProperties(self)
        self.arraylist = self.arraylistwithproperties.arraylist
        self.addWidget(self.arraylistwithproperties)
        self.connect(self.arraylistwithproperties, SIGNAL("PASTE_NO_NAME"),
                     partial(self.csvmodel.pasteArrayNoName, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("PASTE_WITH_NAME"),
                     partial(self.csvmodel.pasteArrayWithName, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("PLOT"),
                     partial(self.csvmodel.plotArray, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("MODIFY_ARRAY"),
                     partial(self.csvmodel.modifyArray, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("PLOT_SCATTER"),
                     partial(self.csvmodel.plotScatter, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("PLOT_HISTOGRAM"),
                     self.plotHist)
        self.connect(self.arraylistwithproperties, SIGNAL("REMOVE"),
                     partial(self.csvmodel.removeArray, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("OPEN_CURVEDIALOG"),
                     self.openCurveDialog)

        #arraylist action signal
        self.connect(self.arraylist, SIGNAL("currentRowChanged(int)"),
                     self.array_current_item_changed)
        self.arrayproperties = self.arraylistwithproperties.properties
        self.connect(self.arrayproperties, SIGNAL("apply_button_clicked()"),
                     self.array_properties_changed)
        self.connect(self.arraylist, SIGNAL("itemSelectionChanged()"),
                     self.array_selection_changed)
        self.connect(self.arraylist,
                     SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
                     partial(self.csvmodel.plotArray, self.arraylist))

        # 設定基本properity
        self.setContentsMargins(10, 10, 10, 10)
        self.setOrientation(Qt.Vertical)
        self.setStretchFactor(0, 0)
        self.setStretchFactor(1, 1)
        self.setHandleWidth(10)
        self.setSizes([1, 2])

    def refresh_list(self):
        self.csvlist.clear()
        for csv in self.csvmodel.csvName:
            self.csvlist.addItem(csv)

    def refresh_array_list(self):
        self.arraylist.clear()
        for array in self.csvmodel.arrayName:
            self.arraylist.addItem(array)

    def selection_changed(self):
        """Image list: selection changed, make right properity box selectable"""
        row = self.csvlist.currentRow()
        self.properties.setDisabled(row == -1)

    def array_selection_changed(self):
        """Array list: selection changed, make right properity box selectable"""
        row = self.arraylist.currentRow()
        self.arrayproperties.setDisabled(row == -1)

    def current_item_changed(self, row):
        """Image list: current image changed"""
        #csvdata, csvname = self.csvmodel.csvData[row], self.csvmodel.csvName[row]
        update_dataset(self.properties.dataset, self.csvmodel.csv[row])
        self.properties.get()

    def array_current_item_changed(self, row):
        """Image list: current image changed"""
        #csvdata, csvname = self.csvmodel.csvData[row], self.csvmodel.csvName[row]
        update_dataset(self.arrayproperties.dataset, self.csvmodel.array[row])
        self.arrayproperties.get()

    def plotHist(self):
        self.histWindow = HistogramWindow(
            self.csvmodel.arrayData[self.arraylist.currentRow()],
            self.csvmodel.arrayName[self.arraylist.currentRow()])
        self.histWindow.show()

    def openCurveDialog(self):
        self.curvedialog = CurveDialog(edit=False,
                                       toolbar=True,
                                       wintitle="CurveDialog",
                                       options=dict(title="Title",
                                                    xlabel="xlabel",
                                                    ylabel="ylabel"))
        plot = self.curvedialog.get_plot()
        for array in self.csvmodel.array:
            item = make.curve(np.array(range(array.data.size)),
                              array.data,
                              color="b")
            plot.add_item(item)
        plot.set_axis_font("left", QFont("Courier"))
        self.curvedialog.get_itemlist_panel().show()
        plot.set_items_readonly(False)
        self.curvedialog.show()
#
#==============================================================================
#     def lut_range_changed(self):
#         row = self.imagelist.currentRow()
#         self.lut_ranges[row] = self.item.get_lut_range()
#==============================================================================

#==============================================================================
#     def show_data(self, data, lut_range=None):
#         plot = self.imagewidget.plot
#         if self.item is not None:
#             self.item.set_data(data)
#             if lut_range is None:
#                 lut_range = self.item.get_lut_range()
#             self.imagewidget.set_contrast_range(*lut_range)
#             self.imagewidget.update_cross_sections()
#         else:
#             self.item = make.image(data)
#             plot.add_item(self.item, z=0)
#         plot.replot()
#==============================================================================

    def properties_changed(self):
        """The properties 'Apply' button was clicked: updating image"""
        row = self.csvlist.currentRow()
        csvdata = self.csvmodel.csv[row]
        update_dataset(csvdata, self.properties.dataset)
        self.csvmodel.csvName[row] = csvdata.title
        self.refresh_list()
        #self.show_data(image.data)

    def array_properties_changed(self):
        """The properties 'Apply' button was clicked: updating image"""
        print("apply button click")
        row = self.arraylist.currentRow()
        arraydata = self.csvmodel.array[row]
        update_dataset(arraydata, self.arrayproperties.dataset)
        self.csvmodel.arrayName[row] = arraydata.title
        self.refresh_array_list()


#==============================================================================
#     def add_image(self, image):
#         self.images.append(image)
#         #self.lut_ranges.append(None)
#         self.refresh_list()
#         self.imagelist.setCurrentRow(len(self.images)-1)
#         plot = self.imagewidget.plot
#         plot.do_autoscale()
#==============================================================================

#def add_csv_from_file(self, filename):

    def showErrorMessage(self, message):
        print("error")
        if message == "NOT_NONAME_ARRAY":
            QMessageBox.about(
                self, "Error message box",
                "Please make sure the data in the clip board is an array")