Skip to content

Commit

Permalink
Soqt port (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
looooo committed Apr 28, 2017
1 parent 4102e36 commit a0c3e84
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 244 deletions.
2 changes: 1 addition & 1 deletion Inventor/Qt/SoQt.i
Expand Up @@ -11,7 +11,7 @@
#ifdef PY_2
if (!strcmp(PyString_AsString(result), ""))
#else
if (!strcmp(PyBytes_AsString(result), ""))
if (!strcmp(PyUnicode_AsUTF8(result), ""))
#endif
{
cc_thread *py_thread = cc_thread_construct(Pivy_PythonInteractiveLoop, NULL);
Expand Down
29 changes: 13 additions & 16 deletions Inventor/Qt/SoQtRenderArea.i
Expand Up @@ -3,36 +3,33 @@ static SbBool
SoQtRenderAreaEventPythonCB(void * closure, QEvent * event)
{
PyObject *func, *arglist;
PyObject *result, *sip, *qt, *qev = NULL;
PyObject *result, *shiboken, *qt, *qev = NULL;
int ret = 0;

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

initialize_pyqt_module_import_name();

/* check if the sip module is available and import it */
if (!(sip = PyDict_GetItemString(PyModule_GetDict(PyImport_AddModule("__main__")), "sip"))) {
sip = PyImport_ImportModule("sip");
}
/* check if the shiboken module is available and import it */
shiboken = getShiboken();

if (sip && PyModule_Check(sip)) {
if (shiboken && PyModule_Check(shiboken)) {
/* check if the qt module is available and import it */
if (!(qt = PyDict_GetItemString(PyModule_GetDict(PyImport_AddModule("__main__")), PYQT_MODULE_IMPORT_NAME))) {
qt = PyImport_ImportModule(PYQT_MODULE_IMPORT_NAME);
if (!(qt = PyDict_GetItemString(PyModule_GetDict(PyImport_AddModule("__main__")), PYSIDE_QTCORE))) {
qt = PyImport_ImportModule(PYSIDE_QTCORE);
}

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

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

arglist = Py_BuildValue("(lO)", event, qevent_type);

if (!(qev = PyEval_CallObject(sip_wrapinst_func, arglist))) {
if (!(qev = PyEval_CallObject(shiboken_wrapinst_func, arglist))) {
PyErr_Print();
}

Expand All @@ -41,7 +38,7 @@ SoQtRenderAreaEventPythonCB(void * closure, QEvent * event)
}
}

/* if no QEvent could be created through sip return a swig QEvent type */
/* if no QEvent could be created through shiboken return a swig QEvent type */
if (!qev) {
qev = SWIG_NewPointerObj((void *)event, SWIGTYPE_p_QEvent, 0);
}
Expand All @@ -57,7 +54,7 @@ SoQtRenderAreaEventPythonCB(void * closure, QEvent * event)
ret = PyInt_AsLong(result);
}

if (sip) {Py_DECREF(sip); }
if (shiboken) {Py_DECREF(shiboken); }
Py_DECREF(arglist);
Py_DECREF(qev);
Py_XDECREF(result);
Expand Down
8 changes: 3 additions & 5 deletions examples/Mentor/10.2.setEventCB.py
Expand Up @@ -37,11 +37,9 @@
from pivy.coin import *
from pivy.gui.soqt import *

# PyQt module has to be imported as last one if used in the same namespace
if SoQt.getVersionToolkitString().startswith('4'):
from PyQt4.Qt import *
else:
from qt import *
# PySide module has to be imported as last one if used in the same namespace
from PySide.QtCore import *
from PySide.QtGui import *

# Timer sensor
# Rotate 90 degrees every second, update 30 times a second
Expand Down
8 changes: 4 additions & 4 deletions examples/QtDesigner/python/main.py
Expand Up @@ -2,10 +2,10 @@

import sys
from pivy.gui.soqt import SoQt
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QObject
from PyQt4.QtCore import SIGNAL
from PyQt4.QtCore import SLOT
from PySide.QtGui import QApplication
from PySide.QtCore import QObject
from PySide.QtCore import SIGNAL
from PySide.QtCore import SLOT
from mainwindow import MainWindow

if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions examples/QtDesigner/python/mainwindow.py
Expand Up @@ -4,11 +4,11 @@
from pivy.coin import *
from pivy.gui.soqt import SoQtExaminerViewer
from ui_test import Ui_MainWindow
from PyQt4.QtGui import QWidget
from PyQt4.QtGui import QMainWindow
from PyQt4.QtGui import QButtonGroup
from PyQt4.QtCore import QObject
from PyQt4.QtCore import SIGNAL
from PySide.QtGui import QWidget
from PySide.QtGui import QMainWindow
from PySide.QtGui import QButtonGroup
from PySide.QtCore import QObject
from PySide.QtCore import SIGNAL

class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent = None):
Expand Down
4 changes: 2 additions & 2 deletions examples/QtDesigner/python/ui_test.py
Expand Up @@ -3,11 +3,11 @@
# Form implementation generated from reading ui file '../test.ui'
#
# Created: Tue Feb 12 18:37:15 2008
# by: PyQt4 UI code generator 4.3.3
# by: PySide UI code generator 4.3.3
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from PySide import QtCore, QtGui

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
Expand Down
4 changes: 2 additions & 2 deletions examples/Quarter/mdi.py
Expand Up @@ -19,8 +19,8 @@
import os
import sys

from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QMainWindow, QWorkspace, QAction, QFileDialog, QApplication
from PySide import QtCore, QtGui
from PySide.QtGui import QMainWindow, QWorkspace, QAction, QFileDialog, QApplication

from pivy.coin import SoInput, SoDB
from pivy.quarter import QuarterWidget
Expand Down
4 changes: 2 additions & 2 deletions examples/examiner_embed4.py
Expand Up @@ -26,8 +26,8 @@
from pivy.coin import *
from pivy.gui.soqt import *

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PySide.QtGui import *
from PySide.QtCore import *

class EmbeddedWindow(QMainWindow):
def __init__(self, *args):
Expand Down
24 changes: 24 additions & 0 deletions examples/soqt/examinar_viewer.py
@@ -0,0 +1,24 @@
import sys
from pivy import coin
from pivy.gui import soqt
# import shiboken if you want to use the widget within qt

# Initialize Coin (returns main window to use)
# If unsuccessful, exit.
myWindow = soqt.SoQt.init(sys.argv[0])
print(myWindow)
# Make a scene containing a red cone.
myMaterial = coin.SoMaterial()
myMaterial.diffuseColor = (1.0, 0.0, 0.0)
scene = coin.SoSeparator()
scene.ref()
scene.addChild(myMaterial)
scene.addChild(coin.SoCone())
# Create a viewer to visualize our scene.
viewer = soqt.SoQtExaminerViewer(myWindow)
# Put our scene into viewer, change the title.
viewer.setSceneGraph(scene)
viewer.setTitle("Examiner Viewer")
viewer.show()
soqt.SoQt.show(myWindow)
soqt.SoQt.mainLoop()
19 changes: 19 additions & 0 deletions examples/soqt/minimal.py
@@ -0,0 +1,19 @@
import sys
from pivy import coin
from pivy.gui import soqt
# import shiboken if you want to use the widget within qt

myWindow = soqt.SoQt.init(sys.argv[0])
print(myWindow)
scene = coin.SoSeparator()
cam = coin.SoPerspectiveCamera()
cam.position = (0, 0, 4)
light = coin.SoLightModel()
light.model = coin.SoLightModel.BASE_COLOR
scene += light, cam, coin.SoCone()
viewer = soqt.SoQtRenderArea(myWindow)
viewer.setSceneGraph(scene)
viewer.setTitle("Examiner Viewer")
viewer.show()
soqt.SoQt.show(myWindow)
soqt.SoQt.mainLoop()

0 comments on commit a0c3e84

Please sign in to comment.