Viewer.add_action

Viewer.add_action(pressed_action, key, released_action=None, modifier=None, name=None)[source]

Add a custom action to the viewer.

Parameters:
pressed_actionCallable

The function to be called when the key is pressed.

keystr

The key to be pressed.

released_actionCallable, optional

The function to be called when the key is released. Default to None.

modifierstr, optional

The modifier of the key. Default to None.

namestr, optional

The name of the action. Default to the name of the pressed_action function.

Returns:
compas_viewer.actions.Action

The action object.

Examples

from compas.geometry import Scale
from compas.geometry import Transformation
from compas_viewer import Viewer
viewer = Viewer()
faces = viewer.add(Mesh.from_obj(compas.get("faces.obj")))
faces.transformation = Transformation()
def pressed_action():
    faces.transformation *= Scale.from_factors([1.1, 1.1, 1.1], Frame.worldXY())
    faces.update()
action = viewer.add_action(pressed_action, "p")
viewer.show()