[segyio] 96/376: Adding new GUI controller for min max threshold

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:14 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 e6cf5f93ed173ddffd519eab2818e6baa4c633b3
Author: Thorvald Johannessen <thorvjo at statoil.com>
Date:   Thu Nov 3 12:52:28 2016 +0100

    Adding new GUI controller for min max threshold
    
    And grouping all controllers in same file.
---
 applications/segyviewer.py           |  30 +++++---
 python/segyview/CMakeLists.txt       |   2 +-
 python/segyview/__init__.py          |   4 +-
 python/segyview/controlwidgets.py    | 133 +++++++++++++++++++++++++++++++++++
 python/segyview/linenavigationbar.py |  51 --------------
 python/segyview/segyplot.py          |   9 +--
 python/segyview/slicewidget.py       |  18 -----
 7 files changed, 158 insertions(+), 89 deletions(-)

diff --git a/applications/segyviewer.py b/applications/segyviewer.py
index 379e985..5f386e2 100755
--- a/applications/segyviewer.py
+++ b/applications/segyviewer.py
@@ -1,5 +1,4 @@
 #!/usr/bin/env python
-
 import sys
 
 from PyQt4 import QtGui, QtCore
@@ -16,7 +15,7 @@ class SegyViewer(QtGui.QMainWindow):
         self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
 
         # signal monitors
-        self.colormap_monitor = ColorMapMonitor(self)
+        self.sliceview_monitor = SliceViewMonitor(self)
         self.line_monitor = LineSelectionMonitor(self)
         self.file_activity_monitor = FileActivityMonitor(self)
 
@@ -25,7 +24,7 @@ class SegyViewer(QtGui.QMainWindow):
 
         # menus
         available_colormaps = ['seismic', 'spectral', 'RdGy', 'hot', 'jet', 'gray']
-        self.configure_main_menu(self.menuBar(), self.colormap_monitor, available_colormaps)
+        self.configure_main_menu(self.menuBar(), self.sliceview_monitor, available_colormaps)
 
         # layout
         self.setWindowTitle("SegyViewer")
@@ -37,6 +36,11 @@ class SegyViewer(QtGui.QMainWindow):
 
         self.ddock = QtGui.QDockWidget("depth slice")
         self.ddock.setFeatures(QtGui.QDockWidget.DockWidgetFloatable | QtGui.QDockWidget.DockWidgetMovable)
+
+
+        self.cdock= QtGui.QDockWidget("Control Panel")
+        self.cdock.setFeatures(QtGui.QDockWidget.DockWidgetFloatable | QtGui.QDockWidget.DockWidgetMovable)
+
         self.setup_dock_widgets()
 
         # progress bar
@@ -61,8 +65,10 @@ class SegyViewer(QtGui.QMainWindow):
     def setup_dock_widgets(self):
         self.setDockOptions(QtGui.QMainWindow.AllowNestedDocks)
         self.addDockWidget(QtCore.Qt.TopDockWidgetArea, self.xdock)
-        self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.idock)
+        self.addDockWidget(QtCore.Qt.TopDockWidgetArea, self.idock)
         self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.ddock)
+        self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.cdock)
+
 
     def configure_main_menu(self, menu, colormap_monitor, available_colormaps):
         menu.fileMenu = menu.addMenu('&File')
@@ -102,7 +108,7 @@ class SegyViewer(QtGui.QMainWindow):
 
         # removing old slice widgets from dock widgets
         for dock_widget in self.findChildren(QtGui.QDockWidget):
-            for widgt in dock_widget.findChildren(SliceWidget):
+            for widgt in dock_widget.findChildren(QtGui.QWidget):
                 widgt.deleteLater()
 
     def open_file_dialogue(self):
@@ -149,7 +155,7 @@ class SegyViewer(QtGui.QMainWindow):
             if status == 0:  # when completed successfully
                 self.initialize_slice_widgets()
             self.progress_bar.hide()
-            self.file_loader_thread.quit()
+
 
         # a memory read, might take some time. Set up a separate thread and update the progressbar
         if read_to_memory:
@@ -166,6 +172,8 @@ class SegyViewer(QtGui.QMainWindow):
 
             # set up finished callback
             self.file_loader_worker.finished.connect(complete_finished_file_load_operation)
+            self.file_loader_worker.finished.connect(self.file_loader_thread.quit)
+
 
             # and start
             self.file_loader_thread.start()
