Skip to content

Commit

Permalink
plugins: disable action button while computing (#2560)
Browse files Browse the repository at this point in the history
* allow plugins to disable button when in progress

* all action buttons get check icon
* optional: plugins can pass action_spinner as a traitlet, in which case the button will automatically disable and show a different icon as the action is being completed, before re-enabling.

* decorator to set traitlet during method

and apply across all plugins

* changelog entry

* use for cubeviz's export movie

* use spinning spinner and remove check by default
  • Loading branch information
kecnry authored Nov 15, 2023
1 parent 64e0974 commit 5b45ba7
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ New Features

- Add button in Plot Options to apply preset RBG options to visible layers when in Monochromatic mode. [#2558, #2568]

- Plugin "action" buttons disable and show icon indicating that an action is in progress. [#2560]

Cubeviz
^^^^^^^

Expand Down
16 changes: 13 additions & 3 deletions jdaviz/components/plugin_add_results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@

<v-row justify="end">
<j-tooltip :tooltipcontent="label_overwrite ? action_tooltip+' and replace existing entry' : action_tooltip">
<v-btn :disabled="label_invalid_msg.length > 0 || action_disabled"
<v-btn :disabled="label_invalid_msg.length > 0 || action_disabled || action_spinner"
text
color="accent"
@click="$emit('click:action')"
>{{action_label}}{{label_overwrite ? ' (Overwrite)' : ''}}
>
<v-progress-circular
v-if="action_spinner"
indeterminate
color="primary"
size="20"
width="3"
style="margin-right: 4px"
></v-progress-circular>
<span v-else style="width: 24px"></span>
{{action_label}}{{label_overwrite ? ' (Overwrite)' : ''}}
</v-btn>
</j-tooltip>
</v-row>
Expand All @@ -75,6 +85,6 @@
module.exports = {
props: ['label', 'label_default', 'label_auto', 'label_invalid_msg', 'label_overwrite', 'label_label', 'label_hint',
'add_to_viewer_items', 'add_to_viewer_selected', 'add_to_viewer_hint',
'action_disabled', 'action_label', 'action_tooltip']
'action_disabled', 'action_spinner', 'action_label', 'action_tooltip']
};
</script>
4 changes: 3 additions & 1 deletion jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from jdaviz.core.template_mixin import (PluginTemplateMixin,
DatasetSelectMixin,
SpectralSubsetSelectMixin,
AddResultsMixin)
AddResultsMixin,
with_spinner)
from jdaviz.core.user_api import PluginUserApi

__all__ = ['MomentMap']
Expand Down Expand Up @@ -91,6 +92,7 @@ def _set_default_results_label(self, event={}):
label_comps += [f"moment {self.n_moment}"]
self.results_label_default = " ".join(label_comps)

@with_spinner()
def calculate_moment(self, add_data=True):
"""
Calculate the moment map
Expand Down
1 change: 1 addition & 0 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
:add_to_viewer_selected.sync="add_to_viewer_selected"
action_label="Calculate"
action_tooltip="Calculate moment map"
:action_spinner="spinner"
@click:action="calculate_moment"
></plugin-add-results>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from jdaviz.core.template_mixin import (PluginTemplateMixin,
SelectPluginComponent,
SpatialSubsetSelectMixin,
AddResultsMixin)
AddResultsMixin,
with_spinner)
from jdaviz.core.user_api import PluginUserApi
from jdaviz.configs.cubeviz.plugins.parsers import _return_spectrum_with_correct_units

Expand Down Expand Up @@ -72,6 +73,7 @@ def user_api(self):
)
)

@with_spinner()
def collapse_to_spectrum(self, add_data=True, **kwargs):
"""
Collapse over the spectral axis.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
:add_to_viewer_selected.sync="add_to_viewer_selected"
action_label="Extract"
action_tooltip="Run spectral extraction with error and mask propagation"
:action_spinner="spinner"
@click:action="spectral_extraction"
></plugin-add-results>

Expand Down
4 changes: 3 additions & 1 deletion jdaviz/configs/default/plugins/collapse/collapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
DatasetSelectMixin,
SelectPluginComponent,
SpectralSubsetSelectMixin,
AddResultsMixin)
AddResultsMixin,
with_spinner)
from jdaviz.core.user_api import PluginUserApi

