Expose attribute to Python to access icon of view provider
This commit is contained in:
parent
4e94c02dda
commit
1808fd83ed
|
@ -64,6 +64,12 @@
|
|||
</Documentation>
|
||||
<Parameter Name="Annotation" Type="Object" />
|
||||
</Attribute>
|
||||
<Attribute Name="Icon" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>The icon of this ViewProvider</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Icon" Type="Object" />
|
||||
</Attribute>
|
||||
<Attribute Name="RootNode" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>A pivy Separator with the root of this ViewProvider</UserDocu>
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <Inventor/nodes/SoSeparator.h>
|
||||
# include <QByteArray>
|
||||
# include <QDataStream>
|
||||
#endif
|
||||
|
||||
#include <Inventor/SoDB.h>
|
||||
|
@ -32,6 +34,7 @@
|
|||
#include <Inventor/nodes/SoSeparator.h>
|
||||
|
||||
#include "ViewProvider.h"
|
||||
#include "WidgetFactory.h"
|
||||
|
||||
// inclusion of the generated files (generated out of ViewProviderPy2.xml)
|
||||
#include "ViewProviderPy.h"
|
||||
|
@ -232,3 +235,19 @@ Py::String ViewProviderPy::getIV(void) const
|
|||
SbString buf = buffer_writeaction(getViewProviderPtr()->getRoot());
|
||||
return Py::String(buf.getString());
|
||||
}
|
||||
|
||||
Py::Object ViewProviderPy::getIcon(void) const
|
||||
{
|
||||
#if 0
|
||||
QByteArray ba;
|
||||
QDataStream str(&ba, QIODevice::WriteOnly);
|
||||
QIcon icon = getViewProviderPtr()->getIcon();
|
||||
str << icon;
|
||||
return Py::String(ba.constData(), ba.size());
|
||||
#else
|
||||
PythonWrapper wrap;
|
||||
wrap.loadGuiModule();
|
||||
QIcon icon = getViewProviderPtr()->getIcon();
|
||||
return wrap.fromQIcon(new QIcon(icon));
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
# undef _POSIX_C_SOURCE
|
||||
# undef _XOPEN_SOURCE
|
||||
# include <basewrapper.h>
|
||||
# include <conversions.h>
|
||||
# include <sbkmodule.h>
|
||||
# include <typeresolver.h>
|
||||
# include <shiboken.h>
|
||||
|
@ -179,6 +180,16 @@ QObject* PythonWrapper::toQObject(const Py::Object& pyobject)
|
|||
return 0;
|
||||
}
|
||||
|
||||
Py::Object PythonWrapper::fromQIcon(const QIcon* icon)
|
||||
{
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
PyObject* pyobj = Shiboken::createWrapper<QIcon>(icon, true);
|
||||
if (pyobj)
|
||||
return Py::asObject(pyobj);
|
||||
#endif
|
||||
throw Py::RuntimeError("Failed to wrap icon");
|
||||
}
|
||||
|
||||
Py::Object PythonWrapper::fromQWidget(QWidget* widget, const char* className)
|
||||
{
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
|
|
|
@ -49,6 +49,11 @@ public:
|
|||
bool toCString(const Py::Object&, std::string&);
|
||||
QObject* toQObject(const Py::Object&);
|
||||
Py::Object fromQWidget(QWidget*, const char* className=0);
|
||||
/*!
|
||||
Create a Python wrapper for the icon. The icon must be created on the heap
|
||||
and the Python wrapper takes ownership of it.
|
||||
*/
|
||||
Py::Object fromQIcon(const QIcon*);
|
||||
static void createChildrenNameAttributes(PyObject* root, QObject* object);
|
||||
static void setParent(PyObject* pyWdg, QObject* parent);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user