casagui.bokeh.sources._data_pipe

Implementation of a general purpose event manager between Python and JavaScript via websockets. This provides a mechanism like the ImagePipe. The difference is that ImagePipe is tuned for use with CASA images but DataPipe can have generic messages.

Module Contents

Classes

DataPipe

This class allows for communication between Python and the JavaScript implementation

class casagui.bokeh.sources._data_pipe.DataPipe(*args, abort=None, **kwargs)

This class allows for communication between Python and the JavaScript implementation running in a browser. It allows Python code to send a message to JavaScript and register a callback which will receive the result. JavaScript code can do the same to request information from Python. Generally messages are expected to be dictionaries in the Python domain and objects in the JavaScript domain. UUIDs are used to keep messages in sync, and messages sent with the same UUID are queued until the currently pending message reply is recieved. A class can use multipe UUIDs to control queuing behavior.

address

the string is the IP address for the network that should be used and the integer is the port number, see casagui.utils.find_ws_address

Type:

tuple of string and int

init_script

this javascript is run when this DataPipe object is initialized. init_script is used to run caller JavaScript which needs to be run at initialization time. This is optional and does not need to be set.

Type:

JavaScript

register(ident, callback)

Register a callback to handle all requests coming from JavaScript. The callback will be called whenever a request arrives.

Parameters:
  • ident (string) – UUID which is associated with the messages that should be delivered to this callback

  • callback ((string) => dictionary) – Callback which receives the message from Python as its sole parameter. The return value of this callback is delivered to the JavaScript code as the ‘’reply’’ to to JavaScript in response to the ‘’request’’ contained in the message.

async send(ident, message, callback)

Send a message to JavaScript identified by ident. Once the reply is received, the callback will be called with the reply message.

Parameters:
  • ident (string) – UUID to associate with this message. It is used to keep track of the callback that should be called when the reply is received.

  • message (dictionary) – This dictionary contains the request for the JavaScript code.

  • callback ((string) => void) – Callback which receives the message that JavaScript generates in response to the request contained in the message parameter.

async process_messages(websocket)

Process messages related to image display updates.

Parameters:
  • websocket (websocket object) – Websocket serve function passes in the websocket object to use.

  • path – Websocket serve provides a second parameter.