make it possible to build mussa with python
[mussa.git] / qui / mussagl.cpp
1 #include <boost/filesystem/operations.hpp>
2 #ifdef USE_PYTHON
3 #include <boost/python.hpp>
4 namespace py = boost::python;
5 extern "C" void initmussa();
6 #endif
7
8 using namespace boost::filesystem;
9
10 #include <stdlib.h>
11 #include <iostream>
12 #include <QApplication>
13
14 #include "qui/MussaWindow.hpp"
15 #include "alg/parse_options.hpp"
16 #include "mussa_exceptions.hpp"
17
18 int main(int argc, char **argv)
19 {
20   MussaOptions opts;
21
22   // if we're under unix and don't have a display, see if we can still run
23 #ifdef Q_WS_X11
24   opts.useGUI = getenv("DISPLAY") != 0;
25   if (opts.useGUI == false) {
26     std::clog << "DISPLAY not set, running in console mode only" << std::endl;
27   }
28 #endif
29
30   QApplication app(argc, argv, opts.useGUI);
31   Q_INIT_RESOURCE(icons);
32
33   initialize_mussa(opts, argc, argv);
34
35   if (opts.analysis == 0) {
36     return 1;
37   }
38
39   try {
40 #ifdef USE_PYTHON
41     if (opts.runAsPythonInterpeter) {
42       PyImport_AppendInittab("mussa", &initmussa);
43       Py_Initialize();
44       PyRun_InteractiveLoop(stdin, "mussa");
45     } else 
46 #endif /* USE_PYTHON */
47     if (opts.useGUI) { 
48       MussaWindow win(opts.analysis);
49       win.show();
50       app.exec();
51     }
52     return 0;
53   } catch (mussa_error e) {
54     qFatal(e.what());
55   } catch (boost::filesystem::filesystem_error e) {
56     qFatal(e.what());
57   }
58 #ifdef USE_PYTHON
59   catch (py::error_already_set e) {
60     PyErr_Print();
61   }
62 #endif /* USE_PYTHON */
63   catch (std::runtime_error e) {
64     qFatal(e.what());
65   } catch (...) {
66     qFatal("unrecognized exception");
67   }
68   return 1; 
69 }