Skip to content
Snippets Groups Projects
Commit 57b5b3f8 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Add Matplotlib python widget

parent 3dcf1cae
No related branches found
No related tags found
No related merge requests found
......@@ -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
)
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()
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment