Example #1
0
    def __init__(self,
                 parent=None,
                 title=None,
                 rtitle=None,
                 xlabel=None,
                 ylabel=None,
                 rxlabel=None,
                 rylabel=None,
                 xunit=None,
                 yunit=None,
                 rxunit=None,
                 ryunit=None,
                 section="plot",
                 rsection="rplot",
                 show_itemlist=False,
                 gridparam=None,
                 rgridparam=None,
                 panels=None):
        BaseCurveWidget2.__init__(self, parent, title, xlabel, ylabel, xunit,
                                  yunit, section, show_itemlist, gridparam,
                                  rtitle, rxlabel, rylabel, rxunit, ryunit,
                                  rsection, rgridparam)
        PlotManager.__init__(self, main=self)

        # Configuring plot manager
        self.add_plot(self.plot)
        self.add_plot(self.rplot)
        self.synchronize_axis("bottom", [self.plot, self.rplot])
        self.add_panel(self.itemlist)
        if panels is not None:
            for panel in panels:
                self.add_panel(panel)
Example #2
0
    def __init__(self, parent=None, rangeSelectionCallback=None):

        PlotterBase.__init__(self, "RT", "I")

        self.rangeSelectionCallback = rangeSelectionCallback

        widget = self.widget
        widget.plot.__class__ = RtPlot

        self.pm = PlotManager(widget)
        self.pm.add_plot(widget.plot)

        t = self.pm.add_tool(RtSelectionTool)
        t.activate()
        self.pm.set_default_tool(t)

        marker = Marker(label_cb=self.widget.plot.label_info,
                        constraint_cb=self.widget.plot.on_plot)
        marker.rts = [0]
        setupStyleRtMarker(marker)
        marker.attach(self.widget.plot)
        self.marker = marker

        self.cursor_info = RtCursorInfo(marker)
        label = make.info_label("T", [self.cursor_info], title=None)
        label.labelparam.label = ""
        label.labelparam.font.size = 12
        label.labelparam.border.color = "#ffffff"
        label.labelparam.update_label(label)
        self.label = label

        self.minRTRangeSelected = None
        self.maxRTRangeSelected = None
Example #3
0
    def __init__(self, wintitle="guiqwt plot", icon="guiqwt.png",
                 toolbar=False, options=None, parent=None, panels=None):
        QDialog.__init__(self, parent)
        self.setWindowFlags(Qt.Window)

        # WidgetMixin copy
        PlotManager.__init__(self, main=self)
        
        self.main_layout = QVBoxLayout(self)
        self.color_layout = QHBoxLayout()
        self.plot_layout = QGridLayout()
        self.option_layout = QHBoxLayout()

        self.plot_widget = None

        if panels is not None:
            for panel in panels:
                self.add_panel(panel)

        self.toolbar = QToolBar(_("Tools"))
        if not toolbar:
            self.toolbar.hide()

        # Configuring widget layout
        self._setup_widget_properties(wintitle=wintitle, icon=icon)
        self._setup_widget_layout()
        
        # Options
        self.option_callbacks = {}
        self.legend = None
Example #4
0
    def __init__(self, wintitle):
        super(Window, self).__init__()
        self.default_tool = None
        self.plots = []
        self.itemlist = PlotItemList(None)
        self.contrast = ContrastAdjustment(None)
        self.xcsw = XCrossSection(None)
        self.ycsw = YCrossSection(None)

        self.manager = PlotManager(self)
        self.toolbar = QToolBar(_("Tools"), self)
        self.manager.add_toolbar(self.toolbar, "default")
        self.toolbar.setMovable(True)
        self.toolbar.setFloatable(True)
        self.addToolBar(Qt.TopToolBarArea, self.toolbar)

        frame = QFrame(self)
        self.setCentralWidget(frame)
        self.layout = QGridLayout()
        layout = QVBoxLayout(frame)
        frame.setLayout(layout)
        layout.addLayout(self.layout)
        self.frame = frame

        self.setWindowTitle(wintitle)
        self.setWindowIcon(get_icon('guiqwt.svg'))
Example #5
0
    def __init__(self):
        super(RealtimeDemo, self).__init__()
        self.setWindowTitle(u"Realtime Demo")

        self.data = {u"t":array("d")}
        for name in sum(PLOT_DEFINE, []):
            self.data[name] = array("d")

        self.curves = {}
        self.t = 0
        vbox = QVBoxLayout()
        vbox.addWidget(self.setup_toolbar())
        self.manager = PlotManager(self)
        self.plots = []
        for i, define in enumerate(PLOT_DEFINE):
            plot = CurvePlot()
            plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(60)
            self.manager.add_plot(plot)
            self.plots.append(plot)
            plot.plot_id = id(plot)
            for j, curve_name in enumerate(define):
                curve = self.curves[curve_name] = make.curve([0], [0], color=COLORS[j], title=curve_name)
                plot.add_item(curve)
            plot.add_item(make.legend("BL"))
            vbox.addWidget(plot)
        self.manager.register_standard_tools()
        self.manager.get_default_tool().activate()
        self.manager.synchronize_axis(CurvePlot.X_BOTTOM, self.manager.plots.keys())
        self.setLayout(vbox)
        self.startTimer(100)
Example #6
0
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowTitle("Signal filtering 2 (guiqwt)")
        self.setWindowIcon(get_icon('guiqwt.svg'))

        hlayout = QHBoxLayout()
        central_widget = QWidget(self)
        central_widget.setLayout(hlayout)
        self.setCentralWidget(central_widget)
        #---guiqwt plot manager
        self.manager = PlotManager(self)
Example #7
0
 def plot_init(self):
     self.manager = PlotManager(self)
     self.plots = []
     self.plot = CurvePlot(xlabel="", ylabel="")
     # self.plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(10)
     self.manager.add_plot(self.plot)
     self.plots.append(self.plot)
     self.plot.plot_id = id(self.plot)
     self.curve = make.curve([0], [0], color="blue", title="gray value")
     self.plot.add_item(self.curve)
     self.plot.add_item(make.legend("TR"))
     self.ui_obj.line_info_display.addWidget(self.plot)
    def _setup_plot(self):
        self.pm = PlotManager(self)
        self.pm.add_plot(self.plot)

        t = self.pm.add_tool(RtSelectionTool)
        t.activate()
        self.pm.set_default_tool(t)

        self._setup_cursor()
        self._setup_range_selector()
        self._setup_label()
        self._setup_axes()
Example #9
0
    def __init__(self,
                 wintitle='Plot window',
                 major_grid=True,
                 minor_grid=False,
                 toolbar=True,
                 parent=None,
                 panels=None,
                 min_plot_width=100,
                 min_plot_height=75):
        QDialog.__init__(self, parent)
        self.setWindowFlags(Qt.Window)

        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(':/Application/Main')),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.setWindowIcon(icon)

        self.major_grid = major_grid
        self.minor_grid = minor_grid
        self.min_plot_width = min_plot_width
        self.min_plot_height = min_plot_height

        # WidgetMixin copy
        PlotManager.__init__(self, main=self)

        self.main_layout = QVBoxLayout(self)
        self.color_layout = QHBoxLayout()
        self.plot_layout = QGridLayout()
        self.plot_layout.setMargin(0)
        self.plot_scroll_widget = QWidget()
        self.plot_scroll_area = QScrollArea()
        self.plot_scroll_area.setFrameShape(QFrame.NoFrame)
        self.plot_scroll_area.setWidgetResizable(True)
        self.option_layout = QHBoxLayout()

        self.plot_widget = None

        if panels is not None:
            for panel in panels:
                self.add_panel(panel)

        self.toolbar = QToolBar('Tools')
        if not toolbar:
            self.toolbar.hide()

        # Configuring widget layout
        self._setup_widget_properties(wintitle=wintitle, icon=icon)
        self._setup_widget_layout()

        # Options
        self.option_callbacks = {}
        self.legend = None
        self.axis_syncplots = {}
Example #10
0
    def __init__(self, parent=None, x=[], y=[], data=[]):
        QWidget.__init__(self, parent)

        if len(x) < 2:
            x = np.linspace(0, 1392, 1392)
            y = np.linspace(0, 1040, 1040)
            data = np.zeros((1040, 1392))

        self.x = x
        self.y = y
        self.data = data

        sx = 600
        sy = int(sx / 1.338)
        stretch_x = 3
        stretch_y = 3

        #self.setGeometry(QRect(0,0,sx,sy))
        layout = QGridLayout(self)
        layout.setMargin(0)

        self.screen = ImageScreen(self, x, y, data)
        self.cutX = CutScreen(self)
        self.cutY = CutScreen(self)

        layout.addWidget(self.screen, 1, 0)
        layout.addWidget(self.cutX, 0, 0)
        layout.addWidget(self.cutY, 1, 1)

        layout.setColumnStretch(0, stretch_x)
        layout.setColumnStretch(1, 1)
        layout.setRowStretch(0, 1)
        layout.setRowStretch(1, stretch_y)

        self.setLayout(layout)

        self.updateGeometry()

        self.manager = PlotManager(self)
        self.manager.add_plot(self.screen.plot)
        self.manager.add_plot(self.cutX.plot)
        self.manager.add_plot(self.cutY.plot)

        #roi = ROISelectTool
        #bkgnd = BKGNDSelectTool

        self.tools = [tools.SelectTool, tools.RectZoomTool, tools.ColormapTool]

        self.manager.register_all_curve_tools()
Example #11
0
   def __init__(self): 
       super(RealtimeDemo, self).__init__() 
       self.setWindowTitle(u"Realtime Demo") 
 
       self.data = {u"t": array("d")}
       for name in sum(PLOT_DEFINE, []): 
           self.data[name] = array("d") 
 
       self.curves = {} 
       self.t = 0 
       vbox = QVBoxLayout() 
       vbox.addWidget(self.setup_toolbar()) 
       self.manager = PlotManager(self) 
       self.plots = [] 
       for i, define in enumerate(PLOT_DEFINE): 
           plot = CurvePlot() 
           plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(60) 
           self.manager.add_plot(plot) 
           self.plots.append(plot) 
           plot.plot_id = id(plot) 
           for j, curve_name in enumerate(define): 
               curve = self.curves[curve_name] = make.curve([0], [0], color=COLORS[j], title=curve_name) 
               plot.add_item(curve) 
           plot.add_item(make.legend("BL")) 
           vbox.addWidget(plot) 
       self.manager.register_standard_tools() 
       self.manager.get_default_tool().activate() 
       self.manager.synchronize_axis(CurvePlot.X_BOTTOM, self.manager.plots.keys()) 
       self.setLayout(vbox) 
       self.startTimer(100) 
Example #12
0
    def __init__(self, rangeSelectionCallback=None):
        super(RtPlotter, self).__init__("RT", "I")

        self.rangeSelectionCallback = rangeSelectionCallback

        widget = self.widget
        widget.plot.__class__ = RtPlot

        # todo: refactor as helper
        a = QwtScaleDraw()
        # render tic labels in modfied format:
        label = lambda self, v: QwtText(formatSeconds(v))
        a.label = new.instancemethod(label, widget.plot, QwtScaleDraw)
        widget.plot.setAxisScaleDraw(widget.plot.xBottom, a)

        self.pm = PlotManager(widget)
        self.pm.add_plot(widget.plot)

        t = self.pm.add_tool(RtSelectionTool)
        self.addTool(RtSelectionTool)
        self.pm.set_default_tool(t)

        marker = Marker(label_cb=self.widget.plot.label_info,
                        constraint_cb=self.widget.plot.on_plot)
        marker.rts = [0]
        setupStyleRtMarker(marker)
        marker.attach(self.widget.plot)
        self.marker = marker

        label = make.info_label("T", [RtCursorInfo(marker)], title=None)
        label.labelparam.label = ""
        self.label = label

        self.minRTRangeSelected = None
        self.maxRTRangeSelected = None
Example #13
0
    def __init__(self, wintitle):
        super(Window, self).__init__()
        self.default_tool = None
        self.plots = []
        self.itemlist = PlotItemList(None)
        self.contrast = ContrastAdjustment(None)
        self.xcsw = XCrossSection(None)
        self.ycsw = YCrossSection(None)
        
        self.manager = PlotManager(self)
        self.toolbar = QToolBar(_("Tools"), self)
        self.manager.add_toolbar(self.toolbar, "default")
        self.toolbar.setMovable(True)
        self.toolbar.setFloatable(True)
        self.addToolBar(Qt.TopToolBarArea, self.toolbar)

        frame = QFrame(self)
        self.setCentralWidget(frame)
        self.layout = QGridLayout()
        layout = QVBoxLayout(frame)
        frame.setLayout(layout)
        layout.addLayout(self.layout)
        self.frame = frame

        self.setWindowTitle(wintitle)
        self.setWindowIcon(get_icon('guiqwt.svg'))
Example #14
0
    def __setup_layout( self ):
        
        self.connect( self.button, QtCore.SIGNAL( 'clicked()' ), self.button_Click )
        self.connect( self.button2, QtCore.SIGNAL( 'clicked()' ), self.button_Click2 )
        self.connect( self.button3, QtCore.SIGNAL( 'clicked()' ), self.button_Click3 )
        self.connect( self.button4, QtCore.SIGNAL( 'clicked()' ), self.button_Click4 )
        self.connect( self.button5, QtCore.SIGNAL( 'clicked()' ), self.button_Click5 )
        self.connect( self.button6, QtCore.SIGNAL( 'clicked()' ), self.button_Click6 )
        
        # Vertical cursor
        self.cursorposition = 0.8
        self.cursorposition2 = 1.2
        self.vcursor1 = make.vcursor(self.cursorposition,  label='x = %.2f')
        self.plot.add_item( self.vcursor1 )
        self.vcursor2 = make.vcursor(self.cursorposition2,  label='x = %.2f')
        self.plot.add_item( self.vcursor2 )

        # Define the y label, x might change depending on user definition
        CurvePlot.set_axis_title(self.plot,CurvePlot.Y_LEFT,"Intensity (counts)")

        # Crate the PlotManager
        self.manager = PlotManager( self )
        self.manager.add_plot( self.plot )
        self.manager.add_plot( self.plot2 )

        # Create Toolbar
        toolbar = self.addToolBar( 'tools' )
        self.manager.add_toolbar( toolbar, id( toolbar ) )

        # Register the ToolBar's type
        self.manager.register_all_curve_tools( )
#        self.manager.register_other_tools()

        # Register a custom tool
        self.manager.add_tool( SelectPointTool, title = 'Position', on_active_item = True, mode = 'create' )
Example #15
0
	def __initLayout(self):
		# layout
		layout = QGridLayout()
		central_widget = QWidget(self)
		central_widget.setLayout(layout)
		self.setCentralWidget(central_widget)
		
		# create plot manager
		self.__p_manager = PlotManager(self)
		
		# toolbar
		if (self.__p_toolbar):
			self.__p_toolbar.clear()
		else:
			self.__p_toolbar = self.addToolBar("tools")
		# end if
		
		# resize button
		icon = QIcon("icons/center.png")
		button = QToolButton()
		button.setIcon(icon)
		button.setToolTip("Resize")
		self.connect(button, SIGNAL("clicked()"), self.__onAutoScale)
		
		self.__p_manager.add_toolbar(self.__p_toolbar, id(self.__p_toolbar))
		self.__p_toolbar.addWidget(button)
		self.__v_wasInitialized = True
Example #16
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle(self.__doc__)
        self.setWindowIcon(get_icon("guiqwt.svg"))

        self.manager = manager = PlotManager(None)
        manager.set_main(self)
        self.subplotwidget = spwidget = SubplotWidget(manager, parent=self)
        self.setLayout(QW.QVBoxLayout())
        toolbar = QW.QToolBar(_("Tools"))
        manager.add_toolbar(toolbar)
        self.layout().addWidget(toolbar)
        self.layout().addWidget(spwidget)

        plot1 = CurvePlot(title="TL")
        plot2 = CurvePlot(title="TR")
        plot3 = CurvePlot(title="BL")
        plot4 = CurvePlot(title="BR")
        spwidget.add_subplot(plot1, 0, 0, "1")
        spwidget.add_subplot(plot2, 0, 1, "2")
        spwidget.add_subplot(plot3, 1, 0, "3")
        spwidget.add_subplot(plot4, 1, 1, "4")
        spwidget.add_itemlist()
        manager.synchronize_axis(BasePlot.X_BOTTOM, ["1", "3"])
        manager.synchronize_axis(BasePlot.X_BOTTOM, ["2", "4"])
        manager.synchronize_axis(BasePlot.Y_LEFT, ["1", "2"])
        manager.synchronize_axis(BasePlot.Y_LEFT, ["3", "4"])

        self.manager.register_all_curve_tools()
Example #17
0
    def __init__(self, wintitle='Plot window', major_grid=True,
                 minor_grid=False, toolbar=True,  parent=None,
                 panels=None, min_plot_width=100, min_plot_height=75):
        QDialog.__init__(self, parent)
        self.setWindowFlags(Qt.Window)

        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(':/Application/Main')),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.setWindowIcon(icon)

        self.major_grid = major_grid
        self.minor_grid = minor_grid
        self.min_plot_width = min_plot_width
        self.min_plot_height = min_plot_height

        # WidgetMixin copy
        PlotManager.__init__(self, main=self)
        
        self.main_layout = QVBoxLayout(self)
        self.color_layout = QHBoxLayout()
        self.plot_layout = QGridLayout()
        self.plot_layout.setMargin(0)
        self.plot_scroll_widget = QWidget()
        self.plot_scroll_area = QScrollArea()
        self.plot_scroll_area.setFrameShape(QFrame.NoFrame)
        self.plot_scroll_area.setWidgetResizable(True)
        self.option_layout = QHBoxLayout()

        self.plot_widget = None

        if panels is not None:
            for panel in panels:
                self.add_panel(panel)

        self.toolbar = QToolBar('Tools')
        if not toolbar:
            self.toolbar.hide()

        # Configuring widget layout
        self._setup_widget_properties(wintitle=wintitle, icon=icon)
        self._setup_widget_layout()
        
        # Options
        self.option_callbacks = {}
        self.legend = None
        self.axis_syncplots = {}
Example #18
0
    def __init__(self, c_callback=None):
        super(MzPlotter, self).__init__("m/z", "I")

        self.c_callback = c_callback

        widget = self.widget

        # inject mofified behaviour of wigets plot attribute:
        widget.plot.__class__ = MzPlot
        widget.plot.register_c_callback(self.handle_c_pressed)
        self.setHalfWindowWidth(0.05)
        self.centralMz = None

        # todo: refactor as helper
        a = QwtScaleDraw()
        label = lambda self, x : QwtText("%s" % x)
        a.label = new.instancemethod(label, widget.plot, QwtScaleDraw)
        widget.plot.setAxisScaleDraw(widget.plot.xBottom, a)

        self.pm = PlotManager(widget)
        self.pm.add_plot(widget.plot)
        self.curve = make.curve([], [], color='b', curvestyle="Sticks")
        # inject modified behaviour:
        self.curve.__class__ = ModifiedCurveItem

        self.widget.plot.add_item(self.curve)

        t = self.pm.add_tool(MzSelectionTool)
        self.pm.set_default_tool(t)
        t.activate()

        marker = Marker(label_cb=widget.plot.label_info,\
                        constraint_cb=widget.plot.on_plot)
        marker.attach(self.widget.plot)

        line   = make.segment(0, 0, 0, 0)
        line.__class__ = ModifiedSegment
        line.setVisible(0)

        setupCommonStyle(line, marker)

        label = make.info_label("TR", [MzCursorInfo(marker, line)], title=None)
        label.labelparam.label = ""

        self.marker = marker
        self.label = label
        self.line = line
Example #19
0
 def __init__(self):
     super(SyncXAxis, self).__init__()
     
     self.data = {u"t":array("d")} 
     for name in sum(PLOT_DEFINE, []): 
         self.data[name] = array("d") 
     
     self.i = 0
     self.x = []
     self.curves = {} 
     self.t = 0
     self.sint = []
     self.get_Roll = []
     self.get_Pitch = []
     self.get_Yaw = []
     self.get_Angle1 = []
     self.get_Angle2 =[]
     self.get_Angle3 = []
     vbox = QtGui.QGridLayout()
     #工具栏
     vbox.addLayout(self.setup_toolbar(),0,0) 
     self.manager = PlotManager(self)
     self.plots = []
     #生成竖直排列图形窗口
     for i, define in enumerate(PLOT_DEFINE): 
         plot = CurvePlot() 
         plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(60) 
         self.manager.add_plot(plot) 
         self.plots.append(plot) 
         plot.plot_id = id(plot) 
         for j, curve_name in enumerate(define): 
             curve = self.curves[curve_name] = make.curve([0], [0], color=COLORS[j], title=curve_name) 
             plot.add_item(curve) 
         plot.add_item(make.legend("BL")) 
         #vbox.addWidget(plot)
     vbox.addWidget(self.plots[0],1,0)
     vbox.addWidget(self.plots[1],1,1)
     vbox.addWidget(self.plots[2],2,0)
     vbox.addWidget(self.plots[3],2,1)
     
     self.manager.register_standard_tools()
     self.manager.get_default_tool().activate()
     self.manager.synchronize_axis(CurvePlot.X_BOTTOM, self.manager.plots.keys()) 
     self.setLayout(vbox)
     
     self.startTimer(20) 
