#include <boost/filesystem/operations.hpp>
using namespace boost::filesystem;
-#include <QApplication>
+#ifdef USE_PYTHON
+#include "py/python.hpp"
+extern "C" void initmussa();
+//extern "C" void initmussaqui();
+#endif
#include "qui/MussaWindow.hpp"
+#include "qui/threading/ThreadManager.hpp"
+#include "qui/threading/InterpreterThread.hpp"
#include "alg/parse_options.hpp"
+#include "mussa_exceptions.hpp"
+
+#include <stdlib.h>
+#include <iostream>
+#include <QApplication>
+
+#if defined(Q_WS_MAC)
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
+std::string get_doc_dir()
+{
+#if defined(Q_WS_MAC)
+ CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
+ CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
+ kCFURLPOSIXPathStyle);
+ const char *pathPtr = CFStringGetCStringPtr(macPath,
+ CFStringGetSystemEncoding());
+ std::string doc_dir(pathPtr);
+ qDebug("Path = %s", pathPtr);
+ CFRelease(pluginRef);
+ CFRelease(macPath);
+#else
+ return std::string(".");
+#endif
+}
int main(int argc, char **argv)
{
- // let boost::filesystem store the path we were initially launched in
- initial_path();
+ MussaOptions opts;
- QApplication app(argc, argv);
- Q_INIT_RESOURCE(icons);
- Mussa *analysis = initialize_mussa(argc, argv);
+ // if we're under unix and don't have a display, see if we can still run
+#ifdef Q_WS_X11
+ opts.useGUI = getenv("DISPLAY") != 0;
+ if (opts.useGUI == false) {
+ std::clog << "DISPLAY not set, running in console mode only" << std::endl;
+ }
+#endif
+ //opts.doc_dir = get_doc_dir();
+ QApplication app(argc, argv, opts.useGUI);
- if (analysis == 0) {
+ initialize_mussa(opts, argc, argv);
+ if (opts.analysis == 0) {
return 1;
}
-
- MussaWindow win(analysis);
- win.show();
- app.exec();
- return 0;
+
+ try {
+#ifdef USE_PYTHON
+ if (opts.runAsPythonInterpeter) {
+ 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();
+ } else
+#endif /* USE_PYTHON */
+ if (opts.useGUI) {
+ MussaWindow *win = new MussaWindow(opts.analysis);
+ win->show();
+ app.exec();
+ }
+ return 0;
+ } catch (mussa_error e) {
+ qFatal(e.what());
+ } catch (boost::filesystem::filesystem_error e) {
+ qFatal(e.what());
+ }
+#ifdef USE_PYTHON
+ catch( boost::python::error_already_set ) {
+ PyErr_Print();
+ }
+#endif
+ catch (std::runtime_error e) {
+ qFatal(e.what());
+ } catch (...) {
+ qFatal("unrecognized exception");
+ }
+ return 1;
}