Dear Sir,
I am trying to build a custom block to plot graphs. For starting this
block is similar to the block of “WX GUI Scope Sink”.
I started with wxPython, the code is below.
The problem is, this block causes the whole flow graph to “freeze”.
So the question is, how to program this block correctly?
(I am new to wxPython)
Thanks & regards,
Activecat
Python code of the block:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy
from gnuradio import gr
import wx
class plotter1(gr.sync_block):
def __init__(self, title, samp_rate, V_scale, T_scale,
adjust):
gr.sync_block.__init__(self,
name="plotter1",
in_sig=[ numpy.float32 ],
out_sig=None )
self.V_scale = V_scale
self.T_scale = T_scale
self.x = 0
self.y = 0
self.width = 1000
self.height = 500
self.data = []
self.app = wx.App(False)
self.frame = wx.Frame( None, title=title,
size=(self.width,
self.height) )
self.panel = wx.Panel(self.frame)
self.panel.Bind(wx.EVT_PAINT, self.myPaint)
def myPaint(self, event):
dc =wx.PaintDC(event.GetEventObject())
dc.Clear()
dc.SetPen(wx.Pen( "BLUE", 1 ))
for i in range(len(self.data)):
newx = self.x + 1
newy = self.height/2.0 - self.data[i] * 30.0 /
self.V_scale
dc.DrawLine( self.x, self.y, newx, newy )
self.x = newx
self.y = newy
if self.x >= self.width:
self.x = 0
break
def work(self, input_items, output_items):
self.data = input_items[0][:]
#self.frame.Refresh() # this cause the flow graph to
freeze even more seriously
self.frame.Show(True)
#self.app.MainLoop() # remove this to avoid blocking
return 0