hier_block 的行为与 GNU Radio 中的 sync_block 的行为究竟有何不同?
How exactly is hier_block 's behaviour different then that of a sync_block in GNU Radio?
这是 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) 的延续。我想在顶部块框架上添加一个面板,这只能通过将面板分配给 __init__
中的 self.win
来完成(就像在 hier_block 示例中一样)。如果我尝试在 sync_block 的工作函数内将面板分配给 self.win
,则会出现错误:'xyz' object has no attribute 'win'。尽管如果我将面板分配给 sync_block 的 __init__
内的 self.win
会起作用( 这就是为什么我想访问 __init__
内的 input_items
第一名)
回应马库斯的回答
如果我想 在 wxPanel 上画一个图,然后将面板放在 top_block wxFrame 上。这是一个例子 -
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
..............
..............
查看我在上面的代码中添加的两个注释。既然这两种方法都行不通,那我想怎么做呢?
How exactly is hier_block 's behaviour different then that of a sync_block in GNU Radio?
您应该阅读 GNU Radio 的 guided tutorials,其中对这一切的解释非常清楚。你提问的内容与你的标题无关,所以我不会回答标题中的问题。
但是,您真正的问题是另一个问题:
在您的工作中尝试设置 GUI 时,出错了。
并且作为在另一个线程中给您的答案的延续:您不在work
函数中设置事物。该方法仅用于信号处理。
在构建期间设置包括 GUI 在内的流程图,即在 top_block
的 __init__
中。只有那个块将图形框架的 window object 设置为 属性.
编辑:您想实现自己的绘图仪:
你说的代码中的注释
# Comment 2 -> this doesnt work as Marcus says "Only init block has the graphical framework's window object set as property."
是一个错误的引用。只有您的 top_block 才能获得胜利 属性,因为那是 top_block 的 属性(没有其他人的)。这是基本的 python 你在这里混淆了。
其他评论
Comment 1 -> this will not work as I dont have access to input_items here
表明您还没有完全理解 GNU Radio 的工作原理。
您必须实现一个工作函数,该函数有一个参数 input_items
;显然,当您不在该函数中时,您无法访问另一个函数参数——这也是 logical/programming 语言的事情。
我在这里所能做的就是重复:阅读指导教程,并在尝试复杂的事情之前完成其中的所有练习。否则,试图帮助你的人必须解释基本的东西,尽管你有高级问题。没有办法首先熟悉如何在 Python 中为 GNU Radio 编程,而指导教程(我有没有提到你应该阅读它们?)让这变得非常容易,因为你对 python。
如果您不熟悉 python,请转到 python.org 并先学习 python2 教程。应该不会花很长时间。在深入研究使用与 GNU Radio 一样多的 object-oriented 范例的东西之前,您确实需要了解 类、方法、构造函数、变量、参数、属性的概念。
我对你的问题的评论:
- 使用现有的绘图块(在 gnuradio/gr-wxgui 中)作为参考。它们大多是用 C++ 编写的,这是有原因的。让它发挥作用非常复杂,因此实现您自己的可视化并不是初学者的任务,尤其是因为您似乎还难以理解一些基本的 python 概念。这很快也会遇到多线程问题。要清楚:你正在尝试做的事情(从块线程调用绘图函数)是有问题的,通常 不会工作。
- 今天扩展 GNU Radio 的 GUI 功能时,不要使用 WX Gui。那迟早会消失;现在 GNU Radio 非常专注于 QT。
- 您确定不能通过向现有的可视化工具提供样本来准确实现您的需求吗?那会更容易,更好地实施,也更普遍。
这是 input_items
in __init__
of a sync_block but we can do so in hier_block
(eg. here) 的延续。我想在顶部块框架上添加一个面板,这只能通过将面板分配给 __init__
中的 self.win
来完成(就像在 hier_block 示例中一样)。如果我尝试在 sync_block 的工作函数内将面板分配给 self.win
,则会出现错误:'xyz' object has no attribute 'win'。尽管如果我将面板分配给 sync_block 的 __init__
内的 self.win
会起作用( 这就是为什么我想访问 __init__
内的 input_items
第一名)
回应马库斯的回答
如果我想 在 wxPanel 上画一个图,然后将面板放在 top_block wxFrame 上。这是一个例子 -
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
..............
..............
查看我在上面的代码中添加的两个注释。既然这两种方法都行不通,那我想怎么做呢?
How exactly is hier_block 's behaviour different then that of a sync_block in GNU Radio?
您应该阅读 GNU Radio 的 guided tutorials,其中对这一切的解释非常清楚。你提问的内容与你的标题无关,所以我不会回答标题中的问题。
但是,您真正的问题是另一个问题:
在您的工作中尝试设置 GUI 时,出错了。
并且作为在另一个线程中给您的答案的延续:您不在work
函数中设置事物。该方法仅用于信号处理。
在构建期间设置包括 GUI 在内的流程图,即在 top_block
的 __init__
中。只有那个块将图形框架的 window object 设置为 属性.
编辑:您想实现自己的绘图仪:
你说的代码中的注释
# Comment 2 -> this doesnt work as Marcus says "Only init block has the graphical framework's window object set as property."
是一个错误的引用。只有您的 top_block 才能获得胜利 属性,因为那是 top_block 的 属性(没有其他人的)。这是基本的 python 你在这里混淆了。
其他评论
Comment 1 -> this will not work as I dont have access to input_items here
表明您还没有完全理解 GNU Radio 的工作原理。
您必须实现一个工作函数,该函数有一个参数 input_items
;显然,当您不在该函数中时,您无法访问另一个函数参数——这也是 logical/programming 语言的事情。
我在这里所能做的就是重复:阅读指导教程,并在尝试复杂的事情之前完成其中的所有练习。否则,试图帮助你的人必须解释基本的东西,尽管你有高级问题。没有办法首先熟悉如何在 Python 中为 GNU Radio 编程,而指导教程(我有没有提到你应该阅读它们?)让这变得非常容易,因为你对 python。 如果您不熟悉 python,请转到 python.org 并先学习 python2 教程。应该不会花很长时间。在深入研究使用与 GNU Radio 一样多的 object-oriented 范例的东西之前,您确实需要了解 类、方法、构造函数、变量、参数、属性的概念。
我对你的问题的评论:
- 使用现有的绘图块(在 gnuradio/gr-wxgui 中)作为参考。它们大多是用 C++ 编写的,这是有原因的。让它发挥作用非常复杂,因此实现您自己的可视化并不是初学者的任务,尤其是因为您似乎还难以理解一些基本的 python 概念。这很快也会遇到多线程问题。要清楚:你正在尝试做的事情(从块线程调用绘图函数)是有问题的,通常 不会工作。
- 今天扩展 GNU Radio 的 GUI 功能时,不要使用 WX Gui。那迟早会消失;现在 GNU Radio 非常专注于 QT。
- 您确定不能通过向现有的可视化工具提供样本来准确实现您的需求吗?那会更容易,更好地实施,也更普遍。