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)

Kamaelia.UI.OpenGL.Interactor

General Interactor

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.

Example Usage

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()

How does it work?

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:

  • makeInteractorLinkages() -- make linkages to and from targets needed
  • setup() -- set up the component
  • handleEvents() -- handle input events ("events" inbox)
  • frame() -- called every frame, to add additional functionality

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:

  • addListenEvents(list of events) -- Request reception of a list of events
  • removeListenEvents(list of events) -- Stop reveiving events

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.


Kamaelia.UI.OpenGL.Interactor.Interactor

class Interactor(Axon.AdaptiveCommsComponent.AdaptiveCommsComponent)

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:

  • target -- OpenGL component to interact with
  • nolink -- if True, no linkages are made (default=False)

Inboxes

  • control : For shutdown messages
  • callback : for the response after a displayrequest
  • inbox : not used
  • events : Input events

Outboxes

  • outbox : used for sending relative tranlational movement
  • signal : For shutdown messages
  • display_signal : Outbox used for communicating to the display surface

Methods defined here

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.

__init__(self, **argd)

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

addListenEvents(self, events)

Sends listening request for pygame events to the display service. The events parameter is expected to be a list of pygame event constants.

frame(self)

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.

handleEvents(self)

Method stub

Override this method to do event handling inside. Should look like this:

while self.dataReady("events"):
    event = self.recv("events")
    # handle event ...

main(self)

makeInteractorLinkages(self)

Method stub

removeListenEvents(self, events)

Sends stop listening request for pygame events to the display service. The events parameter is expected to be a list of pygame event constants.

setup(self)

Method stub

Override this method for component setup. It will be called on the first scheduling of the component.

Feedback

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