- Py_Initialize();
- py::object main_module((py::handle<>(py::borrowed(PyImport_AddModule("__main__")))));
- py::object main_namespace = main_module.attr("__dict__");
-
- py::handle<> ignored((PyRun_String(
- //"from IPython.Shell import IPShellEmbed\n"
- //"shell = IPShellEmbed(['mussa'], '')\n",
- //"import mussa\n"
- "def square(x):\n"
- " r = x * x\n"
- " print 'the square is %d' % (r)\n"
- " return r\n",
- Py_file_input,
- main_namespace.ptr(),
- main_namespace.ptr())
- ));
- py::object square = main_module.attr("square");
- int result = py::extract<int>(square(3));
- std::cout << "C++ has " << result << std::endl;
- PyRun_InteractiveLoop(stdin, "mussa");
+ ThreadManager &thread = ThreadManagerFactory();
+ // allow the user to keep the interpreter open even after
+ // closing all the windows
+ app.setQuitOnLastWindowClosed(false);
+ InterpreterThread *interp = thread.create_interpreter();
+ if (!interp) {
+ std::cerr << "Unable to initialize interpeter thread" << std::endl;
+ return 1;
+ }
+ MussaPython *py = interp->get_py_ptr();
+ if (!py) {
+ std::cerr << "Unable to initialize python interpreter" << std::endl;
+ return 1;
+ }
+ py->add_module("mussa", &initmussa);
+ //py->add_module("mussaqui", &initmussaqui);
+ // quit when the interpreter exits
+ QObject::connect(interp, SIGNAL(finished()),
+ &app, SLOT(quit()));
+ interp->start();
+ app.exec();