Difference between revisions of "ParaView/Plugin HowTo"

From KitwarePublic
Jump to navigationJump to search
Line 216: Line 216:

For the GROUP_NAME, we are using '''ToolBar/SourceToolbar'''; here '''ToolBar''' is a keyword which implies that the action group is a toolbar (and shows up under '''View | Toolbars''' menu) with the name '''SourceToolbar'''. When the plugin is loaded, this toolbar will show up with two buttons.
For the GROUP_NAME, we are using '''ToolBar/SourceToolbar'''; here '''ToolBar''' is a keyword which implies that the action group is a toolbar (and shows up under '''View | Toolbars''' menu) with the name '''SourceToolbar'''. When the plugin is loaded, this toolbar will show up with two buttons.
==Adding a Menu==
Adding a menu to the menu bar of the main window is almost identical to [[#Adding a Toolbar]].  The only difference is that you use the keyword '''MenuBar''' in lieu of '''ToolBar''' in the GROUP_NAME of the action group.  So if you change the ADD_PARAVIEW_ACTION_GROUP command above to the following, the plugin will add a menu titled MyActions to the menu bar.
                          <font color="purple">CLASS_NAME</font> SourceToolbarActions
                          <font color="purple">GROUP_NAME</font> "MenuBar/MyActions")
If you give the name of an existing menu, then the commands will be added to that menu rather than create a new one.  So, for example, if the GROUP_NAME is '''MenuBar/File''', the commands will be added to the bottom of the File menu.

== Adding an object panel ==
== Adding an object panel ==

Revision as of 15:24, 20 February 2009


ParaView comes with plethora of functionality bundled in: several readers, multitude of filters, quite a few different types of views etc. However, it is not uncommon for developers to want to add new functionality to ParaView for eg. to add support to their new file format, incorporate a new filter into paraview etc. ParaView makes it possible to add new functionlity by using an extensive plugin mechanism.

Plugins can be used to extend ParaView in several ways:

  • Add new readers, writers, filters
  • Add custom GUI components such as toolbar buttons to perform common tasks
  • Add new views in for display data

Examples for different types of plugins are provided with the ParaView source under Examples/Plugins/.

This document has major sections:

  • First section covers how to use existing plugins in ParaView.
  • Second section contains information for developers about writing new plugins for ParaView.

Using Plugins

Plugins are distributed as shared libraries (*.so on Unix, *.dylib on Mac, *.dll on Windows etc). For a plugin to be loadable in ParaView, it must be built with the same version of ParaView as it is expected to be deployed on. Plugins can be classified into two broad categories:

  • Server-side plugins
These are plugins that extend the algorithmic capabilities for ParaView eg. new filters, readers, writers etc. Since in ParaView data is processed on the server-side, these plugins need to be loaded on the server.
  • Client-side plugins
These are plugins that extend the ParaView GUI eg. property panels for new filters, toolbars, views etc. These plugins need to be loaded on the client.

Oftentimes a plugin has both server-side as well as client-side components to it eg. a plugin that adds a new filter and a property panel that goes with that filter. Such plugins need to be loaded both on the server as well as the client.

Generally, users don't have to worry whether a plugin is a server-side or client-side plugin. Simply load the plugin on the server as well as the client. ParaView will include relevant components from plugin on each of the processes.

There are three ways for loading plugins:

  • Using the GUI (Plugin Manager)
Plugins can be loaded into ParaView using the Plugin Manager accessible from Tools | Manage Plugins/Extensions menu. The Plugin Manager has two sections for loading local plugins and remote plugins (enabled only when connected to a server). To load a plugin on the local as well as remote side, simply browse to the plugin shared library. If the loading is successful, the plugin will appear in the list of loaded plugins. The Plugin manager also lists the paths it searched to load plugins automatically.
Figure 1: Plugin Manager when not connected to a remote server, showing loaded plugins on the local site.
Figure 2: Plugin Manager when connected to a server showing loaded plugins on the local as well as remote sites.
  • Using environment variable (Auto-loading plugins)
Plugins loaded using the Plugin Manager are not saved across sessions. Hence one has to reload those plugins every time ParaView is started. If one wants ParaView to automatically load a set of plugins on startup, one can use the PV_PLUGIN_PATH environment variable. PV_PLUGIN_PATH can be used to list a set of directories (separated by colon (:) or semi-colon (;)) which ParaView will search on startup to load plugins. This enviromnent variable needs to be set on both the client node to load local plugins as well as the remote server to load remote plugins.
  • Placing the plugins in a recognized location. Recognized locations are:
    • A plugins subdirectory beneath the directory containing the paraview client or server executables. This can be a system-wide location if installed as such.
    • A Plugins subdirectory in the user's home area. On Unix/Linux/Mac, $HOME/.config/ParaView/ParaView<version>/Plugins. On Windows %APPDATA$\ParaView\ParaView<version>\Plugins.

Writing Plugins

This section covers writing and compiling different types of Plugins. To create a plugin, one must have their own build of ParaVeiw3. Binaries downloaded from www.paraview.org do not include necessary header files or import libraries (where applicable) for compiling plugins.

The beginning of a CMakeLists.txt file contains


Where CMake will ask for the ParaView_DIR which you point to your ParaView build. The PARAVIEW_USE_FILE includes build parameters and macros for building plugins.

Adding a Filter

In this plugin, we want to add a new filter ParaView. The filter has to be a VTK-based algorithm, written as following the standard procedures for writing VTK algorithms. Generally for such cases where we are adding a new VTK class to ParaView (be it a filter, reader or a writer), we need to do the following tasks:

  • Write a Server Manager Configuration XML which describes the Proxy interface for the new VTK class. Basically, this defines the interface for the client to create and modify instances of the new class on the server side. Please refer to the ParaView Guide for details about writing these server-manager xmls.
  • Write a configuration XML for the GUI to make ParaView GUI aware of this new class, if applicable. For filters, this is optional, since ParaView automatically recognizes filters added through plugins and lists them in the Alphabetical sub-menu. One may use the GUI configuration xml to add the new filter to a specific category in the Filters menu, or add a new category etc. For readers and writers, this is required since ParaView GUI needs to know what extensions your reader/writer supports etc.

For this example, refer to Examples/Plugins/Filter in the ParaView source. Let's say we have written a new vtkMyElevationFilter (vtkMyElevationFilter.h|cxx), which extends the functionality of the vtkElevationFilter and we want to package that as a plugin for ParaView. For starters, we simply want to use this filter in ParaView (not doing anything fancy with Filters menu categories etc.). As described, we need to write the server manager configuration XML (MyElevationFilter.xml). Once that's done, we write a CMakeLists.txt file to package this into a plugin.

This CMakeLists.txt simply needs to include the following lines:

 # Locate ParaView build and then import CMake configuration, 
 # macros etc. from it.
 # Use the ADD_PARAVIEW_PLUGIN macro to build a plugin
   MyElevation                 #<--Name for the plugin
  "1.0"                        #<--Version string
   SERVER_MANAGER_XML MyElevationFilter.xml  #<-- server manager xml
   SERVER_MANAGER_SOURCES vtkMyElevationFilter.cxx #<-- source files for the new classes

Then using cmake and a build system, one can build a plugin for this new filter. Once this plugin is loaded the filter will appear under the "Alphabetical" list in the Filters menu.

Adding Categories to the Filters Menu

Now suppose we want to add a new category to the Filters menu, called "Extensions" and then show this filter in that submenu. In that case, we'll need a GUI configuration xml to tell the ParaView GUI to create the category. This GUI configuration xml will look as such:

    <Category name="Extensions" menu_label="&amp;Extensions">
      <!-- adds a new category and then adds our filter to it -->
      <Filter name="MyElevationFilter" />

If the name of the category is same as an already existsing category eg. Data Analysis, then the filter gets added to the existing category.

The CMakeLists.txt must change to include this new xml (let's call it MyElevationGUI.xml) as follows:

 ADD_PARAVIEW_PLUGIN(MyElevation "1.0"
   SERVER_MANAGER_XML MyElevationFilter.xml 
   SERVER_MANAGER_SOURCES vtkMyElevationFilter.cxx

Adding Icons

You can see that some filters in the Filters menu (eg. Clip) have icons associated with them. It's possible for the plugin to add icons for filters it adds as well. For that you need to write a Qt resource file (say MyElevation.qrc) as follows:

    <qresource prefix="/MyIcons" >

The GUI configuration xml now refers to the icon provided by this resource as follows:

    <Category name="Extensions" menu_label="&amp;Extensions">
      <!-- adds a new category and then adds our filter to it -->
      <Filter name="MyElevationFilter" icon=":/MyIcons/MyElevationIcon.png" />

Finally, the CMakeLists.txt file much change to include our MyElevation.qrc file as follows:


  SERVER_MANAGER_XML MyElevationFilter.xml 
  SERVER_MANAGER_SOURCES vtkMyElevationFilter.cxx
  GUI_RESOURCES MyElevation.qrc

Enabling a filter in VTK

Sometimes, the filter that one wants to add to ParaView is already available in VTK, it's just not exposed through the ParaView GUI. For such filters too, one can create a plugin as with a new filter. In this case too we need the server manager configuration xml for the filter describing it's API and the optional GUI xml to add the filter to any specific category.

For example, let's say we simply want to expose the vtkCellDerivatives in VTK. Then first, we'll write the server manager configuration XML (call it vtkCellDerivatives.xml), similar to what we would have done for adding a new filter. Please refer to the ParaView Guide for details about writing this XML.

Now we can compile this into a plugin using the following CMakeLists.txt


ADD_PARAVIEW_PLUGIN(CellDerivatives "1.0"
  SERVER_MANAGER_XML CellDerivatives.xml)

However, this would require ParaView built from source (as described earlier). Alternatively, we can simply load the XML from the Plugins Manager (just select the file type to be *.xml in the file open dialog).

Similarly compiled Qt resources (*.bqrc) can be loaded at runtime. *.bqrc is a binary file containing resources which can include icons, the GUI configuration xmls for adding catergories etc. A .bqrc can be made from a .qrc by running the rcc utility provided by Qt:

 rcc -binary -o myfile.bqrc myfile.qrc.

Adding a Reader

Adding a new reader to a plugin is similar to adding a filter except that instead of the GUI configuration xml describing categories in the filter menu, we require the xml to define what file extensions this reader can handle. This xml (MyReaderGUI.xml) looks like this:

    <Reader name="MyPNGReader" extensions="mypng"
            file_description="My PNG Files">

And the CMakeLists.txt looks as follows where vtkMyPNGReader.cxx is the source for the reader, MyPNGReader.xml is the server manager configuration xml, and MyReaderGUI.xml is the GUI configuration xml described above:


If you want your reader to work correctly with a file series, please refer to file series animation for details.

Adding a Writer

Similar to a reader, for a writer we need to tell ParaView what extensions this writer supports. This can be done using the GUI XML as follows:

    <Writer name="MyTIFFWriter"
            file_description="My Tiff Files">

Adding a Toolbar

Filters, reader and writers are by far the most common ways for extending ParaView. However, ParaView plugin functionality goes far beyond that. The following sections cover some of these advanced plugins that can be written.

Applications use toolbars to provide easy access to commonly used functionality. It is possible to have plugins that add new toolbars to ParaView. The plugin developer implements his own C++ code to handle the callback for each button on the toolbar. Hence one can do virtually any operation using the toolbar plugin with some understanding of the ParaView Server Manager framework and the ParaView GUI components.

Please refer to Examples/Plugins/SourceToolbar for this section. There we are adding a toolbar with two buttons to create a sphere and a cylinder source. For adding a toolbar, one needs to implement a subclass for QActionGroup which adds the QActions for each of the toolbar button and then implements the handler for the callback when the user clicks any of the buttons. In the example SourceToobarActions.h|cxx is the QActionGroup subclass that adds the two tool buttons.

To build the plugin, the CMakeLists.txt file is:

 # We need to wrap for Qt stuff such as signals/slots etc. to work correctly.
 QT4_WRAP_CPP(MOC_SRCS SourceToolbarActions.h)
 # This is a macro for adding QActionGroup subclasses automatically as toolbars.
                         CLASS_NAME SourceToolbarActions
                         GROUP_NAME "ToolBar/SourceToolbar")
 # Now create a plugin for the toolbar. Here we pass IFACES and IFACE_SRCS
 # which are filled up by the above macro with relevant entries
 ADD_PARAVIEW_PLUGIN(SourceToolbar "1.0"
                   GUI_INTERFACES ${IFACES}
                   SOURCES ${MOC_SRCS} ${IFACE_SRCS} 

For the GROUP_NAME, we are using ToolBar/SourceToolbar; here ToolBar is a keyword which implies that the action group is a toolbar (and shows up under View | Toolbars menu) with the name SourceToolbar. When the plugin is loaded, this toolbar will show up with two buttons.

Adding a Menu

Adding a menu to the menu bar of the main window is almost identical to #Adding a Toolbar. The only difference is that you use the keyword MenuBar in lieu of ToolBar in the GROUP_NAME of the action group. So if you change the ADD_PARAVIEW_ACTION_GROUP command above to the following, the plugin will add a menu titled MyActions to the menu bar.

                         CLASS_NAME SourceToolbarActions
                         GROUP_NAME "MenuBar/MyActions")

If you give the name of an existing menu, then the commands will be added to that menu rather than create a new one. So, for example, if the GROUP_NAME is MenuBar/File, the commands will be added to the bottom of the File menu.

Adding an object panel

Object Panels are the panels for editing object properties.

ParaView3 contains automatic panel generation code which is suitable for most objects. If you find your object doesn't have a good auto-generated panel, you can make your own.

To make your own, there is an explanation found on CustomObjectPanels

Now let's say we have our own panel we want to make for a ConeSource. In this example, we'll just add a simple label saying that this panel came from the plugin. In ConePanel.h:

 #include "pqAutoGeneratedObjectPanel.h"
 #include <QLabel>
 #include <QLayout>
 class ConePanel : public pqAutoGeneratedObjectPanel
   ConePanel(pqProxy* pxy, QWidget* p)
     : pqAutoGeneratedObjectPanel(pxy, p)
     this->layout()->addWidget(new QLabel("This is from a plugin", this));

Then in our CMakeLists.txt file:

                         CLASS_NAME ConePanel
                         XML_NAME ConeSource XML_GROUP sources)
                    GUI_INTERFACES ${IFACES}
                    SOURCES ${MOC_SRCS} ${IFACE_SRCS})

