Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

865: Auto update from spinbox change #879

Merged
merged 15 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release_notes/next.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ Fixes
- #843 : Error loading stack
- #856 : Move shared array allocation to `multiprocessing.Array` when on Python 3.8
- #854 : Ops window, image selector in preview section skips by 2
- #856 : Operations auto update not triggered on spinbox changes
20 changes: 17 additions & 3 deletions mantidimaging/gui/utility/qt_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
from enum import IntEnum, auto
from logging import getLogger
from typing import Any, Tuple, Union, List
from typing import Any, Tuple, Union, List, Callable

from PyQt5 import Qt
from PyQt5 import uic # type: ignore
Expand Down Expand Up @@ -76,6 +76,18 @@ class Type(IntEnum):
BUTTON = auto()


def _on_change_and_disable(widget: QWidget, on_change: Callable):
"""
Makes sure the widget is disabled while running the on_update method. This is required for spin boxes that
continue increasing when generating a preview image is computationally intensive.
:param widget: The widget to disable.
:param on_change: The method to call when the widget has been changed.
"""
widget.setEnabled(False)
on_change()
widget.setEnabled(True)


def add_property_to_form(label: str,
dtype: Union[Type, str],
default_value=None,
Expand Down Expand Up @@ -134,15 +146,17 @@ def set_spin_box(box, cast_func):

elif dtype == 'int' or dtype == Type.INT:
right_widget = Qt.QSpinBox()
right_widget.setKeyboardTracking(False)
set_spin_box(right_widget, int)
if on_change is not None:
right_widget.editingFinished.connect(lambda: on_change())
right_widget.valueChanged.connect(lambda: _on_change_and_disable(right_widget, on_change))

elif dtype == 'float' or dtype == Type.FLOAT:
right_widget = Qt.QDoubleSpinBox()
set_spin_box(right_widget, float)
right_widget.setKeyboardTracking(False)
if on_change is not None:
right_widget.editingFinished.connect(lambda: on_change())
right_widget.valueChanged.connect(lambda: _on_change_and_disable(right_widget, on_change))

elif dtype == 'bool' or dtype == Type.BOOL:
right_widget = Qt.QCheckBox()
Expand Down
5 changes: 0 additions & 5 deletions mantidimaging/gui/windows/operations/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ def _do_apply_filter_sync(self, apply_to):

def do_update_previews(self):
self.view.clear_previews()
# Disable preview image index scrollbox to prevent double-increase
self.view.previewImageIndex.setEnabled(False)
if self.stack is not None:
stack_presenter = self.stack.presenter
subset: Images = stack_presenter.get_image(self.model.preview_image_idx)
Expand Down Expand Up @@ -255,9 +253,6 @@ def do_update_previews(self):
# Ensure all of it is visible
self.view.previews.auto_range()

# Enable preview image index box when preview has been created
self.view.previewImageIndex.setEnabled(True)

@staticmethod
def _update_preview_image(image_data: Optional[np.ndarray], image: ImageItem):
image.clear()
Expand Down
4 changes: 0 additions & 4 deletions mantidimaging/gui/windows/operations/test/test_presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,3 @@ def test_original_stack_assigned_when_safe_apply_checked(self, _):

stack.presenter.images.copy.assert_called_once()
self.assertEqual(stack_data, self.presenter.original_images_stack)

def test_preview_image_spin_box_disabled_while_updating_preview(self):
self.presenter.do_update_previews()
self.view.previewImageIndex.setEnabled.assert_has_calls([mock.call(False), mock.call(True)])
6 changes: 6 additions & 0 deletions mantidimaging/gui/windows/operations/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,16 @@ def on_auto_update_triggered(self):
Called when the signal indicating the filter, filter properties or data
has changed such that the previews are now out of date.
"""
# Disable the preview image box widget as it can misbehave if making a preview takes too long
self.previewImageIndex.setEnabled(False)

self.clear_notification_dialog()
if self.previewAutoUpdate.isChecked() and self.isVisible():
self.presenter.notify(PresNotification.UPDATE_PREVIEWS)

# Enable the spinbox widget once the preview has been created
self.previewImageIndex.setEnabled(True)

def clear_previews(self):
self.previews.clear_items()

Expand Down