diff --git a/modules/gui/pymod/export_gl_win.cc b/modules/gui/pymod/export_gl_win.cc index 4f69d1542bfafe7b9fb051263401476c252ff6ce..e1179888afe623acc2b51d07f03a3b547212ffc4 100644 --- a/modules/gui/pymod/export_gl_win.cc +++ b/modules/gui/pymod/export_gl_win.cc @@ -17,19 +17,23 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //------------------------------------------------------------------------------ #include <boost/python.hpp> -#include "gl_win_proxy.hh" + +#include <ost/gui/gl_win.hh> + +#include "sip_handler.hh" using namespace boost::python; using namespace ost; using namespace ost::gui; - void export_GLWin() { - class_<GLWinProxy, bases<SipHandlerBase> >("GLWin") - .def("Show", &GLWinProxy::Show) - .def("Hide", &GLWinProxy::Hide) - .def("StatusMessage",&GLWinProxy::StatusMessage) + class_<GLWin, boost::noncopyable >("GLWin", no_init) + .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>) ; } diff --git a/modules/gui/pymod/export_gosty.cc b/modules/gui/pymod/export_gosty.cc index a4000a992cadc87ed1897c8e5610033657094a5e..6b96347d4d1adcf24f05cf88b897f031322448a7 100644 --- a/modules/gui/pymod/export_gosty.cc +++ b/modules/gui/pymod/export_gosty.cc @@ -53,11 +53,6 @@ ToolOptionsWinProxy app_get_tool_options_win(GostyApp* app) return ToolOptionsWinProxy(app->GetToolOptionsWin()); } -GLWinProxy app_get_gl_win(GostyApp* app) -{ - return GLWinProxy(app->GetGLWin()); -} - SceneWinProxy app_get_scene_win(GostyApp* app) { return SceneWinProxy(app->GetSceneWin()); @@ -99,8 +94,10 @@ void export_Gosty() .def("SetAppTitle", &GostyApp::SetAppTitle) .def("GetPyShell", &app_get_py_shell) .add_property("py_shell", &app_get_py_shell) - .def("GetGLWin", &app_get_gl_win) - .add_property("gl_win", &app_get_gl_win) + .def("GetGLWin", &GostyApp::GetGLWin, + return_value_policy<reference_existing_object>()) + .add_property("gl_win", make_function(&GostyApp::GetGLWin, + return_value_policy<reference_existing_object>())) .def("GetSceneWin", &app_get_scene_win) .add_property("scene_win", &app_get_scene_win) .def("GetSequenceViewer", &app_get_seq_viewer) diff --git a/modules/gui/pymod/export_input.cc b/modules/gui/pymod/export_input.cc index b5bc4c51be70ed5b9d2f4c07a862d11895758ee7..cca0989be350998b136d52eba1e1be0a68c89c10 100644 --- a/modules/gui/pymod/export_input.cc +++ b/modules/gui/pymod/export_input.cc @@ -17,7 +17,11 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //------------------------------------------------------------------------------ #include <boost/python.hpp> -#include <iostream> + +#include <ost/gui/input/spnav_input.hh> + +#include "sip_handler.hh" + #include "spnav_input_proxy.hh" using namespace boost::python; @@ -30,22 +34,18 @@ object spnav_get_instance() { static object sip_module=import("sip"); static object pyqt4_module=import("PyQt4.QtCore"); - SpnavInput* spnav = SpnavInput::Instance(); - unsigned long addr = reinterpret_cast<unsigned long>(spnav); - object obj(addr); - object qthread = pyqt4_module.attr("QThread"); - object thread = sip_module.attr("wrapinstance")(addr, qthread); - - return thread; + return ost::gui::get_qobject<SpnavInput>(SpnavInput::Instance()); } } void export_Input() { - class_<SpnavInputProxy, bases<SipHandlerBase> >("SpnavInput",no_init) + class_<SpnavInput, bases<SipHandlerBase>, boost::noncopyable >("SpnavInput",no_init) .def("GetQThread", &spnav_get_instance).staticmethod("GetQThread") - .def("Instance", &SpnavInputProxy::Instance, + .def("GetQObject", &ost::gui::get_qobject<SpnavInput>) + .add_property("qobject", &ost::gui::get_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 8ffdbed9a022d19e08fcfd4d1248bd0416ad3c71..0d5cd71adc49336d554f7dd7b57af73f303ce795 100644 --- a/modules/gui/pymod/export_main_area.cc +++ b/modules/gui/pymod/export_main_area.cc @@ -107,6 +107,30 @@ 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() @@ -121,6 +145,7 @@ void export_MainArea() .def("AddPersistentWidget", &main_area_add_pers_widget_d) .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("width", &MainArea::width) .def("height", &MainArea::height) .def("ShowSubWindow", &MainArea::ShowSubWindow) diff --git a/modules/gui/pymod/export_sip_handler.cc b/modules/gui/pymod/export_sip_handler.cc index 2d746fab72b5ffed2ba7a0f3b7303cbdb623840b..5247c88829f5d3c0d19c351e71386b1572aa4a86 100644 --- a/modules/gui/pymod/export_sip_handler.cc +++ b/modules/gui/pymod/export_sip_handler.cc @@ -27,8 +27,6 @@ using namespace boost::python; using namespace ost; using namespace ost::gui; - - namespace { unsigned long sip_handle(QObject* w) diff --git a/modules/gui/pymod/scene/init_inspector.py b/modules/gui/pymod/scene/init_inspector.py index bc03d5da9aebd5e1758d98ac38174040ae6ce12b..03e88ef63650bbbe1bd695434cb256eefb84ee94 100644 --- a/modules/gui/pymod/scene/init_inspector.py +++ b/modules/gui/pymod/scene/init_inspector.py @@ -42,8 +42,7 @@ class InitInspectorMenu(QtCore.QObject): def _InitInspector(): app=gui.GostyApp.Instance() - gl_win=sip.wrapinstance(app.gl_win.GetSipHandle(),QtGui.QWidget) - mywidget = InspectorDialog(gl_win) + mywidget = InspectorDialog(app.gl_win.qobject) mywidget.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.Tool) mywidget.show() unwrapped = gui.BPQtHandle(sip.unwrapinstance(mywidget)) diff --git a/modules/gui/pymod/sip_handler.hh b/modules/gui/pymod/sip_handler.hh index c006184cebbbcfd52bea7c9297751bf4ee5d1bbd..6216337609c48f7080bcf22780c70c5c2d6ccf7a 100644 --- a/modules/gui/pymod/sip_handler.hh +++ b/modules/gui/pymod/sip_handler.hh @@ -19,15 +19,33 @@ #ifndef OST_GUI_SIP_HANDLER_HH #define OST_GUI_SIP_HANDLER_HH -#include <ost/message.hh> +#include <boost/python.hpp> + #include <QWidget> +#include <ost/message.hh> + +using namespace boost::python; + /* Author: Ansgar Philippsen, Marco Biasini */ namespace ost { namespace gui { + +template <class O> object get_qobject(O* obj) +{ + static object sip_module=import("sip"); + static object pyqt4_module=import("PyQt4.QtCore"); + QObject* qobject = qobject_cast<QObject*>(obj); + unsigned long addr = reinterpret_cast<unsigned long>(qobject); + object py_qobject = pyqt4_module.attr("QObject"); + object object = sip_module.attr("wrapinstance")(addr, py_qobject); + return object; +}; + + class SipHandlerBase { public: virtual ~SipHandlerBase() {} diff --git a/scripts/init.py b/scripts/init.py index 2856501fddd9196e19cfe97eaae5d9d148557d83..94bd347e12edc8ee5e1184f869ba473fe45adbc5 100644 --- a/scripts/init.py +++ b/scripts/init.py @@ -53,7 +53,7 @@ def _InitFrontEnd(): _InitMenuBar(app.perspective.GetMenuBar()) _InitSpaceNav(app.perspective.panels.qwidget) _InitContextMenu() - main_area.AddPersistentWidget("3D Scene", "gl_win" , app.gl_win, int(QtCore.Qt.WindowMaximized)) + main_area.AddPersistentWidget("3D Scene", "gl_win" , app.gl_win.qobject, int(QtCore.Qt.WindowMaximized)) app.perspective.Restore() additional_modules=getattr(__main__, 'ADDITIONAL_GUI_MODULES', []) for module_name in additional_modules: