add prototype wrapping of the qt sequence browser
authorDiane Trout <diane@caltech.edu>
Sat, 25 Aug 2007 00:33:05 +0000 (00:33 +0000)
committerDiane Trout <diane@caltech.edu>
Sat, 25 Aug 2007 00:33:05 +0000 (00:33 +0000)
having two boost::python modules caused some python import problems
so i merged the gui code into the mussa python extension module.

Unfortunately it's a serious pain to create the right objects to be passed
to the browser for it to render anything. I need to switch the browser
to use the seqspans with drawables on them.

CMakeLists.txt
py/CMakeLists.txt
py/module.cpp
py/module_qui.cpp
py/qt.cpp [new file with mode: 0644]
py/sequencebrowserwidget.cpp [new file with mode: 0644]
py/test/CMakeLists.txt
qui/mussagl.cpp
qui/seqbrowser/SequenceBrowserWidget.cpp
qui/seqbrowser/SequenceBrowserWidget.hpp

index 747e7e4cf1b59bb69bf262da61579f0226a35172..28d7b6870aa4647643361e86c433423916d748c4 100644 (file)
@@ -68,7 +68,7 @@ IF(USE_PYTHON)
   TARGET_LINK_LIBRARIES(mussagl
         mussa_py
         ${QT_LIBRARIES}
-        mussaqui_py
+#mussaqui_py
         ${BOOST_PYTHON_LIBRARY}
         ${PYTHON_LIBRARIES}
         ${PYTHON_LINK_LIBRARIES})
index fea3b27930abcbb8db80e2f43b192407b09d1e21..0a7fdc2f6001e2be0fff90e392aeee0fa5b783a3 100644 (file)
@@ -2,7 +2,7 @@ FIND_PACKAGE(Boost)
 FIND_PACKAGE(OpenGL)
 FIND_PACKAGE(PythonLibs)
 FIND_PACKAGE(PythonInterp)
-SET(QT_DONT_USE_QTGUI 1)
+SET(QT_DONT_USE_QTGUI 1)
 FIND_PACKAGE(Qt4)
 INCLUDE( ${QT_USE_FILE} )
 
@@ -17,13 +17,16 @@ IF(BOOST_PYTHON_LIBRARY)
         glsequence.cpp
         module.cpp 
         mussa.cpp
-        # MussaWindow.cpp
         nway_paths.cpp
         sequence.cpp
         )
   SET(QUI_SOURCES
     module_qui.cpp
-    MussaWindow.cpp
+    qt.cpp
+    sequence.cpp
+    glsequence.cpp
+    annotation_colors.cpp
+    sequencebrowserwidget.cpp
   )                        
   SET(MUSSA_LIBRARIES
         mussa_core
@@ -54,26 +57,26 @@ IF(BOOST_PYTHON_LIBRARY)
                         ${PYTHON_LIBRARIES}
                         )
   # configure static gui python library
-  ADD_LIBRARY(mussaqui_py STATIC ${QUI_SOURCES})
-  SET_TARGET_PROPERTIES(mussa_py PROPERTIES 
-                        COMPILE_FLAGS "${PY_CFLAGS}"
-                        LINK_FLAGS "${PY_LDFLAGS}")
+  #ADD_LIBRARY(mussaqui_py STATIC ${QUI_SOURCES})
+  #  SET_TARGET_PROPERTIES(mussa_py PROPERTIES 
+  #                        COMPILE_FLAGS "${PY_CFLAGS}"
+  #                        LINK_FLAGS "${PY_LDFLAGS}")
                         
   # configure gui (shared) python library
-  #ADD_LIBRARY(mussaqui MODULE ${QUI_SOURCES})
-  #SET_TARGET_PROPERTIES(mussaqui PROPERTIES 
-  #                     PREFIX ""
-  #                     COMPILE_FLAGS "${PY_CFLAGS}"
-  #                     LINK_FLAGS "${PY_LDFLAGS}")
-  #TARGET_LINK_LIBRARIES(mussaqui
-  #                      mussa_qui
-  #                      ${MUSSA_LIBRARIES}
-  #                      ${PYTHON_LIBRARIES}
-  #                      optimized ${QT_QTGUI_LIBRARY}
-  #                      debug ${QT_QTGUI_LIBRARY_DEBUG}
-  #                      optimized ${QT_QTOPENGL_LIBRARY}
-  #                      debug ${QT_QTOPENGL_LIBRARY_DEBUG}
-  #                     )
+  ADD_LIBRARY(mussaqui MODULE ${QUI_SOURCES})
+  SET_TARGET_PROPERTIES(mussaqui PROPERTIES 
+                       PREFIX ""
+                       COMPILE_FLAGS "${PY_CFLAGS}"
+                       LINK_FLAGS "${PY_LDFLAGS}")
+  TARGET_LINK_LIBRARIES(mussaqui
+                        mussa_qui
+                        ${MUSSA_LIBRARIES}
+                        ${PYTHON_LIBRARIES}
+                        optimized ${QT_QTGUI_LIBRARY}
+                        debug ${QT_QTGUI_LIBRARY_DEBUG}
+                        optimized ${QT_QTOPENGL_LIBRARY}
+                        debug ${QT_QTOPENGL_LIBRARY_DEBUG}
+                       )
   
   SET_SOURCE_FILES_PROPERTIES(
     ${SOURCES}
index a36c573e1ae1b26c1096f1b7318b87afb63157e3..9b5d54f5c063508df721409a16951c54ee33e066 100644 (file)
@@ -21,5 +21,4 @@ BOOST_PYTHON_MODULE(mussa)
   export_glsequence();
   export_mussa();
   export_nway_paths();
-  //export_mussa_window();
 }
index 2d039d3b7884238fe831f3b83b89932dc0529091..d3fafed2c6f9a457d936e049dfe41d408e5df762 100644 (file)
@@ -1,9 +1,17 @@
 #include <boost/python.hpp>
 using namespace boost::python;
 
-void export_gui_proxy();
+void export_sequence();
+void export_glsequence();
+void export_annotation_colors();
+void export_qt();
+void export_sequencebrowserwidget();
 
 BOOST_PYTHON_MODULE(mussaqui)
 {
-  export_gui_proxy();
+  export_sequence();
+  export_glsequence();
+  export_annotation_colors();
+  export_qt();
+  export_sequencebrowserwidget();
 }
diff --git a/py/qt.cpp b/py/qt.cpp
new file mode 100644 (file)
index 0000000..d7faaac
--- /dev/null
+++ b/py/qt.cpp
@@ -0,0 +1,33 @@
+#include <boost/python.hpp>
+#include <boost/utility.hpp>
+
+namespace py = boost::python;
+
+
+#include "QtGui/QWidget"
+#include "QtGui/QApplication"
+
+
+static char *cstub[] = {  "stub"  };
+char **stub = cstub;
+int one = 1;
+
+struct QApplicationStub : public QApplication {
+  QApplicationStub() : QApplication(one, (char **)stub) {
+  }
+};
+
+void export_qt()
+{
+
+  py::class_<QWidget, boost::noncopyable>("QWidget", py::init<QWidget *, Qt::WindowFlags>())
+  ;
+
+  py::class_<QApplicationStub, boost::noncopyable>(
+      "QApplication", 
+      py::init<>()
+      )
+    .def("execloop", &QApplication::exec)
+    .staticmethod("execloop")
+  ;
+}
diff --git a/py/sequencebrowserwidget.cpp b/py/sequencebrowserwidget.cpp
new file mode 100644 (file)
index 0000000..6056089
--- /dev/null
@@ -0,0 +1,52 @@
+#include <boost/python.hpp>
+namespace py = boost::python;
+#include <vector>
+
+#include "alg/Sequence.hpp"
+#include "alg/glsequence.cpp"
+#include "alg/glseqbrowser.cpp"
+#include "qui/seqbrowser/SequenceBrowserWidget.hpp"
+
+#include "stl_container_adapter.hpp"
+
+void export_sequencebrowserwidget()
+{
+
+  void (SequenceBrowserWidget::*setSequences_g)(
+      std::vector<boost::shared_ptr<GlSequence> > &) = &SequenceBrowserWidget::setSequences;
+
+  py::class_<SequenceBrowserWidget>("SequenceBrowserWidget", 
+                                    py::init<>())
+    // SIGNALS
+    .def("copySelectedSequenceAsFasta", 
+         &SequenceBrowserWidget::copySelectedSequenceAsFasta)
+    .def("setZoom", &SequenceBrowserWidget::setZoom)
+    .def("zoomOut", &SequenceBrowserWidget::zoomOut)
+    .def("zoomToSequence", &SequenceBrowserWidget::zoomToSequence)
+    .def("updatePosition", &SequenceBrowserWidget::updatePosition)
+    .def("promptSaveBrowserPixmap", 
+         &SequenceBrowserWidget::promptSaveBrowserPixmap)
+    .def("update", &SequenceBrowserWidget::update)
+    // Member functions
+    //.def("browser", &SequenceBrowserWidget::browser)
+    //.def("getPopupMenu", &SequenceBrowserWidget::getPopupMenu)
+    //.def("getCopySelectedSequenceAsFastaAction", 
+    //     &SequenceBrowserWidget::getCopySelectedSequenceAsFastaAction)
+    //.def("getCopySelectedSequenceAsStringAction", 
+    //     &SequenceBrowserWidget::getCopySelectedSequenceAsStringAction)
+    //.def("getEditSequencePropertiesAction", 
+    //     &SequenceBrowserWidget::getEditSequencePropertiesAction)
+    //.def("copySelectedTracksAsSeqLocation", 
+    //     &SequenceBrowserWidget::copySelectedTracksAsSeqLocation)
+    .def("zoom", &SequenceBrowserWidget::zoom)
+    .def("clear", &SequenceBrowserWidget::clear)
+    .def("setSequences", setSequences_g)
+    //.def("sequences", &SequenceBrowserWidget::sequences)
+    .def("clear_links", &SequenceBrowserWidget::clear_links)
+    .def("link", &SequenceBrowserWidget::link)
+    .def("selectedPaths", &SequenceBrowserWidget::selectedPaths)
+    .def("centerOnPath", &SequenceBrowserWidget::centerOnPath)
+
+    .def("show", &SequenceBrowserWidget::show)   
+  ;
+}
index 9c5e00b364792a7349c88fe056f450e4767ce578..15c679910f4a88d2899acac1e4b70ef845315467 100644 (file)
@@ -22,7 +22,6 @@ TARGET_LINK_LIBRARIES(mussa_python_test
                         mussa_py
                         mussa_core
                         ${QT_QTCORE_LIBRARY}
-                        mussaqui_py
                         ${OPENGL_gl_LIBRARY}
                         ${BOOST_PROGRAM_OPTIONS_LIBRARY}
                         ${BOOST_FILESYSTEM_LIBRARY}
index a5f9b483eba1e2c98a35813fb3321203645831e4..d0df4c6c05dfc5e56c0e9ed73e6f8ade53c71176 100644 (file)
@@ -4,7 +4,7 @@ using namespace boost::filesystem;
 #ifdef USE_PYTHON
 #include "py/python.hpp"
 extern "C" void initmussa();
-extern "C" void initmussaqui();
+//extern "C" void initmussaqui();
 #endif
 
 #include "qui/MussaWindow.hpp"
@@ -75,7 +75,7 @@ int main(int argc, char **argv)
         return 1;
       }
       py->add_module("mussa", &initmussa);
