-
Notifications
You must be signed in to change notification settings - Fork 5
Console and Scripting
Eidolon loads scripts to execute external Python code within its internal environment. This is used in the tutorials, tests, and to load projects which are simply script files with the same name as the directory they live in. The console window in the Eidolon UI implements the same interface in an interactive mode, allowing the user to access the code and data structures of the framework at runtime. The environment is the same for both in that the same variables are present, although users do not need to import the eidolon module in the console.
Special variables are present in the environment of both console and scripts which link to internal objects:
-
mgr: refers to the
SceneManager
object for the running system -
win: refers to the
VisualizerWindow
object providing the main GUI window - Every loaded plugin is present as a variable with the name given by the plugin at init time. For example, the Nifti plugin is referred to by the variable Nifti. Every plugin name returned by the method
mgr.getPluginNames()
will be present as a variable.
A few special variables are present in loaded script files only:
- scriptdir: contains the path of the directory the script file was loaded from
-
task: the current
Task
object in which the script is being executed
Variables declared on the command line are also present in the environment.
The command line argument to use has the form --var NAME,VALUE
which will inject a variable NAME
into the local variable dictionary with value Value
.
If NAME
is not a valid Python identifier it won't be usable as a variable although it will still appear in locals()
.
Variables declared on the command line, in console, or in scripts persist into subsequently loaded scripts. If multiple scripts are specified on the command line they are executed in the order they are given, this permits arguments or scripts to setup variables to be accessed in subsequent scripts.
Given these facilities, any coding task possible in the source of the platform can be done in scripts or in the console. Learning what is possible is best done by reading the Doxygen docs, wiki pages on the code, and the source code itself, but in short anything is possible through scripts or console.
Through the console it's easy to get started with programming Eidolon by exploring what objects are present and how to manipulate them.
For example, the mgr
object can be used to query what scene objects are currently loaded:
>>> mgr.objs
[MeshSceneObject<'Tri' @ 0x00007f07c10f0310>]
A scene object can be assigned to a local variable and its members queried:
>>> o=mgr.objs[0]
>>> o.plugin
<eidolon.ScenePlugin.MeshScenePlugin object at 0x7f08000d6c90>
The internal PyDataSet
objects representing the timestep data for a mesh can be accessed:
>>> o.datasets
[DataSet<TriDS,['triind'],['vals']>]
Datasets can be cloned as part of the process to create a copy of a scene object, which can then be used in the constructor for MeshSceneObject
:
>>> ds=o.datasets[0].clone('testds')
>>> oo=MeshSceneObject('tests',ds,o.plugin)
>>> mgr.addSceneObject(oo)
The object oo
is a new scene object copied from the old which uses the same plugin.
Usually new scene objects can be created in this way, however plugins may require that objects are created through their interface.
Scripts in the test and tutorial directories give other examples of how to manipulate data in the console, since again anything that can be coded in a script file can be done through the console.