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

Adapt remote loader to new sip export

fixed get_cpp_qobject method (check for None object)
fixed get_py_qobject method (check for NULL pointer)

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2081 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 00e32e2f
No related branches found
No related tags found
No related merge requests found
...@@ -50,9 +50,8 @@ struct WrappedRemoteSiteLoader : public RemoteSiteLoader ...@@ -50,9 +50,8 @@ struct WrappedRemoteSiteLoader : public RemoteSiteLoader
} }
virtual QNetworkReply* ById(const QString& id, const QString& selection=QString()){ virtual QNetworkReply* ById(const QString& id, const QString& selection=QString()){
//This hackish code will be changed soon(er or later) object obj = call_method<object, std::string, std::string>(self, "ById", id.toStdString(), selection.toStdString());
unsigned long addr=call_method<unsigned long, std::string>(self, "ByIdAddr", id.toStdString(), selection.toStdString()); QNetworkReply* network_reply= get_cpp_qobject<QNetworkReply>(obj);
QNetworkReply* network_reply= reinterpret_cast<QNetworkReply*>(addr);
if(network_reply){ if(network_reply){
return network_reply; return network_reply;
} }
......
...@@ -48,13 +48,6 @@ class BaseRemoteLoader(gui.RemoteSiteLoader): ...@@ -48,13 +48,6 @@ class BaseRemoteLoader(gui.RemoteSiteLoader):
else: else:
gui.FileLoader.LoadObject(str(file_name),str(selection)) gui.FileLoader.LoadObject(str(file_name),str(selection))
return None 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): def IsImg(self):
return False return False
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#define OST_GUI_SIP_HANDLER_HH #define OST_GUI_SIP_HANDLER_HH
#include <boost/python.hpp> #include <boost/python.hpp>
#include <iostream>
#include <QWidget> #include <QWidget>
#include <ost/message.hh> #include <ost/message.hh>
...@@ -36,21 +36,29 @@ namespace ost { namespace gui { ...@@ -36,21 +36,29 @@ namespace ost { namespace gui {
template <class O> object get_py_qobject(O* cpp_object) template <class O> object get_py_qobject(O* cpp_object)
{ {
static object sip_module=import("sip"); if (cpp_object != NULL){
static object pyqt4_module=import("PyQt4.QtCore"); static object sip_module=import("sip");
QObject* qobject = qobject_cast<QObject*>(cpp_object); static object pyqt4_module=import("PyQt4.QtCore");
unsigned long addr = reinterpret_cast<unsigned long>(qobject); QObject* qobject = qobject_cast<QObject*>(cpp_object);
object py_qobject = pyqt4_module.attr("QObject"); unsigned long addr = reinterpret_cast<unsigned long>(qobject);
object object = sip_module.attr("wrapinstance")(addr, py_qobject); object py_qobject = pyqt4_module.attr("QObject");
return object; object object = sip_module.attr("wrapinstance")(addr, py_qobject);
return object;
}
return object();
}; };
template <class O> O* get_cpp_qobject(object py_object) template <class O> O* get_cpp_qobject(object py_object)
{ {
static object sip_module=import("sip"); if(py_object.ptr() != Py_None){
unsigned long addr = extract<unsigned long>(sip_module.attr("unwrapinstance")(py_object)); static object sip_module=import("sip");
return reinterpret_cast<O*>(addr); unsigned long addr = extract<unsigned long>(sip_module.attr("unwrapinstance")(py_object));
if(addr){
return reinterpret_cast<O*>(addr);
}
}
return NULL;
}; };
class SipHandlerBase { class SipHandlerBase {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment