diff --git a/src/gepetto/corbaserver/client.py b/src/gepetto/corbaserver/client.py
index 1e1c496bd7ad3b5795bf8b0253ed9ff25c07e0f9..2df5a6e57a7e55c0f6998992a270e90b48cacfbb 100644
--- a/src/gepetto/corbaserver/client.py
+++ b/src/gepetto/corbaserver/client.py
@@ -77,9 +77,10 @@ class Client:
     # In the python interpreter of gepetto-gui, gui.createWindow
     # crashes for an obscure reason. This hack makes it work.
     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
-    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
       pass
 
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index 588b8dc7d5c5fbb9d505b00c30f0096919c649b0..8570ad819035565cb163d33d6863b13025e629fa 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -55,15 +55,19 @@ SET (${PROJECT_NAME}_HEADERS
   ${${PROJECT_NAME}_HEADERS_MOC}
   ${${PROJECT_NAME}_HEADERS_NO_MOC}
   )
+SET (${PROJECT_NAME}_MOC
+  ${${PROJECT_NAME}_HEADERS_MOC}
+  python-decorator.hh
+  )
 
 # Compile meta-objects and executable
 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_ADD_RESOURCES(${PROJECT_NAME}_RESOURCES_RCC ${${PROJECT_NAME}_RESOURCES})
   INCLUDE(${QT_USE_FILE})
 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_ADD_RESOURCES(${PROJECT_NAME}_RESOURCES_RCC ${${PROJECT_NAME}_RESOURCES})
 ENDIF(USE_QT4)
diff --git a/src/gui/python-decorator.hh b/src/gui/python-decorator.hh
new file mode 100644
index 0000000000000000000000000000000000000000..6e0973c44a94d69e34edfdb438908336b7ec6372
--- /dev/null
+++ b/src/gui/python-decorator.hh
@@ -0,0 +1,21 @@
+#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
diff --git a/src/gui/pythonwidget.cc b/src/gui/pythonwidget.cc
index d57cbb0a037579a2470fda74ba0138b44b904c9f..8cc57aeea16af5ad0e57b421e30602d329f58fd3 100644
--- a/src/gui/pythonwidget.cc
+++ b/src/gui/pythonwidget.cc
@@ -12,6 +12,8 @@
 #include "gepetto/gui/mainwindow.hh"
 #include "gepetto/gui/plugin-interface.hh"
 
+#include "../../src/gui/python-decorator.hh"
+
 namespace gepetto {
     namespace gui {
       namespace {
@@ -45,11 +47,16 @@ namespace gepetto {
         PythonQtObjectPtr sys = PythonQt::self()->importModule ("sys");
         sys.evalScript ("argv = ['gepetto-gui']");
         console_ = new PythonQtScriptingConsole(NULL, mainContext);
+
         PythonQt::self()->registerQObjectClassNames(QStringList()
             << "BodyTreeWidget"
             << "BodyTreeItem"
             << "SelectionEvent"
             << "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("windowsManager", MainWindow::instance()->osg().get());
         console_->QTextEdit::clear();
@@ -72,10 +79,6 @@ namespace gepetto {
 
         toggleViewAction()->setShortcut(gepetto::gui::DockKeyShortcutBase + Qt::Key_A);
         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()