From e9389f96f15eeca708b657d7955d5c6ba7256f6b Mon Sep 17 00:00:00 2001 From: stefan <stefan@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Wed, 21 Apr 2010 13:13:25 +0000 Subject: [PATCH] Export of main_area: - support py_objects git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2076 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/gui/pymod/export_gl_win.cc | 4 +- modules/gui/pymod/export_gosty.cc | 1 - modules/gui/pymod/export_input.cc | 6 +-- modules/gui/pymod/export_main_area.cc | 65 ++++++++++++++++----------- modules/gui/pymod/gl_win_proxy.hh | 50 --------------------- modules/gui/pymod/sip_handler.hh | 11 ++++- 6 files changed, 52 insertions(+), 85 deletions(-) delete mode 100644 modules/gui/pymod/gl_win_proxy.hh diff --git a/modules/gui/pymod/export_gl_win.cc b/modules/gui/pymod/export_gl_win.cc index e1179888a..a0ef599d4 100644 --- a/modules/gui/pymod/export_gl_win.cc +++ b/modules/gui/pymod/export_gl_win.cc @@ -32,8 +32,8 @@ void export_GLWin() .def("Show", &GLWin::show) .def("Hide", &GLWin::hide) .def("StatusMessage",&GLWin::StatusMessage) - .def("GetQObject",&ost::gui::get_qobject<GLWin>) - .add_property("qobject", &ost::gui::get_qobject<GLWin>) + .def("GetQObject",&ost::gui::get_py_qobject<GLWin>) + .add_property("qobject", &ost::gui::get_py_qobject<GLWin>) ; } diff --git a/modules/gui/pymod/export_gosty.cc b/modules/gui/pymod/export_gosty.cc index 6b96347d4..88967d519 100644 --- a/modules/gui/pymod/export_gosty.cc +++ b/modules/gui/pymod/export_gosty.cc @@ -30,7 +30,6 @@ using namespace boost::python; #include "transfer_ownership.hh" #include "python_shell_proxy.hh" #include "tool_options_win_proxy.hh" -#include "gl_win_proxy.hh" #include "scene_win_proxy.hh" #include "sequence_viewer_proxy.hh" #if OST_IMG_ENABLED diff --git a/modules/gui/pymod/export_input.cc b/modules/gui/pymod/export_input.cc index cca0989be..f0df02754 100644 --- a/modules/gui/pymod/export_input.cc +++ b/modules/gui/pymod/export_input.cc @@ -34,7 +34,7 @@ object spnav_get_instance() { static object sip_module=import("sip"); static object pyqt4_module=import("PyQt4.QtCore"); - return ost::gui::get_qobject<SpnavInput>(SpnavInput::Instance()); + return ost::gui::get_py_qobject<SpnavInput>(SpnavInput::Instance()); } } @@ -43,8 +43,8 @@ void export_Input() { class_<SpnavInput, bases<SipHandlerBase>, boost::noncopyable >("SpnavInput",no_init) .def("GetQThread", &spnav_get_instance).staticmethod("GetQThread") - .def("GetQObject", &ost::gui::get_qobject<SpnavInput>) - .add_property("qobject", &ost::gui::get_qobject<SpnavInput>) + .def("GetQObject", &ost::gui::get_py_qobject<SpnavInput>) + .add_property("qobject", &ost::gui::get_py_qobject<SpnavInput>) .def("Instance", &SpnavInput::Instance, return_value_policy<reference_existing_object>()).staticmethod("Instance") ; diff --git a/modules/gui/pymod/export_main_area.cc b/modules/gui/pymod/export_main_area.cc index 0d5cd71ad..70c69427a 100644 --- a/modules/gui/pymod/export_main_area.cc +++ b/modules/gui/pymod/export_main_area.cc @@ -45,6 +45,12 @@ void main_area_add_widget_b(MainArea* m, const QString& title, QObject* obj) } } +void main_area_add_widget_c(MainArea* m, const QString& title, object py_object) +{ + if(QWidget* widget = get_cpp_qobject<QWidget>(py_object)){ + m->AddWidget(title, widget); + } +} void main_area_add_pers_widget_a(MainArea* m, const QString& title, const QString& name, @@ -64,6 +70,15 @@ void main_area_add_pers_widget_b(MainArea* m, const QString& title, } void main_area_add_pers_widget_c(MainArea* m, const QString& title, + const QString& name, + object py_object) +{ + if(QWidget* widget = get_cpp_qobject<QWidget>(py_object)){ + m->AddPersistentWidget(title, name, widget); + } +} + +void main_area_add_pers_widget_d(MainArea* m, const QString& title, const QString& name, const SipHandlerBase& sh, int width, int height, int x, int y) { @@ -71,7 +86,7 @@ void main_area_add_pers_widget_c(MainArea* m, const QString& title, reinterpret_cast<QWidget*>(sh.GetSipHandle()), width, height, x, y); } -void main_area_add_pers_widget_d(MainArea* m, const QString& title, +void main_area_add_pers_widget_e(MainArea* m, const QString& title, const QString& name, QWidget* widget, int width, int height, int x, int y) { @@ -80,7 +95,16 @@ void main_area_add_pers_widget_d(MainArea* m, const QString& title, reinterpret_cast<QWidget*>(widget), width, height, x, y); } -void main_area_add_pers_widget_e(MainArea* m, const QString& title, +void main_area_add_pers_widget_f(MainArea* m, const QString& title, + const QString& name, + object py_object, int width, int height, int x, int y) +{ + if(QWidget* widget = get_cpp_qobject<QWidget>(py_object)){ + m->AddPersistentWidget(title, name, widget, width, height, x, y); + } +} + +void main_area_add_pers_widget_g(MainArea* m, const QString& title, const QString& name, const SipHandlerBase& sh, int window_states) { Qt::WindowStates q_window_states =Qt::WindowStates(window_states); @@ -88,7 +112,7 @@ void main_area_add_pers_widget_e(MainArea* m, const QString& title, reinterpret_cast<QWidget*>(sh.GetSipHandle()), q_window_states); } -void main_area_add_pers_widget_f(MainArea* m, const QString& title, +void main_area_add_pers_widget_h(MainArea* m, const QString& title, const QString& name, QWidget* widget, int window_states) { TransferOwnership(widget); @@ -97,6 +121,15 @@ void main_area_add_pers_widget_f(MainArea* m, const QString& title, reinterpret_cast<QWidget*>(widget), q_window_states); } +void main_area_add_pers_widget_i(MainArea* m, const QString& title, + const QString& name, object py_object, int window_states) +{ + if(QWidget* widget = get_cpp_qobject<QWidget>(py_object)){ + Qt::WindowStates q_window_states = Qt::WindowStates(window_states); + m->AddPersistentWidget(title, name, widget, q_window_states); + } +} + void main_area_show_sub_window(MainArea* m, const SipHandlerBase& sh) { m->ShowSubWindow(reinterpret_cast<QWidget*>(sh.GetSipHandle())); @@ -107,30 +140,6 @@ void main_area_hide_sub_window(MainArea* m, const SipHandlerBase& sh) m->HideSubWindow(reinterpret_cast<QWidget*>(sh.GetSipHandle())); } - - - -void main_area_add_pers_widget_g(MainArea* m, const QString& title, - const QString& name, object py_object, int window_states) -{ - static object sip_module=import("sip"); - static object gui_module=import("ost.gui"); - static object pyqt4_module=import("PyQt4.QtCore"); - - unsigned long addr = extract<unsigned long>(sip_module.attr("unwrapinstance")(py_object)); - QWidget* widget = reinterpret_cast<QWidget*>(addr); - if(widget){ - Qt::WindowStates q_window_states =Qt::WindowStates(window_states); - m->AddPersistentWidget(title, name, widget, q_window_states); - } -} - - - - - - - } void export_MainArea() @@ -146,6 +155,8 @@ void export_MainArea() .def("AddPersistentWidget", &main_area_add_pers_widget_e) .def("AddPersistentWidget", &main_area_add_pers_widget_f) .def("AddPersistentWidget", &main_area_add_pers_widget_g) + .def("AddPersistentWidget", &main_area_add_pers_widget_h) + .def("AddPersistentWidget", &main_area_add_pers_widget_i) .def("width", &MainArea::width) .def("height", &MainArea::height) .def("ShowSubWindow", &MainArea::ShowSubWindow) diff --git a/modules/gui/pymod/gl_win_proxy.hh b/modules/gui/pymod/gl_win_proxy.hh deleted file mode 100644 index d6a4c74f0..000000000 --- a/modules/gui/pymod/gl_win_proxy.hh +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2010 by the OpenStructure authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ -#ifndef OST_GUI_GL_WIN_PROXY_HH -#define OST_GUI_GL_WIN_PROXY_HH - -#include <ost/gui/gl_win.hh> - -#include "sip_handler.hh" - -namespace ost { namespace gui { - -class GLWinProxy : public SipHandler<GLWin> { -public: - GLWinProxy(GLWin* gl_win=NULL): - SipHandler<GLWin>(gl_win) - { } - - void Show() - { - return Me()->show(); - } - void Hide() - { - return Me()->hide(); - } - void StatusMessage(const String& message) - { - Me()->StatusMessage(message); - } -}; - -}} - -#endif diff --git a/modules/gui/pymod/sip_handler.hh b/modules/gui/pymod/sip_handler.hh index 621633760..33436e213 100644 --- a/modules/gui/pymod/sip_handler.hh +++ b/modules/gui/pymod/sip_handler.hh @@ -34,11 +34,11 @@ using namespace boost::python; namespace ost { namespace gui { -template <class O> object get_qobject(O* obj) +template <class O> object get_py_qobject(O* cpp_object) { static object sip_module=import("sip"); static object pyqt4_module=import("PyQt4.QtCore"); - QObject* qobject = qobject_cast<QObject*>(obj); + QObject* qobject = qobject_cast<QObject*>(cpp_object); unsigned long addr = reinterpret_cast<unsigned long>(qobject); object py_qobject = pyqt4_module.attr("QObject"); object object = sip_module.attr("wrapinstance")(addr, py_qobject); @@ -46,6 +46,13 @@ template <class O> object get_qobject(O* obj) }; +template <class O> O* get_cpp_qobject(object py_object) +{ + static object sip_module=import("sip"); + unsigned long addr = extract<unsigned long>(sip_module.attr("unwrapinstance")(py_object)); + return reinterpret_cast<O*>(addr); +}; + class SipHandlerBase { public: virtual ~SipHandlerBase() {} -- GitLab