Example #20
0
    def __init__(self, parent=None, x=[], y=[], data=[]):
        QWidget.__init__(self, parent)

        if len(x) < 2:
            x = np.linspace(0, 1392, 1392)
            y = np.linspace(0, 1040, 1040)
            data = np.zeros((1040, 1392))

        self.x = x
        self.y = y
        self.data = data

        layout = QGridLayout(self)
        '''
        self.screen = ImageScreen(self,x,y,data,int(self.sizex*5.0/6.0),int(self.sizey*5.0/6.0))       
        self.cutX = CutScreen(self,sizex=int(self.sizex*5.0/6.0),sizey=int(self.sizey*1.0/6.0))       
        self.cutY = CutScreen(self,sizex=int(self.sizex*1.0/6.0),sizey=int(self.sizey*5.0/6.0))
        '''

        sx = 500
        sy = int(sx / 1.338)
        a = 0.2

        self.screen = ImageScreen(self, x, y, data, sizex=sx, sizey=sy)
        self.cutX = CutScreen(self, sizex=sx, sizey=int(a * sy))
        self.cutY = CutScreen(self, sizex=int(a * sx), sizey=sy)

        layout.addWidget(self.screen, 1, 0)
        layout.addWidget(self.cutX, 0, 0)
        layout.addWidget(self.cutY, 1, 1)

        self.setLayout(layout)

        self.updateGeometry()

        self.manager = PlotManager(self)
        self.manager.add_plot(self.screen.plot)
        self.manager.add_plot(self.cutX.plot)
        self.manager.add_plot(self.cutY.plot)

        roi = RegionSelectTool
        self.tools = [
            tools.SelectTool, tools.RectZoomTool, roi, tools.ColormapTool
        ]
        self.manager.register_all_curve_tools()
    def __init__(self, parent=None):
        super(MzPlottingWidget, self).__init__(parent, xlabel="mz", ylabel="I")

        patch_inner_plot_object(self, MzPlot)
        self.plot.centralMz = None

        def label(self, x):
            # label with full precision:
            return QwtText(str(x))

        a = QwtScaleDraw()
        a.label = new.instancemethod(label, self.plot, QwtScaleDraw)
        self.plot.setAxisScaleDraw(self.plot.xBottom, a)

        self.pm = PlotManager(self)
        self.pm.add_plot(self.plot)
        self.curve = make_unselectable_curve([], [],
                                             color="b",
                                             curvestyle="Sticks")

        self.plot.add_item(self.curve)

        t = self.pm.add_tool(MzSelectionTool)
        self.pm.set_default_tool(t)
        t.activate()

        marker = Marker(label_cb=self.plot.label_info,
                        constraint_cb=self.plot.on_plot)
        marker.attach(self.plot)

        line = make_measurement_line()
        line.setVisible(0)

        setupCommonStyle(line, marker)
        line.shapeparam.line.color = "#555555"
        line.shapeparam.update_shape(line)

        label = make.info_label("TR", [MzCursorInfo(marker, line)], title=None)
        label.labelparam.label = ""
        label.labelparam.font.size = 12
        label.labelparam.update_label(label)

        self.marker = marker
        self.label = label
        self.line = line
Example #22
0
 def __init__(self):
     qg.QMainWindow.__init__(self)
     self.setWindowTitle("Neuron Database")
     self.setWindowIcon(get_icon('guiqwt.png'))
     self.setAttribute(qc.Qt.WA_DeleteOnClose,True)
     
     hlayout = qg.QHBoxLayout()
     central_widget = qg.QWidget(self)
     central_widget.setLayout(hlayout)
     self.setCentralWidget(central_widget)
     #---guiqwt plot manager
     self.manager = PlotManager(self)
     #---
     self.add_plot("1")
     
     self._constructFileMenu()
     self._constructEditMenu()
     self._constructConsoleWidget(central_widget)
Example #23
0
    def __init__(self, parent=None):
        super(ContrastAdjustment, self).__init__(parent)

        self.local_manager = None  # local manager for the histogram plot
        self.manager = None  # manager for the associated image plot

        # Storing min/max markers for each active image
        self.min_markers = {}
        self.max_markers = {}

        # Select point tools
        self.min_select_tool = None
        self.max_select_tool = None

        style = "<span style='color: #444444'><b>%s</b></span>"
        layout, _label = get_image_layout(self.PANEL_ICON,
                                          style % self.PANEL_TITLE,
                                          alignment=Qt.AlignCenter)
        layout.setAlignment(Qt.AlignCenter)
        vlayout = QVBoxLayout()
        vlayout.addLayout(layout)
        self.local_manager = PlotManager(self)
        self.histogram = LevelsHistogram(parent)
        vlayout.addWidget(self.histogram)
        self.local_manager.add_plot(self.histogram)
        hlayout = QHBoxLayout()
        self.setLayout(hlayout)
        hlayout.addLayout(vlayout)

        self.toolbar = toolbar = QToolBar(self)
        toolbar.setOrientation(Qt.Vertical)
        #        toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        hlayout.addWidget(toolbar)

        # Add standard plot-related tools to the local manager
        lman = self.local_manager
        lman.add_tool(SelectTool)
        lman.add_tool(BasePlotMenuTool, "item")
        lman.add_tool(BasePlotMenuTool, "axes")
        lman.add_tool(BasePlotMenuTool, "grid")
        lman.add_tool(AntiAliasingTool)
        lman.get_default_tool().activate()

        self.outliers_param = EliminateOutliersParam(self.PANEL_TITLE)
Example #24
0
    def synchronize_axis(self, axis, plots=None):
        if plots is None:
            if axis in self.axis_syncplots:
                plots = self.axis_syncplots[axis]
            else:
                plots = self.plots.keys()
        if len(plots) < 1:
            return

        PlotManager.synchronize_axis(self, axis, plots)

        # Find interval that needs to be shown in order to include all
        # currently shown parts in the synchronized plots
        plot_objects = [self.plots[p] for p in plots]
        lb = min((p.axisScaleDiv(axis).lowerBound() for p in plot_objects))
        ub = max((p.axisScaleDiv(axis).upperBound() for p in plot_objects))
        for p in plot_objects:
            p.setAxisScale(axis, lb, ub)
            p.replot()
Example #25
0
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowTitle("iScope (TM)")

        hlayout = QHBoxLayout()
        central_widget = QWidget(self)
        central_widget.setLayout(hlayout)
        self.setCentralWidget(central_widget)
        # ---guiqwt plot manager
        self.manager = PlotManager(self)
Example #26
0
    def synchronize_axis(self, axis, plots=None):
        if plots is None:
            if axis in self.axis_syncplots:
                plots = self.axis_syncplots[axis]
            else:
                plots = self.plots.keys()
        if len(plots) < 1:
            return

        PlotManager.synchronize_axis(self, axis, plots)

        # Find interval that needs to be shown in order to include all
        # currently shown parts in the synchronized plots
        plot_objects = [self.plots[p] for p in plots]
        lb = min((p.axisScaleDiv(axis).lowerBound() for p in plot_objects))
        ub = max((p.axisScaleDiv(axis).upperBound() for p in plot_objects))
        for p in plot_objects:
            p.setAxisScale(axis, lb, ub)
            p.replot()
Example #27
0
 def __init__(self):
     QMainWindow.__init__(self)
     self.setWindowTitle("Signal filtering 2 (guiqwt)")
     self.setWindowIcon(get_icon('guiqwt.svg'))
     
     hlayout = QHBoxLayout()
     central_widget = QWidget(self)
     central_widget.setLayout(hlayout)
     self.setCentralWidget(central_widget)
     #---guiqwt plot manager
     self.manager = PlotManager(self)
Example #28
0
    def __init__(self, parent):
        QWidget.__init__(self, parent)

        layout = QGridLayout()
        self.setLayout(layout)

        self.plot1 = ImagePlot(self)
        layout.addWidget(self.plot1, 0, 0, 1, 1)
        self.plot2 = ImagePlot(self)
        layout.addWidget(self.plot2, 1, 0, 1, 1)

        self.contrast = ContrastAdjustment(self)
        layout.addWidget(self.contrast, 2, 0, 1, 2)
        self.itemlist = PlotItemList(self)
        layout.addWidget(self.itemlist, 0, 1, 2, 1)

        self.manager = PlotManager(self)
        for plot in (self.plot1, self.plot2):
            self.manager.add_plot(plot)
        for panel in (self.itemlist, self.contrast):
            self.manager.add_panel(panel)
Example #29
0
    def _setup_plot(self):
        self.pm = PlotManager(self)
        self.pm.add_plot(self.plot)

        t = self.pm.add_tool(RtSelectionTool)
        t.activate()
        self.pm.set_default_tool(t)

        self._setup_cursor()
        self._setup_range_selector()
        self._setup_label()
        self._setup_axes()
Example #30
0
    def configure_plot(self):

        self.marker = add_marker(self.plot)
        self.line = MeasurementLine()
        self.line.setVisible(0)
        self.label = make_label(self.marker, self.line)

        setupCommonStyle(self.line, self.marker)

        manager = PlotManager(self.widget)
        manager.add_plot(self.plot)

        tool = manager.add_tool(MzSelectionTool)
        tool.activate()
        manager.set_default_tool(tool)

        self.plot.add_item(self.marker)
        self.plot.add_item(self.label)
        self.plot.add_item(self.line)

        self.plot.startMeasuring.connect(self.line.start_measuring)
        self.plot.moveMeasuring.connect(self.line.move_measuring)
        self.plot.stopMeasuring.connect(self.line.stop_measuring)
        self.plot.moveMarker.connect(self.marker.move_local_point_to)
        self.line.updated.connect(self.plot.replot)
Example #31
0
class CentralWidget(QWidget):
    def __init__(self, parent):
        QWidget.__init__(self, parent)

        layout = QGridLayout()
        self.setLayout(layout)

        self.plot1 = ImagePlot(self)
        layout.addWidget(self.plot1, 0, 0, 1, 1)
        self.plot2 = ImagePlot(self)
        layout.addWidget(self.plot2, 1, 0, 1, 1)

        self.contrast = ContrastAdjustment(self)
        layout.addWidget(self.contrast, 2, 0, 1, 2)
        self.itemlist = PlotItemList(self)
        layout.addWidget(self.itemlist, 0, 1, 2, 1)

        self.manager = PlotManager(self)
        for plot in (self.plot1, self.plot2):
            self.manager.add_plot(plot)
        for panel in (self.itemlist, self.contrast):
            self.manager.add_panel(panel)

    def register_tools(self):
        self.manager.register_all_image_tools()
