diff --git a/pyplugins/CMakeLists.txt b/pyplugins/CMakeLists.txt index 8cabd85c85819a0714a5ee314ae21668a37fa950..a2d1959cffdbbd1a9a2c04a9811eb77550b858e1 100644 --- a/pyplugins/CMakeLists.txt +++ b/pyplugins/CMakeLists.txt @@ -19,6 +19,8 @@ INSTALL( FILES ${CMAKE_CURRENT_SOURCE_DIR}/gepetto/gui/pythonwidget.py ${CMAKE_CURRENT_SOURCE_DIR}/gepetto/gui/blenderexport.py + ${CMAKE_CURRENT_SOURCE_DIR}/gepetto/gui/matplotlibwidget.py + ${CMAKE_CURRENT_SOURCE_DIR}/gepetto/gui/matplotlib_example.py ${CMAKE_CURRENT_SOURCE_DIR}/gepetto/gui/__init__.py DESTINATION ${PYTHON_SITELIB}/gepetto/gui ) diff --git a/pyplugins/gepetto/gui/matplotlib_example.py b/pyplugins/gepetto/gui/matplotlib_example.py new file mode 100644 index 0000000000000000000000000000000000000000..b80b29ea64e6ce25d41a8291651536889ddd2785 --- /dev/null +++ b/pyplugins/gepetto/gui/matplotlib_example.py @@ -0,0 +1,36 @@ +from PythonQt import QtGui, Qt +from gepetto.corbaserver import Client +import numpy as np + +from gepetto.gui.matplotlibwidget import MatplotlibWidget + +class Plugin(QtGui.QDockWidget): + """ + Example of plugin using matplotlib + """ + def __init__ (self, mainWindow, flags = None): + if flags is None: + super(Plugin, self).__init__ ("Matplotlib example plugin", mainWindow) + else: + super(Plugin, self).__init__ ("Matplotlib example plugin", mainWindow, flags) + self.setObjectName("Matplotlib example plugin") + self.client = Client() + + # This avoids having a widget bigger than what it needs. It avoids having + # a big dock widget and a small osg widget when creating the main osg widget. + p = Qt.QSizePolicy.Ignored + self.testWidget = MatplotlibWidget(self, True) + self.testWidget.setSizePolicy(Qt.QSizePolicy(p,p)) + self.setWidget (self.testWidget) + + # Plot something + x = np.linspace (0, 10, num=100) + y = np.sin(x) + self.testWidget.figure.gca().plot (x, y) + + ### If present, this function is called when a new OSG Widget is created. + def osgWidget(self, osgWindow): + pass + + def resetConnection(self): + self.client = Client() diff --git a/pyplugins/gepetto/gui/matplotlibwidget.py b/pyplugins/gepetto/gui/matplotlibwidget.py new file mode 100644 index 0000000000000000000000000000000000000000..1c8c6e7d32847c3eb0238c7fe287514201e6f337 --- /dev/null +++ b/pyplugins/gepetto/gui/matplotlibwidget.py @@ -0,0 +1,24 @@ +from matplotlib.figure import Figure +import matplotlib.pyplot as plt +from pythonqt.matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg, NavigationToolbar2QT + +from PythonQt import QtGui, Qt +from gepetto.corbaserver import Client + +import numpy as np + +### This class represents one special tab of the new QDockWidget +class MatplotlibWidget (QtGui.QWidget): + def __init__(self, parent, withToolbar = False): + super(MatplotlibWidget, self).__init__ (parent) + + box = QtGui.QVBoxLayout(self) + # Create a figure + self.figure = Figure(figsize=(5,5), dpi=96) + # self.figure = Figure() + self.canvas = FigureCanvasQTAgg (self.figure) + box.addWidget(self.canvas) + + if withToolbar: + self.toolbar = NavigationToolbar2QT(self.canvas, parent, False) + box.addWidget(self.toolbar)