Skip to content

Commit

Permalink
Fix various exceptions with PySide6
Browse files Browse the repository at this point in the history
  • Loading branch information
YakoYakoYokuYoku authored and looooo committed Sep 24, 2024
1 parent 16d64bd commit 0e02e3e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
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

0 comments on commit 0e02e3e

Please sign in to comment.