Example #32
0
class iScope(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowTitle("iScope (TM)")

        hlayout = QHBoxLayout()
        central_widget = QWidget(self)
        central_widget.setLayout(hlayout)
        self.setCentralWidget(central_widget)
        # ---guiqwt plot manager
        self.manager = PlotManager(self)
        # ---

    def add_plot(self, x, y):
        widget = iScopeWidget(self, x, y)
        widget.setup_widget()
        self.centralWidget().layout().addWidget(widget)
        # ---Register plot to manager
        self.manager.add_plot(widget.plot)
        # ---

    def setup_window(self):
        # ---Add toolbar and register manager tools
        toolbar = self.addToolBar("tools")
        self.manager.add_toolbar(toolbar, id(toolbar))
        self.manager.register_standard_tools()
        self.manager.tools[0].activate()
Example #33
0
class TestWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowTitle("Signal filtering 2 (guiqwt)")
        self.setWindowIcon(get_icon('guiqwt.svg'))
        
        hlayout = QHBoxLayout()
        central_widget = QWidget(self)
        central_widget.setLayout(hlayout)
        self.setCentralWidget(central_widget)
        #---guiqwt plot manager
        self.manager = PlotManager(self)
        #---
        
    def add_plot(self, x, y, func, title):
        widget = FilterTestWidget(self, x, y, func)
        widget.setup_widget(title)
        self.centralWidget().layout().addWidget(widget)
        #---Register plot to manager
        self.manager.add_plot(widget.plot)
        #---
        
    def setup_window(self):
        #---Add toolbar and register manager tools
        toolbar = self.addToolBar("tools")
        self.manager.add_toolbar(toolbar, id(toolbar))
        self.manager.register_all_curve_tools()
Example #34
0
class TestWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowTitle("Signal filtering 2 (guiqwt)")
        self.setWindowIcon(get_icon('guiqwt.svg'))

        hlayout = QHBoxLayout()
        central_widget = QWidget(self)
        central_widget.setLayout(hlayout)
        self.setCentralWidget(central_widget)
        #---guiqwt plot manager
        self.manager = PlotManager(self)
        #---

    def add_plot(self, x, y, func, title):
        widget = FilterTestWidget(self, x, y, func)
        widget.setup_widget(title)
        self.centralWidget().layout().addWidget(widget)
        #---Register plot to manager
        self.manager.add_plot(widget.plot)
        #---

    def setup_window(self):
        #---Add toolbar and register manager tools
        toolbar = self.addToolBar("tools")
        self.manager.add_toolbar(toolbar, id(toolbar))
        self.manager.register_all_curve_tools()
Example #35
0
class TestDialog(QDialog):
    def __init__(self):
        QDialog.__init__(self)
        vlayout = QVBoxLayout()
        self.setLayout(vlayout)
        self.widget = CurveWidget()
        self.curve_item = make.curve([], [], color='r')
        self.widget.plot.add_item(self.curve_item)
        self.pm = PlotManager(self.widget)
        self.pm.add_plot(self.widget.plot)
        t = self.pm.add_tool(MyTool)
        t.curve_item = self.curve_item
        self.pm.set_default_tool(t)
        t.activate()
        self.layout().addWidget(self.widget)
        self.update_curve()

    def update_curve(self):
        x = np.arange(0,10,.1)
        y = np.sin(np.sin(x))
        self.curve_item.set_data(x, y)
        self.curve_item.plot().replot()
Example #36
0
    def __init__(self, rangeSelectionCallback = None):
        super(RtPlotter, self).__init__("RT", "I")

        self.rangeSelectionCallback = rangeSelectionCallback

        widget = self.widget
        widget.plot.__class__ = RtPlot

        # todo: refactor as helper
        a = QwtScaleDraw()
        # render tic labels in modfied format:
        label = lambda self, v: QwtText(formatSeconds(v))
        a.label = new.instancemethod(label, widget.plot, QwtScaleDraw)
        widget.plot.setAxisScaleDraw(widget.plot.xBottom, a)

        #a.label = new.instancemethod(label, widget.plot, QwtScaleDraw)

        self.pm = PlotManager(widget)
        self.pm.add_plot(widget.plot)

        t = self.pm.add_tool(RtSelectionTool)
        self.addTool(RtSelectionTool)
        self.pm.set_default_tool(t)

        marker = Marker(label_cb=self.widget.plot.label_info,\
                        constraint_cb=self.widget.plot.on_plot)
        marker.rts = [0]
        setupStyleRtMarker(marker)
        marker.attach(self.widget.plot)
        self.marker = marker

        label = make.info_label("T", [RtCursorInfo(marker)], title=None)
        label.labelparam.label = ""
        self.label=label

        self.minRTRangeSelected = None
        self.maxRTRangeSelected = None
Example #37
0
 def __init__(self):
     QDialog.__init__(self)
     vlayout = QVBoxLayout()
     self.setLayout(vlayout)
     self.widget = CurveWidget()
     self.curve_item = make.curve([], [], color='r')
     self.widget.plot.add_item(self.curve_item)
     self.pm = PlotManager(self.widget)
     self.pm.add_plot(self.widget.plot)
     t = self.pm.add_tool(MyTool)
     t.curve_item = self.curve_item
     self.pm.set_default_tool(t)
     t.activate()
     self.layout().addWidget(self.widget)
     self.update_curve()
Example #38
0
    def __init__(self, c_callback=None, image_plot=None):
        super(MzPlotter, self).__init__("m/z", "I")

        self.c_callback = c_callback

        widget = self.widget

        # inject mofified behaviour of wigets plot attribute:
        widget.plot.__class__ = MzPlot
        widget.plot.register_c_callback(self.handle_c_pressed)
        widget.plot.image_plot = image_plot
        self.setHalfWindowWidth(0.05)
        self.centralMz = None

        # todo: refactor as helper
        a = QwtScaleDraw()
        label = lambda self, x: QwtText("%s" % x)
        a.label = new.instancemethod(label, widget.plot, QwtScaleDraw)
        widget.plot.setAxisScaleDraw(widget.plot.xBottom, a)

        self.pm = PlotManager(widget)
        self.pm.add_plot(widget.plot)
        self.curve = make.curve([], [], color='b', curvestyle="Sticks")
        # inject modified behaviour:
        self.curve.__class__ = ModifiedCurveItem

        self.widget.plot.add_item(self.curve)

        t = self.pm.add_tool(MzSelectionTool)
        self.pm.set_default_tool(t)
        t.activate()

        marker = Marker(label_cb=widget.plot.label_info,
                        constraint_cb=widget.plot.on_plot)
        marker.attach(self.widget.plot)

        line = make.segment(0, 0, 0, 0)
        line.__class__ = ModifiedSegment
        line.setVisible(0)

        setupCommonStyle(line, marker)

        label = make.info_label("TR", [MzCursorInfo(marker, line)], title=None)
        label.labelparam.label = ""

        self.marker = marker
        self.label = label
        self.line = line
Example #39
0
    def loadDialog(self):
        filename = QtGui.QFileDialog.getOpenFileName(self.Form, 'Open File', '.')
        fname = open(filename)
        data = fname.read()
        #self.le.setText(filename)
        do = pandas.read_csv(str(filename), delimiter=",")
        #data = pd.read_csv('C:/Users/se00075/PycharmProjects/Test2/src' + '/' + 'data.csv')
        if (self.startD.text().isEmpty()) & (self.endD.text().isEmpty()):
            d=do
        else:
            do['time_stamp'] = do['time_stamp'].astype('datetime64[ns]')
            st = int(self.startD.text())
            en = int(self.endD.text())
            select = (do['time_stamp'] >= do.time_stamp[0]+datetime.timedelta(days=st-1)) & (do['time_stamp'] < do.time_stamp[0]+datetime.timedelta(days=en))
            d = do[select]
            #d = pandas.read_csv(str(filename), delimiter=",")
            #print d
        ##Lets add clean missing data here

        space = 0
        self.checkboxes = []
        for i in d.columns:
            c = QtGui.QCheckBox(self.Form)
            #print space
            c.setGeometry(QtCore.QRect(10 + space, 50, 70, 17))
            c.setText(_fromUtf8(i))
            c.show()
            c.clicked.connect(self.selected)
            self.checkboxes.append(c)
            space += 68
        self.original_data = d
       #self.original_data=(self.original_data-self.original_data.mean()) / self.original_data.std()

        self.dialog = CurveDialog(edit=False, toolbar=False, parent=self.widget)
        self.plot = self.dialog.get_plot()
        self.plot.set_antialiasing(True)
        self.plot.setAxisTitle(Qwt5.Qwt.QwtPlot.xBottom, 'Time')
        self.plot.setAxisTitle(Qwt5.Qwt.QwtPlot.yLeft, 'Value')
        self.manager = PlotManager(self)
        self.manager.add_plot(self.plot)
        legend = make.legend('TL')
        self.plot.add_item(legend)
        ly = QtGui.QVBoxLayout()
        ly.addWidget(self.plot)
        self.widget.setLayout(ly)
        self.widget.show()
        self.Form.update()
        self.Form.repaint()
Example #40
0
    def create_plot(self, options):
        manager = PlotManager(None)
        self.plotwidget = CurveWidget(self, manager=manager, **options)
        manager.set_main(self.plotwidget)
        plot1 = CurvePlot(title="TL")
        plot2 = CurvePlot(title="TR")
        plot3 = CurvePlot(title="BL")
        plot4 = CurvePlot(title="BR")
        self.plotwidget.add_plot(plot1, 0, 0, "1")
        self.plotwidget.add_plot(plot2, 0, 1, "2")
        self.plotwidget.add_plot(plot3, 1, 0, "3")
        self.plotwidget.add_plot(plot4, 1, 1, "4")
        self.plotwidget.finalize()
        manager.synchronize_axis(BasePlot.X_BOTTOM, ["1", "3"])
        manager.synchronize_axis(BasePlot.X_BOTTOM, ["2", "4"])
        manager.synchronize_axis(BasePlot.Y_LEFT, ["1", "2"])
        manager.synchronize_axis(BasePlot.Y_LEFT, ["3", "4"])

        self.layout.addWidget(self.plotwidget, 0, 0)
Example #41
0
    def __init__(self, parent=None):
        super(ContrastAdjustment, self).__init__(parent)
        
        self.local_manager = None # local manager for the histogram plot
        self.manager = None # manager for the associated image plot
        
        # Storing min/max markers for each active image
        self.min_markers = {}
        self.max_markers = {}
        
        # Select point tools
        self.min_select_tool = None
        self.max_select_tool = None
        
        style = "<span style=\'color: #444444\'><b>%s</b></span>"
        layout, _label = get_image_layout(self.PANEL_ICON,
                                          style % self.PANEL_TITLE,
                                          alignment=Qt.AlignCenter)
        layout.setAlignment(Qt.AlignCenter)
        vlayout = QVBoxLayout()
        vlayout.addLayout(layout)
        self.local_manager = PlotManager(self)
        self.histogram = LevelsHistogram(parent)
        vlayout.addWidget(self.histogram)
        self.local_manager.add_plot(self.histogram)
        hlayout = QHBoxLayout()
        self.setLayout(hlayout)
        hlayout.addLayout(vlayout)
        
        self.toolbar = toolbar = QToolBar(self)
        toolbar.setOrientation(Qt.Vertical)
#        toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        hlayout.addWidget(toolbar)
        
        # Add standard plot-related tools to the local manager
        lman = self.local_manager
        lman.add_tool(SelectTool)
        lman.add_tool(BasePlotMenuTool, "item")
        lman.add_tool(BasePlotMenuTool, "axes")
        lman.add_tool(BasePlotMenuTool, "grid")
        lman.add_tool(AntiAliasingTool)
        lman.get_default_tool().activate()
        
        self.outliers_param = EliminateOutliersParam(self.PANEL_TITLE)
Example #42
0
def Plot_Start_New(widget,PLOT_DEFINE,COLORS,x1,x2,y1,y2):
    newmanager = PlotManager(widget)
    newplots = []
    newcurves = {}
    for name in PLOT_DEFINE:
            plot = CurvePlot()
            #设置图表颜色
            plot.setStyleSheet('''QWidget{   
                                                                border: 1px solid #32435E;   
                                                                border-radius: 3px;   
                                                                font-size:11pt;   
                                                                color:white;   
                                                                font-family:"Microsoft YaHei UI";  
                                                                /* padding: 0 8px; */  
                                                                background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,   
                                                                                             stop: 0 #080B10,   
                                                                                             stop: 1.0 #212C3F);   
                                                                selection-background-color: #0A246A;   
                                                            } '''  
                                         )
            plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(20)
            newplots.append(plot)
            newmanager.add_plot(plot)
            plot.plot_id = id(plot)
            for curve_color, curve_name in map(None,COLORS,name):
                if  u"状态" in curve_name or  u"打角/100" in curve_name :
                    newcurves[curve_name] = guiqwt_make.curve([0], [0],markerfacecolor = 'black', markeredgecolor=curve_color, title=curve_name,marker = 'Diamond',linestyle = 'NoPen',markersize = 6)
                else:    
                    newcurves[curve_name] = guiqwt_make.curve([0], [0], color=curve_color, title=curve_name)
                
                plot.add_item(newcurves[curve_name])
            #设置X轴y轴
            plot.set_axis_limits(newcurves[curve_name].yAxis(),y1,y2)
            plot.set_axis_limits(newcurves[curve_name].xAxis(),x1,x2)
            plot.add_item(guiqwt_make.legend("BL"))
            
    
    newmanager.register_standard_tools()
    newmanager.get_default_tool().activate()
    return (newmanager,newplots,newcurves)
Example #43
0
    def __init__(self, parent=None):
        super(MzPlottingWidget, self).__init__(parent, xlabel="mz", ylabel="I")

        patch_inner_plot_object(self, MzPlot)
        self.plot.centralMz = None

        def label(self, x):
            # label with full precision:
            return QwtText(str(x))

        a = QwtScaleDraw()
        a.label = new.instancemethod(label, self.plot, QwtScaleDraw)
        self.plot.setAxisScaleDraw(self.plot.xBottom, a)

        self.pm = PlotManager(self)
        self.pm.add_plot(self.plot)
        self.curve = make_unselectable_curve([], [], color="b", curvestyle="Sticks")

        self.plot.add_item(self.curve)

        t = self.pm.add_tool(MzSelectionTool)
        self.pm.set_default_tool(t)
        t.activate()

        marker = Marker(label_cb=self.plot.label_info, constraint_cb=self.plot.on_plot)
        marker.attach(self.plot)

        line = make_measurement_line()
        line.setVisible(0)

        setupCommonStyle(line, marker)
        line.shapeparam.line.color = "#555555"
        line.shapeparam.update_shape(line)

        label = make.info_label("TR", [MzCursorInfo(marker, line)], title=None)
        label.labelparam.label = ""
        label.labelparam.font.size = 12
        label.labelparam.update_label(label)

        self.marker = marker
        self.label = label
        self.line = line
    def setupUi(self):
        """loads numpy array

        Args:
            self

        Returns:
            nothing
        """
        #self.plot = CurvePlot(self)
        self.dialog = CurveDialog(edit=False, toolbar=True, parent=self)
        self.plot = self.dialog.get_plot()
        self.plot.set_antialiasing(True)

        #x = np.linspace(-10,10,200)
        #dy = x/100.
        #y = np.sin(np.sin(np.sin(x)))
        #self.plot.add_item(make.curve(x,y))

        self.loadButton = QtGui.QPushButton("Load")
        self.trainButton = QtGui.QPushButton("Train Model")

        ly = QtGui.QVBoxLayout()
        ly.addWidget(self.plot)
        #ly.addWidget(self.loadButton)
        #ly.addWidget(self.trainButton)

        self.plot.setAxisTitle(Qwt5.Qwt.QwtPlot.xBottom, 'Time')
        self.plot.setAxisTitle(Qwt5.Qwt.QwtPlot.yLeft, 'Value')



        self.manager = PlotManager(self)
        self.manager.add_plot(self.plot)
        #self.manager.
        legend = make.legend('TL')
        self.plot.add_item(legend)

        self.setLayout(ly)
        self.move(300, 200)
        self.show()
        self.dataController = DataController.DataController()
Example #45
0
    def __init__(self, parent=None):
        super(CrossSectionWidget, self).__init__(parent)

        self.export_ac = None
        self.autoscale_ac = None
        self.refresh_ac = None
        self.autorefresh_ac = None

        self.manager = None  # manager for the associated image plot

        self.local_manager = PlotManager(self)
        self.cs_plot = self.CrossSectionPlotKlass(parent)
        self.cs_plot.SIG_CS_CURVE_CHANGED.connect(self.cs_curve_has_changed)
        self.export_tool = None
        self.setup_plot()

        self.toolbar = QToolBar(self)
        self.toolbar.setOrientation(Qt.Vertical)

        self.setup_widget()
Example #46
0
    def configure_plot(self):

        set_x_axis_scale_draw(self.widget)
        manager = PlotManager(self.widget)
        manager.add_plot(self.plot)

        tool = manager.add_tool(RtSelectionTool)
        tool.activate()
        manager.set_default_tool(tool)

        self.marker = add_marker(self.plot)
        setupStyleRtMarker(self.marker)
        self.marker.rts = (0, )
        self.plot.moveMarker.connect(self.marker.move_local_point_to)
        self.plot.moveMarker.connect(self.move_rt_cursor)
Example #47
0
 def create_plot(self, options):
     manager = PlotManager(None)
     self.plotwidget = CurveWidget(self, manager=manager, **options)
     manager.set_main(self.plotwidget)
     plot1 = CurvePlot(title="TL")
     plot2 = CurvePlot(title="TR")
     plot3 = CurvePlot(title="BL")
     plot4 = CurvePlot(title="BR")
     self.plotwidget.add_plot(plot1, 0, 0, "1")
     self.plotwidget.add_plot(plot2, 0, 1, "2")
     self.plotwidget.add_plot(plot3, 1, 0, "3")
     self.plotwidget.add_plot(plot4, 1, 1, "4")
     self.plotwidget.finalize()
     manager.synchronize_axis(BasePlot.X_BOTTOM, ["1", "3"])
     manager.synchronize_axis(BasePlot.X_BOTTOM, ["2", "4"])
     manager.synchronize_axis(BasePlot.Y_LEFT,   ["1", "2"])
     manager.synchronize_axis(BasePlot.Y_LEFT,   ["3", "4"])
     
     self.layout.addWidget(self.plotwidget, 0, 0)
Example #48
0
	def __init__(self, parent, signal_names, sample_rate):
		'''Do the initialization work.
		A PlottingHelper object helps plotting a group of signals all of which 
		has the same number of points to plot at one time.
		signal_names: 
			a dictionary {'list_name':['list of signal names']}
		sample_rate:
			the sample_rate of the signals
		'''

		self.sample_rate = sample_rate
		self.signal_names = signal_names
		self.curve_items = {}
		self.curve_plots = {}
		self.plot_manager = PlotManager(parent)

		for list_name, sig_name_list in self.signal_names.items():
			# One CurvePlot object for every sig_name_list
			curve_plot = CurvePlot()
			curve_plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(10)
			self.curve_plots[list_name] = curve_plot
			curve_plot.plot_id = id(curve_plot)
			for i, sig_name in enumerate(sig_name_list):
				# One CurveItem object for every signal_name 
				print sig_name, colors[i]
				self.curve_items[sig_name] = make.curve([0], [0], \
					color=colors[i], title=sig_name)
				curve_plot.add_item(self.curve_items[sig_name])

			# add the curve_plot object to plot_manager
			self.plot_manager.add_plot(curve_plot) 

		# register and activate the tools 
		self.plot_manager.register_standard_tools()
		self.plot_manager.get_default_tool().activate()
		self.plot_manager.synchronize_axis(CurvePlot.X_BOTTOM, \
									self.plot_manager.plots.keys())
Example #49
0
    def __init__(self,parent=None):
    
        QtGui.QMainWindow.__init__(self, parent)
        self.setupUi(self) # Ui_Form.setupUi
        '''
        #最小化&关闭
        self.minibutton = QtGui.QToolButton(self)
        self.minibutton.setGeometry(self.width()-45,5,20,20)
        self.closebutton = QtGui.QToolButton(self)
        self.closebutton.setGeometry(self.width()-25,5,20,20)
        '''

        #加入设置窗口
        #setting_ui  = UI_Settings()
        #self.setting = QtGui.QWidget()
        #setting_ui.setupUi(self.setting)
        
        #新建窗口
        self.ShowData = []
        self.SD_data = []
        #打开的窗体
        self.open_widget = []
        #显示文件的路径
        self.ShowDataFileName = []
        #设置lineedit
        self.lineEdit.selectAll()
        self.lineEdit.setFocus()
        #curves曲线 名字:曲线
        self.curves = {}
        #图像管理器
        self.manager = PlotManager(self)
        #data 数据 double型 t
        self.data = {u"t":array("d")}
        for name in sum(PLOT_DEFINE, []):
            self.data[name] = array("d")
        self.data['tn'] = 0
        self.data['xmax'] = 0
        self.data['xmin']  = 0
        self.progressbar = []
        
        #车辆设置数据
        
        self.data['angle_p'] =  0
        self.data['angle_i'] = 0
        self.data['angle_d'] = 0
        self.data['speed_up_p'] = 0
        self.data['speed_up_i'] = 0
        self.data['speed_up_d'] = 0
        self.data['speed_curve'] = 0
        self.data['speed_straight'] = 0
        self.data['k_ccd'] = 0
        self.data['k_different'] = 0
        self.data['light_time'] = 0
        self.data['different_len'] = 0
        self.data['different_size'] = 0
        #主图表
        self.plots = []
        #副图标
        self.plots_extra = []
        #图表设置
        (self.manager,self.plots,self.curves) = Plot_Start_New(self,PLOT_DEFINE,COLORS,0,5,-5,200)
        for plot in self.plots:
            self.left_layout1.addWidget(plot)
        #self.manager.synchronize_axis(CurvePlot.X_BOTTOM, self.manager.plots.keys())
        
        
        #添加设置窗口
        self.setting_widget = setting_widget(self)
        self.open_widget.append(self.setting_widget)
        #连接 
        self.connect(self.pushButton_collect, QtCore.SIGNAL("clicked()"), self.AddingData_Start)
        self.connect(self.action_open,QtCore.SIGNAL("triggered()"),self.OpenFile)
        self.connect(self.action_save,QtCore.SIGNAL("triggered()"),self.SaveFile)
        self.connect(self.lineEdit,QtCore.SIGNAL("returnPressed()"),lambda:self.Line2Brower(self.lineEdit))
        #self.connect(self.lineEdit_2,QtCore.SIGNAL("returnPressed()"),lambda:self.Line2Brower(self.lineEdit_2))
        self.connect(self.checkBox_x, QtCore.SIGNAL("clicked()"), self.Flx)
        self.connect(self.checkBox_y, QtCore.SIGNAL("clicked()"), self.Auto)
        #self.connect(self.pushButton_car_setting,QtCore.SIGNAL("clicked()"),self.Settings)
        self.connect(self.pushButton_com,QtCore.SIGNAL("clicked()"), self.ReScanUart)
        self.connect(self.about_qt,QtCore.SIGNAL("triggered()"), lambda:QtGui.QMessageBox.aboutQt(self))
        self.connect(self.action_car,QtCore.SIGNAL("triggered()"),self.setting_widget.show)
        self.connect(self.pushButton_cleandata, QtCore.SIGNAL("clicked()"),self.CleanData)
        #self.connect(self.pushButton_run,QtCore.SIGNAL("clicked()"),self.CarStartRun)
#------------------------------------------------------小车设置连接----------------------------------------------------------------------------
    #    self.connect(self.setting_widget.pushButton_Stop, QtCore.SIGNAL("clicked()"),lambda :self.SetAngleP(20))
        self.connect(self.setting_widget.pushButton_Stop, QtCore.SIGNAL("clicked()"),self.CarStopRun)
        self.connect(self.setting_widget.apply, QtCore.SIGNAL("clicked()"),self.SettingApply)
        self.connect(self.setting_widget.pushButton_Start, QtCore.SIGNAL("clicked()"),self.CarStartRun)       
        #进度条
        msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, "", "", QtGui.QMessageBox.NoButton,parent = self )
        msgBox.setStandardButtons( QtGui.QMessageBox.NoButton )
        l = msgBox.layout()
        self.progressbar.append(msgBox)
        l.itemAtPosition( l.rowCount() - 1, 0 ).widget().hide()
        progress = QtGui.QProgressBar()
        self.progressbar.append(progress)
        progress.setValue(0)
        l.addWidget(progress,l.rowCount(), 0, 1, l.columnCount(), Qt.AlignCenter )
        
