From 02fc4144044a430f8bee6617c0c9871d4ebe5e4d Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Sat, 25 Aug 2007 00:33:05 +0000 Subject: [PATCH] add prototype wrapping of the qt sequence browser 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 | 2 +- py/CMakeLists.txt | 45 ++++++++++---------- py/module.cpp | 1 - py/module_qui.cpp | 12 +++++- py/qt.cpp | 33 +++++++++++++++ py/sequencebrowserwidget.cpp | 52 ++++++++++++++++++++++++ py/test/CMakeLists.txt | 1 - qui/mussagl.cpp | 4 +- qui/seqbrowser/SequenceBrowserWidget.cpp | 31 ++++++++++++++ qui/seqbrowser/SequenceBrowserWidget.hpp | 5 +++ 10 files changed, 158 insertions(+), 28 deletions(-) create mode 100644 py/qt.cpp create mode 100644 py/sequencebrowserwidget.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 747e7e4..28d7b68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/py/CMakeLists.txt b/py/CMakeLists.txt index fea3b27..0a7fdc2 100644 --- a/py/CMakeLists.txt +++ b/py/CMakeLists.txt @@ -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} diff --git a/py/module.cpp b/py/module.cpp index a36c573..9b5d54f 100644 --- a/py/module.cpp +++ b/py/module.cpp @@ -21,5 +21,4 @@ BOOST_PYTHON_MODULE(mussa) export_glsequence(); export_mussa(); export_nway_paths(); - //export_mussa_window(); } diff --git a/py/module_qui.cpp b/py/module_qui.cpp index 2d039d3..d3fafed 100644 --- a/py/module_qui.cpp +++ b/py/module_qui.cpp @@ -1,9 +1,17 @@ #include 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 index 0000000..d7faaac --- /dev/null +++ b/py/qt.cpp @@ -0,0 +1,33 @@ +#include +#include + +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", py::init()) + ; + + py::class_( + "QApplication", + py::init<>() + ) + .def("execloop", &QApplication::exec) + .staticmethod("execloop") + ; +} diff --git a/py/sequencebrowserwidget.cpp b/py/sequencebrowserwidget.cpp new file mode 100644 index 0000000..6056089 --- /dev/null +++ b/py/sequencebrowserwidget.cpp @@ -0,0 +1,52 @@ +#include +namespace py = boost::python; +#include + +#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 > &) = &SequenceBrowserWidget::setSequences; + + py::class_("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) + ; +} diff --git a/py/test/CMakeLists.txt b/py/test/CMakeLists.txt index 9c5e00b..15c6799 100644 --- a/py/test/CMakeLists.txt +++ b/py/test/CMakeLists.txt @@ -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} diff --git a/qui/mussagl.cpp b/qui/mussagl.cpp index a5f9b48..d0df4c6 100644 --- a/qui/mussagl.cpp +++ b/qui/mussagl.cpp @@ -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())); diff --git a/qui/seqbrowser/SequenceBrowserWidget.cpp b/qui/seqbrowser/SequenceBrowserWidget.cpp index 0ec2a6a..34c7a9a 100644 --- a/qui/seqbrowser/SequenceBrowserWidget.cpp +++ b/qui/seqbrowser/SequenceBrowserWidget.cpp @@ -18,6 +18,21 @@ #include 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 empty_dir(new QDir); + default_dir = empty_dir; + + init(); +} + SequenceBrowserWidget::SequenceBrowserWidget( boost::shared_ptr 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 diff --git a/qui/seqbrowser/SequenceBrowserWidget.hpp b/qui/seqbrowser/SequenceBrowserWidget.hpp index f57f9bb..8f957c7 100644 --- a/qui/seqbrowser/SequenceBrowserWidget.hpp +++ b/qui/seqbrowser/SequenceBrowserWidget.hpp @@ -20,6 +20,8 @@ class SequenceBrowserWidget : public QScrollArea Q_OBJECT public: + SequenceBrowserWidget(QWidget *parent=0); + SequenceBrowserWidget(const SequenceBrowserWidget &); SequenceBrowserWidget(boost::shared_ptr, 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 converted_sequences; + + //! shared code for constructors + void init(); }; #endif -- 2.30.2