How exactly is hier_block 's behaviour differe

2019-03-02 12:56发布

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?

1条回答
混吃等死
2楼-- · 2019-03-02 13:26

How exactly is hier_block 's behaviour different then that of a sync_block in GNU Radio?

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 your top_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

# Comment 2 -> this doesnt work as Marcus says "Only init block has the graphical framework's window object set as property."

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

Comment 1 -> this will not work as I dont have access to input_items here

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:

  1. use the existing plot blocks (in gnuradio/gr-wxgui) as reference. They're mostly written in C++, for a reason. It's quite complex to get this to work, so implementing your own visualization is not a beginner's task, especially since you also seem to struggle with some basic python concepts. This will quickly also get a multithreading problem. To be clear: What you're trying to do (call a plotting function from a block thread) is problematic and usually won't work.
  2. when extending GNU Radio's GUI capabilities today, don't use WX Gui. That will go away sooner or later; GNU Radio is concentrating very strongly on QT nowadays.
  3. Are you sure you can't implement exactly what you need by feeding an existing visualizer with samples? That would be so much easier, and better to implement, and more universal.
查看更多
登录 后发表回答