views:

37

answers:

2

I'm going to throw out some pseudocode. Then explain what I want, because I am not sure how to otherwise.

File_A
class Panel_A(wx.Panel)
    def __init__(self):
        button_a = wx.Button(parent=self)

    def onButton(self, event):
        pass to list view

File_B
class Panel_B(wx.panel):
    def __init__(self):
        listview_a = wx.ListView(parent=self)

File_C
import File_A
import File_B

panel_a = Panel_A()
panel_b = Panel_B()

OK, I have a panel in one module, that searches a database when I push button_a. The second module has a listview in it. Both modules are imported into a third module. I need to be able to pass the information from the search to listview_a in another module. I am not sure how to do this, since all the objects are declared in File_C but I need to use them in File_A.

+1  A: 

Use the delegate design pattern: (Pass in panel_b as an argument when instantiating Panel_A objects):

# File_A
class Panel_A(wx.Panel)
    def __init__(self,panel_b):
        self.panel_b=panel_b
        button_a = wx.Button(parent=self)

    def onButton(self, event):
        pass to self.panel_b.listview_a

# File_B
class Panel_B(wx.panel):
    def __init__(self):
        listview_a = wx.ListView(parent=self)

# File_C
import File_A
import File_B

panel_b = Panel_B()
panel_a = Panel_A(panel_b)

You may want to pass in just the ListView, instead of the whole panel. I don't know enough about your situation to know what one would be best.

unutbu
A: 

You can use a simplified version of the Observer pattern: the Panel_A class has a listener field with a fillView method that gets the list, the Panel_B implements such a method.

After the construction of both Panel_A and Panel_B, just assign to the Panel_A object's field and call self.listener.fillView(list) from inside the onButton method

Iacopo