minor improvements to python embedding code
authorDiane Trout <diane@caltech.edu>
Thu, 8 Jun 2006 01:25:46 +0000 (01:25 +0000)
committerDiane Trout <diane@caltech.edu>
Thu, 8 Jun 2006 01:25:46 +0000 (01:25 +0000)
tweak the cmake files a bit, and shorten the namespace name

qui/CMakeLists.txt
qui/mussagl.cpp

index 7a62c7aeabcc1c8ada5bd6f42b7acd7728526b58..c38f1dab59186680bb30b1dc34588395321ea4e8 100644 (file)
@@ -56,18 +56,20 @@ SET(GUI_SOURCES
       seqbrowser/SequenceDescription.cpp
 
      )
-SET(SOURCES
+SET(MAIN_SOURCES
       mussagl.cpp)
 SET(RCCS ../icons.qrc)
 
 QT4_ADD_RESOURCES(RCC_SOURCE ${RCCS})
 QT4_WRAP_CPP(MOC_SOURCES ${MOC_HEADERS})
+SET(SOURCES  ${MOC_SOURCES} ${GUI_SOURCES} ${RCC_SOURCES} ${MAIN_SOURCES})
 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} )
+ADD_EXECUTABLE(mussagl WIN32 MACOSX_BUNDLE ${MAIN_SOURCES} )
 # ${SOURCES} ${MOC_SOURCES} ${RCC_SOURCE} )
 LINK_DIRECTORIES(${MUSSA_BINARY_DIR}/alg
                  ${MUSSA_BINARY_DIR}/py)
@@ -80,6 +82,10 @@ TARGET_LINK_LIBRARIES(mussagl
                         ${BOOST_FILESYSTEM_LIBRARY}
                       )
 IF(USE_PYTHON)
+  SET_SOURCE_FILES_PROPERTIES(${SOURCES}
+                              PROPERTIES
+                              COMPILE_FLAGS "-DUSE_PYTHON=1"
+                             )
   TARGET_LINK_LIBRARIES(mussagl
                           ${BOOST_PYTHON_LIBRARY}
                           optimized ${PYTHON_LIBRARIES}
index 15b01b23a3799fb0a7b83d930cfbdf9cb7cad12f..dcf393b146178300d918aa6b6d912910ee8bf8d4 100644 (file)
@@ -1,6 +1,7 @@
 #include <boost/filesystem/operations.hpp>
 #ifdef USE_PYTHON
 #include <boost/python.hpp>
+namespace py = boost::python;
 #endif
 
 using namespace boost::filesystem;
@@ -35,10 +36,10 @@ int main(int argc, char **argv)
 #ifdef USE_PYTHON
     if (opts.runAsPythonInterpeter) {
       Py_Initialize();
-      boost::python::object main_module((boost::python::handle<>(boost::python::borrowed(PyImport_AddModule("__main__")))));
-      boost::python::object main_namespace = main_module.attr("__dict__");
+      py::object main_module((py::handle<>(py::borrowed(PyImport_AddModule("__main__")))));
+      py::object main_namespace = main_module.attr("__dict__");
 
-      boost::python::handle<> ignored((PyRun_String(
+      py::handle<> ignored((PyRun_String(
                         //"from IPython.Shell import IPShellEmbed\n"
                         //"shell = IPShellEmbed(['mussa'], '')\n",
                         //"import mussa\n"
@@ -50,8 +51,8 @@ int main(int argc, char **argv)
                         main_namespace.ptr(),
                         main_namespace.ptr())
                       ));
-      boost::python::object square = main_module.attr("square");
-      int result = boost::python::extract<int>(square(3));
+      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");
     } else 
@@ -68,7 +69,7 @@ int main(int argc, char **argv)
     qFatal(e.what());
   }
 #ifdef USE_PYTHON
-  catch (boost::python::error_already_set e) {
+  catch (py::error_already_set e) {
     PyErr_Print();
   }
 #endif /* USE_PYTHON */