Last active
March 10, 2017 12:52
-
-
Save cpascual/16b7fa2cab18ae27f1483d79400f7051 to your computer and use it in GitHub Desktop.
Proof of concept for plotting a taurus attribute with pyqtgraph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import numpy | |
from taurus.external.qt import QtGui | |
from taurus.qt.qtgui.application import TaurusApplication | |
from taurus.qt.qtgui.base import TaurusBaseComponent | |
from pyqtgraph import PlotDataItem | |
class TaurusPlotDataItem(PlotDataItem, TaurusBaseComponent): | |
"""A taurus-ified PlotDataItem""" | |
def __init__(self, *args, **kwargs): | |
PlotDataItem.__init__(self, *args, **kwargs) | |
TaurusBaseComponent.__init__(self, 'TaurusBaseComponent') | |
def handleEvent(self, evt_src, evt_type, evt_value): | |
try: | |
y = evt_value.rvalue | |
self.setData(y) | |
except Exception, e: | |
self.warning('Exception in handleEvent: %s', e) | |
if __name__ == '__main__': | |
import pyqtgraph as pg | |
app = TaurusApplication() | |
# a standard pyqtgraph widget | |
w = pg.PlotWidget() | |
# adding a regular data item (non-taurus) | |
c1 = pg.PlotDataItem(pen='b', fillLevel=0, brush='c') | |
c1.setData(numpy.arange(300)/300.) | |
w.addItem(c1) | |
# adding a taurus data item | |
c2 = TaurusPlotDataItem(pen='r', symbol='o') | |
c2.setModel('eval:Quantity(rand(256),"m")') | |
w.addItem(c2) | |
w.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that pyqtgraph accepts pint.Quantities out-of-the-box!!