#--------------------------------------------------添加图像窗口-------------------------------------------------------------------------------
        self.ccd_realshow = []
        t = 0
        t_past = 0
        ccd_realshow = show_realdata_widget()
        
        data = {}
        
        data[u't'] = 0
        data[u't_past'] = 0
        temp_d = array('d')
        for i in range(128):
                temp_d.append(0)
                
        ccd_realshow.setWindowTitle(u"图像显示")
        ccd_realshow.setGeometry(200,200,400,400)
        
        for x in range(3):
            (memger,plots,curves) = Plot_Start_New(
                                                                                ccd_realshow,
                                                                                (
                                                                                     (u'CCD图像%d'%(x+1),
                                                                                      u'CCD图像%d左'%(x+1),
                                                                                      u'CCD图像%d中'%(x+1),
                                                                                      u'CCD图像%d右'%(x+1),
                                                                                     ),
                                                                                 ),
                                                                                ('white','red','green','blue'),0,128,0,255
                                                                              )

            temp_data = data.copy()
            temp_data[u'CCD图像%d'%(x+1)] = temp_d[:]
            temp_data[u'CCD图像%d左'%(x+1)] = temp_d[:]
            temp_data[u'CCD图像%d中'%(x+1)] = temp_d[:]
            temp_data[u'CCD图像%d右'%(x+1)] = temp_d[:]
            
            self.ccd_realshow.append([u'CCD图像%d'%(x+1),ccd_realshow,plots,curves,temp_data])
            for plot in plots: 
                ccd_realshow.gridLayout.addWidget(plot)
                
        for x in self.ccd_realshow:
            for y in x[2]:     
                y.hide()
                
        
        ccd_realshow.checkBox_ccd1.setChecked(0)
        ccd_realshow.checkBox_ccd2.setChecked(0)
        ccd_realshow.checkBox_ccd3.setChecked(0)
        self.connect(ccd_realshow.checkBox_ccd1, QtCore.SIGNAL("stateChanged(int)"),lambda x: self.Ccd_Realshow_Setting(0,x))
        self.connect(ccd_realshow.checkBox_ccd2, QtCore.SIGNAL("stateChanged(int)"),lambda x: self.Ccd_Realshow_Setting(1,x))
        self.connect(ccd_realshow.checkBox_ccd3, QtCore.SIGNAL("stateChanged(int)"),lambda x: self.Ccd_Realshow_Setting(2,x))
        self.connect(self.setting_widget.checkBox_ccd1,QtCore.SIGNAL("stateChanged(int)"),ccd_realshow.checkBox_ccd1.setChecked)
        self.connect(self.setting_widget.checkBox_ccd2,QtCore.SIGNAL("stateChanged(int)"),ccd_realshow.checkBox_ccd2.setChecked)
        self.connect(self.setting_widget.checkBox_ccd3,QtCore.SIGNAL("stateChanged(int)"),ccd_realshow.checkBox_ccd3.setChecked)
        self.connect(ccd_realshow.checkBox_ccd1,QtCore.SIGNAL("stateChanged(int)"),self.setting_widget.checkBox_ccd1.setChecked)
        self.connect(ccd_realshow.checkBox_ccd2,QtCore.SIGNAL("stateChanged(int)"),self.setting_widget.checkBox_ccd2.setChecked)
        self.connect(ccd_realshow.checkBox_ccd3,QtCore.SIGNAL("stateChanged(int)"),self.setting_widget.checkBox_ccd3.setChecked)
        self.connect(self.setting_widget.checkBox_ccd3,QtCore.SIGNAL("stateChanged(int)"),ccd_realshow.checkBox_ccd3.setChecked)
        self.connect(self.setting_widget.pushButton_real_data_Show,QtCore.SIGNAL("clicked()"),ccd_realshow.show)
        self.connect(ccd_realshow.pushButton_single, QtCore.SIGNAL("clicked()"),self.SdRunSingle)
        self.connect(ccd_realshow.pushButton_back, QtCore.SIGNAL("clicked()"),self.SdRunSingleBack)
