View Single Post
  #1  
Old 08-10-2005, 05:55 AM
Gilliard Gilliard is offline
Member
 
Join Date: Jul 2005
Location: Switzerland
Posts: 7
method of a class instance not accepted as Callback

Is it impossible to use a method of an instance as callback ?
(As it can be done in Tkinter e.g. in x = Button(self, text="quit", command=self.quit)

My piece of code : (without indentation ! ??, why)

class VizServer:

def __init__(self):
self.clientName = None
self.clientMailbox = None

def networkCallback(self, message):
print "Message content : ", message[2:]

def connect(self, theClientName):
self.clientName = theClientName
try:
self.clientMailbox = viz.add(viz.NETWORK, self.clientName)
except:
print __name__, ": EXCEPTION : Connection failed"
viz.callback(viz.NETWORK_EVENT, self.networkCallback) # --> ERROR : "** Error: Invalid callback type"

# End of class !

If I put my "networkCallback(message) outside the class, it works ... but I don't have access to the instance attributes and methods anymore !
__________________
Bertrand Gilliard

Last edited by Gilliard; 08-10-2005 at 05:57 AM.
Reply With Quote