__all__ = ['Collapse']
Expand Down Expand Up @@ -69,6 +70,7 @@ def _set_default_results_label(self, event={}):
label_comps += ["collapsed"]
self.results_label_default = " ".join(label_comps)

@with_spinner()
def collapse(self, add_data=True):
"""
Collapse over the spectral axis.
Expand Down
1 change: 1 addition & 0 deletions jdaviz/configs/default/plugins/collapse/collapse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
:add_to_viewer_selected.sync="add_to_viewer_selected"
action_label="Collapse"
action_tooltip="Collapse data"
:action_spinner="spinner"
@click:action="collapse"
></plugin-add-results>

Expand Down
6 changes: 2 additions & 4 deletions jdaviz/configs/default/plugins/export_plot/export_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from jdaviz.core.custom_traitlets import FloatHandleEmpty, IntHandleEmpty
from jdaviz.core.events import AddDataMessage, SnackbarMessage
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import PluginTemplateMixin, ViewerSelectMixin
from jdaviz.core.template_mixin import PluginTemplateMixin, ViewerSelectMixin, with_spinner
from jdaviz.core.user_api import PluginUserApi

try:
Expand Down Expand Up @@ -146,6 +146,7 @@ def vue_save_figure(self, filetype):
"""
self.save_figure(filetype=filetype)

@with_spinner('movie_recording')
def _save_movie(self, i_start, i_end, fps, filename, rm_temp_files):
# NOTE: All the stuff here has to be in the same thread but
# separate from main app thread to work.
Expand All @@ -161,8 +162,6 @@ def _save_movie(self, i_start, i_end, fps, filename, rm_temp_files):
i_step = 1 # Need n_frames check if we allow tweaking

try:
self.movie_recording = True

while i <= i_end:
if self.movie_interrupt:
break
Expand Down Expand Up @@ -190,7 +189,6 @@ def _save_movie(self, i_start, i_end, fps, filename, rm_temp_files):
if video:
video.release()
slice_plg._on_slider_updated({'new': orig_slice})
self.movie_recording = False

if rm_temp_files or self.movie_interrupt:
for cur_pngfile in temp_png_files:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from jdaviz.core.events import SnackbarMessage
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import (PluginTemplateMixin, DatasetSelectMixin,
SelectPluginComponent, AddResultsMixin)
SelectPluginComponent, AddResultsMixin,
with_spinner)
from jdaviz.core.user_api import PluginUserApi

__all__ = ['GaussianSmooth']
Expand Down Expand Up @@ -176,6 +177,7 @@ def smooth(self, add_data=True):

return results

@with_spinner()
def spectral_smooth(self):
"""
Smooth the input spectrum along the spectral axis. To add the resulting spectrum into
Expand All @@ -199,6 +201,7 @@ def spectral_smooth(self):

return spec_smoothed

@with_spinner('spinner')
def spatial_smooth(self):
"""
Use astropy convolution machinery to smooth the spatial dimensions of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
:add_to_viewer_selected.sync="add_to_viewer_selected"
action_label="Smooth"
action_tooltip="Smooth data"
:action_spinner="spinner"
@click:action="apply"
></plugin-add-results>
</j-tray-plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
NonFiniteUncertaintyMismatchMixin,
AutoTextField,
AddResultsMixin,
TableMixin)
TableMixin,
with_spinner)
from jdaviz.core.custom_traitlets import IntHandleEmpty
from jdaviz.core.user_api import PluginUserApi
from jdaviz.configs.default.plugins.model_fitting.fitting_backend import fit_model_to_spectrum
Expand Down Expand Up @@ -767,6 +768,7 @@ def _update_viewer_filters(self, event={}):
# only want spectral viewers in the options
self.add_results.viewer.filters = ['is_spectrum_viewer']

