[Tutor] use of WxPython class, method, etc

Jeff Shannon jeff@ccvcorp.com
Wed, 24 Oct 2001 09:49:02 -0700


>
> On Thu, 25 Oct 2001 03:56:40, "Adinda Praditya" <pemrograman@telkom.net> wrote:
>
> I restarted over then. here's another story about my problem. From manual :
> ===
> There are two different ways to use this class:
>
>  You may derive a new class from wxTimer and override the Notify member to
> perform the required action.

Try something like this:
-------------------------------
class MyTimer(wxTimer):
    def __init__(self):
        wxTimer.__init__(self)  # just in case...
    def Notify(self):
        SomeOtherControl.AddText('Timer went off!')
---------------------------------
Now, use this MyTimer class where you're currently trying to use a wxTimer.  MyTimer
*is* a wxTimer--but it's also got a newer Notify method, that actually does something.
What exactly it does is up to you.  :)  I've also included an __init__() method, which
does nothing other than call the base class (wxTimer) __init__().  This shouldn't be
strictly necessary, as the base method should be called automatically if you don't
define one in the derived class, but it doesn't hurt, and makes it a bit easier if you
later decide that you need to do something special when setting up the timer (storing
the start time, etc).


> Did i miss something? I think the manual doesn't give me a clear definition
> and syntax or i'm a stupid person! I still don't get it. Does anyone has a
> better explanation to understand these stuff (how to use, work with class, method,
> object) Please help me.

The manual *is* a bit confusing--for starters, it's really written for C++, not Python,
and even though most of the information carries straight over, it does require a bit of
translating, which can be difficult if you know nothing of C++.  It also assumes
moderate familiarity with object-oriented programming and the typical terms in OOP.  Any
time you're told to "override this method", it really means "create a subclass of this
class, and give that subclass a method with this name and call signature (number and
type of parameters, return value, etc)".  I wish I knew a site with a good description
of OOP to recommend--maybe someone else can suggest something?


> thank you,
>
> Adinda Praditya

You're welcome.  Hope that this was helpful for you.  :)

Jeff Shannon
Technician/Programmer
Credit International