[segyio] 116/376: Added resources and LayoutCombo widget

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:17 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 fa61a71c85b687aee6f697eb6eee796d36287532
Author: Jean-Paul Balabanian <jepebe at users.noreply.github.com>
Date:   Thu Nov 17 10:44:44 2016 +0100

    Added resources and LayoutCombo widget
---
 .travis.yml                                     |   2 +-
 CMakeLists.txt                                  |   1 +
 appveyor.yml                                    |   2 +-
 cmake/python.cmake                              |   1 +
 examples/CMakeLists.txt                         |   1 +
 examples/showcase_gui.py                        |  46 +++++++++++
 python/segyview/CMakeLists.txt                  |   1 +
 python/segyview/__init__.py                     |  20 +++++
 python/segyview/layoutcombo.py                  |  97 ++++++++++++++++++++++++
 resources/CMakeLists.txt                        |   1 +
 resources/img/CMakeLists.txt                    |  21 +++++
 resources/img/layouts_four_grid.png             | Bin 0 -> 1428 bytes
 resources/img/layouts_single.png                | Bin 0 -> 1246 bytes
 resources/img/layouts_three_bottom_grid.png     | Bin 0 -> 2345 bytes
 resources/img/layouts_three_horizontal_grid.png | Bin 0 -> 2228 bytes
 resources/img/layouts_three_top_grid.png        | Bin 0 -> 2397 bytes
 resources/img/layouts_three_vertical_grid.png   | Bin 0 -> 1408 bytes
 resources/img/layouts_two_horizontal_grid.png   | Bin 0 -> 2341 bytes
 resources/img/layouts_two_vertical_grid.png     | Bin 0 -> 2277 bytes
 resources/img/readme.txt                        |   7 ++
 tests/test_segyview.py                          |  23 ++----
 21 files changed, 205 insertions(+), 18 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 3e4eae7..42b04dc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -49,4 +49,4 @@ before_script:
   - make
   - export LD_LIBRARY_PATH=$PWD
 
-script: make && ctest --output-on-failure
+script: make && ctest --output-on-failure -E gui
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 324b3f2..97ce261 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,6 +56,7 @@ add_subdirectory(python)
 add_subdirectory(applications)
 add_subdirectory(examples)
 add_subdirectory(tests)
+add_subdirectory(resources)
 
 # install the library
 install(FILES src/segyio/segy.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/segyio)
diff --git a/appveyor.yml b/appveyor.yml
index 4dd1118..e451145 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -23,4 +23,4 @@ build_script:
     - pushd build
     - cmake C:\projects\SegyIO -DBUILD_MEX=OFF -DBUILD_PYTHON=ON -DCMAKE_BUILD_TYPE=%configuration%
     - cmake --build . --config %configuration%
-    - ctest -C %configuration% --output-on-failure
+    - ctest -C %configuration% --output-on-failure -E gui
diff --git a/cmake/python.cmake b/cmake/python.cmake
index 219dead..e435a1a 100644
--- a/cmake/python.cmake
+++ b/cmake/python.cmake
@@ -22,6 +22,7 @@ function(add_python_package PACKAGE_NAME PACKAGE_PATH PYTHON_FILES)
                 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${CMAKE_BINARY_DIR}/python/${PACKAGE_PATH}
                 )
     endforeach ()
+    set_target_properties(package_${PACKAGE_NAME} PROPERTIES PACKAGE_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX}/${PACKAGE_PATH})
     install(FILES ${PYTHON_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX}/${PACKAGE_PATH})
 endfunction()
 
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index ee72a57..4e52c01 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -6,3 +6,4 @@ add_python_example(python.examples.write write.py test-data/small.sgy)
 add_python_example(python.examples.makefile make-file.py test-data/large-file.sgy 20 1 20 1 20)
 add_python_example(python.examples.subcube copy-sub-cube.py test-data/small.sgy test-data/copy.sgy)
 add_python_example(python.examples.scan_min_max scan_min_max.py test-data/small.sgy)