@with_spinner()
def calculate_fit(self, add_data=True):
"""
Calculate the fit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
action_label="Fit Model"
action_tooltip="Fit the model to the data"
:action_disabled="model_equation_invalid_msg.length > 0 || !spectral_subset_valid"
:action_spinner="spinner"
@click:action="apply"
>
<div v-if="config!=='cubeviz' || !cube_fit">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from jdaviz.core.region_translators import regions2aperture, _get_region_from_spatial_subset
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import (PluginTemplateMixin, DatasetMultiSelectMixin,
SubsetSelect, TableMixin, PlotMixin)
SubsetSelect, TableMixin, PlotMixin, with_spinner)
from jdaviz.core.tools import ICON_DIR
from jdaviz.utils import PRIHDR_KEY

Expand Down Expand Up @@ -305,6 +305,7 @@ def _background_selected_changed(self, event={}):
self.hub.broadcast(SnackbarMessage(
f"Failed to extract {background_selected}: {repr(e)}", color='error', sender=self))

@with_spinner()
def calculate_photometry(self, dataset=None, aperture=None, background=None,
background_value=None, pixel_area=None, counts_factor=None,
flux_scaling=None, add_to_table=True, update_plots=True):
Expand Down Expand Up @@ -726,6 +727,7 @@ def _unpack_dict_list(mult_values, single_values):

return _unpack_dict_list(mult_values, single_values)

@with_spinner()
def calculate_batch_photometry(self, options=[], add_to_table=True, update_plots=True,
full_exceptions=False):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
</v-row>

<v-row justify="end">
<v-btn color="primary" text @click="do_aper_phot" :disabled="aperture_selected === background_selected">Calculate</v-btn>
<v-btn color="primary" text @click="do_aper_phot" :disabled="aperture_selected === background_selected || spinner">Calculate</v-btn>
</v-row>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion jdaviz/configs/imviz/plugins/catalogs/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from jdaviz.core.events import SnackbarMessage
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import (PluginTemplateMixin, ViewerSelectMixin,
FileImportSelectPluginComponent, HasFileImportSelect)
FileImportSelectPluginComponent, HasFileImportSelect,
with_spinner)

__all__ = ['Catalogs']

Expand Down Expand Up @@ -55,6 +56,7 @@ def _file_parser(path):

return '', {path: table}

@with_spinner()
def search(self):
"""
Search the catalog, display markers on the viewer, and return a table of results (or None
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/imviz/plugins/catalogs/catalogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<v-btn color="primary" text @click="do_clear">Clear</v-btn>
</v-col>
<v-col>
<v-btn color="primary" text @click="do_search">Search</v-btn>
<v-btn color="primary" text @click="do_search" :disabled="spinner">Search</v-btn>
</v-col>
</v-row>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
SelectPluginComponent,
DatasetSelect,
AddResults,
skip_if_no_updates_since_last_active)
skip_if_no_updates_since_last_active,
with_spinner)
from jdaviz.core.user_api import PluginUserApi
from jdaviz.core.custom_traitlets import IntHandleEmpty, FloatHandleEmpty
from jdaviz.core.marks import PluginLine
Expand Down Expand Up @@ -130,6 +131,7 @@ class SpectralExtraction(PluginTemplateMixin):
trace_results_label_overwrite = Bool().tag(sync=True)
trace_add_to_viewer_items = List().tag(sync=True)
trace_add_to_viewer_selected = Unicode().tag(sync=True)
trace_spinner = Bool(False).tag(sync=True)

# BACKGROUND
bg_dataset_items = List().tag(sync=True)
Expand All @@ -156,6 +158,7 @@ class SpectralExtraction(PluginTemplateMixin):
bg_results_label_overwrite = Bool().tag(sync=True)
bg_add_to_viewer_items = List().tag(sync=True)
bg_add_to_viewer_selected = Unicode().tag(sync=True)
bg_img_spinner = Bool(False).tag(sync=True)

