这是这个问题的延续。我知道我们无法访问input_items
sync_block__init__
但我们可以访问hier_block
(例如,here)。我想在顶部块框架上添加一个面板,这只能通过将面板分配给self.win
in来完成__init__
(就像在 hier_block 示例中一样)。如果我尝试将面板分配给self.win
sync_block 的工作函数内部,则会出现错误:'xyz' object has no attribute 'win'。虽然如果我将面板分配到sync_blockself.win
内部它会起作用(这就是我想首先访问内部的原因)__init__
input_items
__init__
回应马库斯的回答
如果我想在 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
..............
..............
查看我在上面代码中添加的两个注释。既然这两种方式都行不通,那我该怎么做呢?