@@ -173,16 +181,15 @@ class SegyViewer(QtGui.QMainWindow):
             complete_finished_file_load_operation(0)
 
     def initialize_slice_widgets(self):
-        self.addToolBar(LineNavigationBar(self.swrap.xlines,
-                                          self.swrap.ilines,
-                                          range(self.swrap.samples),
-                                          self.line_monitor))
+        self.addToolBar(SegyViewerToolBar(self.swrap,
+                                          self.line_monitor, self.sliceview_monitor))
 
-        x_wdgt, i_wdgt, d_wdgt = viewer.initialize_slice_widgets(self.swrap, self.line_monitor, self.colormap_monitor)
+        x_wdgt, i_wdgt, d_wdgt = viewer.initialize_slice_widgets(self.swrap, self.line_monitor, self.sliceview_monitor)
 
         self.xdock.setWidget(x_wdgt)
         self.idock.setWidget(i_wdgt)
         self.ddock.setWidget(d_wdgt)
+        self.cdock.setWidget(ColorBarWidget(self.swrap, colormap_monitor=self.sliceview_monitor))
 
 def main():
 
@@ -201,3 +208,4 @@ if __name__ == '__main__':
 
 
 
+
diff --git a/python/segyview/CMakeLists.txt b/python/segyview/CMakeLists.txt
index 89bd465..2b1766f 100644
--- a/python/segyview/CMakeLists.txt
+++ b/python/segyview/CMakeLists.txt
@@ -1,6 +1,6 @@
 set(PYTHON_SOURCES
     __init__.py
-    linenavigationbar.py
+    controlwidgets.py
     progresswidget.py
     segyiowrapper.py
     segyplot.py
diff --git a/python/segyview/__init__.py b/python/segyview/__init__.py
index 273d2c7..126dbb9 100644
--- a/python/segyview/__init__.py
+++ b/python/segyview/__init__.py
@@ -2,10 +2,10 @@ from .segyplot import SegyPlot
 from .segyiowrapper import SegyIOWrapper, SlicesWrapper
 
 try:
-    from .linenavigationbar import LineNavigationBar
     from .progresswidget import ProgressWidget
-    from .slicewidget import SliceWidget
+    from .slicewidget import SliceWidget, ColorBarWidget
     from .segyiowrapper import SegyIOWrapper, SlicesWrapper
+    from .controlwidgets import *
     from .viewer import *
 except ImportError as e:
     import sys
diff --git a/python/segyview/controlwidgets.py b/python/segyview/controlwidgets.py
new file mode 100644
index 0000000..4b81657
--- /dev/null
+++ b/python/segyview/controlwidgets.py
@@ -0,0 +1,133 @@
+import sys
+from PyQt4 import QtGui, QtCore
+
+
+class LineSelector(QtGui.QWidget):
+    indexChanged = QtCore.pyqtSignal(int)
+
+    def __init__(self, parent, label, indexes, monitor_func):
+        super(QtGui.QWidget, self).__init__(parent)
+        self.label = label
+        self.indexes = indexes
+        self.monitor_func = monitor_func
+
+        self.layout = QtGui.QHBoxLayout()
+        self.slabel = QtGui.QLabel(self.label)
+        self.sbox = QtGui.QSpinBox(self)
+        self.sbox.setRange(self.indexes[0], self.indexes[-1])
+        self.sbox.valueChanged.connect(self.monitor_func)
+        self.layout.addWidget(self.slabel)
+        self.layout.addWidget(self.sbox)
+        self.setLayout(self.layout)
+
+    def index_changed(self, val):
+        self.indexChanged.emit(val)
+
+    def set_index(self, val):
+        self.sbox.blockSignals(True)
+        self.sbox.setValue(val)
+        self.sbox.blockSignals(False)
+
+
+class MinMaxControls(QtGui.QWidget):
+    def __init__(self, segyio_wrapper, sliceview_monitor=None):
+        super(MinMaxControls, self).__init__()
+
+        self.swrap = segyio_wrapper
+        self.colormap_monitor = sliceview_monitor
+
+        # default to 0,1 when not set
+        minv, maxv = self.swrap.min_max or (0,1)
+
+        stepsize = (maxv - minv) / float(100)
+        number_of_decimals = self._get_number_of_decimals_for_spinbox(stepsize)
+        self.min_input = self._setup_spinbox(stepsize, number_of_decimals, minv)
+        self.max_input = self._setup_spinbox(stepsize, number_of_decimals, maxv)
+
+        self.min_input.setToolTip("step in 1% intervals")
+        self.max_input.setToolTip("step in 1% intervals")
+
+        # signals
+        self.min_input.valueChanged.connect(self.min_input_changed)
+        self.max_input.valueChanged.connect(self.max_input_changed)
+
+        # reset button to reset spinboxes to original value from segyio_wrapper
+        self.reset_btn = QtGui.QToolButton()
+        self.reset_btn.clicked.connect(self.reset_min_max)
+        self.reset_btn.setIcon(QtGui.QIcon.fromTheme("edit-undo"))
+
+        self.layout = QtGui.QHBoxLayout(self)
+        self.layout.addWidget(QtGui.QLabel("min"))
+        self.layout.addWidget(self.min_input)
+        self.layout.addWidget(QtGui.QLabel("max"))
+        self.layout.addWidget(self.max_input)
+        self.layout.addWidget(self.reset_btn)
+
+    @staticmethod
+    def _get_number_of_decimals_for_spinbox(step_s):
+        # identify the number of decimals for spinbox
+        no_of_dec, upper_bound = 1, 1.0
+
+        while step_s < upper_bound:
+            upper_bound /= 10
+            no_of_dec += 1
+
+        return no_of_dec
+
+    @staticmethod
+    def _setup_spinbox(step_s, decimals, initial_value):
+        sbox = QtGui.QDoubleSpinBox()
+        sbox.setSingleStep(step_s)
+        sbox.setDecimals(decimals)
+        sbox.setRange(-sys.float_info.max, sys.float_info.max)
+        sbox.setValue(initial_value)
+        return sbox
+
+
+    def reset_min_max(self):
+        min_v, max_v = self.swrap.min_max or (0, 1)
+        self.min_input.setValue(min_v)
+        self.max_input.setValue(max_v)
+
+    def min_input_changed(self, val):
+        self.max_input.setMinimum(val)
+        self.colormap_monitor.min_max_updated((self.min_input.value(),
+                                               self.max_input.value()))
+
+    def max_input_changed(self, val):
+        self.min_input.setMaximum(val)
+        self.colormap_monitor.min_max_updated((self.min_input.value(),
+                                               self.max_input.value()))
+
+
+class SegyViewerToolBar(QtGui.QToolBar):
+    def __init__(self, segyio_wrapper, line_selection_monitor, sliceview_monitor):
+        super(SegyViewerToolBar, self).__init__("")
+        self.swrap = segyio_wrapper
+        self.xline_indexes = self.swrap.xlines
+        self.iline_indexes = self.swrap.ilines
+        self.depth_indexes = range(self.swrap.samples)
+
+        self.line_selection_monitor = line_selection_monitor
+        self.colormap_monitor = sliceview_monitor
+
+        # xline
+        self.xline_selector = LineSelector(self, "x-line", self.xline_indexes, self.line_selection_monitor.xline_updated)
+        self.line_selection_monitor.xline_changed.connect(self.xline_selector.set_index)
+        self.addWidget(self.xline_selector)
+
+        # iline
+        self.iline_selector = LineSelector(self, "i-line", self.iline_indexes, self.line_selection_monitor.iline_updated)
+        self.line_selection_monitor.iline_changed.connect(self.iline_selector.set_index)
+        self.addWidget(self.iline_selector)
+
+        # depth
+        self.depth_selector = LineSelector(self, "depth", self.depth_indexes, self.line_selection_monitor.depth_updated)
+        self.addWidget(self.depth_selector)
+
+        # seperator
+        self.addSeparator()
+
+        # controls for adjusting min and max threshold for the slice plots, and colorbar
+        self.minmax_ctrls = MinMaxControls(self.swrap, sliceview_monitor=self.colormap_monitor)
+        self.addWidget(self.minmax_ctrls)
diff --git a/python/segyview/linenavigationbar.py b/python/segyview/linenavigationbar.py
deleted file mode 100644
index aebff7e..0000000
--- a/python/segyview/linenavigationbar.py
+++ /dev/null
@@ -1,51 +0,0 @@
-from PyQt4 import QtGui, QtCore
-
-
-class LineSelector(QtGui.QWidget):
-    indexChanged = QtCore.pyqtSignal(int)
-
-    def __init__(self, parent, label, indexes, monitor_func):
-        super(QtGui.QWidget, self).__init__(parent)
-        self.label = label
-        self.indexes = indexes
-        self.monitor_func = monitor_func
-
-        self.layout = QtGui.QHBoxLayout()
-        self.slabel = QtGui.QLabel(self.label)
-        self.sbox = QtGui.QSpinBox(self)
-        self.sbox.setRange(self.indexes[0], self.indexes[-1])
-        self.sbox.valueChanged.connect(self.monitor_func)
-        self.layout.addWidget(self.slabel)
-        self.layout.addWidget(self.sbox)
-        self.setLayout(self.layout)
-
-    def index_changed(self, val):
-        self.indexChanged.emit(val)
-
-    def set_index(self, val):
-        self.sbox.blockSignals(True)
-        self.sbox.setValue(val)
-        self.sbox.blockSignals(False)
-
-
-class LineNavigationBar(QtGui.QToolBar):
-    def __init__(self, xline_indexes, iline_indexes, depth_indexes, line_selection_monitor):
-        super(LineNavigationBar, self).__init__("")
-        self.xline_indexes = xline_indexes
-        self.iline_indexes = iline_indexes
-        self.depth_indexes = depth_indexes
-        self.line_selection_monitor = line_selection_monitor
-
-        # xline
-        self.xline_selector = LineSelector(self, "x-line", self.xline_indexes, self.line_selection_monitor.xline_updated)
-        self.line_selection_monitor.xline_changed.connect(self.xline_selector.set_index)
-        self.addWidget(self.xline_selector)
-
-        # iline
-        self.iline_selector = LineSelector(self, "i-line", self.iline_indexes, self.line_selection_monitor.iline_updated)
-        self.line_selection_monitor.iline_changed.connect(self.iline_selector.set_index)
-        self.addWidget(self.iline_selector)
-
-        # depth
-        self.depth_selector = LineSelector(self, "depth", self.depth_indexes, self.line_selection_monitor.depth_updated)
-        self.addWidget(self.depth_selector)
diff --git a/python/segyview/segyplot.py b/python/segyview/segyplot.py
index 669fc93..348f5c8 100644
--- a/python/segyview/segyplot.py
+++ b/python/segyview/segyplot.py
@@ -126,13 +126,13 @@ class SegyPlot(object):
 
 class ColorBarPlot(object):
     def __init__(self, axes, cmap=None, v_min_max=None):
-        print(v_min_max)
         self.axes = axes
         self.cmap = cmap
 
-        min, max = v_min_max
-        norm = matplotlib.colors.Normalize(vmin=min, vmax=max)
+        # default to 0,1 when not set
+        min, max = v_min_max or (0,1)
 
+        norm = matplotlib.colors.Normalize(vmin=min, vmax=max)
         self.colorbar = matplotlib.colorbar.ColorbarBase(self.axes, cmap=cmap, norm=norm)
 
     def set_cmap(self, cmap):
@@ -144,6 +144,3 @@ class ColorBarPlot(object):
         self.colorbar.set_clim(min, max)
         self.colorbar.draw_all()
 
-    def mouse_clicked(self, evt):
-        if evt.inaxes is not None:
-            print(evt)
diff --git a/python/segyview/slicewidget.py b/python/segyview/slicewidget.py
index 69e0bde..033821c 100644
--- a/python/segyview/slicewidget.py
+++ b/python/segyview/slicewidget.py
@@ -85,23 +85,6 @@ class SliceWidget(QtGui.QWidget):
         self.segy_plot.set_horizontal_line_indicator(line)
         self.figure_canvas.draw()
 
-    def toggle_disabled_state(self):
-
-        self.overlay = Overlay(self)
-        self.overlay.setGeometry(self.layout.geometry())
-        self.overlay.show()
-
-
-class Overlay(QtGui.QWidget):
-    def __init__(self, parent):
-        super(Overlay, self).__init__(parent)
-        self.parent = parent
-    def paintEvent(self, QPaintEvent):
-
-        painter = QtGui.QPainter(self)
-
-        color = QtGui.QColor(0,0,0,50)
-        painter.fillRect(self.rect(), color)
 
 
 class ColorBarWidget(QtGui.QWidget):
@@ -123,7 +106,6 @@ class ColorBarWidget(QtGui.QWidget):
 
         # signals
         self.colormap_monitor.cmap_changed.connect(self.set_cmap)
-        self.figure_canvas.mpl_connect('button_press_event', self.cbar_plt.mouse_clicked)
 
         self.colormap_monitor.min_max_changed.connect(self.set_min_max)
 

-- 
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