multiple frame instances?

In the for loop I’m created 2 instances of a wx.MiniFrame, and 2 menu items.

for ContSetting in self.ContSettings:
ContLabel = ContSetting[‘Label’] # get value from the dictionary.
ContSetting[‘MenuItem’] = wx.MenuItem(self.TopiView, wx.ID_ANY, ContLabel, ‘’, wx.ITEM_CHECK)
self.Containers.AppendItem(ContSetting[‘MenuItem’]) # appends menu item to Containers Menu.
self.Bind(wx.EVT_MENU, lambda event, data=ContSetting: self.ContainerCallBack(event, data), ContSetting[‘MenuItem’])
class Container(wx.MiniFrame):
def init(self, parent, id):
wx.MiniFrame.init(self, parent, id, title=ContSetting[‘Label’], size=(500,150))
ContSetting[‘Frame’] = Container(self, 1)

def ContainerCallBack(self, event, data):
if data[‘MenuItem’].IsChecked():
if not hasattr(self, ‘Cont’):
self.Cont = data[‘Frame’]
self.Cont.Show(True)
event.Skip()
else:
if hasattr(self, ‘Cont’):
self.Cont.Hide()
event.Skip()

And the ContainerCallBack tries to “show” each instance. What I get is the same instance shown and hidden.

Someone show me the right way to create multiple instances of a frame dependant on data in a dictionary.

I think someone showed me before, but I couldn’t find the message.

Thanks in advance.

Steve

Steve Freedenburg wrote:

In the for loop I'm created 2 instances of a wx.MiniFrame, and 2 menu items.

And the ContainerCallBack tries to "show" each instance. What I get is the same instance shown and hidden.
Someone show me the right way to create multiple instances of a frame dependant on data in a dictionary.

I won't take the time to decipher your code, but will instead lay out the basic principle and let you apply it yourself. Ready? Here it is: In order to access an object later, you need to save a reference to it in a place that is accessible at the point where you need it later. It's as simple as that. Where that place is and what kind of thing it is depends on the needs of your app, how many references you are saving, and how you need to access them later. It's just basic Python.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin...
Sometimes the simplest explaination is the best. You explaination was what I've been doing all along,
sticking "things" in dictionaries... I took a look at the code, and simplified it... Thanks for the help!
Works like a champ.

    def ContainerCallBack(self, event, data):
        if data['MenuItem'].IsChecked():
            data['Frame'].Show(True)
            event.Skip()
        else:
            data['Frame'].Hide()
            event.Skip()

···

----- Original Message ----- From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Wednesday, 13 August, 2008 17:47
Subject: Re: [wxpython-users] multiple frame instances?

Steve Freedenburg wrote:

In the for loop I'm created 2 instances of a wx.MiniFrame, and 2 menu items.

And the ContainerCallBack tries to "show" each instance. What I get is the same instance shown and hidden.
Someone show me the right way to create multiple instances of a frame dependant on data in a dictionary.

I won't take the time to decipher your code, but will instead lay out the basic principle and let you apply it yourself. Ready? Here it is: In order to access an object later, you need to save a reference to it in a place that is accessible at the point where you need it later. It's as simple as that. Where that place is and what kind of thing it is depends on the needs of your app, how many references you are saving, and how you need to access them later. It's just basic Python.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users