diff --git a/modules/gui/pymod/export_remote_site_loader.cc b/modules/gui/pymod/export_remote_site_loader.cc index 3446fd6c09425f7b98fed48dcc41efc6e63ee79c..91b80ca7727c7abc619749f1bf311977906bbfd0 100644 --- a/modules/gui/pymod/export_remote_site_loader.cc +++ b/modules/gui/pymod/export_remote_site_loader.cc @@ -50,9 +50,8 @@ struct WrappedRemoteSiteLoader : public RemoteSiteLoader } virtual QNetworkReply* ById(const QString& id, const QString& selection=QString()){ - //This hackish code will be changed soon(er or later) - unsigned long addr=call_method<unsigned long, std::string>(self, "ByIdAddr", id.toStdString(), selection.toStdString()); - QNetworkReply* network_reply= reinterpret_cast<QNetworkReply*>(addr); + object obj = call_method<object, std::string, std::string>(self, "ById", id.toStdString(), selection.toStdString()); + QNetworkReply* network_reply= get_cpp_qobject<QNetworkReply>(obj); if(network_reply){ return network_reply; } diff --git a/modules/gui/pymod/scene/file_loader.py b/modules/gui/pymod/scene/file_loader.py index 105ec8910efb314ff93c0a7606a0c9618d509dea..522dd6934deeb8bfa45b17ebd1aea6646ecf3d44 100644 --- a/modules/gui/pymod/scene/file_loader.py +++ b/modules/gui/pymod/scene/file_loader.py @@ -48,13 +48,6 @@ class BaseRemoteLoader(gui.RemoteSiteLoader): else: gui.FileLoader.LoadObject(str(file_name),str(selection)) return None - - #Hack for C++ (will be changed soon) - def ByIdAddr(self,id,selection): - reply = self.ById(id,selection) - if reply is not None: - return sip.unwrapinstance(reply) - return 0 def IsImg(self): return False diff --git a/modules/gui/pymod/sip_handler.hh b/modules/gui/pymod/sip_handler.hh index 33436e2136aa40aa39e1e7cfae5ae56e9a5ec828..9eb6ac7c4d3ad0aba5196ed4f81ad808b5a08b53 100644 --- a/modules/gui/pymod/sip_handler.hh +++ b/modules/gui/pymod/sip_handler.hh @@ -20,7 +20,7 @@ #define OST_GUI_SIP_HANDLER_HH #include <boost/python.hpp> - +#include <iostream> #include <QWidget> #include <ost/message.hh> @@ -36,21 +36,29 @@ namespace ost { namespace gui { 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*>(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); - return object; + if (cpp_object != NULL){ + static object sip_module=import("sip"); + static object pyqt4_module=import("PyQt4.QtCore"); + 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); + return object; + } + return object(); }; 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); + if(py_object.ptr() != Py_None){ + static object sip_module=import("sip"); + unsigned long addr = extract<unsigned long>(sip_module.attr("unwrapinstance")(py_object)); + if(addr){ + return reinterpret_cast<O*>(addr); + } + } + return NULL; }; class SipHandlerBase {