#--------------------------------------------------添加图像窗口-------------------------------------------------------------------------------
        self.connect(self.action_sd_open,QtCore.SIGNAL("triggered()"),self.OpenSDFile)
        
        #定时显示
        self.startTimer(40)
Example #50
0
class ContrastAdjustment(PanelWidget):
    """Contrast adjustment tool"""

    __implements__ = (IPanel, )
    PANEL_ID = ID_CONTRAST
    PANEL_TITLE = _("Contrast adjustment tool")
    PANEL_ICON = "contrast.png"

    def __init__(self, parent=None):
        super(ContrastAdjustment, self).__init__(parent)

        self.local_manager = None  # local manager for the histogram plot
        self.manager = None  # manager for the associated image plot

        # Storing min/max markers for each active image
        self.min_markers = {}
        self.max_markers = {}

        # Select point tools
        self.min_select_tool = None
        self.max_select_tool = None

        style = "<span style='color: #444444'><b>%s</b></span>"
        layout, _label = get_image_layout(self.PANEL_ICON,
                                          style % self.PANEL_TITLE,
                                          alignment=Qt.AlignCenter)
        layout.setAlignment(Qt.AlignCenter)
        vlayout = QVBoxLayout()
        vlayout.addLayout(layout)
        self.local_manager = PlotManager(self)
        self.histogram = LevelsHistogram(parent)
        vlayout.addWidget(self.histogram)
        self.local_manager.add_plot(self.histogram)
        hlayout = QHBoxLayout()
        self.setLayout(hlayout)
        hlayout.addLayout(vlayout)

        self.toolbar = toolbar = QToolBar(self)
        toolbar.setOrientation(Qt.Vertical)
        #        toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        hlayout.addWidget(toolbar)

        # Add standard plot-related tools to the local manager
        lman = self.local_manager
        lman.add_tool(SelectTool)
        lman.add_tool(BasePlotMenuTool, "item")
        lman.add_tool(BasePlotMenuTool, "axes")
        lman.add_tool(BasePlotMenuTool, "grid")
        lman.add_tool(AntiAliasingTool)
        lman.get_default_tool().activate()

        self.outliers_param = EliminateOutliersParam(self.PANEL_TITLE)

    def register_panel(self, manager):
        """Register panel to plot manager"""
        self.manager = manager
        default_toolbar = self.manager.get_default_toolbar()
        self.manager.add_toolbar(self.toolbar, "contrast")
        self.manager.set_default_toolbar(default_toolbar)
        self.setup_actions()
        for plot in manager.get_plots():
            self.histogram.connect_plot(plot)

    def configure_panel(self):
        """Configure panel"""
        self.min_select_tool = self.manager.add_tool(
            SelectPointTool,
            title=_("Minimum level"),
            on_active_item=True,
            mode="create",
            tip=_("Select minimum level on image"),
            toolbar_id="contrast",
            end_callback=self.apply_min_selection,
        )
        self.max_select_tool = self.manager.add_tool(
            SelectPointTool,
            title=_("Maximum level"),
            on_active_item=True,
            mode="create",
            tip=_("Select maximum level on image"),
            toolbar_id="contrast",
            end_callback=self.apply_max_selection,
        )

    def get_plot(self):
        return self.manager.get_active_plot()

    def closeEvent(self, event):
        self.hide()
        event.ignore()

    def setup_actions(self):
        fullrange_ac = create_action(
            self,
            _("Full range"),
            icon=get_icon("full_range.png"),
            triggered=self.histogram.set_full_range,
            tip=_("Scale the image's display range "
                  "according to data range"),
        )
        autorange_ac = create_action(
            self,
            _("Eliminate outliers"),
            icon=get_icon("eliminate_outliers.png"),
            triggered=self.eliminate_outliers,
            tip=_("Eliminate levels histogram "
                  "outliers and scale the image's "
                  "display range accordingly"),
        )
        add_actions(self.toolbar, [fullrange_ac, autorange_ac])

    def eliminate_outliers(self):
        def apply(param):
            self.histogram.eliminate_outliers(param.percent)

        if self.outliers_param.edit(self, apply=apply):
            apply(self.outliers_param)

    def apply_min_selection(self, tool):
        item = self.get_plot().get_last_active_item(IVoiImageItemType)
        point = self.min_select_tool.get_coordinates()
        z = item.get_data(*point)
        self.histogram.set_min(z)

    def apply_max_selection(self, tool):
        item = self.get_plot().get_last_active_item(IVoiImageItemType)
        point = self.max_select_tool.get_coordinates()
        z = item.get_data(*point)
        self.histogram.set_max(z)

    def set_range(self, _min, _max):
        """Set contrast panel's histogram range"""
        self.histogram.set_range(_min, _max)
        # Update the levels histogram in case active item data has changed:
        self.histogram.selection_changed(self.get_plot())
