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)