+add_python_example(python.examples.gui showcase_gui.py display_nothing)
diff --git a/examples/showcase_gui.py b/examples/showcase_gui.py
new file mode 100644
index 0000000..f18834a
--- /dev/null
+++ b/examples/showcase_gui.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+import sys
+
+from PyQt4.QtCore import Qt
+from PyQt4.QtGui import QMainWindow, QWidget, QApplication, QLabel, QVBoxLayout
+
+from segyview import LayoutCombo
+
+
+class TestGUI(QMainWindow):
+    def __init__(self):
+        QMainWindow.__init__(self)
+
+        self.setAttribute(Qt.WA_DeleteOnClose)
+        self.setWindowTitle("GUI Test")
+
+        toolbar = self.addToolBar("Stuff")
+        """:type: QToolBar"""
+
+        layout_combo = LayoutCombo()
+        toolbar.addWidget(layout_combo)
+        layout_combo.layout_changed.connect(self._layout_changed)
+
+        central_widget = QWidget()
+        layout = QVBoxLayout()
+        central_widget.setLayout(layout)
+
+        self._layout_label = QLabel()
+        layout.addWidget(self._layout_label)
+
+        self.setCentralWidget(central_widget)
+
+    def _layout_changed(self, layout):
+        self._layout_label.setText(str(layout))
+
+
+if __name__ == '__main__':
+    if len(sys.argv) > 1:
+        sys.exit()
+    else:
+        q_app = QApplication(sys.argv)
+
+        gui = TestGUI()
+        gui.show()
+        gui.raise_()
+        sys.exit(q_app.exec_())
diff --git a/python/segyview/CMakeLists.txt b/python/segyview/CMakeLists.txt
index 2b1766f..5a22a8d 100644
--- a/python/segyview/CMakeLists.txt
+++ b/python/segyview/CMakeLists.txt
@@ -6,6 +6,7 @@ set(PYTHON_SOURCES
     segyplot.py
     slicewidget.py
     viewer.py
+    layoutcombo.py
     )
 
 add_python_package(segyview segyview "${PYTHON_SOURCES}")
diff --git a/python/segyview/__init__.py b/python/segyview/__init__.py
index d68eeb8..ae29323 100644
--- a/python/segyview/__init__.py
+++ b/python/segyview/__init__.py
@@ -1,7 +1,27 @@
+import os.path as path
+
 from .segyplot import SegyPlot
 from .segyiowrapper import SegyIOWrapper, SlicesWrapper
 
+img_prefix = path.abspath(path.join(path.dirname(path.abspath(__file__)), "resources", "img"))
+
+if not path.exists(img_prefix):
+    img_prefix = path.abspath(path.join(path.dirname(path.abspath(__file__)), "..", "..", "resources", "img"))
+
+
+def resource_icon_path(name):
+    return path.join(img_prefix, name)
+
+
+def resource_icon(name):
+    """Load an image as an icon"""
+    # print("Icon used: %s" % name)
+    from PyQt4.QtGui import QIcon
+    return QIcon(resource_icon_path(name))
+
+
 try:
+    from .layoutcombo import LayoutCombo
     from .progresswidget import ProgressWidget
     from .slicewidget import SliceWidget, ColorBarWidget
     from .segyiowrapper import SegyIOWrapper, SlicesWrapper