Adding components to Display Panel (decorating display panels)

Display panel is the panel shown on the Display tab in the Object Inspector. It is possible to add GUI components to existing display panels.

In this example we want to add a GUI element to the display panel shown for the spread sheet view to size of data that is fetched to the client at one time referred to as the Block Size.

For that we write the implementation in QObject subclass (say MySpreadsheetDecorator) with a constructor that takes in the pqDisplayPanel which is to be decorated.

class MySpreadsheetDecorator : public QObject
  MySpreadsheetDecorator(pqDisplayPanel* panel);
  virtual ~MySpreadsheetDecorator();

In the constructor, we have access to the panel, hence we can get the layout from it and add custom widgets to it. In this case, it would be a spin-box or a line edit to enter the block size. pqDisplayPanel::getRepresentation() provides access to the representation being shown on the panel. We can use pqPropertyLinks to link the "BlockSize" property on the representation with the spin-box for the block size so that when the widget is changed by the user, the property changes and vice-versa.

Now the CMakeLists.txt to package this plugin looks like follows:

 QT4_WRAP_CPP(MOC_SRCS MySpreadsheetDecorator.h)
 # This is the macro to add a display panel decorator.
 # It needs the class name, and the panel types we are decorating. It fills up 
 # IFACES and IFACE_SRCS with proper values as needed by ADD_PARAVIEW_PLUGIN macro.
   CLASS_NAME MySpreadsheetDecorator
   PANEL_TYPES pqSpreadSheetDisplayEditor 
       # <-- This identifies the panel type(s) to decorate
       # Our decorator will only be instantiated for the panel types indicated here
 # create a plugin
 ADD_PARAVIEW_PLUGIN(MySpreadsheetDecorator "1.0" 
   SOURCES MySpreadsheetDecorator.cxx ${MOC_SRCS} ${IFACE_SRCS})

