Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with PySide6 #122

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions interfaces/soqt.i
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ template <typename T> 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()
Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion pivy/qt/QtWidgets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
try:
from PySide6.QtWidgets import *
from PySide6.QtGui import QActionGroup
except ImportError:
from PySide2.QtWidgets import *
7 changes: 6 additions & 1 deletion pivy/quarter/ContextMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 14 additions & 18 deletions pivy/quarter/QuarterWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -165,26 +166,23 @@ def postrenderCB(userdata, manager):
statemachine.postGLRender()


class QuarterWidget(QtOpenGL.QGLWidget):
class QuarterWidget(QOpenGLWidget):

_sensormanager = None
_imagereader = None

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):
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pivy/quarter/devices/DeviceHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions pivy/quarter/devices/MouseHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Loading