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

Add MainWindow class decorator to PythonQt.

parent e95d503b
No related branches found
No related tags found
No related merge requests found
...@@ -77,9 +77,10 @@ class Client: ...@@ -77,9 +77,10 @@ class Client:
# In the python interpreter of gepetto-gui, gui.createWindow # In the python interpreter of gepetto-gui, gui.createWindow
# crashes for an obscure reason. This hack makes it work. # crashes for an obscure reason. This hack makes it work.
try: try:
self.gui.createWindow = lambda x: mainWindow.createView(x).wid() from PythonQt.gepetto import MainWindow
# At this point, we are in the python interpreter of gepetto-gui # At this point, we are in the python interpreter of gepetto-gui
except: self.gui.createWindow = lambda x: MainWindow.instance().createView(x).wid()
except ImportError:
# At this point, we are NOT in the python interpreter of gepetto-gui # At this point, we are NOT in the python interpreter of gepetto-gui
pass pass
......
...@@ -55,15 +55,19 @@ SET (${PROJECT_NAME}_HEADERS ...@@ -55,15 +55,19 @@ SET (${PROJECT_NAME}_HEADERS
${${PROJECT_NAME}_HEADERS_MOC} ${${PROJECT_NAME}_HEADERS_MOC}
${${PROJECT_NAME}_HEADERS_NO_MOC} ${${PROJECT_NAME}_HEADERS_NO_MOC}
) )
SET (${PROJECT_NAME}_MOC
${${PROJECT_NAME}_HEADERS_MOC}
python-decorator.hh
)
# Compile meta-objects and executable # Compile meta-objects and executable
IF(USE_QT4) IF(USE_QT4)
QT4_WRAP_CPP(${PROJECT_NAME}_HEADERS_MOCED ${${PROJECT_NAME}_HEADERS_MOC}) QT4_WRAP_CPP(${PROJECT_NAME}_HEADERS_MOCED ${${PROJECT_NAME}_MOC})
QT4_WRAP_UI(${PROJECT_NAME}_FORMS_HEADERS ${${PROJECT_NAME}_FORMS}) QT4_WRAP_UI(${PROJECT_NAME}_FORMS_HEADERS ${${PROJECT_NAME}_FORMS})
QT4_ADD_RESOURCES(${PROJECT_NAME}_RESOURCES_RCC ${${PROJECT_NAME}_RESOURCES}) QT4_ADD_RESOURCES(${PROJECT_NAME}_RESOURCES_RCC ${${PROJECT_NAME}_RESOURCES})
INCLUDE(${QT_USE_FILE}) INCLUDE(${QT_USE_FILE})
ELSE(USE_QT4) ELSE(USE_QT4)
QT5_WRAP_CPP(${PROJECT_NAME}_HEADERS_MOCED ${${PROJECT_NAME}_HEADERS_MOC}) QT5_WRAP_CPP(${PROJECT_NAME}_HEADERS_MOCED ${${PROJECT_NAME}_MOC})
QT5_WRAP_UI(${PROJECT_NAME}_FORMS_HEADERS ${${PROJECT_NAME}_FORMS}) QT5_WRAP_UI(${PROJECT_NAME}_FORMS_HEADERS ${${PROJECT_NAME}_FORMS})
QT5_ADD_RESOURCES(${PROJECT_NAME}_RESOURCES_RCC ${${PROJECT_NAME}_RESOURCES}) QT5_ADD_RESOURCES(${PROJECT_NAME}_RESOURCES_RCC ${${PROJECT_NAME}_RESOURCES})
ENDIF(USE_QT4) ENDIF(USE_QT4)
......
#ifndef GEPETTO_GUI_PYTHON_DECORATOR_HH
#define GEPETTO_GUI_PYTHON_DECORATOR_HH
#include <PythonQt/PythonQt.h>
#include <gepetto/gui/mainwindow.hh>
#include <gepetto/gui/osgwidget.hh>
namespace gepetto {
namespace gui {
class PythonDecorator : public QObject
{
Q_OBJECT
public slots:
MainWindow* static_MainWindow_instance () const { return MainWindow::instance (); }
};
} // namespace gui
} // namespace gepetto
#endif // GEPETTO_GUI_PYTHON_DECORATOR_HH
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "gepetto/gui/mainwindow.hh" #include "gepetto/gui/mainwindow.hh"
#include "gepetto/gui/plugin-interface.hh" #include "gepetto/gui/plugin-interface.hh"
#include "../../src/gui/python-decorator.hh"
namespace gepetto { namespace gepetto {
namespace gui { namespace gui {
namespace { namespace {
...@@ -45,11 +47,16 @@ namespace gepetto { ...@@ -45,11 +47,16 @@ namespace gepetto {
PythonQtObjectPtr sys = PythonQt::self()->importModule ("sys"); PythonQtObjectPtr sys = PythonQt::self()->importModule ("sys");
sys.evalScript ("argv = ['gepetto-gui']"); sys.evalScript ("argv = ['gepetto-gui']");
console_ = new PythonQtScriptingConsole(NULL, mainContext); console_ = new PythonQtScriptingConsole(NULL, mainContext);
PythonQt::self()->registerQObjectClassNames(QStringList() PythonQt::self()->registerQObjectClassNames(QStringList()
<< "BodyTreeWidget" << "BodyTreeWidget"
<< "BodyTreeItem" << "BodyTreeItem"
<< "SelectionEvent" << "SelectionEvent"
<< "WindowsManager"); << "WindowsManager");
PythonQt::self()->addDecorators (new PythonDecorator());
PythonQt::self()->registerCPPClass ("MainWindow", "QMainWindow", "gepetto");
PythonQt::self()->registerCPPClass ("OSGWidget" , "QWidget" , "gepetto");
mainContext.addObject("mainWindow", MainWindow::instance()); mainContext.addObject("mainWindow", MainWindow::instance());
mainContext.addObject("windowsManager", MainWindow::instance()->osg().get()); mainContext.addObject("windowsManager", MainWindow::instance()->osg().get());
console_->QTextEdit::clear(); console_->QTextEdit::clear();
...@@ -72,10 +79,6 @@ namespace gepetto { ...@@ -72,10 +79,6 @@ namespace gepetto {
toggleViewAction()->setShortcut(gepetto::gui::DockKeyShortcutBase + Qt::Key_A); toggleViewAction()->setShortcut(gepetto::gui::DockKeyShortcutBase + Qt::Key_A);
connect(button_, SIGNAL(clicked()), SLOT(browseFile())); connect(button_, SIGNAL(clicked()), SLOT(browseFile()));
// Hack to make "createWindow" function work properly
PythonQtObjectPtr client = PythonQt::self()->importModule ("gepetto.corbaserver.client");
client.addObject ("mainWindow", MainWindow::instance());
} }
PythonWidget::~PythonWidget() PythonWidget::~PythonWidget()
......
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