diff --git a/src/addons/Display/SimpleGui.py b/src/addons/Display/SimpleGui.py index a8e89f088..e2d53a3e8 100644 --- a/src/addons/Display/SimpleGui.py +++ b/src/addons/Display/SimpleGui.py @@ -199,6 +199,7 @@ def add_function_to_menu(self, menu_name, _callable): win = MainWindow() win.show() win.canva.InitDriver() + win.canva.qApp = app display = win.canva._display if sys.platform != "linux2": display.EnableAntiAliasing() diff --git a/src/addons/Display/icons/cursor-magnify-area.png b/src/addons/Display/icons/cursor-magnify-area.png new file mode 100644 index 000000000..34eb056ee Binary files /dev/null and b/src/addons/Display/icons/cursor-magnify-area.png differ diff --git a/src/addons/Display/icons/cursor-magnify.png b/src/addons/Display/icons/cursor-magnify.png new file mode 100644 index 000000000..2c7966710 Binary files /dev/null and b/src/addons/Display/icons/cursor-magnify.png differ diff --git a/src/addons/Display/icons/cursor-pan.png b/src/addons/Display/icons/cursor-pan.png new file mode 100644 index 000000000..69c292b3b Binary files /dev/null and b/src/addons/Display/icons/cursor-pan.png differ diff --git a/src/addons/Display/icons/cursor-rotate.png b/src/addons/Display/icons/cursor-rotate.png new file mode 100644 index 000000000..014b517a5 Binary files /dev/null and b/src/addons/Display/icons/cursor-rotate.png differ diff --git a/src/addons/Display/qtDisplay.py b/src/addons/Display/qtDisplay.py index 40e96e0e5..65d94de12 100644 --- a/src/addons/Display/qtDisplay.py +++ b/src/addons/Display/qtDisplay.py @@ -20,6 +20,7 @@ from __future__ import print_function import logging +import os import sys logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) @@ -68,7 +69,7 @@ def GetHandle(self): ''' win_id = self.winId() # this returns either an int or voitptr - if "%s"%type(win_id) == "": # PySide + if "%s" % type(win_id) == "": # PySide ### with PySide, self.winId() does not return an integer if sys.platform == "win32": ## Be careful, this hack is py27 specific @@ -79,7 +80,7 @@ def GetHandle(self): ctypes.pythonapi.PyCObject_AsVoidPtr.argtypes = [ ctypes.py_object] win_id = ctypes.pythonapi.PyCObject_AsVoidPtr(win_id) - elif type(win_id) is not int: #PyQt4 or 5 + elif type(win_id) is not int: # PyQt4 or 5 ## below integer cast may be required because self.winId() can ## returns a sip.voitptr according to the PyQt version used ## as well as the python version @@ -103,6 +104,16 @@ def __init__(self, *kargs): self._rightisdown = False self._selection = None self._drawtext = True + self._qApp = None + + @property + def qApp(self): + # reference to QApplication instance + return self._qApp + + @qApp.setter + def qApp(self, value): + self._qApp = value def InitDriver(self): self._display = OCCViewer.Viewer3d(self.GetHandle()) @@ -118,6 +129,26 @@ def InitDriver(self): self._SetupKeyMap() # self._display.thisown = False + self.createCursors() + + def createCursors(self): + module_pth = os.path.abspath(os.path.dirname(__file__)) + icon_pth = os.path.join(module_pth, "icons") + + _CURSOR_PIX_ROT = QtGui.QPixmap(os.path.join(icon_pth, "cursor-rotate.png")) + _CURSOR_PIX_PAN = QtGui.QPixmap(os.path.join(icon_pth, "cursor-pan.png")) + _CURSOR_PIX_ZOOM = QtGui.QPixmap(os.path.join(icon_pth, "cursor-magnify.png")) + _CURSOR_PIX_ZOOM_AREA = QtGui.QPixmap(os.path.join(icon_pth, "cursor-magnify-area.png")) + + self.CURSORS = { + "arrow": QtGui.QCursor(QtCore.Qt.ArrowCursor), # default + "pan": QtGui.QCursor(_CURSOR_PIX_PAN), + "rotate": QtGui.QCursor(_CURSOR_PIX_ROT), + "zoom": QtGui.QCursor(_CURSOR_PIX_ZOOM), + "zoom-area": QtGui.QCursor(_CURSOR_PIX_ZOOM_AREA), + } + + self._cursor = "arrow" def _SetupKeyMap(self): def set_shade_mode(): @@ -188,6 +219,22 @@ def wheelEvent(self, event): def dragMoveEvent(self, event): pass + @property + def cursor(self): + return self._cursor + + @cursor.setter + def cursor(self, value): + if not self._cursor == value: + + self._cursor = value + cursor = self.CURSORS.get(value) + + if cursor: + self.qApp.setOverrideCursor(cursor) + else: + self.qApp.restoreOverrideCursor() + def mousePressEvent(self, event): self.setFocus() self.dragStartPos = point(event.pos()) @@ -210,12 +257,15 @@ def mouseReleaseEvent(self, event): else: # single select otherwise self._display.Select(pt.x, pt.y) + elif event.button() == QtCore.Qt.RightButton: if self._zoom_area: [Xmin, Ymin, dx, dy] = self._drawbox self._display.ZoomArea(Xmin, Ymin, Xmin + dx, Ymin + dy) self._zoom_area = False + self.cursor = "arrow" + def DrawBox(self, event): tolerance = 2 pt = point(event.pos()) @@ -235,11 +285,13 @@ def mouseMoveEvent(self, evt): not modifiers == QtCore.Qt.ShiftModifier): dx = pt.x - self.dragStartPos.x dy = pt.y - self.dragStartPos.y + self.cursor = "rotate" self._display.Rotation(pt.x, pt.y) self._drawbox = False # DYNAMIC ZOOM elif (buttons == QtCore.Qt.RightButton and - not modifiers == QtCore.Qt.ShiftModifier): + not modifiers == QtCore.Qt.ShiftModifier): + self.cursor = "zoom" self._display.Repaint() self._display.DynamicZoom(abs(self.dragStartPos.x), abs(self.dragStartPos.y), abs(pt.x), @@ -253,19 +305,22 @@ def mouseMoveEvent(self, evt): dy = pt.y - self.dragStartPos.y self.dragStartPos.x = pt.x self.dragStartPos.y = pt.y + self.cursor = "pan" self._display.Pan(dx, -dy) self._drawbox = False # DRAW BOX # ZOOM WINDOW elif (buttons == QtCore.Qt.RightButton and - modifiers == QtCore.Qt.ShiftModifier): + modifiers == QtCore.Qt.ShiftModifier): self._zoom_area = True + self.cursor = "zoom-area" self.DrawBox(evt) # SELECT AREA elif (buttons == QtCore.Qt.LeftButton and - modifiers == QtCore.Qt.ShiftModifier): + modifiers == QtCore.Qt.ShiftModifier): self._select_area = True self.DrawBox(evt) else: self._drawbox = False self._display.MoveTo(pt.x, pt.y) + self.cursor = "arrow"