Skip to content

Commit

Permalink
adding start/stop menu item to plotters for static inspection on streams
Browse files Browse the repository at this point in the history
  • Loading branch information
osh committed May 31, 2015
1 parent 75dc123 commit 89d0a8d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
9 changes: 7 additions & 2 deletions python/plotter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, blkname="pyqt_plotter", label="", *args):
gr.sync_block.__init__(self,blkname,[],[])
Qwt.QwtPlot.__init__(self, *args)


self.enabled = True
self.setMinimumWidth(100)
self.setMinimumHeight(100)

Expand Down Expand Up @@ -77,7 +77,8 @@ def __init__(self, blkname="pyqt_plotter", label="", *args):


# Set up menu actions
actions = [("Toggle Grid", self.toggle_grid),
actions = [("Start/Stop", self.toggle_enabled),
("Toggle Grid", self.toggle_grid),
("Toggle Axes", self.toggle_axes),
("Clear Markers", self.clear_markers)
]
Expand Down Expand Up @@ -128,6 +129,8 @@ def mousePressEvent(self, ev):
self.markers.append(m)
self.trigger_update()

def toggle_enabled(self):
self.enabled = not self.enabled

# turn curve[0] line off (dots only)
def line_off(self, size=2):
Expand Down Expand Up @@ -180,6 +183,8 @@ def alignScales(self):
Qwt.QwtAbstractScaleDraw.Backbone, False)

def do_plot(self, a):
if not self.enabled:
return
# set curve data for known curves
for cd in self.curve_data:
for c in cd:
Expand Down
60 changes: 43 additions & 17 deletions python/raster_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ def __init__(self, title = Qwt.QwtText(), mincol = 50, minrow = 50):
self.xyzs = None

self.X = numpy.zeros([minrow, mincol])
# self.setData(self.X)
# __init__()



def setData(self, xyzs, xRange = None, yRange = None):
self.xyzs = xyzs
shape = xyzs.shape
Expand Down Expand Up @@ -140,6 +139,7 @@ class raster_plot(gr.sync_block, Qwt.QwtPlot):
def __init__(self, blkname="pyqt_raster", label="", *args):
gr.sync_block.__init__(self,blkname,[],[])
Qwt.QwtPlot.__init__(self, *args)
self.enabled = True

# set up message port
self.message_port_register_in(pmt.intern("pdus"))
Expand Down Expand Up @@ -185,6 +185,31 @@ def __init__(self, blkname="pyqt_raster", label="", *args):
Qwt.QwtPicker.AlwaysOff,
self.canvas())
self.zoomer.setRubberBandPen(Qt.QPen(Qt.Qt.black))

# Set up menu actions
actions = [("Start/Stop", self.toggle_enabled),
]
self.actions = [];
for a in actions:
action = QtGui.QAction(a[0], self)
action.triggered.connect(a[1])
self.actions.append(action)

# pop up a context menu
def triggerMenu(self, pos):
menu = QtGui.QMenu(self)
for a in self.actions:
menu.addAction(a)
menu.exec_(pos)

# override default mousePressEvent
def mousePressEvent(self, ev):
# context menu on middle click
if(ev.buttons() == Qt.Qt.MiddleButton):
self.triggerMenu(ev.globalPos())

def toggle_enabled(self):
self.enabled = not self.enabled

def alignScales(self):
self.canvas().setFrameStyle(Qt.QFrame.Box | Qt.QFrame.Plain)
Expand All @@ -209,20 +234,21 @@ def work(self, input_items, output_items):
pass

def handler(self, msg):
self._lock.acquire();

# get input msg
meta = pmt.car(msg);
samples = pmt.cdr(msg);
x = pmt.to_python(pmt.cdr(msg))*1.0

# add to raster
self.__data.add_row(x)

# update plot
self.emit(QtCore.SIGNAL("updatePlot(int)"), 0)

self._lock.release();
if(self.enabled):
self._lock.acquire();

# get input msg
meta = pmt.car(msg);
samples = pmt.cdr(msg);
x = pmt.to_python(pmt.cdr(msg))*1.0

# add to raster
self.__data.add_row(x)

# update plot
self.emit(QtCore.SIGNAL("updatePlot(int)"), 0)

self._lock.release();

class raster_test_top_block(gr.top_block, Qt.QWidget):

Expand Down

0 comments on commit 89d0a8d

Please sign in to comment.