diff --git a/python/segyview/layoutcombo.py b/python/segyview/layoutcombo.py
new file mode 100644
index 0000000..f74f620
--- /dev/null
+++ b/python/segyview/layoutcombo.py
@@ -0,0 +1,97 @@
+from PyQt4.QtCore import Qt, pyqtSignal, QVariant
+from PyQt4.QtGui import QComboBox, QIcon
+
+from segyview import resource_icon
+
+
+class LayoutCombo(QComboBox):
+    layout_changed = pyqtSignal(object)
+
+    def __init__(self, parent=None):
+        QComboBox.__init__(self, parent)
+
+        layouts = [
+            # {
+            #     "icon": "layouts_four_grid.png",
+            #     "spec": {
+            #         "dims": (2, 2),
+            #         "grid": [(0, 0), (0, 1), (1, 0), (1, 1)]
+            #     }
+            # },
+            {
+                "icon": "layouts_three_bottom_grid.png",
+                "spec": {
+                    "dims": (2, 2),
+                    "grid": [(0, 0), (0, 1), (1, slice(0, 2))]
+                }
+            },
+            {
+                "icon": "layouts_three_top_grid.png",
+                "spec": {
+                    "dims": (2, 2),
+                    "grid": [(0, slice(0, 2)), (1, 0), (1, 1)]
+                }
+            },
+            {
+                "icon": "layouts_two_horizontal_grid.png",
+                "spec": {
+                    "dims": (2, 1),
+                    "grid": [(0, 0), (1, 0)]
+                }
+            },
+            {
+                "icon": "layouts_two_vertical_grid.png",
+                "spec": {
+                    "dims": (1, 2),
+                    "grid": [(0, 0), (0, 1)]
+                }
+            },
+            {
+                "icon": "layouts_three_horizontal_grid.png",
+                "spec": {
+                    "dims": (3, 1),
+                    "grid": [(0, 0), (1, 0), (2, 0)]
+                }
+            },
+            {
+                "icon": "layouts_three_vertical_grid.png",
+                "spec": {
+                    "dims": (1, 3),
+                    "grid": [(0, 0), (0, 1), (0, 2)]
+                }
+            },
+            {
+                "icon": "layouts_single.png",
+                "spec": {
+                    "dims": (1, 1),
+                    "grid": [(0, 0)]
+                }
+            }
+        ]
+
+        for layout in layouts:
+            self.add_layout_item(layout)
+
+        self.setMinimumHeight(45)
+        self.setMinimumWidth(60)
+        self.setMaximumWidth(60)
+        self.setMaximumHeight(45)
+
+        self.currentIndexChanged.connect(self._layout_changed)
+
+    def add_layout_item(self, layout_item):
+        self.addItem(resource_icon(layout_item['icon']), "", layout_item['spec'])
+
+    def _layout_changed(self, index):
+        spec = self._get_spec(index)
+        self.layout_changed.emit(spec)
+
+    def _get_spec(self, index):
+        user_data = self.itemData(index)
+        """ :type: QVariant"""
+        spec = user_data.toPyObject()
+        spec = {str(key): value for key, value in spec.items()}
+        return spec
+
+    def get_current_layout(self):
+        return self._get_spec(self.currentIndex())
diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt
new file mode 100644
index 0000000..58720c2
--- /dev/null
+++ b/resources/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(img)
diff --git a/resources/img/CMakeLists.txt b/resources/img/CMakeLists.txt
new file mode 100644
index 0000000..1866304
--- /dev/null
+++ b/resources/img/CMakeLists.txt
@@ -0,0 +1,21 @@
+set(RESOURCES
+    layouts_four_grid.png
+    layouts_single.png
+    layouts_three_bottom_grid.png
+    layouts_three_horizontal_grid.png
+    layouts_three_top_grid.png
+    layouts_three_vertical_grid.png
+    layouts_two_horizontal_grid.png
+    layouts_two_vertical_grid.png
+)
+
+add_custom_target(install_resources ALL)
+
+foreach (file ${RESOURCES})
+    add_custom_command(TARGET install_resources
+            COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/resources
+            COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${CMAKE_BINARY_DIR}/resources/img
+            )
+endforeach ()
+get_target_property(INSTALL_PATH package_segyview PACKAGE_INSTALL_PATH)
+install(FILES ${RESOURCES} DESTINATION ${INSTALL_PATH}/resources/img)
diff --git a/resources/img/layouts_four_grid.png b/resources/img/layouts_four_grid.png
new file mode 100755
index 0000000..2473593
Binary files /dev/null and b/resources/img/layouts_four_grid.png differ
diff --git a/resources/img/layouts_single.png b/resources/img/layouts_single.png
new file mode 100755
index 0000000..3b7eff2
Binary files /dev/null and b/resources/img/layouts_single.png differ
diff --git a/resources/img/layouts_three_bottom_grid.png b/resources/img/layouts_three_bottom_grid.png
new file mode 100644
index 0000000..99568e3
Binary files /dev/null and b/resources/img/layouts_three_bottom_grid.png differ
diff --git a/resources/img/layouts_three_horizontal_grid.png b/resources/img/layouts_three_horizontal_grid.png
new file mode 100644
index 0000000..da39ea4
Binary files /dev/null and b/resources/img/layouts_three_horizontal_grid.png differ
diff --git a/resources/img/layouts_three_top_grid.png b/resources/img/layouts_three_top_grid.png
new file mode 100644
index 0000000..bf67b0f
Binary files /dev/null and b/resources/img/layouts_three_top_grid.png differ
diff --git a/resources/img/layouts_three_vertical_grid.png b/resources/img/layouts_three_vertical_grid.png
new file mode 100755
index 0000000..412b49f
Binary files /dev/null and b/resources/img/layouts_three_vertical_grid.png differ
diff --git a/resources/img/layouts_two_horizontal_grid.png b/resources/img/layouts_two_horizontal_grid.png
new file mode 100644
index 0000000..ded8588
Binary files /dev/null and b/resources/img/layouts_two_horizontal_grid.png differ
diff --git a/resources/img/layouts_two_vertical_grid.png b/resources/img/layouts_two_vertical_grid.png
new file mode 100644
index 0000000..c83b880
Binary files /dev/null and b/resources/img/layouts_two_vertical_grid.png differ
diff --git a/resources/img/readme.txt b/resources/img/readme.txt
new file mode 100644
index 0000000..e699b19
--- /dev/null
+++ b/resources/img/readme.txt
@@ -0,0 +1,7 @@
+Free FatCow-Farm Fresh Icons
+http://www.fatcow.com/free-icons
+
+These icons are licensed under a Creative Commons Attribution 3.0 License.
+http://creativecommons.org/licenses/by/3.0/us/ if you do not know how to link
+back to FatCow's website, you can ask https://plus.google.com/+MarcisGasuns
+Biggest icon set drawn by a single designer (in pixel smooth style) worldwide.
\ No newline at end of file
diff --git a/tests/test_segyview.py b/tests/test_segyview.py
index bc8da50..a14f19c 100644
--- a/tests/test_segyview.py
+++ b/tests/test_segyview.py
@@ -1,34 +1,25 @@
+import os
 from unittest import TestCase
 import segyio
