Passing Python string between frames.

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.

Ken Hayse EIT

Project Engineer

Geo-Marine, Inc. - Energy Services Group
146-E Market Place Boulevard

Knoxville, TN
37922

khayse@geo-marine.com

Office: 865.692.0084 ext. 206

Fax: 865.692.0560

···

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

Ken,

two approaches here:

1. Put the list in the app, and give it to the frame constructor:

class myapp(wx.App):
    def __init__(self):
       self.thelist =

    def createFrame(self):
       frm = myframe(self, self.thelist)

class myframe(wx.Frame):
    def __init__(self, parent, thelist):
       self.thelist = thelist

    def anyotherfunction(self):
       wx.MessageBox("Number of items in list:" + str(len(self.thelist))

2. Put the list in a separate module and import this module everywhere you need the list

--- this is mylist.py ---
thelist =

--- this is myframe.py ---

import wx, mylist
class myframe(wx.Frame):
    def anyotherfunction(self):
       wx.MessageBox("Number of items in list:" + str(len(mylist.thelist))

HTH
Markus
      Ken Hayse schrieb:

···

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.

//Ken Hayse EIT//

Project Engineer

Geo-Marine, Inc. - Energy Services Group 146-E Market Place Boulevard Knoxville, TN 37922
khayse@geo-marine.com <mailto:khayse@geo-marine.com>
Office: 865.692.0084 ext. 206
Fax: 865.692.0560