Developer Documentation
Scripting Interface


ScriptInterface.png


OpenFlipper uses QTs scripting system to provide scripting functions to the user and to the plugins. It also includes a batch mode where OpenFlipper is started without an user interface. All plugins which support this mode can than be controlled by command line supplied batch scripts without any user interaction.

The ScriptingInterface has several functions to support scripting.

  • Execute scripts which are provided in a simple QString (ScriptInterface::executeScript()).
    emit executeScript( "translate( 5 , Vector(1 , 0 , 0 ) )" );
    This will translate The object with id 6 by the given vector.
  • Execute scripts which are provided in a file (ScriptInterface::executeFileScript()).
    emit executeFileScript( "/home/user/script.ofs" );
  • If a scriptable slot is executed, it can add an entry to OpenFlippers script history. This history can later be used to rerun a process in batch mode ( ScriptInterface::scriptInfo() ).

    The following example code shows a function called translate in a plugin, that gets an ObjectId as a parameter. The plugin which emits this function will automatically be added in the history ( e.g. move.translate( ObjectId , Vector(1 , 0 , 0 ) ) )

    emit scriptInfo( "translate( ObjectId , Vector(1 , 0 , 0 ) )" );
  • Get Information about scriptable functions ( ScriptInterface::getAvailableFunctions(),ScriptInterface::getDescription() ).

    The first function ( ScriptInterface::getAvailableFunctions() ) can be used to get a QStringlist of all available functions. Each string is of the form pluginname.functionname

    // Update list of available functions
    QStringList completeList;
    emit getAvailableFunctions( completeList );

    The second function ( ScriptInterface::getDescription() ) can be used to get information about a function, if it was provided by the developer.

To use the ScriptInterface:

  • include ScriptInterface.hh in your plugins header file
  • derive your plugin from the class ScriptInterface
  • add Q_INTERFACES(ScriptInterface) to your plugin class
  • And add the signals or slots you want to use to your plugin class (You don't need to implement all of them)

An easier interface to call functions is available by the RPC Interface. Additionally it is possible to connect signals and slots across plugins via the Plugin Connection Interface