Example #51
0
class RealtimeDemo(QWidget):
    def __init__(self):
        super(RealtimeDemo, self).__init__()
        self.setWindowTitle(u"Realtime Demo")

        self.data = {u"t":array("d")}
        for name in sum(PLOT_DEFINE, []):
            self.data[name] = array("d")

        self.curves = {}
        self.t = 0
        vbox = QVBoxLayout()
        vbox.addWidget(self.setup_toolbar())
        self.manager = PlotManager(self)
        self.plots = []
        for i, define in enumerate(PLOT_DEFINE):
            plot = CurvePlot()
            plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(60)
            self.manager.add_plot(plot)
            self.plots.append(plot)
            plot.plot_id = id(plot)
            for j, curve_name in enumerate(define):
                curve = self.curves[curve_name] = make.curve([0], [0], color=COLORS[j], title=curve_name)
                plot.add_item(curve)
            plot.add_item(make.legend("BL"))
            vbox.addWidget(plot)
        self.manager.register_standard_tools()
        self.manager.get_default_tool().activate()
        self.manager.synchronize_axis(CurvePlot.X_BOTTOM, self.manager.plots.keys())
        self.setLayout(vbox)
        self.startTimer(100)

    def setup_toolbar(self):
        toolbar = QToolBar()
        self.auto_yrange_checkbox = QCheckBox(u"Y轴自动调节")
        self.auto_xrange_checkbox = QCheckBox(u"X轴自动调节")
        self.xrange_box = QSpinBox()
        self.xrange_box.setMinimum(1)
        self.xrange_box.setMaximum(50)
        self.xrange_box.setValue(1)
        self.auto_xrange_checkbox.setChecked(True)        
        self.auto_yrange_checkbox.setChecked(True)
        toolbar.addWidget(self.auto_yrange_checkbox)
        toolbar.addWidget(self.auto_xrange_checkbox)        
        toolbar.addWidget(self.xrange_box)
        return toolbar

    def timerEvent(self, event):
        global bin_ori
        # writecache = []
        drawcache = []
        MAXRANGE = 65535
        AMPL = 6
        for i in range(n_channel):
            # writecache.append([])
            drawcache.append([])
        for i in range(collecttime):
            n = ser.inWaiting()
            # print(n)
            ori = ser.read(n)
            bin_ori += str(binascii.b2a_hex(ori))[2:-1]

        ffff_list = bin_ori.split('fffffffe')
        bin_ori = ffff_list[-1]
        wrong_no = 0
        # print(len(ffff_list))
        for i in range(1, len(ffff_list)):
            if len(ffff_list[i]) != 4 * n_channel:
                # print(i)
                # print('receive wrong')
                wrong_no += 1
                # print(ffff_list[i])
                continue

            for j in range(n_channel):
                temp = int(ffff_list[i][4 * j:4 * (j + 1)], 16)
                drawcache[j].append((temp))# - MAXRANGE / 2) / (MAXRANGE / 2) * AMPL)
                # writecache[j].append(str(temp))

        # print(wrong_no)
        # print(wrong_no / len(ffff_list))
        for i in xrange(len(drawcache[0])):
            t = self.t
            self.data[u"t"].append(t)
            # for j in xrange(n_channel):
            #     self.data[u"signal_"+str(j)].append(drawcache[j][i])
            # self.data[u"signal_0"].append(drawcache[0][i])
            self.data[u"signal_1"].append(drawcache[1][i])
            # self.data[u"signal_2"].append(drawcache[2][i])
            # self.data[u"signal_3"].append(drawcache[3][i])
            self.data[u"signal_4"].append(drawcache[4][i])
            # self.data[u"signal_5"].append(drawcache[5][i])
            # self.data[u"signal_6"].append(drawcache[6][i])
            self.data[u"signal_7"].append(drawcache[7][i])
            # self.data[u"signal_8"].append(drawcache[8][i])
            # self.data[u"signal_9"].append(drawcache[9][i])
            self.t += DT

        # for i in xrange(100):
        #     t = self.t
        #     self.data[u"t"].append(t)
        #     self.data[u"sin1f"].append(sin(t))
        #     self.data[u"cos1f"].append(cos(t))
        #     self.data[u"sin3f"].append(sin(3*t)/6)
        #     self.data[u"cos3f"].append(cos(3*t)/6)
        #     self.data[u"sin合成"].append(sin(t)+sin(3*t)/6)
        #     self.data[u"cos合成"].append(cos(t)+cos(3*t)/6)
        #     self.t += DT

        if self.auto_xrange_checkbox.isChecked():
            xmax = self.data["t"][-1]
            xmin = max(xmax - self.xrange_box.value(), 0)
        else:
            xmin, xmax = self.plots[0].get_axis_limits('bottom')

        for key, curve in self.curves.iteritems():
            xdata = self.data["t"]
            ydata = self.data[key]
            x, y = get_peak_data(xdata, ydata, xmin, xmax, 600, 1/DT)
            curve.set_data(x, y)

        for plot in self.plots:
            if self.auto_yrange_checkbox.isChecked() and self.auto_xrange_checkbox.isChecked():
                plot.do_autoscale()
            elif self.auto_xrange_checkbox.isChecked():
                plot.set_axis_limits("bottom", xmin, xmax)
                plot.replot()
            else:
                plot.replot()
Example #52
0
class RealtimeDemo(QWidget):
    def __init__(self):
        super(RealtimeDemo, self).__init__()
        self.setWindowTitle(u"Realtime Demo")

        self.data = {u"t":array("d")}
        for name in sum(PLOT_DEFINE, []):
            self.data[name] = array("d")

        self.curves = {}
        self.t = 0
        vbox = QVBoxLayout()
        vbox.addWidget(self.setup_toolbar())
        self.manager = PlotManager(self)
        self.plots = []
        for i, define in enumerate(PLOT_DEFINE):
            plot = CurvePlot()
            plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(60)
            self.manager.add_plot(plot)
            self.plots.append(plot)
            plot.plot_id = id(plot)
            for j, curve_name in enumerate(define):
                curve = self.curves[curve_name] = make.curve([0], [0], color=COLORS[j], title=curve_name)
                plot.add_item(curve)
            plot.add_item(make.legend("BL"))
            vbox.addWidget(plot)
        self.manager.register_standard_tools()
        self.manager.get_default_tool().activate()
        self.manager.synchronize_axis(CurvePlot.X_BOTTOM, self.manager.plots.keys())
        self.setLayout(vbox)
        self.startTimer(100)

    def setup_toolbar(self):
        toolbar = QToolBar()
        self.auto_yrange_checkbox = QCheckBox(u"Y-axis auto-adjust")
        self.auto_xrange_checkbox = QCheckBox(u"X-axis auto-adjust")
        self.xrange_box = QSpinBox()
        self.xrange_box.setMinimum(5)
        self.xrange_box.setMaximum(50)
        self.xrange_box.setValue(10)
        self.auto_xrange_checkbox.setChecked(True)        
        self.auto_yrange_checkbox.setChecked(True)
        toolbar.addWidget(self.auto_yrange_checkbox)
        toolbar.addWidget(self.auto_xrange_checkbox)        
        toolbar.addWidget(self.xrange_box)
        return toolbar

    def timerEvent(self, event):
        for i in range(100):
            t = self.t
            self.data[u"t"].append(t)
            self.data[u"sin1f"].append(sin(t))

            self.data[u"sin3f"].append(sin(3*t)/6)

            self.t += DT

        if self.auto_xrange_checkbox.isChecked():
            xmax = self.data["t"][-1]
            xmin = max(xmax - self.xrange_box.value(), 0)
        else:
            xmin, xmax = self.plots[0].get_axis_limits('bottom')

        for key, curve in self.curves.items():
            xdata = self.data["t"]
            ydata = self.data[key]
            x, y = get_peak_data(xdata, ydata, xmin, xmax, 600, 1/DT)
            curve.set_data(x, y)

        for plot in self.plots:
            if self.auto_yrange_checkbox.isChecked() and self.auto_xrange_checkbox.isChecked():
                plot.do_autoscale()
            elif self.auto_xrange_checkbox.isChecked():
                plot.set_axis_limits("bottom", xmin, xmax)
                plot.replot()
            else:
                plot.replot()
class MzPlottingWidget(CurveWidget):
    def __init__(self, parent=None):
        super(MzPlottingWidget, self).__init__(parent, xlabel="mz", ylabel="I")

        patch_inner_plot_object(self, MzPlot)
        self.plot.centralMz = None

        def label(self, x):
            # label with full precision:
            return QwtText(str(x))

        a = QwtScaleDraw()
        a.label = new.instancemethod(label, self.plot, QwtScaleDraw)
        self.plot.setAxisScaleDraw(self.plot.xBottom, a)

        self.pm = PlotManager(self)
        self.pm.add_plot(self.plot)
        self.curve = make_unselectable_curve([], [],
                                             color="b",
                                             curvestyle="Sticks")

        self.plot.add_item(self.curve)

        t = self.pm.add_tool(MzSelectionTool)
        self.pm.set_default_tool(t)
        t.activate()

        marker = Marker(label_cb=self.plot.label_info,
                        constraint_cb=self.plot.on_plot)
        marker.attach(self.plot)

        line = make_measurement_line()
        line.setVisible(0)

        setupCommonStyle(line, marker)
        line.shapeparam.line.color = "#555555"
        line.shapeparam.update_shape(line)

        label = make.info_label("TR", [MzCursorInfo(marker, line)], title=None)
        label.labelparam.label = ""
        label.labelparam.font.size = 12
        label.labelparam.update_label(label)

        self.marker = marker
        self.label = label
        self.line = line

    def plot_spectra(self, all_peaks, labels):
        self.plot.del_all_items()
        self.plot.add_item(self.marker)
        self.plot.add_item(make.legend("TL"))
        self.plot.add_item(self.label)

        for i, (peaks, label) in enumerate(zip(all_peaks, labels)):
            config = dict(color=getColor(i))
            curve = make_unselectable_curve([], [],
                                            title=label,
                                            curvestyle="Sticks",
                                            **config)
            curve.set_data(peaks[:, 0], peaks[:, 1])
            self.plot.add_item(curve)
            self.plot.resample_config = []

        self.plot.add_item(self.line)
        if len(all_peaks):
            self.plot.all_peaks = np.vstack(all_peaks)
        else:
            self.plot.all_peaks = np.zeros((0, 2))

    def _setup_configs_and_titles(self, configs, titles, n):
        configs = configs if configs is not None else [None] * n
        titles = titles if titles is not None else [""] * n

        def default(i):
            return dict(color=getColor(i))

        configs = [
            ci if ci is not None else default(i)
            for (i, ci) in enumerate(configs)
        ]
        return configs, titles

    def set_overall_range(self, mzmin, mzmax):
        self.plot.overall_x_min = mzmin
        self.plot.overall_x_max = mzmax

    def plot_peakmaps(self, peakmap_ranges, configs=None, titles=None):

        has_titles = titles is not None
        configs, titles = self._setup_configs_and_titles(
            configs, titles, len(peakmap_ranges))

        self.plot.del_all_items()
        self.plot.add_item(self.marker)
        if has_titles:
            self.plot.add_item(make.legend("TL"))
        self.plot.add_item(self.label)

        self.plot.plot_peakmap_ranges(peakmap_ranges, configs, titles)
        self.plot.add_item(self.line)

    def set_cursor_pos(self, mz):
        self.plot.set_mz(mz)

    def resetAxes(self):
        self.plot.reset_x_limits()

    def reset_mz_limits(self, xmin=None, xmax=None, fac=1.1):
        self.plot.reset_x_limits(xmin, xmax, fac)

    def reset(self):
        self.plot.del_all_items()
        self.replot()

    def replot(self):
        self.plot.replot()

    def set_visible(self, visible):
        self.plot.setVisible(visible)

    def updateAxes(self):
        self.plot.updateAxes()

    def shrink_and_replot(self, mzmin, mzmax):
        self.reset_mz_limits(mzmin, mzmax)
        self.plot.reset_y_limits()
        self.plot.replot()
