summaryrefslogtreecommitdiff
path: root/silx/gui/plot3d
diff options
context:
space:
mode:
authorPicca Frédéric-Emmanuel <picca@debian.org>2017-11-25 16:55:20 +0100
committerPicca Frédéric-Emmanuel <picca@debian.org>2017-11-25 16:55:20 +0100
commite19c96eff0c310c06c4f268c8b80cb33bd08996f (patch)
treef2b4a365ed899be04766f3937bcc2d58d22be065 /silx/gui/plot3d
parentbfa4dba15485b4192f8bbe13345e9658c97ecf76 (diff)
New upstream version 0.6.1+dfsg
Diffstat (limited to 'silx/gui/plot3d')
-rw-r--r--silx/gui/plot3d/Plot3DWindow.py2
-rw-r--r--silx/gui/plot3d/SFViewParamTree.py28
-rw-r--r--silx/gui/plot3d/actions/__init__.py7
-rw-r--r--silx/gui/plot3d/actions/viewpoint.py98
4 files changed, 126 insertions, 9 deletions
diff --git a/silx/gui/plot3d/Plot3DWindow.py b/silx/gui/plot3d/Plot3DWindow.py
index 1bc2738..d8c393e 100644
--- a/silx/gui/plot3d/Plot3DWindow.py
+++ b/silx/gui/plot3d/Plot3DWindow.py
@@ -35,6 +35,7 @@ __date__ = "26/01/2017"
from silx.gui import qt
from .Plot3DWidget import Plot3DWidget
+from .actions.viewpoint import RotateViewport
from .tools import OutputToolBar, InteractiveModeToolBar
from .tools import ViewpointToolButton
@@ -58,6 +59,7 @@ class Plot3DWindow(qt.QMainWindow):
toolbar = qt.QToolBar(self)
toolbar.addWidget(ViewpointToolButton(plot3D=self._plot3D))
+ toolbar.addAction(RotateViewport(parent=toolbar, plot3d=self._plot3D))
self.addToolBar(toolbar)
toolbar = OutputToolBar(parent=self)
diff --git a/silx/gui/plot3d/SFViewParamTree.py b/silx/gui/plot3d/SFViewParamTree.py
index 8b144df..e67c17e 100644
--- a/silx/gui/plot3d/SFViewParamTree.py
+++ b/silx/gui/plot3d/SFViewParamTree.py
@@ -304,7 +304,10 @@ class ColorItem(SubjectItem):
def getEditor(self, parent, option, index):
editor = QColorEditor(parent)
editor.color = self.getColor()
- editor.sigColorChanged.connect(self._editorSlot)
+
+ # Wrapping call in lambda is a workaround for PySide with Python 3
+ editor.sigColorChanged.connect(
+ lambda color: self._editorSlot(color))
return editor
def _editorSlot(self, color):
@@ -645,7 +648,9 @@ class IsoSurfaceColorItem(SubjectItem):
color = self.subject.getColor()
color.setAlpha(255)
editor.color = color
- editor.sigColorChanged.connect(self.__editorChanged)
+ # Wrapping call in lambda is a workaround for PySide with Python 3
+ editor.sigColorChanged.connect(
+ lambda color: self.__editorChanged(color))
return editor
def __editorChanged(self, color):
@@ -740,7 +745,9 @@ class IsoSurfaceAlphaItem(SubjectItem):
color = self.subject.getColor()
editor.setValue(color.alpha())
- editor.valueChanged.connect(self.__editorChanged)
+ # Wrapping call in lambda is a workaround for PySide with Python 3
+ editor.valueChanged.connect(
+ lambda value: self.__editorChanged(value))
return editor
@@ -1007,7 +1014,10 @@ class PlaneOrientationItem(SubjectItem):
editor = qt.QComboBox(parent)
for iconName, text, tooltip, normal in self._PLANE_ACTIONS:
editor.addItem(getQIcon(iconName), text)
- editor.currentIndexChanged[int].connect(self.__editorChanged)
+
+ # Wrapping call in lambda is a workaround for PySide with Python 3
+ editor.currentIndexChanged[int].connect(
+ lambda index: self.__editorChanged(index))
return editor
def __editorChanged(self, index):
@@ -1074,7 +1084,10 @@ class PlaneColormapItem(ColormapBase):
def getEditor(self, parent, option, index):
editor = qt.QComboBox(parent)
editor.addItems(self.listValues)
- editor.currentIndexChanged[int].connect(self.__editorChanged)
+
+ # Wrapping call in lambda is a workaround for PySide with Python 3
+ editor.currentIndexChanged[int].connect(
+ lambda index: self.__editorChanged(index))
return editor
@@ -1154,7 +1167,10 @@ class NormalizationNode(ColormapBase):
def getEditor(self, parent, option, index):
editor = qt.QComboBox(parent)
editor.addItems(self.listValues)
- editor.currentIndexChanged[int].connect(self.__editorChanged)
+
+ # Wrapping call in lambda is a workaround for PySide with Python 3
+ editor.currentIndexChanged[int].connect(
+ lambda index: self.__editorChanged(index))
return editor
diff --git a/silx/gui/plot3d/actions/__init__.py b/silx/gui/plot3d/actions/__init__.py
index ebc57d2..26243cf 100644
--- a/silx/gui/plot3d/actions/__init__.py
+++ b/silx/gui/plot3d/actions/__init__.py
@@ -28,6 +28,7 @@ __authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "06/09/2017"
-from .Plot3DAction import Plot3DAction
-from . import io
-from . import mode
+from .Plot3DAction import Plot3DAction # noqa
+from . import viewpoint # noqa
+from . import io # noqa
+from . import mode # noqa
diff --git a/silx/gui/plot3d/actions/viewpoint.py b/silx/gui/plot3d/actions/viewpoint.py
new file mode 100644
index 0000000..6aa7400
--- /dev/null
+++ b/silx/gui/plot3d/actions/viewpoint.py
@@ -0,0 +1,98 @@
+# coding: utf-8
+# /*##########################################################################
+#
+# Copyright (c) 2017 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
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# ###########################################################################*/
+"""This module provides Plot3DAction controlling the viewpoint.
+
+It provides QAction to rotate or pan a Plot3DWidget.
+"""
+
+from __future__ import absolute_import, division
+
+__authors__ = ["T. Vincent"]
+__license__ = "MIT"
+__date__ = "03/10/2017"
+
+
+import time
+import logging
+
+from silx.gui import qt
+from silx.gui.icons import getQIcon
+from .Plot3DAction import Plot3DAction
+
+
+_logger = logging.getLogger(__name__)
+
+
+class RotateViewport(Plot3DAction):
+ """QAction to rotate the scene of a Plot3DWidget
+
+ :param parent: See :class:`QAction`
+ :param Plot3DWidget plot3d: Plot3DWidget the action is associated with
+ """
+
+ _TIMEOUT_MS = 50
+ """Time interval between to frames (in milliseconds)"""
+
+ _DEGREE_PER_SECONDS = 360. / 5.
+ """Rotation speed of the animation"""
+
+ def __init__(self, parent, plot3d=None):
+ super(RotateViewport, self).__init__(parent, plot3d)
+
+ self._previousTime = None
+
+ self._timer = qt.QTimer(self)
+ self._timer.setInterval(self._TIMEOUT_MS) # 20fps
+ self._timer.timeout.connect(self._rotate)
+
+ self.setIcon(getQIcon('cube-rotate'))
+ self.setText('Rotate scene')
+ self.setToolTip('Rotate the 3D scene around the vertical axis')
+ self.setCheckable(True)
+ self.triggered[bool].connect(self._triggered)
+
+
+ def _triggered(self, checked=False):
+ plot3d = self.getPlot3DWidget()
+ if plot3d is None:
+ _logger.error(
+ 'Cannot start/stop rotation, no associated Plot3DWidget')
+ elif checked:
+ self._previousTime = time.time()
+ self._timer.start()
+ else:
+ self._timer.stop()
+ self._previousTime = None
+
+ def _rotate(self):
+ """Perform a step of the rotation"""
+ if self._previousTime is None:
+ _logger.error('Previous time not set!')
+ angleStep = 0.
+ else:
+ angleStep = self._DEGREE_PER_SECONDS * (time.time() - self._previousTime)
+
+ self.getPlot3DWidget().viewport.orbitCamera('left', angleStep)
+ self._previousTime = time.time()