discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] Graph plotting using wxPython


From: Activecat
Subject: [Discuss-gnuradio] Graph plotting using wxPython
Date: Sat, 8 Mar 2014 14:35:48 +0800

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:
[code]
        #!/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 = "">                 #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
[/code]

reply via email to

[Prev in Thread] Current Thread [Next in Thread]