Example #54
0
class Ui_PlotWidget_Feature_Set(QtGui.QWidget):
    """"""

    def __init__(self, parent=None):
        """Constructor for Ui_PlotWidget"""
        QtGui.QWidget.__init__(self, parent)
        self.setupUi()

    def setupUi(self):
        """loads numpy array

        Args:
            self

        Returns:
            nothing
        """
        # self.plot = CurvePlot(self)
        self.dialog = CurveDialog(edit=False, toolbar=True, parent=self)
        self.plot = self.dialog.get_plot()
        self.plot.set_antialiasing(True)

        # x = np.linspace(-10,10,200)
        # dy = x/100.
        # y = np.sin(np.sin(np.sin(x)))
        # self.plot.add_item(make.curve(x,y))

        self.loadButton = QtGui.QPushButton("Load")
        self.trainButton = QtGui.QPushButton("Train Model")

        ly = QtGui.QVBoxLayout()
        ly.addWidget(self.plot)
        # ly.addWidget(self.loadButton)
        # ly.addWidget(self.trainButton)

        self.plot.setAxisTitle(Qwt5.Qwt.QwtPlot.xBottom, "Time")
        self.plot.setAxisTitle(Qwt5.Qwt.QwtPlot.yLeft, "Value")

        self.manager = PlotManager(self)
        self.manager.add_plot(self.plot)
        # self.manager.
        legend = make.legend("TL")
        self.plot.add_item(legend)

        self.setLayout(ly)
        self.move(300, 200)
        self.show()
        self.dataController = DataController.DataController()

    def loadData(self):
        self.trainingData = self.dataController.loadSampleData()
        import logic.dimreduce.paa as PAA

        p = PAA.paa()
        data = p.process(self.trainingData["PIR"][:], 100)

        r = np.array(range(len(data))).reshape(len(data), 1)
        s = np.array(data).reshape(len(data), 1)
        rs = np.hstack((s, s))
        print rs
        import logic.featurex.kmeans as km

        k = km.kmeans()
        labels = k.process(rs, 2)
        print labels
        self.plot.add_item(make.curve(range(0, len(data)), data))
        from guiqwt.styles import AnnotationParam

        i = 0
        i_beg = 0
        i_end = 0
        while i < len(labels):
            cur = labels[i_end]

            if i < len(labels) - 1:
                if labels[i_end + 1] != cur:
                    i_end = i
                    from guiqwt.annotations import AnnotatedRectangle

                    param = AnnotationParam()
                    param.title = str(labels[int(i_beg)])
                    param.show_computations = False

                    anno = AnnotatedRectangle(r[int(i_beg)], 0.5, r[int(i_end)], 0.2, param)  # TODO: y axis scaling
                    self.plot.add_item(anno)
                    i_beg = i_end
                    print "s1"
                else:
                    i_end = i
                    print "s2"
                print "s3"
            print "s4", i_end, len(labels)
            i += 1
        # param = AnnotationParam()
        # param.title = "alright"
        # param.show_computations = False

        ##anno = AnnotatedRectangle(0., 1., 1.5, 0.5, param)
        # anno.set_style("plot", "shape/drag")
        # anno.set_style("shape/drag/fill/color", "white")
        # self.plot.add_item(anno)
        # self.rangeSelection = make.range(-2, 2)
        # disp0 = make.range_info_label(self.rangeSelection, 'BR', u"x = %.1f +- %.1f cm",
        #                              title="Range infos")
        # self.plot.add_item(self.rangeSelection)
        # self.plot.add_item(disp0)
        self.plot.replot()

    def trainData(self, string_length, vocab, window_length, clusterN):
        a, b = self.rangeSelection.get_range()
        if a > b:
            a, b = b, a
        print a, b
        print "in widget", int(string_length), int(vocab), int(window_length), int(clusterN)
        self.dataController.trainData(a, b, int(string_length), int(vocab), int(window_length), int(clusterN))
Example #55
0
class RtPlotter(PlotterBase):

    def __init__(self, parent=None, rangeSelectionCallback=None):

        PlotterBase.__init__(self, "RT", "I")

        self.rangeSelectionCallback = rangeSelectionCallback

        widget = self.widget
        widget.plot.__class__ = RtPlot

        self.pm = PlotManager(widget)
        self.pm.add_plot(widget.plot)

        t = self.pm.add_tool(RtSelectionTool)
        t.activate()
        self.pm.set_default_tool(t)

        marker = Marker(label_cb=self.widget.plot.label_info,
                        constraint_cb=self.widget.plot.on_plot)
        marker.rts = [0]
        setupStyleRtMarker(marker)
        marker.attach(self.widget.plot)
        self.marker = marker

        self.cursor_info = RtCursorInfo(marker)
        label = make.info_label("T", [self.cursor_info], title=None)
        label.labelparam.label = ""
        label.labelparam.font.size = 12
        label.labelparam.border.color = "#ffffff"
        label.labelparam.update_label(label)
        self.label = label

        self.minRTRangeSelected = None
        self.maxRTRangeSelected = None

    def _set_rt_x_axis_labels(self):
        # todo: refactor as helper
        a = QwtScaleDraw()
        # render tic labels in modfied format:
        label = lambda self, v: QwtText(formatSeconds(v))
        a.label = new.instancemethod(label, self.widget.plot, QwtScaleDraw)
        self.widget.plot.setAxisScaleDraw(self.widget.plot.xBottom, a)

    def _set_ts_x_axis_labels(self, data):
        # todo: refactor as helper
        all_ts = [tsi for ts in data for tsi in ts.x]
        pos = find_datetime_split_pos(all_ts)
        a = QwtScaleDraw()
        # render tic labels in modfied format:
        label = lambda self, v, pos=pos: QwtText(format_datetime_value(pos, v)) # QwtText(str(v))
        a.label = new.instancemethod(label, self.widget.plot, QwtScaleDraw)
        self.widget.plot.setAxisScaleDraw(self.widget.plot.xBottom, a)


    def reset(self):
        """empties plot"""
        self.plot([])
        self.marker.rts = [0]
        self.replot()

    def plot(self, data, is_time_series=False, titles=None, configs=None,
             withmarker=False):
        """ do not forget to call replot() after calling this function ! """
        allrts = []
        self.widget.plot.del_all_items()

        if is_time_series:
            self._set_ts_x_axis_labels(data)
            self.widget.plot.set_axis_title("bottom", "time")
        else:
            self._set_rt_x_axis_labels()
            self.widget.plot.set_axis_title("bottom", "RT")

        labels = set()
        legend_items = []
        if is_time_series:
            seen = set()
            for i, ts in enumerate(data):
                # we do not plot duplicates, which might happen if multiple lines in the
                # table explorer are sellected !
                if id(ts) in seen:
                    continue
                seen.add(id(ts))
                config = None
                if configs is not None:
                    config = configs[i]
                if config is None:
                    config = dict(color=getColor(i))
                title = ts.label
                labels.add(title)
                for j, (x, y) in enumerate(ts.for_plotting()):
                    x = [xi.toordinal() if isinstance(xi, datetime) else xi for xi in x]
                    allrts.extend(x)
                    curve = make.curve(x, y, title="<pre>%s</pre>" % title, **config)
                    curve.__class__ = ModifiedCurveItem
                    self.widget.plot.add_item(curve)
                    self.cursor_info.is_time_series = True
                    if j == 0:
                        legend_items.append(curve)
        else:
            seen = set()
            for i, (rts, chromatogram) in enumerate(data):
                # we do not plot duplicates, which might happen if multiple lines in the
                # table explorer are sellected !
                if (id(rts), id(chromatogram)) in seen:
                    continue
                seen.add((id(rts), id(chromatogram)))
                config = None
                if configs is not None:
                    config = configs[i]
                if config is None:
                    config = dict(color=getColor(i))
                if titles:
                    title = "<pre>%s</pre>" % titles[i]
                else:
                    title = ""
                labels.add(title)
                curve = make.curve(rts, chromatogram, title=title, **config)
                curve.__class__ = ModifiedCurveItem
                allrts.extend(rts)
                self.widget.plot.add_item(curve)
                self.cursor_info.is_time_series = False


        if withmarker:
            self.widget.plot.add_item(self.label)
            allrts = sorted(set(allrts))
            self.marker.rts = allrts
            self.marker.attach(self.widget.plot)
            self.widget.plot.add_item(self.marker)

        labels -= set((None,))
        labels -= set(("",))
        if labels:
            legend = make.legend("TL", restrict_items=legend_items)
            legend.labelparam.font.size = 12
            legend.labelparam.update_label(legend)
            self.widget.plot.add_item(legend)
        if not is_time_series:
            self._add_range_selector(allrts)

    def setEnabled(self, enabled):
        self.widget.plot.setVisible(enabled)

    def _add_range_selector(self, rtvalues):

        self.rtvalues = rtvalues
        self.minRTRangeSelected = 0
        self.maxRTRangeSelected = 0

        range_ = SnappingRangeSelection(self.minRTRangeSelected,
                                        self.maxRTRangeSelected, self.rtvalues)
        setupStyleRangeMarker(range_)
        self.range_ = range_

        # you have to register item to plot before you can register the
        # rtSelectionHandler:
        self.widget.plot.add_item(range_)
        range_.SIG_RANGE_CHANGED.connect(self._range_selection_handler)
        #self.widget.disconnect(range_.plot(), SIG_RANGE_CHANGED,
                               #self._range_selection_handler)
        #self.widget.connect(range_.plot(), SIG_RANGE_CHANGED,
                            #self._range_selection_handler)

        cc = make.info_label("TR", [RtRangeSelectionInfo(range_)], title=None)
        cc.labelparam.label = ""
        cc.labelparam.font.size = 12
        cc.labelparam.update_label(cc)
        self.widget.plot.add_item(cc)

    def getRangeSelectionLimits(self):
        return sorted((self.range_._min, self.range_._max))

    def setRangeSelectionLimits(self, xleft, xright):
        saved = self.rangeSelectionCallback
        self.rangeSelectionCallback = None
        self.minRTRangeSelected = xleft
        self.maxRTRangeSelected = xright
        # left and right bar of range marker
        self.range_.move_point_to(0, (xleft, 0))
        self.range_.move_point_to(1, (xright, 0))
        self.rangeSelectionCallback = saved

    @protect_signal_handler
    def _range_selection_handler(self, obj, left, right):
        min_, max_ = sorted((left, right))
        self.minRTRangeSelected = min_
        self.maxRTRangeSelected = max_
        if self.rangeSelectionCallback is not None:
            self.rangeSelectionCallback()

    reset_rt_limits = PlotterBase.reset_x_limits
    reset_intensity_limits = PlotterBase.reset_y_limits
Example #56
0
class Window(QMainWindow):
    def __init__(self, wintitle):
        super(Window, self).__init__()
        self.default_tool = None
        self.plots = []
        self.itemlist = PlotItemList(None)
        self.contrast = ContrastAdjustment(None)
        self.xcsw = XCrossSection(None)
        self.ycsw = YCrossSection(None)

        self.manager = PlotManager(self)
        self.toolbar = QToolBar(_("Tools"), self)
        self.manager.add_toolbar(self.toolbar, "default")
        self.toolbar.setMovable(True)
        self.toolbar.setFloatable(True)
        self.addToolBar(Qt.TopToolBarArea, self.toolbar)

        frame = QFrame(self)
        self.setCentralWidget(frame)
        self.layout = QGridLayout()
        layout = QVBoxLayout(frame)
        frame.setLayout(layout)
        layout.addLayout(self.layout)
        self.frame = frame

        self.setWindowTitle(wintitle)
        self.setWindowIcon(get_icon('guiqwt.svg'))

    def closeEvent(self, event):
        global _figures, _current_fig, _current_axes
        figure_title = to_text_string(self.windowTitle())
        if _figures.pop(figure_title) == _current_fig:
            _current_fig = None
            _current_axes = None
        self.itemlist.close()
        self.contrast.close()
        self.xcsw.close()
        self.ycsw.close()
        event.accept()

    def add_plot(self, i, j, plot):
        self.layout.addWidget(plot, i, j)
        self.manager.add_plot(plot)
        self.plots.append(plot)

    def replot(self):
        for plot in self.plots:
            plot.replot()
            item = plot.get_default_item()
            if item is not None:
                plot.set_active_item(item)
                item.unselect()

    def add_panels(self, images=False):
        self.manager.add_panel(self.itemlist)
        if images:
            for panel in (self.ycsw, self.xcsw, self.contrast):
                panel.hide()
                self.manager.add_panel(panel)

    def register_tools(self, images=False):
        if images:
            self.manager.register_all_image_tools()
        else:
            self.manager.register_all_curve_tools()

    def display(self):
        self.show()
        self.replot()
        self.manager.get_default_tool().activate()
        self.manager.update_tools_status()