This is a continuation of this question. I understand that we cannot access input_items
in __init__
of a sync_block but we can do so in hier_block
(eg. here). I wanted to add a panel on the top block frame which can only be done by assigning a panel to self.win
in __init__
(like in the hier_block example). If I try to assign a panel to self.win
inside the work function of a sync_block then it gives the error : 'xyz' object has no attribute 'win'. Though it works if I assign a panel to self.win
inside __init__
of a sync_block (that's why I wanted to access input_items
inside __init__
in the first place)
In response to Marcus answer
If I want to draw a plot on a wxPanel and then put the panel on the top_block wxFrame. Here is an example -
class xyz(gr.sync_block):
"""
docstring for block add_python
"""
def __init__(self,parent):
.......
gr.sync_block.__init__(self,
name="xyz",
in_sig=[numpy.float32,numpy.float32],
out_sig=None)
self.win = xyzPlot(parent,input_items) # Comment 1 -> this will not work as I dont have access to input_items here
def work(self, input_items, output_items):
..........
..........
self.win = xyzPlot(parent,input_items) # Comment 2 -> this doesnt work as Marcus says "Only __init__ block has the graphical framework's window object set as property."
..........
..........
class xyzPlot(wx.Panel):
def __init__(self, parent , input_items):
wx.Panel.__init__(self , parent , -1 ,size=(1000,1000))
..............
..............
#plots a plot on the panel depending on the input_items
..............
..............
Check out both the comments I have added in the code above. Since both ways don't work , how to do what I want to that?
You should read the guided tutorials of GNU Radio where this is all explained very neatly. The content of your question has nothing to do with your title, so I'm not going to answer the question in the title.
However, your real question is a different one:
when trying to set up GUI in your work, things go wrong.
And as a continuation of the answers given you in the other thread: You don't do set up of things in the
work
function. That method is only used for signal processing.Set up your flow graph including the GUI during construction, that is, in the
__init__
of yourtop_block
. Only that block has the graphical framework's window object set as property.EDIT: You want to implement your own plotter:
The comment in the code where you said
is a wrong quote. Only your top_block has access to the win property, because that's a property of that top_block (and noone else's). That's basic python you're mixing up here.
The other comment
shows that you still haven't quite understood how GNU Radio works. There's a work function that you have to implement, and that function has a parameter
input_items
; obviously, you can't access another functions parameter when you're not in that function -- that's a logical/programming language thing, too.All I can do here is repeat: Read the guided tutorials, and do all the exercises within before trying something as complex. Otherwise, the people who try to help you have to explain basic stuff, although you have advanced problems. There's no way around getting familiar with how to program for GNU Radio in Python first, and the guided tutorials (did I mention you should read them?) make that quite easy, given that you're somewhat familiar with python. If you aren't familiar with python, go to python.org and do a python2 tutorial first. Shouldn't take long. You really need to understand the concept of classes, methods, constructors, variables, parameters, properties before you can dive into something that uses as much object-oriented paradigms as GNU Radio.
My remarks on your question: