summaryrefslogtreecommitdiff
path: root/silx/gui/data/DataViewer.py
diff options
context:
space:
mode:
Diffstat (limited to 'silx/gui/data/DataViewer.py')
-rw-r--r--silx/gui/data/DataViewer.py153
1 files changed, 127 insertions, 26 deletions
diff --git a/silx/gui/data/DataViewer.py b/silx/gui/data/DataViewer.py
index 750c654..5e0b25e 100644
--- a/silx/gui/data/DataViewer.py
+++ b/silx/gui/data/DataViewer.py
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
+# Copyright (c) 2016-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
@@ -32,10 +32,12 @@ from silx.gui.data.DataViews import _normalizeData
import logging
from silx.gui import qt
from silx.gui.data.NumpyAxesSelector import NumpyAxesSelector
+from silx.utils import deprecation
+from silx.utils.property import classproperty
__authors__ = ["V. Valls"]
__license__ = "MIT"
-__date__ = "03/10/2017"
+__date__ = "26/02/2018"
_logger = logging.getLogger(__name__)
@@ -68,16 +70,65 @@ class DataViewer(qt.QFrame):
viewer.setVisible(True)
"""
- EMPTY_MODE = 0
- PLOT1D_MODE = 10
- PLOT2D_MODE = 20
- PLOT3D_MODE = 30
- RAW_MODE = 40
- RAW_ARRAY_MODE = 41
- RAW_RECORD_MODE = 42
- RAW_SCALAR_MODE = 43
- STACK_MODE = 50
- HDF5_MODE = 60
+ # TODO: Can be removed for silx 0.8
+ @classproperty
+ @deprecation.deprecated(replacement="DataViews.EMPTY_MODE", since_version="0.7", skip_backtrace_count=2)
+ def EMPTY_MODE(self):
+ return DataViews.EMPTY_MODE
+
+ # TODO: Can be removed for silx 0.8
+ @classproperty
+ @deprecation.deprecated(replacement="DataViews.PLOT1D_MODE", since_version="0.7", skip_backtrace_count=2)
+ def PLOT1D_MODE(self):
+ return DataViews.PLOT1D_MODE
+
+ # TODO: Can be removed for silx 0.8
+ @classproperty
+ @deprecation.deprecated(replacement="DataViews.PLOT2D_MODE", since_version="0.7", skip_backtrace_count=2)
+ def PLOT2D_MODE(self):
+ return DataViews.PLOT2D_MODE
+
+ # TODO: Can be removed for silx 0.8
+ @classproperty
+ @deprecation.deprecated(replacement="DataViews.PLOT3D_MODE", since_version="0.7", skip_backtrace_count=2)
+ def PLOT3D_MODE(self):
+ return DataViews.PLOT3D_MODE
+
+ # TODO: Can be removed for silx 0.8
+ @classproperty
+ @deprecation.deprecated(replacement="DataViews.RAW_MODE", since_version="0.7", skip_backtrace_count=2)
+ def RAW_MODE(self):
+ return DataViews.RAW_MODE
+
+ # TODO: Can be removed for silx 0.8
+ @classproperty
+ @deprecation.deprecated(replacement="DataViews.RAW_ARRAY_MODE", since_version="0.7", skip_backtrace_count=2)
+ def RAW_ARRAY_MODE(self):
+ return DataViews.RAW_ARRAY_MODE
+
+ # TODO: Can be removed for silx 0.8
+ @classproperty
+ @deprecation.deprecated(replacement="DataViews.RAW_RECORD_MODE", since_version="0.7", skip_backtrace_count=2)
+ def RAW_RECORD_MODE(self):
+ return DataViews.RAW_RECORD_MODE
+
+ # TODO: Can be removed for silx 0.8
+ @classproperty
+ @deprecation.deprecated(replacement="DataViews.RAW_SCALAR_MODE", since_version="0.7", skip_backtrace_count=2)
+ def RAW_SCALAR_MODE(self):
+ return DataViews.RAW_SCALAR_MODE
+
+ # TODO: Can be removed for silx 0.8
+ @classproperty
+ @deprecation.deprecated(replacement="DataViews.STACK_MODE", since_version="0.7", skip_backtrace_count=2)
+ def STACK_MODE(self):
+ return DataViews.STACK_MODE
+
+ # TODO: Can be removed for silx 0.8
+ @classproperty
+ @deprecation.deprecated(replacement="DataViews.HDF5_MODE", since_version="0.7", skip_backtrace_count=2)
+ def HDF5_MODE(self):
+ return DataViews.HDF5_MODE
displayedViewChanged = qt.Signal(object)
"""Emitted when the displayed view changes"""
@@ -129,7 +180,7 @@ class DataViewer(qt.QFrame):
"""Inisialize the available views"""
views = self.createDefaultViews(self.__stack)
self.__views = list(views)
- self.setDisplayMode(self.EMPTY_MODE)
+ self.setDisplayMode(DataViews.EMPTY_MODE)
def createDefaultViews(self, parent=None):
"""Create and returns available views which can be displayed by default
@@ -137,7 +188,7 @@ class DataViewer(qt.QFrame):
overwriten to provide a different set of viewers.
:param QWidget parent: QWidget parent of the views
- :rtype: list[silx.gui.data.DataViews.DataView]
+ :rtype: List[silx.gui.data.DataViews.DataView]
"""
viewClasses = [
DataViews._EmptyView,
@@ -262,6 +313,7 @@ class DataViewer(qt.QFrame):
def getViewFromModeId(self, modeId):
"""Returns the first available view which have the requested modeId.
+ Return None if modeId does not correspond to an existing view.
:param int modeId: Requested mode id
:rtype: silx.gui.data.DataViews.DataView
@@ -269,7 +321,7 @@ class DataViewer(qt.QFrame):
for view in self.__views:
if view.modeId() == modeId:
return view
- return view
+ return None
def setDisplayMode(self, modeId):
"""Set the displayed view using display mode.
@@ -278,13 +330,14 @@ class DataViewer(qt.QFrame):
:param int modeId: Display mode, one of
- - `EMPTY_MODE`: display nothing
- - `PLOT1D_MODE`: display the data as a curve
- - `PLOT2D_MODE`: display the data as an image
- - `PLOT3D_MODE`: display the data as an isosurface
- - `RAW_MODE`: display the data as a table
- - `STACK_MODE`: display the data as a stack of images
- - `HDF5_MODE`: display the data as a table
+ - `DataViews.EMPTY_MODE`: display nothing
+ - `DataViews.PLOT1D_MODE`: display the data as a curve
+ - `DataViews.IMAGE_MODE`: display the data as an image
+ - `DataViews.PLOT3D_MODE`: display the data as an isosurface
+ - `DataViews.RAW_MODE`: display the data as a table
+ - `DataViews.STACK_MODE`: display the data as a stack of images
+ - `DataViews.HDF5_MODE`: display the data as a table of HDF5 info
+ - `DataViews.NXDATA_MODE`: display the data as NXdata
"""
try:
view = self.getViewFromModeId(modeId)
@@ -377,21 +430,21 @@ class DataViewer(qt.QFrame):
on rendering.
:param object data: data which will be displayed
- :param list[view] available: List of available views, from highest
+ :param List[view] available: List of available views, from highest
priority to lowest.
:rtype: DataView
"""
hdf5View = self.getViewFromModeId(DataViewer.HDF5_MODE)
if hdf5View in available:
return hdf5View
- return self.getViewFromModeId(DataViewer.EMPTY_MODE)
+ return self.getViewFromModeId(DataViews.EMPTY_MODE)
def getDefaultViewFromAvailableViews(self, data, available):
"""Returns the default view which will be used according to available
views.
:param object data: data which will be displayed
- :param list[view] available: List of available views, from highest
+ :param List[view] available: List of available views, from highest
priority to lowest.
:rtype: DataView
"""
@@ -403,7 +456,7 @@ class DataViewer(qt.QFrame):
view = available[0]
else:
# else returns the empty view
- view = self.getViewFromModeId(DataViewer.EMPTY_MODE)
+ view = self.getViewFromModeId(DataViews.EMPTY_MODE)
return view
def __setCurrentAvailableViews(self, availableViews):
@@ -462,3 +515,51 @@ class DataViewer(qt.QFrame):
def displayMode(self):
"""Returns the current display mode"""
return self.__currentView.modeId()
+
+ def replaceView(self, modeId, newView):
+ """Replace one of the builtin data views with a custom view.
+ Return True in case of success, False in case of failure.
+
+ .. note::
+
+ This method must be called just after instantiation, before
+ the viewer is used.
+
+ :param int modeId: Unique mode ID identifying the DataView to
+ be replaced. One of:
+
+ - `DataViews.EMPTY_MODE`
+ - `DataViews.PLOT1D_MODE`
+ - `DataViews.IMAGE_MODE`
+ - `DataViews.PLOT2D_MODE`
+ - `DataViews.COMPLEX_IMAGE_MODE`
+ - `DataViews.PLOT3D_MODE`
+ - `DataViews.RAW_MODE`
+ - `DataViews.STACK_MODE`
+ - `DataViews.HDF5_MODE`
+ - `DataViews.NXDATA_MODE`
+ - `DataViews.NXDATA_INVALID_MODE`
+ - `DataViews.NXDATA_SCALAR_MODE`
+ - `DataViews.NXDATA_CURVE_MODE`
+ - `DataViews.NXDATA_XYVSCATTER_MODE`
+ - `DataViews.NXDATA_IMAGE_MODE`
+ - `DataViews.NXDATA_STACK_MODE`
+
+ :param DataViews.DataView newView: New data view
+ :return: True if replacement was successful, else False
+ """
+ assert isinstance(newView, DataViews.DataView)
+ isReplaced = False
+ for idx, view in enumerate(self.__views):
+ if view.modeId() == modeId:
+ self.__views[idx] = newView
+ isReplaced = True
+ break
+ elif isinstance(view, DataViews.CompositeDataView):
+ isReplaced = view.replaceView(modeId, newView)
+ if isReplaced:
+ break
+
+ if isReplaced:
+ self.__updateAvailableViews()
+ return isReplaced