August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
This component implements the basic functionality of an Interactor. An Interactor listens to events of another component and tranlates them into movement which is applied to the target component. It provides methods to be overridden for adding functionality.
A very simple Interactor could look like this:
class VerySimpleInteractor(Interactor):
def makeInteractorLinkages(self):
self.link( (self,"outbox"), (self.target, "rel_rotation") )
def setup(self):
self.addListenEvents([pygame.MOUSEBUTTONDOWN])
def handleEvents(self):
while self.dataReady("events"):
event = self.recv("events")
if self.identifier in event.hitobjects:
self.send((0,90,0))
For examples of how to create Interactors have a look at the files XXXInteractor.py.
A MatchedInteractor and a RotationInteractor each interacting with a SimpleCube:
CUBE1 = SimpleCube(size=(1,1,1), position=(1,0,0)).activate()
CUBE2 = SimpleCube(size=(1,1,1), position=(-1,0,0)).activate()
INTERACTOR1 = MatchedTranslationInteractor(target=CUBE1).activate()
INTERACTOR2 = SimpleRotationInteractor(target=CUBE2).activate()
Axon.Scheduler.scheduler.run.runThreads()
Interactor provides functionality for interaction with the OpenGL display service and OpenGL components. It is designed to be subclassed. The following methods are provided to be overridden:
Stubs method are provided, so missing these out does not result in broken code. The methods get called from the main method, the following code shows in which order:
def main(self):
# create and send eventspy request
...
# setup function from derived objects
self.setup()
...
while 1:
yield 1
# handle events function from derived objects
self.handleEvents()
# frame function from derived objects
self.frame()
If you need to override the __init__() method, e.g. to get initialisation parameters, make sure to pass on all keyword arguments to __init__(...) of the superclass, e.g.:
def __init__(self, **argd):
super(ClassName, self).__init__(**argd)
# get an initialisation parameter
myparam = argd.get("myparam", defaultvalue)
The following methods are provided to be used by inherited objects:
The are inteded to simplify component handling. For their functionality see their description.
The event identifier of the target component gets saved in self.identifier. Use this variable in event handling to determine if the target component has been hit.
Interactor components terminate if a producerFinished or shutdownMicroprocess message is received on their "control" inbox. The received message is also forwarded to the "signal" outbox. Upon termination, this component does not unbind itself from the OpenGLDisplay service and does not free any requested resources.
Interactor(...) -> A new Interactor object (not very useful, designed to be subclassed)
This component implements the basic functionality of an Interactor. An Interactor listens to events of another component and tranlates them into movement which is applied to the target component. It provides methods to be overridden for adding functionality.
Keyword arguments:
Warning!
You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Sends listening request for pygame events to the display service. The events parameter is expected to be a list of pygame event constants.
Method stub
Override this method for operations you want to do every frame. It will be called every time the component is scheduled. Do not include infinite loops, the method has to return every time it gets called.
Method stub
Override this method to do event handling inside. Should look like this:
while self.dataReady("events"):
event = self.recv("events")
# handle event ...
Method stub
Sends stop listening request for pygame events to the display service. The events parameter is expected to be a list of pygame event constants.
Method stub
Override this method for component setup. It will be called on the first scheduling of the component.
Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!
Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.
-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT