Vizard 7 » Reference » Clustering » Cluster callbacks
7.7

Cluster callbacks

The communication between the cluster master and clients is generally a one-way communication (i.e. the master sends commands to the clients to execute). However, there is limited functionality to have clients notify the master of certain input events (e.g. mouse, keyboard).

Registering callbacks

Cluster clients are capable of notifying the master of the following input events:

Cluster client events

viz.KEYDOWN_EVENT

viz.KEYUP_EVENT

viz.KEY_CHAR_EVENT

viz.MOUSEDOWN_EVENT

viz.MOUSEUP_EVENT

viz.MOUSEWHEEL_EVENT

viz.MOUSE_MOVE_EVENT

viz.DOUBLE_CLICK_EVENT

viz.BUTTON_EVENT

viz.SLIDER_EVENT

viz.LIST_EVENT

viz.WINDOW_SIZE_EVENT

To register a callback for a cluster client event, you must use the <viz>.callback command, and specify the cluster mask through the optional mask parameter. When the event is triggered on any of the specified client machines, the registered function will be called. You can determine which client triggered the event within the callback by using the <viz:cluster>.getClient command.

 

Here is an example that allows each client machine to change the background color by pressing the '1', '2', or '3' key:

import viz
viz.go()

COLORS = {'1':viz.RED,'2':viz.GREEN,'3':viz.BLUE}

def onKeyDown(key):

    if key in COLORS:

        # The client that triggered the event
        client = viz.cluster.getClient()

        # Set color only on client machine
        with viz.cluster.MaskedContext(client):
            viz.clearcolor(COLORS[key])

viz.callback(viz.KEYDOWN_EVENT, onKeyDown, mask=viz.ALLCLIENTS)

See also

In this section:

Cluster basics

Connecting your cluster

Collaboration

Cluster masks

Handling project resources

Clustering Command Table

Other sections:

Vizcave

Networking basics