Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/looooo/pivy
Browse files Browse the repository at this point in the history
  • Loading branch information
looooo committed Jun 9, 2017
2 parents e04c03e + 670323a commit 0641ba8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dist: trusty
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
before_install:
Expand Down
25 changes: 13 additions & 12 deletions Inventor/Qt/SoQtRenderArea.i
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
static SbBool
SoQtRenderAreaEventPythonCB(void * closure, QEvent * event)
{
PyObject *func, *arglist;
PyObject *result, *shiboken, *qt, *qev = NULL;
int ret = 0;
PyObject *func = NULL, *arglist = NULL;
PyObject *result = NULL, *shiboken, *qt = NULL, *qev = NULL;
SbBool ret = TRUE; // assume success as default

/* try to create a QEvent PySide instance over shiboken */


/* check if the shiboken module is available and import it */
shiboken = getShiboken();

Expand All @@ -21,24 +20,24 @@ SoQtRenderAreaEventPythonCB(void * closure, QEvent * event)

if (qt && PyModule_Check(qt)) {
/* grab the wrapinstance(addr, type) function */
PyObject *shiboken_wrapinst_func;
PyObject *shiboken_wrapinst_func = NULL;
shiboken_wrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "wrapInstance");

if (PyCallable_Check(shiboken_wrapinst_func)) {
PyObject *qevent_type;
PyObject *qevent_type = NULL;
qevent_type = PyDict_GetItemString(PyModule_GetDict(qt), get_typename(*event));

// TODO: find better solution for QKeyEvent
if (!qevent_type){
if (strcmp(get_typename(*event), "QKeyEventEx") == 0)
if (strcmp(get_typename(*event), "QKeyEventEx") == 0) {
qevent_type = PyDict_GetItemString(PyModule_GetDict(qt), "QKeyEvent");
else
} else {
qevent_type = PyDict_GetItemString(PyModule_GetDict(qt), "QEvent");
}
}

if (qevent_type)
{
arglist = Py_BuildValue("(lO)", event, qevent_type);
arglist = Py_BuildValue("(nO)", event, qevent_type);

if (!(qev = PyEval_CallObject(shiboken_wrapinst_func, arglist))) {
PyErr_Print();
Expand All @@ -63,10 +62,12 @@ SoQtRenderAreaEventPythonCB(void * closure, QEvent * event)
if (!(result = PyEval_CallObject(func, arglist))) {
PyErr_Print();
} else {
ret = PyInt_AsLong(result);
ret = FALSE;
}

if (shiboken) {Py_DECREF(shiboken); }
if (shiboken) {
Py_DECREF(shiboken);
}
Py_DECREF(arglist);
Py_DECREF(qev);
Py_XDECREF(result);
Expand Down
42 changes: 20 additions & 22 deletions interfaces/soqt.i
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ otherwise it will fall back to regular SWIG structures."
Coppied from: https://github.com/Kagami/pygraphviz/commit/fe442dc16accb629c3feaf157af75f67ccabbd6e
*/
#if PY_MAJOR_VERSION >= 3
static PyObject *PyIOBase_TypeObj;
static PyObject *PyIOBase_TypeObj = NULL;

static int init_file_emulator(void)
{
Expand Down Expand Up @@ -111,9 +111,7 @@ template <typename T> const char* get_typename(T& object)
#else
template <typename T> const char* get_typename(T& object)
{
const char* simpleNonUnicodeAsciiCStyleString = typeid(object).name();
const char* shortenedVersion = simpleNonUnicodeAsciiCStyleString + 6;
return shortenedVersion;
return (typeid(object).name() + 6); // the +6 advanced the pointer 6 bytes (6 asc ii characters) to cut off prefix "class " from the object's class name
}
#endif
/////////////////////////////////////////////////////
Expand All @@ -126,10 +124,10 @@ static PyObject* getShiboken()
// this function asumes shiboken is available directly
// pip installs it in a wrong place
// if you have installed shiboken with pip please symlink to correct directory
PyObject * shiboken;
PyObject * shiboken = NULL;
if (!(shiboken = PyDict_GetItemString(PyModule_GetDict(PyImport_AddModule("__main__")), "shiboken"))) {
// simple import shiboken from python.
shiboken = PyImport_ImportModule("shiboken");
shiboken = PyImport_ImportModule("shiboken");
}
return shiboken;
}
Expand All @@ -146,7 +144,7 @@ static PyObject* getShiboken()
%typemap(out) QEvent * {
$result = NULL;
{
PyObject *qt;
PyObject *qt = NULL;

/* try to create a PySide QEvent instance through shiboken */

Expand All @@ -160,14 +158,14 @@ static PyObject* getShiboken()

if (qt && PyModule_Check(qt)) {
/* grab the wrapInstance(addr, type) function */
PyObject *shiboken_wrapinst_func;
PyObject *shiboken_wrapinst_func = NULL;
shiboken_wrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "wrapInstance");

if (PyCallable_Check(shiboken_wrapinst_func)) {
PyObject *qevent_type, *arglist;
PyObject *qevent_type = NULL, *arglist = NULL;
qevent_type = PyDict_GetItemString(PyModule_GetDict(qt), "QEvent");

arglist = Py_BuildValue("(lO)", $1, qevent_type);
arglist = Py_BuildValue("(nO)", $1, qevent_type);

if (!($result = PyEval_CallObject(shiboken_wrapinst_func, arglist))) {
PyErr_Print();
Expand All @@ -189,7 +187,7 @@ static PyObject* getShiboken()
%typemap(out) QWidget * {
$result = NULL;
{
PyObject *qt;
PyObject *qt = NULL;

/* try to create a PySide QWidget instance through shiboken */

Expand All @@ -203,14 +201,14 @@ static PyObject* getShiboken()

if (qt && PyModule_Check(qt)) {
/* grab the wrapInstance(addr, type) function */
PyObject *shiboken_wrapinst_func;
PyObject *shiboken_wrapinst_func = NULL;
shiboken_wrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "wrapInstance");

if (PyCallable_Check(shiboken_wrapinst_func)) {
PyObject *qwidget_type, *arglist;
PyObject *qwidget_type = NULL, *arglist = NULL;
qwidget_type = PyDict_GetItemString(PyModule_GetDict(qt), "QWidget");

arglist = Py_BuildValue("(lO)", $1, qwidget_type);
arglist = Py_BuildValue("(nO)", $1, qwidget_type);

if (!($result = PyEval_CallObject(shiboken_wrapinst_func, arglist))) {
PyErr_Print();
Expand All @@ -235,11 +233,11 @@ static PyObject* getShiboken()

if (shiboken && PyModule_Check(shiboken)) {
/* grab the unwrapInstance(obj) function */
PyObject *shiboken_unwrapinst_func;
PyObject *shiboken_unwrapinst_func = NULL;
shiboken_unwrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "getCppPointer");

if (PyCallable_Check(shiboken_unwrapinst_func)) {
PyObject *arglist, *address;
PyObject *arglist = NULL, *address = NULL;
arglist = Py_BuildValue("(O)", $input);
if (!(address = PyEval_CallObject(shiboken_unwrapinst_func, arglist))) {
PyErr_Print();
Expand Down Expand Up @@ -270,11 +268,11 @@ static PyObject* getShiboken()

if (shiboken && PyModule_Check(shiboken)) {
/* grab the unwrapInstance(obj) function */
PyObject *shiboken_unwrapinst_func;
PyObject *shiboken_unwrapinst_func = NULL;
shiboken_unwrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "getCppPointer");

if (PyCallable_Check(shiboken_unwrapinst_func)) {
PyObject *arglist, *address;
PyObject *arglist = NULL, *address = NULL;
arglist = Py_BuildValue("(O)", $input);
if (!(address = PyEval_CallObject(shiboken_unwrapinst_func, arglist))) {
PyErr_Print();
Expand Down Expand Up @@ -307,11 +305,11 @@ class QWidget { QWidget(QWidget* parent=0, const char* name=0, WFlags f=0); };

if (shiboken && PyModule_Check(shiboken)) {
/* grab the unwrapInstance(obj) function */
PyObject *shiboken_unwrapinst_func;
PyObject *shiboken_unwrapinst_func = NULL;
shiboken_unwrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "getCppPointer");

if (PyCallable_Check(shiboken_unwrapinst_func)) {
PyObject *arglist, *address;
PyObject *arglist = NULL, *address = NULL;
arglist = Py_BuildValue("(O)", $input);
if (!(address = PyEval_CallObject(shiboken_unwrapinst_func, arglist))) {
PyErr_Print();
Expand Down Expand Up @@ -343,11 +341,11 @@ class QWidget { QWidget(QWidget* parent=0, const char* name=0, WFlags f=0); };

if (shiboken && PyModule_Check(shiboken)) {
/* grab the unwrapInstance(obj) function */
PyObject *shiboken_unwrapinst_func;
PyObject *shiboken_unwrapinst_func = NULL;
shiboken_unwrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "getCppPointer");

if (PyCallable_Check(shiboken_unwrapinst_func)) {
PyObject *arglist, *address;
PyObject *arglist = NULL, *address = NULL;
arglist = Py_BuildValue("(O)", $input);
if (!(address = PyEval_CallObject(shiboken_unwrapinst_func, arglist))) {
PyErr_Print();
Expand Down
15 changes: 10 additions & 5 deletions tests/coin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,7 @@ def testSFVec3f(self):
s.setValue(t)
self.failUnless(t.getValue() == s.getValue(),
'setValue other SoSFVec3f on SoSFVec3f failed')
# test division support
s.setValue(1, 1, 1)
self.failUnless(s / 2. == SoSFVec3f(0.5, 0.5, 0.5),
'divison does not give correct solution')
# TODO: support ints!


def testSFVec2f(self):
"""check setValue for SoSFVec2f"""
Expand Down Expand Up @@ -1199,6 +1195,15 @@ def setUp(self):
def testSetBuffer(self):
self.input.setBuffer(self.text)


class SbVecTests(unittest.TestCase):
def setUp(self):
self.sbvec3f = coin.SbVec3f(1, 1, 1)

def multDivTest(self):
self.assertEqual(self.sbvec3f, self.sbvec3f * 2. / 2.)
# TODO: also support ints

class SbPLaneTests(unittest.TestCase):

def setUp(self):
Expand Down

0 comments on commit 0641ba8

Please sign in to comment.