Pass data to subclass

I am working on a program that creates a list. Upon the occurrence of an event, I want to create a dialog that will display the items in the list. So I have created a subclass of wxDialog, and I am creating an instance of that subclass in my main code. I am having trouble figuring out how to pass the list to the instance of the subclass. The “*args” and “**kwds” confuse me, and I am having trouble finding an explaination of how to use them.

class Results(wx.Dialog):
def init(self, *args, **kwds):
kwds[“style”] = wx.DEFAULT_DIALOG_STYLE
wx.Dialog.init(self, *args, **kwds)

<<<Do something to LI>>

I am creating the instance of the subclass with code snippet as follows:

    LI = [a, b, c, d]

    dialog_results = Results(None)
    result = dialog_results.ShowModal()
    dialog_results.Destroy()  

How do I pass LI to Result?

Regards,

Russ

Hi,

I am working on a program that creates a list. Upon the occurrence of an event, I want to create a dialog that will display the items in the list. So I have created a subclass of wxDialog, and I am creating an instance of that subclass in my main code. I am having trouble figuring out how to pass the list to the instance of the subclass. The “*args” and “**kwds” confuse me, and I am having trouble finding an explaination of how to use them.

class Results(wx.Dialog):
def init(self, *args, **kwds):
kwds[“style”] = wx.DEFAULT_DIALOG_STYLE
wx.Dialog.init(self, *args, **kwds)

<<<Do something to LI>>

I am creating the instance of the subclass with code snippet as follows:

    LI = [a, b, c, d]
    dialog_results = Results(None)
    result = dialog_results.ShowModal()
    dialog_results.Destroy()  

How do I pass LI to Result?

There are a bunch of ways to do this.

class Result(wx.Dialog):

def init(self, parent, my_list, *args, **kwds):

wx.Dialog.init(self, parent, *args, **kwds)

self.LI = my_list

dialog_results = Results(None, LI)

Or you could add a setter method to the dialog and

dialog_results.SetList(LI)

*args is basically just a shortcut way to capture any ordered parameters, **kwds is for keyword parameters. For clarity its usually better to write out the parameters and not use these shortcuts.

Cody

···

On Mar 23, 2010, at 5:21 AM, R. P. Hintze wrote: