Skip to content
Snippets Groups Projects
Commit e9389f96 authored by stefan's avatar stefan
Browse files

Export of main_area:

 - support py_objects

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2076 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 5e776460
Branches
Tags
No related merge requests found
...@@ -32,8 +32,8 @@ void export_GLWin() ...@@ -32,8 +32,8 @@ void export_GLWin()
.def("Show", &GLWin::show) .def("Show", &GLWin::show)
.def("Hide", &GLWin::hide) .def("Hide", &GLWin::hide)
.def("StatusMessage",&GLWin::StatusMessage) .def("StatusMessage",&GLWin::StatusMessage)
.def("GetQObject",&ost::gui::get_qobject<GLWin>) .def("GetQObject",&ost::gui::get_py_qobject<GLWin>)
.add_property("qobject", &ost::gui::get_qobject<GLWin>) .add_property("qobject", &ost::gui::get_py_qobject<GLWin>)
; ;
} }
......
...@@ -30,7 +30,6 @@ using namespace boost::python; ...@@ -30,7 +30,6 @@ using namespace boost::python;
#include "transfer_ownership.hh" #include "transfer_ownership.hh"
#include "python_shell_proxy.hh" #include "python_shell_proxy.hh"
#include "tool_options_win_proxy.hh" #include "tool_options_win_proxy.hh"
#include "gl_win_proxy.hh"
#include "scene_win_proxy.hh" #include "scene_win_proxy.hh"
#include "sequence_viewer_proxy.hh" #include "sequence_viewer_proxy.hh"
#if OST_IMG_ENABLED #if OST_IMG_ENABLED
......
...@@ -34,7 +34,7 @@ object spnav_get_instance() ...@@ -34,7 +34,7 @@ object spnav_get_instance()
{ {
static object sip_module=import("sip"); static object sip_module=import("sip");
static object pyqt4_module=import("PyQt4.QtCore"); 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() ...@@ -43,8 +43,8 @@ void export_Input()
{ {
class_<SpnavInput, bases<SipHandlerBase>, boost::noncopyable >("SpnavInput",no_init) class_<SpnavInput, bases<SipHandlerBase>, boost::noncopyable >("SpnavInput",no_init)
.def("GetQThread", &spnav_get_instance).staticmethod("GetQThread") .def("GetQThread", &spnav_get_instance).staticmethod("GetQThread")
.def("GetQObject", &ost::gui::get_qobject<SpnavInput>) .def("GetQObject", &ost::gui::get_py_qobject<SpnavInput>)
.add_property("qobject", &ost::gui::get_qobject<SpnavInput>) .add_property("qobject", &ost::gui::get_py_qobject<SpnavInput>)
.def("Instance", &SpnavInput::Instance, .def("Instance", &SpnavInput::Instance,
return_value_policy<reference_existing_object>()).staticmethod("Instance") return_value_policy<reference_existing_object>()).staticmethod("Instance")
; ;
......
...@@ -45,6 +45,12 @@ void main_area_add_widget_b(MainArea* m, const QString& title, QObject* obj) ...@@ -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, void main_area_add_pers_widget_a(MainArea* m, const QString& title,
const QString& name, const QString& name,
...@@ -64,6 +70,15 @@ void main_area_add_pers_widget_b(MainArea* m, const QString& title, ...@@ -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, 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 QString& name,
const SipHandlerBase& sh, int width, int height, int x, int y) 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, ...@@ -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); 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, const QString& name,
QWidget* widget, int width, int height, int x, int y) 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, ...@@ -80,7 +95,16 @@ void main_area_add_pers_widget_d(MainArea* m, const QString& title,
reinterpret_cast<QWidget*>(widget), width, height, x, y); 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) const QString& name, const SipHandlerBase& sh, int window_states)
{ {
Qt::WindowStates q_window_states =Qt::WindowStates(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, ...@@ -88,7 +112,7 @@ void main_area_add_pers_widget_e(MainArea* m, const QString& title,
reinterpret_cast<QWidget*>(sh.GetSipHandle()), q_window_states); 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) const QString& name, QWidget* widget, int window_states)
{ {
TransferOwnership(widget); TransferOwnership(widget);
...@@ -97,6 +121,15 @@ void main_area_add_pers_widget_f(MainArea* m, const QString& title, ...@@ -97,6 +121,15 @@ void main_area_add_pers_widget_f(MainArea* m, const QString& title,
reinterpret_cast<QWidget*>(widget), q_window_states); 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) void main_area_show_sub_window(MainArea* m, const SipHandlerBase& sh)
{ {
m->ShowSubWindow(reinterpret_cast<QWidget*>(sh.GetSipHandle())); m->ShowSubWindow(reinterpret_cast<QWidget*>(sh.GetSipHandle()));
...@@ -107,30 +140,6 @@ void main_area_hide_sub_window(MainArea* m, const SipHandlerBase& sh) ...@@ -107,30 +140,6 @@ void main_area_hide_sub_window(MainArea* m, const SipHandlerBase& sh)
m->HideSubWindow(reinterpret_cast<QWidget*>(sh.GetSipHandle())); 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() void export_MainArea()
...@@ -146,6 +155,8 @@ 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_e)
.def("AddPersistentWidget", &main_area_add_pers_widget_f) .def("AddPersistentWidget", &main_area_add_pers_widget_f)
.def("AddPersistentWidget", &main_area_add_pers_widget_g) .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("width", &MainArea::width)
.def("height", &MainArea::height) .def("height", &MainArea::height)
.def("ShowSubWindow", &MainArea::ShowSubWindow) .def("ShowSubWindow", &MainArea::ShowSubWindow)
......
//------------------------------------------------------------------------------
// 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
...@@ -34,11 +34,11 @@ using namespace boost::python; ...@@ -34,11 +34,11 @@ using namespace boost::python;
namespace ost { namespace gui { 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 sip_module=import("sip");
static object pyqt4_module=import("PyQt4.QtCore"); 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); unsigned long addr = reinterpret_cast<unsigned long>(qobject);
object py_qobject = pyqt4_module.attr("QObject"); object py_qobject = pyqt4_module.attr("QObject");
object object = sip_module.attr("wrapinstance")(addr, py_qobject); object object = sip_module.attr("wrapinstance")(addr, py_qobject);
...@@ -46,6 +46,13 @@ template <class O> object get_qobject(O* obj) ...@@ -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 { class SipHandlerBase {
public: public:
virtual ~SipHandlerBase() {} virtual ~SipHandlerBase() {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment