Skip to content

Commit

Permalink
replace ping plugin with method
Browse files Browse the repository at this point in the history
* to avoid unnecessary traitlet syncing
  • Loading branch information
kecnry committed Jul 18, 2023
1 parent 0443bbf commit 39098f0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/dev/ui_style_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Tray Plugins
In order to be consistent with layout, styling, and spacing, UI development on plugins should
try to adhere to the following principles:

* Any tray plugin should utilize ``<j-tray-plugin :uses_active_status="uses_active_status" :plugin_ping.sync="plugin_ping" :keep_active.sync="keep_active" :disabled_msg='disabled_msg' :popout_button="popout_button">`` as the
* Any tray plugin should utilize ``<j-tray-plugin :uses_active_status="uses_active_status" @plugin-ping="plugin_ping($event)" :keep_active.sync="keep_active" :disabled_msg='disabled_msg' :popout_button="popout_button">`` as the
outer-container (which provides consistent styling rules). Any changes to style
across all plugins should then take place in the
``j-tray-plugin`` stylesheet (``jdaviz/components/tray_plugin.vue``).
Expand Down
4 changes: 2 additions & 2 deletions jdaviz/components/tray_plugin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<script>
module.exports = {
props: ['disabled_msg', 'description', 'link', 'popout_button',
'uses_active_status', 'plugin_ping', 'keep_active'],
'uses_active_status', 'keep_active'],
methods: {
isDisabled() {
return this.getDisabledMsg().length > 0
Expand All @@ -43,7 +43,7 @@ module.exports = {
return
}
if (!document.hidden) {
this.$emit('update:plugin_ping', Date.now())
this.$emit('plugin-ping', Date.now())
}
if (!recursive) {
return
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/default/plugins/markers/markers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
description='Create and export markers. Press "m" with the cursor over a viewer to log the mouseover information. To change the selected layer, click the layer cycler in the mouseover information section of the app-level toolbar.'
:link="'https://jdaviz.readthedocs.io/en/'+vdocs+'/'+config+'/plugins.html#markers'"
:uses_active_status="uses_active_status"
:plugin_ping.sync="plugin_ping"
@plugin-ping="plugin_ping($event)"
:keep_active.sync="keep_active"
:popout_button="popout_button">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
description="Return statistics for a single spectral line."
:link="'https://jdaviz.readthedocs.io/en/'+vdocs+'/'+config+'/plugins.html#line-analysis'"
:uses_active_status="uses_active_status"
:plugin_ping.sync="plugin_ping"
@plugin-ping="plugin_ping($event)"
:keep_active.sync="keep_active"
:disabled_msg="disabled_msg"
:popout_button="popout_button">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
description="2D to 1D spectral extraction."
:link="'https://jdaviz.readthedocs.io/en/'+vdocs+'/'+config+'/plugins.html#spectral-extraction'"
:uses_active_status="uses_active_status"
:plugin_ping.sync="plugin_ping"
@plugin-ping="plugin_ping($event)"
:keep_active.sync="keep_active"
:popout_button="popout_button">

Expand Down
14 changes: 6 additions & 8 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from glue_jupyter.bqplot.image import BqplotImageView
from glue_jupyter.widgets.linked_dropdown import get_choices as _get_glue_choices
from specutils import Spectrum1D
from traitlets import Any, Bool, HasTraits, Integer, List, Unicode, observe
from traitlets import Any, Bool, HasTraits, List, Unicode, observe

from ipywidgets import widget_serialization
from ipypopout import PopoutButton
Expand Down Expand Up @@ -228,7 +228,6 @@ class PluginTemplateMixin(TemplateMixin):
This base class can be inherited by all sidebar/tray plugins to expose common functionality.
"""
disabled_msg = Unicode("").tag(sync=True)
plugin_ping = Integer(0).tag(sync=True)
plugin_opened = Bool(False).tag(sync=True) # noqa any instance of the plugin is open (recently sent an "alive" ping)
uses_active_status = Bool(False).tag(sync=True) # noqa whether the plugin has live-preview marks, set to True in plugins to expose keep_active switch
keep_active = Bool(False).tag(sync=True) # noqa whether the live-preview marks show regardless of active state, inapplicable unless uses_active_status is True
Expand All @@ -237,6 +236,7 @@ class PluginTemplateMixin(TemplateMixin):
def __init__(self, **kwargs):
self._viewer_callbacks = {}
self._inactive_thread = None # thread checking for alive pings to control plugin_opened
self._ping_timestamp = 0
super().__init__(**kwargs)

@property
Expand All @@ -245,11 +245,9 @@ def user_api(self):
# can even be dependent on config, etc.
return PluginUserApi(self, expose=[])

@observe('plugin_ping')
def _plugin_ping_changed(self, *args):
if self.plugin_ping == 0:
# initial traitlet state
return
def vue_plugin_ping(self, ping_timestamp):
self._ping_timestamp = ping_timestamp

# we've received a ping, so immediately set plugin_opened state to True
if not self.plugin_opened:
self.plugin_opened = True
Expand All @@ -271,7 +269,7 @@ def _watch_active(self):
expected_delay_ms = 200
# plugin_ping (ms) set by setTimeout in tray_plugin.vue
# time.time() is in s, so need to convert to ms
while time.time()*1000 - self.plugin_ping < 2 * expected_delay_ms:
while time.time()*1000 - self._ping_timestamp < 2 * expected_delay_ms:
# at least one plugin has sent an "alive" ping within twice of the expected
# interval, wait a full (double) interval and then check again
time.sleep(2 * expected_delay_ms / 1000)
Expand Down

0 comments on commit 39098f0

Please sign in to comment.