An example panel decorator is available under Examples/Plugins/DisplayPanelDecorator in the ParaView source.

Autostart Plugins

This refers to a plugin which needs to be notified when ParaView starts up or the plugin is loaded which ever happens later and then notified when ParaView quits. Example is in Examples/Plugins/Autostart in the ParaView source. For such a plugin, we need to provide a QObject subclass (pqMyApplicationStarter) with methods that need to be called on startup and shutdown.

class pqMyApplicationStarter : public QObject
  // Callback for startup.
  // This cannot take any arguments
  void onStartup();

  // Callback for shutdown.
  // This cannot take any arguments
  void onShutdown();

The CMakeLists.txt looks as follows:

 QT4_WRAP_CPP(MOC_SRCS pqMyApplicationStarter.h)
 # Macro for auto-start plugins. We specify the class name
 # and the methods to call on startup and shutdown on an instance of that class.
 # It fills IFACES and IFACE_SRCS with proper values as needed by ADD_PARAVIEW_PLUGIN macro.
   CLASS_NAME pqMyApplicationStarter # the class name for our class
   STARTUP onStartup   # specify the method to call on startup
   SHUTDOWN onShutdown # specify the method to call on shutdown
 # Create a plugin for this starter 
 ADD_PARAVIEW_PLUGIN(Autostart "1.0" 
   SOURCES pqMyApplicationStarter.cxx ${MOC_SRCS} ${IFACE_SRCS})

