WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   custom events within classes (https://forum.worldviz.com/showthread.php?t=2028)

Penguin 05-12-2009 11:48 AM

custom events within classes
 
Hi, is it possible to register more than one function for listing on a custom event? When pressing the 'e'-button the following code should print out 'B' and 'C'. But only 'C' is printed out. When I swap the two *.enableEvent(EVENT) lines then 'B' is printed out.

Therefore I guess only one function can listen to an event at the same time. Am I right?

Code:

import viz

class A(object):
        def __init__(self):
                pass
       
        def enableEvent(self, EventID):
                viz.callback(EventID,self.doit)
               
        def doit(self):
                pass
               
class B(A):
        def __init__(self):
                pass
               
        def doit(self):
                print "B"
               
class C(A):
        def __init__(self):
                pass
               
        def doit(self):
                print "C"

viz.go()

EVENT = viz.getEventID('EVENT')

b = B()
b.enableEvent(EVENT)
c = C()
c.enableEvent(EVENT)


def sendEvent():
        viz.sendEvent(EVENT)

vizact.onkeydown('e',sendEvent)


farshizzo 05-12-2009 12:04 PM

Yes, have a look in the documentation under the Reference -> Events -> Event basics section. It contains sample code showing how to use the viz.EventClass for registering multiple objects with an event.

Gladsomebeast 05-12-2009 12:09 PM

the vizact.onevent function is pritty handy for this too

Penguin 05-12-2009 02:42 PM

Hm, could you illustrate it on my sample code please? I had a look on the event classes but I don't know how to process my own event in class A respectively B and C.

The vizact.onevent documentation is unfortunately to scarce.

Gladsomebeast 05-12-2009 03:10 PM

Code:

class A(object):
        def __init__(self):
                pass
       
        def enableEvent(self, EventID):
                vizact.onevent(EventID, lambda : (True,None),self.doit)



All times are GMT -7. The time now is 05:11 PM.

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