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
}
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;
}
......
......@@ -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
......
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment