From 16ef30fa0e3fe225790f5dbc8ff19fbb3be13784 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sun, 5 Jun 2022 12:05:48 +0100 Subject: [PATCH 1/3] Fix closing `crop_signal1D` --- hyperspy_gui_traitsui/tools.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/hyperspy_gui_traitsui/tools.py b/hyperspy_gui_traitsui/tools.py index 66971b7..6751142 100644 --- a/hyperspy_gui_traitsui/tools.py +++ b/hyperspy_gui_traitsui/tools.py @@ -96,10 +96,12 @@ def next(self, info, *args, **kwargs): class Signal1DRangeSelectorHandler(tu.Handler): def close(self, info, is_ok): - # Removes the span selector from the plot - info.object.span_selector_switch(False) if is_ok is True: self.apply(info) + + # Removes the span selector from the plot + info.object.span_selector_switch(False) + return True def apply(self, info, *args, **kwargs): @@ -107,11 +109,16 @@ def apply(self, info, *args, **kwargs): """ obj = info.object - if obj.ss_left_value != obj.ss_right_value: - info.object.span_selector_switch(False) - for method, cls in obj.on_close: - method(cls, obj.ss_left_value, obj.ss_right_value) - info.object.span_selector_switch(True) + extents = obj.span_selector.extents + # when the traits and span extent are out of sync, which happen after + # "apply" and before making a new selection + if obj.ss_left_value == obj.ss_right_value or extents[0] == extents[1]: + return + + obj.span_selector_switch(False) + for method, cls in obj.on_close: + method(cls, obj.ss_left_value, obj.ss_right_value) + obj.span_selector_switch(True) obj.is_ok = True From 081766839c145f3da4b1dc725a0f6bea0f1bbab5 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sun, 5 Jun 2022 12:06:38 +0100 Subject: [PATCH 2/3] Remove code to support hyperspy < 1.7 --- hyperspy_gui_traitsui/tests/test_axes.py | 6 ------ hyperspy_gui_traitsui/tests/test_tools.py | 10 ---------- 2 files changed, 16 deletions(-) diff --git a/hyperspy_gui_traitsui/tests/test_axes.py b/hyperspy_gui_traitsui/tests/test_axes.py index 029c448..7eabf0d 100755 --- a/hyperspy_gui_traitsui/tests/test_axes.py +++ b/hyperspy_gui_traitsui/tests/test_axes.py @@ -1,7 +1,6 @@ import numpy as np import hyperspy.api as hs -import pytest from hyperspy_gui_traitsui.tests.utils import KWARGS @@ -33,11 +32,6 @@ def test_axes_manager_gui(self): def test_non_uniform_axes(): - try: - from hyperspy.axes import UniformDataAxis - except ImportError: - pytest.skip("HyperSpy version doesn't support non-uniform axis") - dict0 = {'scale': 1.0, 'size':2} dict1 = {'expression': 'a / (x+b)', 'a': 1240, 'b': 1, 'size': 3, 'name': 'plumage', 'units': 'beautiful', 'navigate': False} diff --git a/hyperspy_gui_traitsui/tests/test_tools.py b/hyperspy_gui_traitsui/tests/test_tools.py index 031c0b0..f2f5e96 100644 --- a/hyperspy_gui_traitsui/tests/test_tools.py +++ b/hyperspy_gui_traitsui/tests/test_tools.py @@ -16,12 +16,8 @@ # You should have received a copy of the GNU General Public License # along with HyperSpy. If not, see . -from packaging.version import Version - import numpy as np -import pytest -import hyperspy import hyperspy.api as hs from hyperspy.signal_tools import ( ImageContrastEditor, @@ -57,8 +53,6 @@ def test_image_contrast_tool(): assert ceditor.norm == norm -@pytest.mark.skipif(Version(hyperspy.__version__) < Version("1.7.0.dev"), - reason="Only supported for hyperspy>=1.7") def test_remove_background_tool(): s = hs.datasets.artificial_data.get_core_loss_eels_signal(True, False) @@ -72,8 +66,6 @@ def test_remove_background_tool(): assert s.isig[:500.0].data.mean() < 1 -@pytest.mark.skipif(Version(hyperspy.__version__) < Version("1.7.0.dev"), - reason="Only supported for hyperspy>=1.7") def test_signal_2d_calibration(): s = hs.signals.Signal2D(np.zeros((100, 100))) s.plot() @@ -86,8 +78,6 @@ def test_signal_2d_calibration(): assert s.axes_manager[1].scale == 2 -@pytest.mark.skipif(Version(hyperspy.__version__) < Version("1.7.0.dev"), - reason="Only supported for hyperspy>=1.7") def test_signal_2d_calibration_3d_data(): s = hs.signals.Signal2D(np.zeros((5, 100, 100))) s.plot() From fde259465930fd0c12f6fb5f7ffca1cb5c3d5647 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sun, 5 Jun 2022 12:15:46 +0100 Subject: [PATCH 3/3] Add changelog entry --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 240ab3c..69a3c1b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ ## v1.6.0.dev0 (UNRELEASED) +* Fix error when pressing "OK" button after "Apply" was pressed in `crop_signal1D` ([#49](https://github.com/hyperspy/hyperspy_gui_traitsui/pull/49)) ## v1.5.1 (2022-05-03)