integrating loops in wxPython MainLoop()

Hi,
I have a looped code which looks like this (http://franklinmint.fm/blog/archives/000603.html)

import sys,xmpp

# Google Talk constants
GMAIL_ID = "recipient@gmail.com"
GMAIL_PASS = "secret"
GTALK_SERVER = "talk.google.com"

def messageHandler(conn,mess_node):
    print "Message From:",mess_node.getFrom()
    print mess_node.getChildren()[0]

def step(conn):
    try:
        conn.Process(1)
    except KeyboardInterrupt: return 0
    return 1

def loop(conn):
    while step(conn): pass

jid=xmpp.protocol.JID(GMAIL_ID)
cl=xmpp.Client(jid.getDomain(),debug=[])
if not cl.connect((GTALK_SERVER,5222)):
    raise IOError('Can not connect to server.')
if not cl.auth(jid.getNode(),GMAIL_PASS):
    raise IOError('Can not auth with server.')
cl.RegisterHandler('message',messageHandler)
cl.sendInitPresence()
print "Google Talk Client started."

loop(cl)

And Im trying to integrate it with wx.App so that I can control my GUI as well as this loop with wx. How do I do this? I know I have to create a class inherited from wx.App with special methods (overwriting the old one), which ones are they?
Or are there examples of how to do this?
Thanks for any help!
Astan

Astan Chee wrote:

Hi,
I have a looped code which looks like this (http://franklinmint.fm/blog/archives/000603.html)

import sys,xmpp

# Google Talk constants
GMAIL_ID = "recipient@gmail.com"
GMAIL_PASS = "secret"
GTALK_SERVER = "talk.google.com"

def messageHandler(conn,mess_node):
   print "Message From:",mess_node.getFrom()
   print mess_node.getChildren()[0]

def step(conn):
   try:
       conn.Process(1)
   except KeyboardInterrupt: return 0
   return 1

def loop(conn):
   while step(conn): pass

jid=xmpp.protocol.JID(GMAIL_ID)
cl=xmpp.Client(jid.getDomain(),debug=)
if not cl.connect((GTALK_SERVER,5222)):
   raise IOError('Can not connect to server.')
if not cl.auth(jid.getNode(),GMAIL_PASS):
   raise IOError('Can not auth with server.')
cl.RegisterHandler('message',messageHandler)
cl.sendInitPresence()
print "Google Talk Client started."

loop(cl)

And Im trying to integrate it with wx.App so that I can control my GUI as well as this loop with wx. How do I do this? I know I have to create a class inherited from wx.App with special methods (overwriting the old one), which ones are they?
Or are there examples of how to do this?

There is an example in samples/mainloop, but I would first try things like decomposing your other loop such that it can be run in chunks from a wx.EVT_TIMER or similar. You'll probably also want to take a look at LongRunningTasks - wxPyWiki

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!