provide python interpreter for mussa qui via a seperate thread
[mussa.git] / qui / mussagl.cpp
index 04418d2a655a5f3e0d41cfcbae394825b5ad9e0b..55afefd02bf37ca5a4fc74470def09ca02306027 100644 (file)
@@ -6,6 +6,8 @@ using namespace boost::filesystem;
 #endif
 
 #include "qui/MussaWindow.hpp"
+#include "qui/threading/ThreadManager.hpp"
+#include "qui/threading/InterpreterThread.hpp"
 #include "alg/parse_options.hpp"
 #include "mussa_exceptions.hpp"
 
@@ -56,10 +58,18 @@ int main(int argc, char **argv)
     return 1;
   }
 
+  ThreadManager &thread = ThreadManagerFactory();
   try {
 #ifdef USE_PYTHON
     if (opts.runAsPythonInterpeter) {
-      get_py().interpreter();
+      // allow the user to keep the interpreter open even after
+      // closing all the windows
+      app.setQuitOnLastWindowClosed(false);
+      const InterpreterThread *interp = thread.create_interpreter();
+      // quit when the interpreter exits
+      QObject::connect(interp, SIGNAL(finished()),
+                       &app, SLOT(quit()));
+      app.exec();
     } else 
 #endif /* USE_PYTHON */
     if (opts.useGUI) {