This patch does let the python extension launch the gui successfully.
I tried to get the C++ gui app to also be able to talk to the python extension
but that didn't work so well. (causes a crash on os x when I statically
link the python extension module in).
MussaOptions::MussaOptions()
: analysis(0),
- useGUI(true)
+ useGUI(true),
+ runAsPythonInterpeter(false)
{
}
("view-analysis", po::value<std::string>(),
"load a previously run analysis")
("no-gui", "terminate without running an analysis")
+ ("python", "launch as a python interpreter")
;
po::variables_map vm;
if (vm.count("no-gui")) {
opts.useGUI=false;
}
+ if (vm.count("python")) {
+ opts.runAsPythonInterpeter = true;
+ }
}
Mussa *analysis;
//! should we use the gui?
bool useGUI;
+ //! launch as python
+ bool runAsPythonInterpeter;
};
//! initialize a mussa analysis from command line arguments
FIND_PACKAGE(OpenGL)
FIND_PACKAGE(PythonLibs)
FIND_PACKAGE(PythonInterp)
+SET(QT_USE_QTOPENGL 1)
+FIND_PACKAGE(Qt4)
+INCLUDE( ${QT_USE_FILE} )
+
# IF(BOOST_PYTHON_LIB)
- INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
+ INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH} ${QT_INCLUDES})
SET(SOURCES
conserved_path.cpp
glsequence.cpp
module.cpp
mussa.cpp
+ MussaWindow.cpp
nway_paths.cpp
sequence.cpp
)
LINK_DIRECTORIES(${MUSSA_BINARY_DIR}/alg)
TARGET_LINK_LIBRARIES(mussa
mussa_core
+ mussa_qui
${BOOST_PYTHON_LIBRARY}
${BOOST_FILESYSTEM_LIBRARY}
${OPENGL_gl_LIBRARY}
${PYTHON_LIBRARIES}
+ ${QT_QTCORE_LIBRARY}
+ ${QT_QTGUI_LIBRARY}
+ ${QT_QTOPENGL_LIBRARY}
)
IF(PYTHON_EXECUTABLE)
--- /dev/null
+
+#include <boost/python.hpp>
+
+#include <QApplication>
+#include <QPushButton>
+#include "alg/mussa.hpp"
+#include "qui/MussaWindow.hpp"
+
+struct gui {
+ QApplication *app;
+ QPushButton *b;
+ MussaWindow *mw;
+
+ gui() : b(0), mw(0) {
+ char *argv[] = {"mussagl"};
+ int argc = 1;
+ app = new QApplication(argc, (char **)argv);
+ Q_INIT_RESOURCE(icons);
+ }
+
+ void button() {
+ b = new QPushButton("hi");
+ b->show();
+ }
+
+ void mussa() {
+ Mussa *analysis = new Mussa();
+ mw = new MussaWindow(analysis);
+ mw->show();
+ }
+
+ int run() {
+ return app->exec();
+ }
+};
+
+void export_mussa_window()
+{
+ /*
+ class_<MussaWindow>("MussaWindow", init<Mussa *, QObject *>)
+ .def("show", &MussaWindow::show)
+ ;
+ */
+ boost::python::class_<gui>("gui")
+ .def("button", &gui::button)
+ .def("mussa", &gui::mussa)
+ .def("run", &gui::run)
+ ;
+}
void export_mussa();
void export_nway_paths();
void export_sequence();
+void export_mussa_window();
BOOST_PYTHON_MODULE(mussa)
{
export_mussa();
export_nway_paths();
export_sequence();
+ export_mussa_window();
}
INCLUDE( ${QT_USE_FILE} )
FIND_PACKAGE(OpenGL)
FIND_PACKAGE(Boost)
+FIND_PACKAGE(PythonLibs)
SET(MOC_HEADERS
ImageSaveDialog.hpp
seqbrowser/SequenceBrowserWidget.hpp
seqbrowser/SequenceDescription.hpp
)
-SET(SOURCES
+SET(GUI_SOURCES
ImageSaveDialog.cpp
ImageScaler.cpp
IntAction.cpp
MussaAlignedWindow.cpp
- mussagl.cpp
MussaWindow.cpp
ThresholdWidget.cpp
ZoomWidget.cpp
seqbrowser/SequenceBrowserSidebar.cpp
seqbrowser/SequenceBrowserWidget.cpp
seqbrowser/SequenceDescription.cpp
+
)
+SET(SOURCES
+ mussagl.cpp)
SET(RCCS ../icons.qrc)
QT4_ADD_RESOURCES(RCC_SOURCE ${RCCS})
QT4_WRAP_CPP(MOC_SOURCES ${MOC_HEADERS})
-ADD_EXECUTABLE(mussagl WIN32 MACOSX_BUNDLE ${SOURCES} ${MOC_SOURCES} ${RCC_SOURCE})
-LINK_DIRECTORIES(${MUSSA_BINARY_DIR}/alg)
+INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}
+ ${QT_INCLUDES})
+ADD_LIBRARY(mussa_qui STATIC ${MOC_SOURCES} ${GUI_SOURCES} ${RCC_SOURCE})
+TARGET_LINK_LIBRARIES(mussa_qui
+ mussa_core)
+ADD_EXECUTABLE(mussagl WIN32 MACOSX_BUNDLE ${SOURCES} )
+# ${SOURCES} ${MOC_SOURCES} ${RCC_SOURCE} )
+LINK_DIRECTORIES(${MUSSA_BINARY_DIR}/alg
+ ${MUSSA_BINARY_DIR}/py)
TARGET_LINK_LIBRARIES(mussagl
mussa_core
+ mussa_qui
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTOPENGL_LIBRARY}
${OPENGL_gl_LIBRARY}
${BOOST_PROGRAM_OPTIONS_LIBRARY}
${BOOST_FILESYSTEM_LIBRARY}
+ ${BOOST_PYTHON_LIBRARY}
+ optimized ${PYTHON_LIBRARIES}
+ debug ${PYTHON_DEBUG_LIBRARIES}
)
#include <boost/filesystem/operations.hpp>
+#include <boost/python.hpp>
+
using namespace boost::filesystem;
#include <stdlib.h>
+#include <iostream>
#include <QApplication>
#include "qui/MussaWindow.hpp"
QApplication app(argc, argv, opts.useGUI);
Q_INIT_RESOURCE(icons);
+ //PyImport_AppendInittab("mussa", initmussa);
+ Py_Initialize();
initialize_mussa(opts, argc, argv);
}
try {
- if (opts.useGUI) {
+ if (opts.runAsPythonInterpeter) {
+ boost::python::object main_module((boost::python::handle<>(boost::python::borrowed(PyImport_AddModule("__main__")))));
+ boost::python::object main_namespace = main_module.attr("__dict__");
+
+ boost::python::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())
+ ));
+ boost::python::object square = main_module.attr("square");
+ int result = boost::python::extract<int>(square(3));
+ std::cout << "C++ has " << result << std::endl;
+ PyRun_InteractiveLoop(stdin, "mussa");
+ } else if (opts.useGUI) {
MussaWindow win(opts.analysis);
win.show();
app.exec();
qFatal(e.what());
} catch (boost::filesystem::filesystem_error e) {
qFatal(e.what());
- } catch (std::runtime_error e) {
+ } catch (boost::python::error_already_set e) {
+ PyErr_Print();
+ } catch (std::runtime_error e) {
qFatal(e.what());
} catch (...) {
qFatal("unrecognized exception");
}
- return 1;
+ Py_Finalize();
+ return 1;
}
SequenceBrowser(QWidget *parent=0);
QSize sizeHint() const;
-
void clear();
void push_sequence(const Sequence &s);
void push_sequence(GlSequence &);