REVEN-Axion 2015v1.1-r3
Python API help

Reven can be extended by using scripts and plugins.

A script and a plugin are similar except that a plugin can interact with REVEN Axion's display and can be called whith a shorcut in REVEN Axion.

Here is a quick overview on how to achieve that.

API

There are two API:

  • The main one resides in the reven library. It is used to manipulate the execution data.

    This library is accessible from everywhere on the system through a standart Python CLI and the REVEN Axion's python consolE.

    1 import reven

    The first step is to connect to an existing Reven instance, for example on port 13370 of the host localhost:

    1 client = reven.reven_connection('localhost', 13370)

    From there, all functions that permit to communicate with the Reven instance are accessible as members of client. For example, you can get the names of all runs using run_get_all():

    1 for run_name in client.run_get_all():
    2  print run_name

    In this documentation, code examples assume that there is a valid variable client that corresponds to a reven_connection instance, as described above.

  • The second one resides in the axion_api library. This API is used to interact with Reven Axion's display.

    It is accessible only in the context of REVEN Axion thougth a plugin or the REVEN Axion's python console.

    1 from axion_api import axion

    From there you can, for example, get the selected instruction:

    1 run, seq, instr = axion.selected_sequence()

REVEN Axion's python console

  • To open a REVEN Axion's python console, use the shortcut Alt+Shit+P.
  • The libraries reven and axion_api are loaded automatically.
  • A reven_connection instance is already created and is accessible under the name rvn_client.

Script

A script is a standart python program that can use the reven library but not the axion_api library.

It can be execute outside REVEN Axion as follows:

1 $ python my_script.py

Or inside the REVEN Axion's python console as follows:

1 py> axion.exec_script('<path_to_plugin/my_plugin.py')

Plugin

A plugin can use the axion_api library to interact with the REVEN Axion's display.

To make and use a plugin through REVEN Axion, process as follows:

  1. Create a file my_plugin.py in your autoload directory and define the axion_calling function.

    axion_calling plays the role of the main function for REVEN Axion.

  2. Load your plugin in REVEN Axion through the REVEN Axion's python console as follows:

    1 py> axion.load_plugin('name', 'path_to_plugin/my_plugin.py')

    Remark: 'name' will be the name of the plugin in REVEN Axion and can be different of name of the plugin file.

    To reload the plugin, use:

    1 py> axion.plugins().reload_plugin('name')
  3. Define a shortcut (using menu Action Edit shortcut or F11 by default).
  4. Call your plugin by using the shorcut.

The axion_calling function is important because when you use the shortcut define for your plugin, REVEN Axion will try to call this function. If it is not define, nothing will happen.

Reference

If you want to learn more, the following reference pages will help you:

Note the Examples section (in the header of this page) contains various python examples as well, which might provide good starting points.