-from segyview import SegyIOWrapper
+from segyview import SegyIOWrapper, resource_icon_path
 import itertools
 
 
 class TestSegyView(TestCase):
-
     def setUp(self):
         self.filename = "test-data/small.sgy"
 
-    def test_read_all_traces_to_memory_compare_with_depth_slice_and_verify_cube_rotation(self):
-
+    def test_resources(self):
+        path = resource_icon_path("layouts_single.png")
+        print(path)
+        self.assertTrue(os.path.exists(path))
 
+    def test_read_all_traces_to_memory_compare_with_depth_slice_and_verify_cube_rotation(self):
         with segyio.open(self.filename, "r") as segy:
             swrap = SegyIOWrapper.wrap(segy)
             swrap.read_all_traces_to_memory()
             for i, depth_slice in enumerate(swrap.depth_slices):
                 for ilno, xlno in itertools.product(range(len(segy.ilines)), range(len(segy.xlines))):
-
                     self.assertEqual(depth_slice[ilno, xlno], segy.depth_slice[i][ilno, xlno],
                                      "the cube values from read_all_traces and depth_slice differ {0} != {1}"
                                      .format(depth_slice[ilno, xlno], segy.depth_slice[i][ilno, xlno]))
-
-
-
-
-
-
-
-
-
-
-

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