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