How do you subclass various wx.Windows?

What about a special init method ?

class MyDialog(wx.Dialog)

     def init (self,p1,p2)
          # Do something with p1 and p2

So you can call:
        myDialog(parent...).init(p1,p2)

in this way you don't have to override __init__ method.

Ciao

G.

···

Il giorno 06/gen/07, alle ore 01:50, Christopher Barker ha scritto:

Hi all,

When I subclass a wx.Window (could be a panel, Dialog, whatever), I often need to pass in a small set of parameters. In addition to these, I'd like to be able to pass in the usual wx.Window set: size, position, flags, etc. I'm not sure the best way to do this, so I thought I'd see what you all do.

For just a couple, I tend to do something like this:

class MyDialog(wx.Dialog):

    def __init__(self, param1, param2, *args, **kwargs):
        wx.Dialog.__init__(self, *args, **kwargs)

  # Do something with param1 and param2

Which then needs to be called with:

MyDialog(p1,p2, parent, ....)

The problem with this is that param1 and param2 are non-keyword, required arguments. That's usually fine if there are just a couple, but if there are 6 or seven , and many are optional, I'm not sure what to do. Also, we're all so used to passing the parent in first.
I could do:

class MyDialog(wx.Dialog):

    def __init__(self, parent, param1=None, param2=None, **kwargs):
        wx.Dialog.__init__(self, *args, **kwargs)

  # Do something with param1 and param2

That would be OK, but then all the usual arguments need to be passed in with keywords -- not too bad.

Another option is this:

class MyDialog(wx.Dialog):
    def __init__(self, *args, **kwargs):

        self.param1 = kwargs.pop("param1", None)
        self.param2 = kwargs.pop("param2", None)

        wx.Dialog.__init__(self, *args, **kwargs)

But that requires that all extra parameters be given as keyword args (not too bad, I like to do that anyway), and also is a bit confusing, and the function signature doesn't give you any info about what's expected.

Any thoughts?

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org