[segyio] 117/376: Added ColormapCombo widget

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:18 UTC 2017


This is an automated email from the git hooks/post-receive script.

jokva-guest pushed a commit to branch debian
in repository segyio.

commit 40ba14c374a1bf7888beecfe52f8427ea4c780cd
Author: Jean-Paul Balabanian <jepebe at users.noreply.github.com>
Date:   Thu Nov 17 13:24:39 2016 +0100

    Added ColormapCombo widget
---
 examples/showcase_gui.py         | 15 ++++++-
 python/segyview/CMakeLists.txt   |  1 +
 python/segyview/__init__.py      |  1 +
 python/segyview/colormapcombo.py | 84 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 99 insertions(+), 2 deletions(-)

diff --git a/examples/showcase_gui.py b/examples/showcase_gui.py
index f18834a..e16c8ed 100644
--- a/examples/showcase_gui.py
+++ b/examples/showcase_gui.py
@@ -4,7 +4,7 @@ import sys
 from PyQt4.QtCore import Qt
 from PyQt4.QtGui import QMainWindow, QWidget, QApplication, QLabel, QVBoxLayout
 
-from segyview import LayoutCombo
+from segyview import LayoutCombo, ColormapCombo
 
 
 class TestGUI(QMainWindow):
@@ -21,6 +21,10 @@ class TestGUI(QMainWindow):
         toolbar.addWidget(layout_combo)
         layout_combo.layout_changed.connect(self._layout_changed)
 
+        self._colormap_combo = ColormapCombo()
+        toolbar.addWidget(self._colormap_combo)
+        self._colormap_combo.currentIndexChanged[int].connect(self._colormap_changed)
+
         central_widget = QWidget()
         layout = QVBoxLayout()
         central_widget.setLayout(layout)
@@ -28,10 +32,17 @@ class TestGUI(QMainWindow):
         self._layout_label = QLabel()
         layout.addWidget(self._layout_label)
 
+        self._colormap_label = QLabel()
+        layout.addWidget(self._colormap_label)
+
         self.setCentralWidget(central_widget)
 
     def _layout_changed(self, layout):
-        self._layout_label.setText(str(layout))
+        self._layout_label.setText("Layout selected: %s" % str(layout))
+
+    def _colormap_changed(self, index):
+        colormap = str(self._colormap_combo.itemText(index))
+        self._colormap_label.setText("Colormap selected: %s" % colormap)
 
 
 if __name__ == '__main__':
diff --git a/python/segyview/CMakeLists.txt b/python/segyview/CMakeLists.txt
index 5a22a8d..8de829f 100644
--- a/python/segyview/CMakeLists.txt
+++ b/python/segyview/CMakeLists.txt
@@ -7,6 +7,7 @@ set(PYTHON_SOURCES
     slicewidget.py
     viewer.py
     layoutcombo.py
+    colormapcombo.py
     )
 
 add_python_package(segyview segyview "${PYTHON_SOURCES}")
diff --git a/python/segyview/__init__.py b/python/segyview/__init__.py
index ae29323..f248bac 100644
--- a/python/segyview/__init__.py
+++ b/python/segyview/__init__.py
@@ -21,6 +21,7 @@ def resource_icon(name):
 
 
 try:
+    from .colormapcombo import ColormapCombo
     from .layoutcombo import LayoutCombo
     from .progresswidget import ProgressWidget
     from .slicewidget import SliceWidget, ColorBarWidget
diff --git a/python/segyview/colormapcombo.py b/python/segyview/colormapcombo.py
new file mode 100644
index 0000000..ba4e195
--- /dev/null
+++ b/python/segyview/colormapcombo.py
@@ -0,0 +1,84 @@
+from PyQt4.QtCore import QSize
+from PyQt4.QtGui import QComboBox, QPixmap, qRgb
+from PyQt4.QtCore import Qt
+from PyQt4.QtGui import QImage
+
+import numpy as np
+from matplotlib.cm import ScalarMappable
+
+
+class ColormapCombo(QComboBox):
+    def __init__(self, color_maps=None, parent=None):
+        QComboBox.__init__(self, parent)
+        self.setMaxVisibleItems(10)
+        self.setStyleSheet("QComboBox { combobox-popup: 0; }")
+
+        if color_maps is None:
+            color_maps = self._type_sorted_color_maps()
+
+        self.setMinimumWidth(170)
+        self.setMaximumWidth(170)
+        self.setMinimumHeight(30)
+
+        self.setIconSize(QSize(128, 16))
+
+        icon_width = 256
+        icon_height = 16
+        values = np.linspace(0, 1, icon_width)
+        color_indexes = np.linspace(0, 255, icon_width, dtype=np.uint8)
+        color_indexes = np.tile(color_indexes, icon_height)
+        image = QImage(color_indexes.data, icon_width, icon_height, QImage.Format_Indexed8)
+
+        for index, item in enumerate(color_maps):
+            self.addItem(item)
+            pix_map = self._create_icon(item, image, values)
+            self.setItemData(index, "", Qt.DisplayRole)
+            self.setItemData(index, item, Qt.ToolTipRole)
+            self.setItemData(index, pix_map, Qt.DecorationRole)
+
+    def _create_icon(self, color_map_name, image, values):
+        """"
+        :type color_map_name: str
+        :type image: QImage
+        :type values: np.ndarray
+        """
+
+        color_map = ScalarMappable(cmap=color_map_name)
+        rgba = color_map.to_rgba(values, bytes=True)
+
+        color_table = [qRgb(c[0], c[1], c[2]) for c in rgba]
+        image.setColorTable(color_table)
+
+        return QPixmap.fromImage(image).scaledToWidth(128)
+
+    def _type_sorted_color_maps(self):
+        cmaps = [('Perceptually Uniform Sequential', ['viridis', 'inferno', 'plasma', 'magma']),
+                 ('Sequential', ['Blues', 'BuGn', 'BuPu',
+                                 'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
+                                 'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu',
+                                 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']),
+                 ('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool',
+                                     'copper', 'gist_heat', 'gray', 'hot',
+                                     'pink', 'spring', 'summer', 'winter']),
+                 ('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
+                                'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral', 'seismic']),
+                 ('Qualitative', ['Accent', 'Dark2', 'Paired', 'Pastel1',
+                                  'Pastel2', 'Set1', 'Set2', 'Set3']),
+                 ('Miscellaneous', ['gist_earth', 'terrain', 'ocean', 'gist_stern',
+                                    'brg', 'CMRmap', 'cubehelix',
+                                    'gnuplot', 'gnuplot2', 'gist_ncar',
+                                    'nipy_spectral', 'jet', 'rainbow',
+                                    'gist_rainbow', 'hsv', 'flag', 'prism'])
+                 ]
+
+        # color_maps = sorted(m for m in cm.datad if not m.endswith("_r"))
+
+        color_maps = []
+
+        for cm_group in cmaps:
+            color_maps.extend(cm_group[1])
+
+        return color_maps
+
+    def itemText(self, index):
+        return str(self.itemData(index, Qt.ToolTipRole).toString())

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/segyio.git



More information about the debian-science-commits mailing list