From 6c610cc36e4c55479d6b256ec0e948f3aab801b2 Mon Sep 17 00:00:00 2001 From: Martin Rodriguez Reboredo Date: Wed, 18 Sep 2024 16:30:56 -0300 Subject: [PATCH 1/4] Revert "move QActionGroup to pivy.qt.QtWidgets" This reverts commit 931d18f8aa98126f738ff9224ba0ccbd6beed75c. --- pivy/qt/QtWidgets/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pivy/qt/QtWidgets/__init__.py b/pivy/qt/QtWidgets/__init__.py index 8e3a979..0eb0db7 100644 --- a/pivy/qt/QtWidgets/__init__.py +++ b/pivy/qt/QtWidgets/__init__.py @@ -1,5 +1,4 @@ try: from PySide6.QtWidgets import * - from PySide6.QtGui import QActionGroup except ImportError: from PySide2.QtWidgets import * \ No newline at end of file From 651eab783c95ffef41b73f869ff51c0f1b8f2249 Mon Sep 17 00:00:00 2001 From: Martin Rodriguez Reboredo Date: Wed, 18 Sep 2024 16:31:56 -0300 Subject: [PATCH 2/4] Appropiate include dirs for selected Qt version --- interfaces/CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt index 92f9af6..46bbe59 100644 --- a/interfaces/CMakeLists.txt +++ b/interfaces/CMakeLists.txt @@ -66,11 +66,16 @@ if (SoQt_FOUND) target_link_libraries(soqt PUBLIC ${Python_LIBRARIES}) endif () + if (PIVY_USE_QT6) + set(QT_INC_DIRS ${Qt6Gui_INCLUDE_DIRS} ${Qt6Widgets_INCLUDE_DIRS}) + else () + set(QT_INC_DIRS ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) + endif () + target_include_directories(soqt PUBLIC ${SoQt_INCLUDE_DIRS} - ${Qt5Gui_INCLUDE_DIRS} - ${Qt5Widgets_INCLUDE_DIRS} + ${QT_INC_DIRS} ${Python_INCLUDE_DIRS} PRIVATE ${CMAKE_SOURCE_DIR}/interfaces From 1b0cb805f96182ad31f66de700eb5af7bd002b10 Mon Sep 17 00:00:00 2001 From: Martin Rodriguez Reboredo Date: Wed, 18 Sep 2024 18:00:24 -0300 Subject: [PATCH 3/4] Fix conversions with PySide6 --- interfaces/soqt.i | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/interfaces/soqt.i b/interfaces/soqt.i index 0213afa..466250c 100644 --- a/interfaces/soqt.i +++ b/interfaces/soqt.i @@ -119,6 +119,12 @@ template const char* get_typename(T& object) #endif ///////////////////////////////////////////////////// +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#define SHIBOKEN "shiboken6" +#else +#define SHIBOKEN "shiboken2" +#endif + static const char * PYSIDE_QT = "pivy.gui.qt"; static PyObject* getShiboken() @@ -128,9 +134,9 @@ static PyObject* getShiboken() // pip installs it in a wrong place // if you have installed shiboken with pip please symlink to correct directory PyObject * shiboken = NULL; - if (!(shiboken = PyDict_GetItemString(PyModule_GetDict(PyImport_AddModule("__main__")), "shiboken2"))) { + if (!(shiboken = PyDict_GetItemString(PyModule_GetDict(PyImport_AddModule("__main__")), SHIBOKEN))) { // simple import shiboken from python. - shiboken = PyImport_ImportModule("shiboken2"); + shiboken = PyImport_ImportModule(SHIBOKEN); } return shiboken; } From 2efadb3908c50f1d3ccefadb1e4e2a7a983acf93 Mon Sep 17 00:00:00 2001 From: Martin Rodriguez Reboredo Date: Wed, 18 Sep 2024 18:05:22 -0300 Subject: [PATCH 4/4] Fix various exceptions with PySide6 --- pivy/quarter/ContextMenu.py | 7 +++++- pivy/quarter/QuarterWidget.py | 32 ++++++++++++--------------- pivy/quarter/devices/DeviceHandler.py | 6 ++--- pivy/quarter/devices/MouseHandler.py | 4 ++-- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/pivy/quarter/ContextMenu.py b/pivy/quarter/ContextMenu.py index 9eb4335..f3553d5 100644 --- a/pivy/quarter/ContextMenu.py +++ b/pivy/quarter/ContextMenu.py @@ -17,7 +17,12 @@ from pivy.qt import QtCore from pivy.qt.QtCore import QObject from pivy.qt.QtGui import QMouseEvent -from pivy.qt.QtWidgets import QMenu, QActionGroup, QAction +from pivy.qt.QtWidgets import QMenu + +try: + from pivy.qt.QtGui import QActionGroup, QAction +except ImportError: + from pivy.qt.QtWidgets import QActionGroup, QAction from pivy import coin from pivy.coin import SoEventManager, SoScXMLStateMachine, SoRenderManager, SoGLRenderAction diff --git a/pivy/quarter/QuarterWidget.py b/pivy/quarter/QuarterWidget.py index 42131be..d0bd811 100644 --- a/pivy/quarter/QuarterWidget.py +++ b/pivy/quarter/QuarterWidget.py @@ -112,6 +112,11 @@ from pivy.qt import QtCore, QtGui, QtOpenGL +try: + from pivy.qt.QtOpenGLWidgets import QOpenGLWidget +except ImportError: + from pivy.qt.QtWidgets import QOpenGLWidget + from pivy import coin from .devices import DeviceManager @@ -131,11 +136,7 @@ def renderCB(closure, manager): assert(closure) thisp = closure - thisp.makeCurrent() - thisp.actualRedraw() - if (thisp.doubleBuffer()): - thisp.swapBuffers() - thisp.doneCurrent() + thisp.update() # FIXME jkg: figure out what foo is def statechangeCB(userdata, statemachine, stateid, enter, foo): @@ -165,7 +166,7 @@ def postrenderCB(userdata, manager): statemachine.postGLRender() -class QuarterWidget(QtOpenGL.QGLWidget): +class QuarterWidget(QOpenGLWidget): _sensormanager = None _imagereader = None @@ -173,18 +174,15 @@ class QuarterWidget(QtOpenGL.QGLWidget): def __init__(self, *args, **kwargs): """ Constructs a QuarterWidget. - QuarterWidget(QWidget parent = None, QGLWidget sharewidget = None, Qt.WindowFlags f = 0, scxml = "coin:scxml/navigation/examiner.xml") - QuarterWidget(QGLContext context, QWidget parent = None, QGLWidget sharewidget = None, Qt.WindowFlags f = 0, scxml = "coin:scxml/navigation/examiner.xml") - QuarterWidget(QGLFormat format, QWidget parent = None, QGLWidget sharewidget = None, Qt.WindowFlags f = 0, scxml = "coin:scxml/navigation/examiner.xml") + QuarterWidget(QWidget parent = None, QOpenGLWidget sharewidget = None, Qt.WindowFlags f = 0, scxml = "coin:scxml/navigation/examiner.xml") + QuarterWidget(QSurfaceFormat format, QWidget parent = None, QOpenGLWidget sharewidget = None, Qt.WindowFlags f = 0, scxml = "coin:scxml/navigation/examiner.xml") """ params = ["parent", "sharewidget"] values = {"parent": None, "sharewidget": None, "f": 0, "scxml": "coin:scxml/navigation/examiner.xml"} values.update(kwargs) - if len(args) > 0 and isinstance(args[0], QtOpenGL.QGLContext) or "context" in kwargs: - params.insert(0, "context") - elif len(args) > 0 and isinstance(args[0], QtOpenGL.QGLFormat) or "format" in kwargs: + if len(args) > 0 and isinstance(args[0], QtGui.QSurfaceFormat) or "format" in kwargs: params.insert(0, "format") if len(args) > len(params): @@ -193,11 +191,9 @@ def __init__(self, *args, **kwargs): if len(args) > len(params) + 1: values["scxml"] = args[len(params) + 1] - for i in range(len(args), len(params)): - args += (values[params[i]],) - - QtOpenGL.QGLWidget.__init__(self, *args[:len(params)]) - if values["f"]: self.setWindowFlags(values["f"]) + QOpenGLWidget.__init__(self, values["parent"]) + if "f" in values and values["f"]: self.setWindowFlags(values["f"]) + if "format" in values: self.setFormat(values["format"]) # initialize Sensormanager and ImageReader instances only once if not QuarterWidget._sensormanager: @@ -341,7 +337,7 @@ def event(self, qevent): return True # NOTE jkg: we must return True or False - return QtOpenGL.QGLWidget.event(self, qevent) + return QOpenGLWidget.event(self, qevent) def setStateCursor(self, state, cursor): self.statecursormap[state] = cursor diff --git a/pivy/quarter/devices/DeviceHandler.py b/pivy/quarter/devices/DeviceHandler.py index b6a1a39..d2700bc 100644 --- a/pivy/quarter/devices/DeviceHandler.py +++ b/pivy/quarter/devices/DeviceHandler.py @@ -35,6 +35,6 @@ def setModifiers(self, soevent, qevent): # Note: On Mac OS X, the ControlModifier value corresponds to the # Command keys on the Macintosh keyboard, and the MetaModifier # value corresponds to the Control keys. - soevent.setShiftDown(int(qevent.modifiers() & QtCore.Qt.ShiftModifier) == QtCore.Qt.ShiftModifier) - soevent.setAltDown(int(qevent.modifiers() & QtCore.Qt.AltModifier) == QtCore.Qt.AltModifier) - soevent.setCtrlDown(int(qevent.modifiers() & QtCore.Qt.ControlModifier) == QtCore.Qt.ControlModifier) + soevent.setShiftDown(qevent.modifiers() & QtCore.Qt.ShiftModifier == QtCore.Qt.ShiftModifier) + soevent.setAltDown(qevent.modifiers() & QtCore.Qt.AltModifier == QtCore.Qt.AltModifier) + soevent.setCtrlDown(qevent.modifiers() & QtCore.Qt.ControlModifier == QtCore.Qt.ControlModifier) diff --git a/pivy/quarter/devices/MouseHandler.py b/pivy/quarter/devices/MouseHandler.py index 776e634..dbe1d8b 100644 --- a/pivy/quarter/devices/MouseHandler.py +++ b/pivy/quarter/devices/MouseHandler.py @@ -74,7 +74,7 @@ def mouseWheelEvent(self, qevent): # value indicates that the wheel was rotated backwards toward the # user. - if qevent.delta() > 0: + if qevent.angleDelta().y() > 0: self.mousebutton.setButton(coin.SoMouseButtonEvent.BUTTON4) else: self.mousebutton.setButton(coin.SoMouseButtonEvent.BUTTON5) @@ -97,7 +97,7 @@ def mouseButtonEvent(self, qevent): self.mousebutton.setButton(coin.SoMouseButtonEvent.BUTTON1) elif qevent.button() == QtCore.Qt.RightButton: self.mousebutton.setButton(coin.SoMouseButtonEvent.BUTTON2) - elif qevent.button() == QtCore.Qt.MidButton: + elif qevent.button() == QtCore.Qt.MiddleButton: self.mousebutton.setButton(coin.SoMouseButtonEvent.BUTTON3) else: self.mousebutton.setButton(coin.SoMouseButtonEvent.ANY)