Adding a custom view

ParaView contains a render view for rendering 3d images. It also contains chart views to visualize data in line charts and histogram charts. You may want to create another custom view that does your own view of the data.

For this example, we'll just make a simple Qt widget with labels showing the displays that have been added to the view.

To make a custom view, we need both client and server side plugins.

For our server side, we simply have:

  <ProxyGroup name="displays">
   <GenericViewDisplayProxy name="MyDisplay"
     base_proxygroup="displays" base_proxyname="GenericViewDisplay">
  <ProxyGroup name="views">
   <ViewModuleProxy name="MyViewViewModule"
     base_proxygroup="rendermodules" base_proxyname="ViewModule"
  <ProxyGroup name="filters">
   <SourceProxy name="MyExtractEdges" class="vtkExtractEdges"
     label="My Extract Edges">
         <ProxyGroupDomain name="groups">
           <Group name="sources"/>
           <Group name="filters"/>
         <DataTypeDomain name="input_type">
           <DataType value="vtkDataSet"/>
       <View type="MyView"/>

We define "MyDisplay" as a simple display proxy, and "MyViewModule" as a simple view module. We have our own filter "MyExtractEdges" with a hint saying it prefers to be shown in a view of type "MyView." So if we create a MyExtractEdges in ParaView3, it'll automatically be shown in our custom view.