bg_spec_results_label = Unicode().tag(sync=True)
bg_spec_results_label_default = Unicode().tag(sync=True)
Expand All @@ -164,6 +167,7 @@ class SpectralExtraction(PluginTemplateMixin):
bg_spec_results_label_overwrite = Bool().tag(sync=True)
bg_spec_add_to_viewer_items = List().tag(sync=True)
bg_spec_add_to_viewer_selected = Unicode().tag(sync=True)
bg_spec_spinner = Bool(False).tag(sync=True)

bg_sub_results_label = Unicode().tag(sync=True)
bg_sub_results_label_default = Unicode().tag(sync=True)
Expand All @@ -172,6 +176,7 @@ class SpectralExtraction(PluginTemplateMixin):
bg_sub_results_label_overwrite = Bool().tag(sync=True)
bg_sub_add_to_viewer_items = List().tag(sync=True)
bg_sub_add_to_viewer_selected = Unicode().tag(sync=True)
bg_sub_spinner = Bool(False).tag(sync=True)

# EXTRACT
ext_dataset_items = List().tag(sync=True)
Expand All @@ -195,6 +200,7 @@ class SpectralExtraction(PluginTemplateMixin):
ext_results_label_overwrite = Bool().tag(sync=True)
ext_add_to_viewer_items = List().tag(sync=True)
ext_add_to_viewer_selected = Unicode().tag(sync=True)
# uses default "spinner"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -682,6 +688,7 @@ def import_trace(self, trace):
else: # pragma: no cover
raise NotImplementedError(f"trace of type {trace.__class__.__name__} not supported")

@with_spinner('trace_spinner')
def export_trace(self, add_data=False, **kwargs):
"""
Create a specreduce Trace object from the input parameters
Expand Down Expand Up @@ -780,6 +787,7 @@ def import_bg(self, bg):

self.bg_width = bg.width

@with_spinner('bg_spinner')
def export_bg(self, **kwargs):
"""
Create a specreduce Background object from the input parameters defined in the plugin.
Expand Down Expand Up @@ -817,6 +825,7 @@ def export_bg(self, **kwargs):

return bg

@with_spinner('bg_img_spinner')
def export_bg_img(self, add_data=False, **kwargs):
"""
Create a background 2D spectrum from the input parameters defined in the plugin.
Expand All @@ -843,6 +852,7 @@ def vue_create_bg_img(self, *args):
color='error', sender=self)
)

@with_spinner('bg_spec_spinner')
def export_bg_spectrum(self, add_data=False, **kwargs):
"""
Create a background 1D spectrum from the input parameters defined in the plugin.
Expand All @@ -863,6 +873,7 @@ def export_bg_spectrum(self, add_data=False, **kwargs):
def vue_create_bg_spec(self, *args):
self.export_bg_spectrum(add_data=True)

@with_spinner('bg_sub_spinner')
def export_bg_sub(self, add_data=False, **kwargs):
"""
Create a background-subtracted 2D spectrum from the input parameters defined in the plugin.
Expand Down Expand Up @@ -936,6 +947,7 @@ def export_extract(self, **kwargs):

return ext

@with_spinner('spinner')
def export_extract_spectrum(self, add_data=False, **kwargs):
"""
Create an extracted 1D spectrum from the input parameters defined in the plugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
:add_to_viewer_selected.sync="trace_add_to_viewer_selected"
action_label="Create"
action_tooltip="Create Trace"
:action_spinner="trace_spinner"
@click:action="create_trace"
></plugin-add-results>
</v-expansion-panel-content>
Expand Down Expand Up @@ -293,6 +294,7 @@
:add_to_viewer_selected.sync="bg_add_to_viewer_selected"
action_label="Export"
action_tooltip="Create Background Image"
:action_spinner="bg_img_spinner"
@click:action="create_bg_img"
></plugin-add-results>
</v-expansion-panel-content>
Expand Down Expand Up @@ -415,6 +417,7 @@
action_label="Extract"
action_tooltip="Extract 1D Spectrum"
:action_disabled="ext_specreduce_err.length > 0"
:action_spinner="spinner"
@click:action="extract_spectrum"
></plugin-add-results>
</div>
Expand Down
Loading

0 comments on commit 5b45ba7

Please sign in to comment.