'Manual' update() variation on filtertest2.py
SHOW = True # Show test in GUI-based test launcher
from guidata.qt.QtGui import (QWidget, QVBoxLayout, QHBoxLayout,
QPushButton,
QMainWindow)
from guidata.qt.QtCore import SIGNAL
#---Import plot widget base class
from guiqwt.curve import CurvePlot
from guiqwt.plot import PlotManager
from guiqwt.builder import make
from guidata.configtools import get_icon
import numpy as np
#---
class TestWidget(QWidget):
"""
Testing widget
parent: parent widget (QWidget)
x, y: NumPy arrays
func: function object (the signal filter to be tested)
"""
def __init__(self, parent, x, y):
QWidget.__init__(self, parent)
self.setMinimumSize(320, 200)
self.x = x
self.y = y
#---guiqwt related attributes:
self.plot = None
self.curve_item = None
#---
def setup_widget(self, title):
#---Create the plot widget:
self.plot = CurvePlot(self)
self.curve_item = make.curve([], [], color='b')
self.plot.add_item(self.curve_item)
self.plot.set_antialiasing(True)
#---
button = QPushButton(u"Push: %s" % title)
self.connect(button, SIGNAL('clicked()'), self.process_data)
vlayout = QVBoxLayout()
vlayout.addWidget(self.plot)
vlayout.addWidget(button)
self.setLayout(vlayout)
self.update_curve()
def process_data(self):
## self.y = self.func(self.y)
self.x,self.y=np.loadtxt('test.dat',unpack=True)
self.update_curve()
def update_curve(self):
#---Update curve
self.curve_item.set_data(self.x, self.y)
self.plot.replot()
axis_id=self.plot.get_axis_id('bottom')
self.plot.set_axis_limits(axis_id,np.min(self.x),np.max(self.x))
axis_id=self.plot.get_axis_id('left')
self.plot.set_axis_limits(axis_id,np.min(self.y),np.max(self.y))
#---
class TestWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setWindowTitle("Signal filtering 2 (guiqwt)")
self.setWindowIcon(get_icon('guiqwt.png'))
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, title):
widget = TestWidget(self, x, y)
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()
#---
def test():
"""Testing this simple Qt/guiqwt example"""
from guidata.qt.QtGui import QApplication
import numpy as np
import scipy.signal as sps, scipy.ndimage as spi
app = QApplication([])
win = TestWindow()
x,y=np.loadtxt('test.dat',unpack=True)
win.add_plot(x, y, "Update")
#---Setup window
win.setup_window()
#---
win.show()
app.exec_()
if __name__ == '__main__':
test()
Post by OliverI just joined this forum after being very impressed by the possibilities
offered by guiqwt/guidata. A big thanks to the developpers of this
library. I am a newbie and I have mostly studied the simplest examples
provided in the distribution: still a little bit overwhelmed by the number
of new objects to learn. I would like to ask the community if someone will
have a small template of code that will perform a monitor of a data stream
by for example linking/updating a plot to the tail of a data file?
--
You received this message because you are subscribed to the Google Groups "guidata/guiqwt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guidata_guiqwt+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.