Link Search Menu Expand Document

Events in arena-py

Events are ways to interact with user input in the ARENA.

See object definition reference.

Event handlers

To handle events in arena-py, you must set a function to the evt_handler parameter. When you attach an evt_handler to an Object, you will receive Event objects in your handler. Below is how you access attributes of the Event object.

# [scene] is the Scene that called the callback
# [evt] will be an Event instance
# [msg] is the raw JSON message as a dict
def click_handler(scene, evt, msg):
    ## Get Event type
    evt.type # == "buttonClick", "mousedown", "mouseup", "mouseenter", "mouseleave", etc.

    ## Get Event data
    # etc.

box = Box(..., evt_handler=click_handler) # note the use of "evt_handler=click_handler"
# could also do box.evt_handler = click_handler
# or box.update_attributes(evt_handler=click_handler)

Generating events with arena-py Scenes

Click Events

There are several types of click events that you can generate (mousedown, mouseup, mouseenter, mouseleave, triggerdown, triggerup):

scene.generate_click_event(obj, type, ...)

# add a click listener to an object to be able to click it
# generate a "fake" click event from arena-py
# arena-py will "click" obj with mouseup. In JSON, "source" will be defined as "arena_lib_[some random ID here]".

Camera Manipulation Events

You can also move a user’s camera and/or make it look at a specific location or object:

scene.manipulate_camera(obj, type, ...)

# move camera:

# make camera look at something/some position:
    target=box # can also do a position: (0,0,0)

Generic Events

If there is an event that does not exist yet, you can use this to have more freedom in the event type:

# define custom event
evt = Event(type="my_custom_event", position=(3,4,5), target=sphere)
# generate custom event with arena-py client
scene.generate_custom_event(evt, action="clientEvent")


Event(object_id, action, type, ...)