gepetto::gui::PythonWidget Class Reference

#include <gepetto/gui/pythonwidget.hh>

Inheritance diagram for gepetto::gui::PythonWidget:
Collaboration diagram for gepetto::gui::PythonWidget:

Public Slots

void loadModulePlugin (QString moduleName)
 
void unloadModulePlugin (QString moduleName)
 
void loadScriptPlugin (QString moduleName, QString fileName)
 
void runScript (QString fileName)
 
void browseFile ()
 

Public Member Functions

 PythonWidget (QWidget *parent=0)
 
void addToContext (QString const &name, QObject *obj)
 
virtual ~PythonWidget ()
 
QVariantList callPluginMethod (const QString &method, const QVariantList &args=QVariantList(), const QVariantMap &kwargs=QVariantMap()) const
 
void saveHistory (QSettings &settings)
 
void restoreHistory (QSettings &settings)
 
bool hasPlugin (const QString &name)
 

Detailed Description

Python plugin interface

Overview

A Python plugin is a Python module containing a class Plugin, with a constructor taking a pointer to the MainWindow as input.

For instance, if you have

[pyplugins]
module.submodule=true

in your configuration file (Settings::readSettingFile), then the Plugin class will be accessed by the GUI in a way similar to:

from module.submodule import Plugin
pluginInstance = Plugin(mainWindow)

Plugin can interact with the interface in following ways.

Dock widgets:

Your plugin may inherits from class PythonQt.QtGui.QDockWidget. In this case, an instance of the Plugin will be added to the MainWindow as a QDockWidget.

Signals and slots:

The most important signals and slots you should know about are listed here. A more up-to-date list of the available_in_python

The following method will be automatically connected to Qt signals:

  • Plugin.osgWidget when a new OSGWidget is created (MainWindow::viewCreated(OSGWidget*)).
  • Plugin.resetConnection triggered when CORBA connection should be reset. This is mandatory is you have a CORBA Client
  • Plugin.refreshInterface triggered when users request to refresh the interface.

Logging information

Logging can be done from Python through:

See also
See examples pyplugin/pythonwidget.py.

Constructor & Destructor Documentation

◆ PythonWidget()

gepetto::gui::PythonWidget::PythonWidget ( QWidget *  parent = 0)
explicit

◆ ~PythonWidget()

virtual gepetto::gui::PythonWidget::~PythonWidget ( )
virtual

Member Function Documentation

◆ addToContext()

void gepetto::gui::PythonWidget::addToContext ( QString const &  name,
QObject *  obj 
)

◆ browseFile

void gepetto::gui::PythonWidget::browseFile ( )
slot

◆ callPluginMethod()

QVariantList gepetto::gui::PythonWidget::callPluginMethod ( const QString &  method,
const QVariantList &  args = QVariantList(),
const QVariantMap &  kwargs = QVariantMap() 
) const

Calls a method on each plugin that has it.

Returns
a list of QVariant returned by each call.

◆ hasPlugin()

bool gepetto::gui::PythonWidget::hasPlugin ( const QString &  name)

◆ loadModulePlugin

void gepetto::gui::PythonWidget::loadModulePlugin ( QString  moduleName)
slot

Load a plugin by importing a module

This is mostly equivalent to running the following code in the Python console

import modulename
pluginInstance = modulename.Plugin(mainWindow)
mainWindow.addDockWidget (1, pluginInstance)
# Some extra code to add dock widget toggle button to the right place.
Note
The module must contain a class Plugin that inherits from class PythonQt.QtGui.QDockWidget

◆ loadScriptPlugin

void gepetto::gui::PythonWidget::loadScriptPlugin ( QString  moduleName,
QString  fileName 
)
slot

◆ restoreHistory()

void gepetto::gui::PythonWidget::restoreHistory ( QSettings &  settings)

◆ runScript

void gepetto::gui::PythonWidget::runScript ( QString  fileName)
slot

◆ saveHistory()

void gepetto::gui::PythonWidget::saveHistory ( QSettings &  settings)

◆ unloadModulePlugin

void gepetto::gui::PythonWidget::unloadModulePlugin ( QString  moduleName)
slot

The documentation for this class was generated from the following file: