WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #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
  #2  
Old 08-10-2005, 05:49 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

This issue has been resolved since version 2.52a. I believe the latest version will be released sometime next week. When you do have the latest version you can do the following:
Code:
class VizServer(viz.EventClass):
    def __init__(self):
        viz.EventClass.__init__(self)
        self.clientName = None
        self.clientMailbox = None

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

    def connect(self, theClientName):
        self.clientName = theClientName
        self.clientMailbox = viz.add(viz.NETWORK, self.clientName)
        if not self.clientMailbox.valid():
            print __name__, ": EXCEPTION : Connection failed"
        self.callback(viz.NETWORK_EVENT, self.networkCallback)
Note that I changed your class to inherit from viz.EventClass.

Also, when posting snippets of code, you can use the following tag: [code ] insert code [/code ]
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:45 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC