summaryrefslogtreecommitdiff
path: root/silx/gui/plot3d/Plot3DWidget.py
diff options
context:
space:
mode:
Diffstat (limited to 'silx/gui/plot3d/Plot3DWidget.py')
-rw-r--r--silx/gui/plot3d/Plot3DWidget.py60
1 files changed, 52 insertions, 8 deletions
diff --git a/silx/gui/plot3d/Plot3DWidget.py b/silx/gui/plot3d/Plot3DWidget.py
index aae3955..15e2356 100644
--- a/silx/gui/plot3d/Plot3DWidget.py
+++ b/silx/gui/plot3d/Plot3DWidget.py
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2015-2017 European Synchrotron Radiation Facility
+# Copyright (c) 2015-2018 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -54,12 +54,26 @@ class _OverviewViewport(scene.Viewport):
:param Camera camera: The camera to track.
"""
+ _SIZE = 100
+ """Size in pixels of the overview square"""
+
def __init__(self, camera=None):
super(_OverviewViewport, self).__init__()
- self.size = 100, 100
+ self.size = self._SIZE, self._SIZE
+ self.background = None # Disable clear
self.scene.transforms = [transform.Scale(2.5, 2.5, 2.5)]
+ # Add a point to draw the background (in a group with depth mask)
+ backgroundPoint = primitives.ColorPoints(
+ x=0., y=0., z=0.,
+ color=(1., 1., 1., 0.5),
+ size=self._SIZE)
+ backgroundPoint.marker = 'o'
+ noDepthGroup = primitives.GroupNoDepth(mask=True, notest=True)
+ noDepthGroup.children.append(backgroundPoint)
+ self.scene.children.append(noDepthGroup)
+
axes = primitives.Axes()
self.scene.children.append(axes)
@@ -86,6 +100,12 @@ class Plot3DWidget(glu.OpenGLWidget):
"""Signal emitted when the interactive mode has changed
"""
+ sigStyleChanged = qt.Signal(str)
+ """Signal emitted when the style of the scene has changed
+
+ It provides the updated property.
+ """
+
def __init__(self, parent=None, f=qt.Qt.WindowFlags()):
self._firstRender = True
@@ -108,7 +128,6 @@ class Plot3DWidget(glu.OpenGLWidget):
# Main viewport
self.viewport = scene.Viewport()
- self.viewport.background = 0.2, 0.2, 0.2, 1.
self._sceneScale = transform.Scale(1., 1., 1.)
self.viewport.scene.transforms = [self._sceneScale,
@@ -143,18 +162,27 @@ class Plot3DWidget(glu.OpenGLWidget):
self.viewport,
orbitAroundCenter=False,
mode='position',
- scaleTransform=self._sceneScale)
+ scaleTransform=self._sceneScale,
+ selectCB=None)
elif mode == 'pan':
self.eventHandler = interaction.PanCameraControl(
self.viewport,
+ orbitAroundCenter=False,
mode='position',
scaleTransform=self._sceneScale,
selectCB=None)
+ elif isinstance(mode, interaction.StateMachine):
+ self.eventHandler = mode
+
else:
raise ValueError('Unsupported interactive mode %s', str(mode))
+ if (self.eventHandler is not None and
+ qt.QApplication.keyboardModifiers() & qt.Qt.ControlModifier):
+ self.eventHandler.handleEvent('keyPress', qt.Qt.Key_Control)
+
self.sigInteractiveModeChanged.emit()
def getInteractiveMode(self):
@@ -208,8 +236,9 @@ class Plot3DWidget(glu.OpenGLWidget):
QColor, str or array-like of 3 or 4 float in [0., 1.] or uint8
"""
color = rgba(color)
- self.viewport.background = color
- self.overview.background = color[0]*0.5, color[1]*0.5, color[2]*0.5, 1.
+ if color != self.viewport.background:
+ self.viewport.background = color
+ self.sigStyleChanged.emit('backgroundColor')
def getBackgroundColor(self):
"""Returns the RGBA background color (QColor)."""
@@ -233,6 +262,7 @@ class Plot3DWidget(glu.OpenGLWidget):
self._window.viewports = [self.viewport, self.overview]
else:
self._window.viewports = [self.viewport]
+ self.sigStyleChanged.emit('orientationIndicatorVisible')
def centerScene(self):
"""Position the center of the scene at the center of rotation."""
@@ -315,7 +345,7 @@ class Plot3DWidget(glu.OpenGLWidget):
self.eventHandler.handleEvent('wheel', xpixel, ypixel, angle)
def keyPressEvent(self, event):
- keycode = event.key()
+ keyCode = event.key()
# No need to accept QKeyEvent
converter = {
@@ -324,7 +354,7 @@ class Plot3DWidget(glu.OpenGLWidget):
qt.Qt.Key_Up: 'up',
qt.Qt.Key_Down: 'down'
}
- direction = converter.get(keycode, None)
+ direction = converter.get(keyCode, None)
if direction is not None:
if event.modifiers() == qt.Qt.ControlModifier:
self.viewport.camera.rotate(direction)
@@ -334,9 +364,23 @@ class Plot3DWidget(glu.OpenGLWidget):
self.viewport.orbitCamera(direction)
else:
+ if (keyCode == qt.Qt.Key_Control and
+ self.eventHandler is not None and
+ self.isValid()):
+ self.eventHandler.handleEvent('keyPress', keyCode)
+
# Key not handled, call base class implementation
super(Plot3DWidget, self).keyPressEvent(event)
+ def keyReleaseEvent(self, event):
+ """Catch Ctrl key release"""
+ keyCode = event.key()
+ if (keyCode == qt.Qt.Key_Control and
+ self.eventHandler is not None and
+ self.isValid()):
+ self.eventHandler.handleEvent('keyRelease', keyCode)
+ super(Plot3DWidget, self).keyReleaseEvent(event)
+
# Mouse events #
_MOUSE_BTNS = {1: 'left', 2: 'right', 4: 'middle'}