We build the server plugin with a CMakeLists.txt file as:


Our client side plugin will contain an extension of pqGenericViewModule. We can let ParaView give us a display panel for these displays, or we can make our own deriving from pqDisplayPanel. In this example, we'll make a simple display panel.

We implement MyView in MyView.h:

 #include "pqGenericViewModule.h"
 #include <QMap>
 #include <QLabel>
 #include <QVBoxLayout>
 #include <vtkSMProxy.h>
 #include <pqDisplay.h>
 #include <pqServer.h>
 #include <pqPipelineSource.h>
 /// a simple view that shows a QLabel with the display's name in the view
 class MyView : public pqGenericViewModule
  MyView(const QString& viewtypemodule, const QString& group, const QString& name,
         vtkSMAbstractViewModuleProxy* viewmodule, pqServer* server, QObject* p)
     : pqGenericViewModule(viewtypemodule, group, name, viewmodule, server, p)
    this->MyWidget = new QWidget;
    new QVBoxLayout(this->MyWidget);
    // connect to display creation so we can show them in our view
    this->connect(this, SIGNAL(displayAdded(pqDisplay*)),
    this->connect(this, SIGNAL(displayRemoved(pqDisplay*)),
    delete this->MyWidget;
  /// we don't support save images
  bool saveImage(int, int, const QString& ) { return false; }
  vtkImageData* captureImage(int) { return NULL; }
  /// return the QWidget to give to ParaView's view manager
  QWidget* getWidget()
    return this->MyWidget;
  /// returns whether this view can display the given source
  bool canDisplaySource(pqPipelineSource* source) const
    if(!source ||
       this->getServer()->GetConnectionID() != source->getServer()->GetConnectionID() ||
       QString("MyExtractEdges") != source->getProxy()->GetXMLName())
      return false;
    return true;
 protected slots:
  void onDisplayAdded(pqDisplay* d)
    QString text = QString("Display (%1)").arg(d->getProxy()->GetSelfIDAsString());
    QLabel* label = new QLabel(text, this->MyWidget);
    this->Labels.insert(d, label);
  void onDisplayRemoved(pqDisplay* d)
    QLabel* label = this->Labels.take(d);
      delete label;
  QWidget* MyWidget;
  QMap<pqDisplay*, QLabel*> Labels;

And MyDisplay.h is:

 #include "pqDisplayPanel.h"
 #include <QVBoxLayout>
 #include <QLabel>
 class MyDisplay : public pqDisplayPanel
   MyDisplay(pqDisplay* display, QWidget* p)
     : pqDisplayPanel(display, p)
     QVBoxLayout* l = new QVBoxLayout(this);
     l->addWidget(new QLabel("From Plugin", this));

The CMakeLists.txt file to build the client plugin would be:


QT4_WRAP_CPP(MOC_SRCS MyView.h MyDisplay.h)
                         DISPLAY_XML MyDisplay DISPLAY_PANEL MyDisplay)

                    SOURCES ${MOC_SRCS} ${IFACE_SRCS})

