A lightweight Python IDE can be accessed through the graphical interface of Tulip in order to run scripts on the graph currently visualized. Starting Tulip 3.6, it is integrated as a view plugin named “Python Script view” and can be accessed through the “View” menu. The interface of this component is composed of four tabs :
- the “Script editor” tab (see Figure 1) that allows to write scripts that can be applied to the graph currently loaded in Tulip. To do so, the “main(graph)” has to be defined and is used as the script entry point. The graph currently loaded is wrapped as a tlp.Graph object and provided as parameter of the “main” function. The currently edited script can be launched through the control panel located in the lower part of the interface. Once started, the script execution can be stopped at any time.
- the “Modules editor” tab (see Figure 2) that enables to write and edit Python modules that can be immediately imported in the main script.
- the “Interactive session” tab (see Figure 3) that provides an interactive Python shell. The graph currently loaded in Tulip is wrapped to a tlp.Graph object and bound to the “graph” variable.
- The “Tulip plugin editor” tab (see Figure 4) that allows to develop Tulip plugins in Python and registers them immediately in the interface to test them. Different kinds of plugins can be develop : General Algorithms, Property Algorithms, Import plugins and Export plugins.
Warning
If you installed Tulip from a bundle and want to import external Python modules from the Python Script view, proceed the following way according to your sytem :
The Tulip Python bindings can also be used through the classical Python Interpreter. But some setup has to be done before importing the tulip module.
First, the path to the tulip module must be provided to Python. In the following, <tulip_install_dir> represents the root directory of a Tulip installation. The Tulip Python module is installed in the following directory according to your system :
- Linux : <tulip_install_dir>/lib
- Windows : <tulip_install_dir>/bin
- Mac OS : <tulip_install_dir>/Contents/Frameworks (if you install Tulip from a bundle, <tulip_install_dir> should be /Applications/Tulip-3.X.Y.app/)
This path has to be added to the list of Python module search path. To do so, you can add it in the PYTHONPATH environment variable or add it to the sys.path list.
Second, your system must be able to find the Tulip C++ libraries in order to use the bindings. These libraries are also installed in the directory provided above. You have to add this path to :
- the LD_LIBRARY_PATH environment variable on Linux
- the DYLD_LIBRARY_PATH environment variable on Mac OS
- the PATH environment variable on Windows.
You should now be able to import the tulip module through the Python shell. Issue the following command at the shell prompt to perform that task:
>>> from tulip import *
Note
If you have installed Tulip from a bundle, the Tulip bindings were built against a specific version of Python and you need to use the same to be able to import the tulip module. The Python version differs according to your system:
- Linux and Windows : Python 2.7
- Mac OS : Python 2.5 (as we use Mac OS Leopard to build the bundle).
Note
If you want to use Tulip algorithms implemented as plugins written in C++ (e.g. graph layout algorithms), you have to load them before being able to call them (see tlp.applyAlgorithm(), tlp.Graph.computeLayoutProperty(), ...). To load all the Tulip plugins written in C++, you have to execute the following sequence of command if you compiled Tulip yourself:
>>> tlp.initTulipLib()
>>> tlp.loadPlugins()
If you installed Tulip from a bundle, you need to specify the path to the Tulip binary as parameter of the tlp.initTulipLib() because some paths were hardcoded during the compilation:
>>> tlp.initTulipLib("<path_to_tulip_binary>")
>>> tlp.loadPlugins()
The path to the Tulip binary is given below according to your system:
- Linux and Windows : <tulip_install_dir>/bin
- Mac OS : <tulip_install_dir>/Contents/MacOS