events/callbacks - best practices

HankC hankc at nospam.com
Tue Oct 14 02:38:25 EDT 2003


Greetings:

I'm been programming Delphi for a while and am trying to get into the
Python mindset.  In Delphi, you can have a component class that has
properties, methods, and events.  Properties and methods translate
pretty easily to Python but I'm not sure about the best way to handle
events.  For example, from fxn retrbinary in ftplib there is:

        while 1:
            data = conn.recv(blocksize)
            if not data:
                break
            callback(data)
        conn.close()
 
In delphi this would be something like:

        while 1:
            data = conn.recv(blocksize)
            if not data:
                break
            if assigned(OnProgress) then    
                callback(data)
        conn.close()
 
In other words, the class can handle a number of events but passing a
callback function is not mandatory.  If you want to handle an event,
it is assigned and dealt with.

I'm especially interested in non-visual components (like the ftplib)
and the examples I can find all deal with the events of visual
components that interjects more complexity than I'd like at this stage
of my knowledge.

My goal is to rewrite a number of non visual components in Python.
What I'd like to find is a 'non visual component design in Python'
guide somewhere.  So...  I'm more than willing to study if I can find
the resources - if you have any please lay them on me!  Part of my
problem, I'm sure, is poor terminology use.

Of course, any general comments are welcomed - I'm not really
expecting a tutorial here, though :-)

Thanks!




More information about the Python-list mailing list