Ken Hayse a écrit :
I am working on an application that needs to edit a List using several different frames. Each frame is dedicated to editing a specific item type in the List. No more than one editing frame will be allowed to be open at once. I am having trouble pass the List between frames. I am not sure how if and how to make the List a global variable or do I need to do something a little more subtle.
How is the list filled? Is it from a database? If so, the frames should be passed the item's ID, update the database, then just refill the list upon closing. (or refresh the modified item if the list has a _lot_ of items)...
Anyways, no need to make the list a global variable. You could just use the 'parent' parameter of the editing frame:
class EditingType2Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Title", <stuff>)
editedlist=parent.list
In the main frame (heh... mainframe. Ahem. Sorry.), just make sure that the list is accessible to 'self':
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__( [stuff...] )
self.list = wx.ListCtrl(self, -1)
# ... Layout and events init stuff ...
self.FillList()
def OnEditListItem(self,event):
itemID=self.GetItemData(event.GetIndex())
itemtype=self.GetItemType(itemID)
if itemtype==TYPE_1:
#Opening the editing frame for type 1...
win = EditingType1Frame(self)
win.CenterOnScreen()
val = win.Show()
...
elif itemtype==TYPE_2:
#Opening the editing frame for type 2...
win = EditingType2Frame(self)
win.CenterOnScreen()
val = win.Show()
...
elif ...
else:
print "Wrong type, can't find the right frame"
The GetItemData line works if you assigned an unique ID to your listitems as an ItemData.
If the items open different frames depending on their type, I'm guessing you already have a function GetItemType(itemID) to extract that item's type.
Also, instead of many different frames to edit your items, you may want to have only one frame, which will create different layouts upon its creation depending on which type is needed. But that's just me.
Hope that helps.
Nicolas
···
--
"If you try to stay sane in life, it'll just
drive you crazy. So, you may as well go crazy
now and have fun with life."
--MegaZone