-      py->add_module("mussaqui", &initmussaqui);
+      //py->add_module("mussaqui", &initmussaqui);
       // quit when the interpreter exits
       QObject::connect(interp, SIGNAL(finished()),
                        &app, SLOT(quit()));
index 0ec2a6afe8fe098ba21ce08fafd853d1840233b1..34c7a9a14067f690eb35b82967726c6d7890232e 100644 (file)
 #include <math.h>
 using namespace std;
 
+SequenceBrowserWidget::SequenceBrowserWidget(
+    QWidget *parent)
+  : QScrollArea(parent),
+    left_sidebar(0),
+    scrollable_browser(0),
+    right_sidebar(0),
+    layout(0),
+    layout_container(0)
+{
+  boost::shared_ptr<QDir> empty_dir(new QDir);
+  default_dir = empty_dir;
+
+  init();
+}
+
 SequenceBrowserWidget::SequenceBrowserWidget(
     boost::shared_ptr<QDir> default_dir_,
     QWidget *parent
@@ -31,6 +46,11 @@ SequenceBrowserWidget::SequenceBrowserWidget(
 {
   default_dir = default_dir_;
 
+  init();
+}
+
+void SequenceBrowserWidget::init()
+{
   layout_container = new QWidget(this);
   layout = new QHBoxLayout(layout_container);
   left_sidebar = new SequenceBrowserSidebar(layout_container);
@@ -56,6 +76,17 @@ SequenceBrowserWidget::SequenceBrowserWidget(
           this, SIGNAL(mouseWheelZoom(double)));
 }
 
+
+SequenceBrowserWidget::SequenceBrowserWidget(const SequenceBrowserWidget &o)
+  : QScrollArea(o.window()),
+    left_sidebar(o.left_sidebar),
+    scrollable_browser(o.scrollable_browser),
+    right_sidebar(o.right_sidebar),
+    layout(o.layout),
+    layout_container(o.layout_container)
+{
+}
+
 QSize SequenceBrowserWidget::sizeHint() const
 {
   // don't trust the layouts size computation
index f57f9bb3a256703b30bca7a4ec864448e1593a93..8f957c76a1d975198205103a71f67a60266ec5f8 100644 (file)
@@ -20,6 +20,8 @@ class SequenceBrowserWidget : public QScrollArea
   Q_OBJECT 
 
 public:
+  SequenceBrowserWidget(QWidget *parent=0);
+  SequenceBrowserWidget(const SequenceBrowserWidget &);
   SequenceBrowserWidget(boost::shared_ptr<QDir>, QWidget *parent=0);
 
   //! return our wrapped browser, so we can test it.
@@ -99,5 +101,8 @@ private:
   /*! I need to save them so i can free them to avoid a memory leak 
    */
   std::vector<GlSequenceRef > converted_sequences;
+
+  //! shared code for constructors
+  void init();
 };
 #endif