diff options
Diffstat (limited to 'silx/gui/dialog/ColormapDialog.py')
-rw-r--r-- | silx/gui/dialog/ColormapDialog.py | 134 |
1 files changed, 8 insertions, 126 deletions
diff --git a/silx/gui/dialog/ColormapDialog.py b/silx/gui/dialog/ColormapDialog.py index 9c956f8..dddec4c 100644 --- a/silx/gui/dialog/ColormapDialog.py +++ b/silx/gui/dialog/ColormapDialog.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2004-2018 European Synchrotron Radiation Facility +# Copyright (c) 2004-2019 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 @@ -79,6 +79,7 @@ from silx.gui.widgets.FloatEdit import FloatEdit import weakref from silx.math.combo import min_max from silx.gui import icons +from silx.gui.widgets.ColormapNameComboBox import ColormapNameComboBox from silx.math.histogram import Histogramnd _logger = logging.getLogger(__name__) @@ -150,128 +151,6 @@ class _BoundaryWidget(qt.QWidget): self._updateDisplayedText() -class _ColormapNameCombox(qt.QComboBox): - def __init__(self, parent=None): - qt.QComboBox.__init__(self, parent) - self.__initItems() - - LUT_NAME = qt.Qt.UserRole + 1 - LUT_COLORS = qt.Qt.UserRole + 2 - - def __initItems(self): - for colormapName in preferredColormaps(): - index = self.count() - self.addItem(str.title(colormapName)) - self.setItemIcon(index, self.getIconPreview(name=colormapName)) - self.setItemData(index, colormapName, role=self.LUT_NAME) - - def getIconPreview(self, name=None, colors=None): - """Return an icon preview from a LUT name. - - This icons are cached into a global structure. - - :param str name: Name of the LUT - :param numpy.ndarray colors: Colors identify the LUT - :rtype: qt.QIcon - """ - if name is not None: - iconKey = name - else: - iconKey = tuple(colors) - icon = _colormapIconPreview.get(iconKey, None) - if icon is None: - icon = self.createIconPreview(name, colors) - _colormapIconPreview[iconKey] = icon - return icon - - def createIconPreview(self, name=None, colors=None): - """Create and return an icon preview from a LUT name. - - This icons are cached into a global structure. - - :param str name: Name of the LUT - :param numpy.ndarray colors: Colors identify the LUT - :rtype: qt.QIcon - """ - colormap = Colormap(name) - size = 32 - if name is not None: - lut = colormap.getNColors(size) - else: - lut = colors - if len(lut) > size: - # Down sample - step = int(len(lut) / size) - lut = lut[::step] - elif len(lut) < size: - # Over sample - indexes = numpy.arange(size) / float(size) * (len(lut) - 1) - indexes = indexes.astype("int") - lut = lut[indexes] - if lut is None or len(lut) == 0: - return qt.QIcon() - - pixmap = qt.QPixmap(size, size) - painter = qt.QPainter(pixmap) - for i in range(size): - rgb = lut[i] - r, g, b = rgb[0], rgb[1], rgb[2] - painter.setPen(qt.QColor(r, g, b)) - painter.drawPoint(qt.QPoint(i, 0)) - - painter.drawPixmap(0, 1, size, size - 1, pixmap, 0, 0, size, 1) - painter.end() - - return qt.QIcon(pixmap) - - def getCurrentName(self): - return self.itemData(self.currentIndex(), self.LUT_NAME) - - def getCurrentColors(self): - return self.itemData(self.currentIndex(), self.LUT_COLORS) - - def findLutName(self, name): - return self.findData(name, role=self.LUT_NAME) - - def findLutColors(self, lut): - for index in range(self.count()): - if self.itemData(index, role=self.LUT_NAME) is not None: - continue - colors = self.itemData(index, role=self.LUT_COLORS) - if colors is None: - continue - if numpy.array_equal(colors, lut): - return index - return -1 - - def setCurrentLut(self, colormap): - name = colormap.getName() - if name is not None: - self._setCurrentName(name) - else: - lut = colormap.getColormapLUT() - self._setCurrentLut(lut) - - def _setCurrentLut(self, lut): - index = self.findLutColors(lut) - if index == -1: - index = self.count() - self.addItem("Custom") - self.setItemIcon(index, self.getIconPreview(colors=lut)) - self.setItemData(index, None, role=self.LUT_NAME) - self.setItemData(index, lut, role=self.LUT_COLORS) - self.setCurrentIndex(index) - - def _setCurrentName(self, name): - index = self.findLutName(name) - if index < 0: - index = self.count() - self.addItem(str.title(name)) - self.setItemIcon(index, self.getIconPreview(name=name)) - self.setItemData(index, name, role=self.LUT_NAME) - self.setCurrentIndex(index) - - @enum.unique class _DataInPlotMode(enum.Enum): """Enum for each mode of display of the data in the plot.""" @@ -329,7 +208,7 @@ class ColormapDialog(qt.QDialog): formLayout.setSpacing(0) # Colormap row - self._comboBoxColormap = _ColormapNameCombox(parent=formWidget) + self._comboBoxColormap = ColormapNameComboBox(parent=formWidget) self._comboBoxColormap.currentIndexChanged[int].connect(self._updateLut) formLayout.addRow('Colormap:', self._comboBoxColormap) @@ -584,6 +463,7 @@ class ColormapDialog(qt.QDialog): color='black', symbol='o', linestyle='-', + z=2, resetzoom=False) scale = self._plot.getXAxis().getScale() @@ -823,7 +703,8 @@ class ColormapDialog(qt.QDialog): legend="Histogram", color='gray', align='center', - fill=True) + fill=True, + z=1) self._updateMinMaxData() def getColormap(self): @@ -874,7 +755,8 @@ class ColormapDialog(qt.QDialog): legend="Range", color='gray', align='center', - fill=True) + fill=True, + z=1) self._dataRange = minimum, positiveMin, maximum self._updateMinMaxData() |