We load the plugins in ParaView, and we create something like a Cone, then create a "My Extract Edges" filter. The multiview manager will create a new view and the label "Display (151)".

In ParaView 3.4, there's also a macro, ADD_PARAVIEW_VIEW_OPTIONS() which allows adding options pages for the custom view, accessible from Edit -> View Settings. The example in ParaView3/Examples/Plugins/GUIView demonstrates this (until more information is put here).

Adding a new Representation (in progress)

A representation controls how a dataset is represented in a view. There are several reasons why one would want to add a new representation eg. to incorporate a new mapper. For this example let's say that we have a new mapper "vtkMyPolyDataMapper" which we want to add to ParaView. We want to add a type to the "Representation" combo-box on the Display Tab and on the toolbar called "MyRepresentation". When the user chooses this representation type our mapper will be used. Please refers to Examples/Plugins/Representation for the implementation.

The steps involved in this case are as follows:

  • Create a new representation that uses the new mapper (vtkSMMyRepresentationProxy.*, MyRepresentation.xml).
  • Now we need to tell ParaView to create our representation when it creates the default representation for different data types/views. For the 3D view, ParaView creates "GeometryRepresentation" for polydata, "UnstructuredGridRepresentation" for unstructured grid and "UniformGridRepresentation" for uniform grid. vtkSMMyProxyManagerExtension is used to modify the XML used to create the representations such that our representation also gets created (MyExtension.xml, vtkSMMyProxyManagerExtension.*).
  • Finally, we need to register the vtkSMMyProxyManagerExtension instance with the proxy manager. This is done by using the auto-start plugin (pqMyRepresentationStarter).

Note: This interface is bound to change. This process can definitely use some simplification.

Embedding Python Source as Modules

Embedding Python source was first available in ParaView 3.6. Also be aware that you need Python 2.3 or greater to be able to load a plugin with embedded Python source.

It is possible to take a Python module written in Python source code and embed it into a ParaView plugin. Once the plugin is loaded, the Python interpreter within the ParaView client (or pvpython or pvbatch) can access your module using the Python import command. Of course, Python has its own way of distributing modules; however, if your Python source relies on, say, a filter defined in a plugin or something else in a plugin, like a toolbar, relies on executing your Python module, then it can be more convenient to distribute and load everything if they are all wrapped into a single plugin.

Let us say that you have a file named helloworld.py with the following contents.

def hello():
    print "Hello world"

You can add this to a plugin by simply listing the file in the PYTHON_MODULES option of ADD_PARAVIEW_PLUGIN. Note that the file must be located in the same directory as the CMakeLists.txt file (more on that later).

ADD_PARAVIEW_PLUGIN(MyPythonModules "1.0"
  PYTHON_MODULES helloworld.py

Once you load this plugin into ParaView (no matter how you do it), you can then access this source code by importing the helloworld module.

>>> paraview.servermanager.LoadPlugin('libPythonTest.dylib')
>>> import helloworld
>>> helloworld.hello()
Hello world

Note that if you are using the ParaView client GUI, you can load the plugin through the GUI's Plugin Manager or by autoloading the plugin (as described in #Using Plugins) instead of using the LoadPlugin Python command. You do, however, need the import command.

It is also possible to have multiple multiple modules and to embed packages with their own submodules (with an arbitrary depth of packages). You can set this up by simply arranging your Python source in directories representing the packages in the same way you set them up if you were loading them directly from Python (in fact, that might simplify debugging your Python code). If you have a file named __init__.py, that file is taken to be the implementation of the package represented by the directory it is contained in. This is the same behavior as Python itself.

ADD_PARAVIEW_PLUGIN(MyPythonModules "1.0"
  PYTHON_MODULES helloworld.py     # Becomes module helloworld
                 hello/__init__.py # Becomes package hello
                 hello/world.py    # Becomes module hello.world

Note that when Python imports a module, it first imports all packages in which it is contained. The upshot is that if you define a module in a package within your plugin, you must also make sure that the package is also defined somewhere. In the example above, if you removed the hello/__init__.py source file, you would not be able to load the hello/world.py file. Thus, it is best to include a __init__.py in every package directory you make, even if it is empty.


The ParaView CVS repository contains many examples in the Plugins directory. Additional examples are available on this wiki at the Plugin Examples entry.

ParaView: [Welcome | Site Map]