From feb259a29b311e1ed2d01d7d3efd1ccb94991687 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Thu, 9 Jan 2025 09:29:02 -0500 Subject: [PATCH 1/5] POC: user-api method/attr filtering in plugin tray --- jdaviz/app.py | 1 + jdaviz/app.vue | 16 ++++++++++++++-- jdaviz/core/template_mixin.py | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/jdaviz/app.py b/jdaviz/app.py index 2b92c1747a..e738eb7e51 100644 --- a/jdaviz/app.py +++ b/jdaviz/app.py @@ -2848,6 +2848,7 @@ def compose_viewer_area(viewer_area_items): 'name': name, 'label': tray_item_label, 'tray_item_description': tray_item_description, + 'api_methods': tray_item_instance.api_methods, 'is_relevant': len(tray_item_instance.irrelevant_msg) == 0, 'widget': "IPY_MODEL_" + tray_item_instance.model_id }) diff --git a/jdaviz/app.vue b/jdaviz/app.vue index 3a529d5123..aa27ac46fa 100644 --- a/jdaviz/app.vue +++ b/jdaviz/app.vue @@ -128,6 +128,9 @@ plg = {{ config }}.plugins['{{ trayItem.label }}'] + + plg.{{ api_method }} + {{ trayItem.tray_item_description }} @@ -194,8 +197,17 @@ export default { if (tray_items_filter === null || tray_items_filter.length == 0) { return true } - // simple exact text search match on the plugin title for now. - return trayItem.label.toLowerCase().indexOf(tray_items_filter.toLowerCase()) !== -1 || trayItem.tray_item_description.toLowerCase().indexOf(tray_items_filter.toLowerCase()) !== -1 + // simple exact text search match on the plugin title/description for now. + return trayItem.label.toLowerCase().includes(tray_items_filter.toLowerCase()) || trayItem.tray_item_description.toLowerCase().includes(tray_items_filter.toLowerCase()) || this.trayItemMethodMatch(trayItem, tray_items_filter).length > 0 + }, + trayItemMethodMatch(trayItem, tray_items_filter ) { + if (tray_items_filter === null) { + return [] + } + if (tray_items_filter === '.') { + return trayItem.api_methods + } + return trayItem.api_methods.filter((item) => ("."+item.toLowerCase()).includes(tray_items_filter.toLowerCase())) }, onLayoutChange() { /* Workaround for #1677, can be removed when bqplot/bqplot#1531 is released */ diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index 5348957fcd..3036cb0225 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -419,6 +419,7 @@ class PluginTemplateMixin(TemplateMixin): previews_temp_disabled = Bool(False).tag(sync=True) # noqa use along-side @with_temp_disable() and previews_last_time = Float(0).tag(sync=True) supports_auto_update = Bool(False).tag(sync=True) # noqa whether this plugin supports auto-updating plugin results (requires __call__ method) + api_methods = List([]).tag(sync=True) # noqa list of methods exposed to the user API, searchable def __init__(self, app, tray_instance=False, **kwargs): self._plugin_name = kwargs.pop('plugin_name', None) @@ -465,6 +466,11 @@ def __init__(self, app, tray_instance=False, **kwargs): super().__init__(app=app, **kwargs) + # set user-API methods + self.api_methods = sorted([attr + for attr in self.user_api.__dir__() + if attr not in ('open_in_tray', 'show', 'api_hints_enabled', 'close_in_tray')]) + def new(self): new = self.__class__(app=self.app) new._plugin_name = self._plugin_name From 43821e935b1e7bc0373ea477ec76656a12bff9ce Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Thu, 9 Jan 2025 11:24:06 -0500 Subject: [PATCH 2/5] include open/show and stylize methods --- jdaviz/core/template_mixin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index 3036cb0225..89931ee0be 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -6,6 +6,7 @@ import bqplot from contextlib import contextmanager import numpy as np +import inspect import logging import os import threading @@ -467,9 +468,8 @@ def __init__(self, app, tray_instance=False, **kwargs): super().__init__(app=app, **kwargs) # set user-API methods - self.api_methods = sorted([attr - for attr in self.user_api.__dir__() - if attr not in ('open_in_tray', 'show', 'api_hints_enabled', 'close_in_tray')]) + self.api_methods = sorted([name+"()" if type(obj).__name__ == 'method' else name + for name, obj in inspect.getmembers(self.user_api)]) def new(self): new = self.__class__(app=self.app) From a255e76fe0a4e22e81cbe5db2c290d10355dc047 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Thu, 9 Jan 2025 11:33:38 -0500 Subject: [PATCH 3/5] include method signature --- jdaviz/core/template_mixin.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jdaviz/core/template_mixin.py b/jdaviz/core/template_mixin.py index 89931ee0be..443948effd 100644 --- a/jdaviz/core/template_mixin.py +++ b/jdaviz/core/template_mixin.py @@ -468,7 +468,11 @@ def __init__(self, app, tray_instance=False, **kwargs): super().__init__(app=app, **kwargs) # set user-API methods - self.api_methods = sorted([name+"()" if type(obj).__name__ == 'method' else name + def get_api_text(name, obj): + if type(obj).__name__ == 'method': + return f"{name}{inspect.signature(obj)}" + return name + self.api_methods = sorted([get_api_text(name, obj) for name, obj in inspect.getmembers(self.user_api)]) def new(self): From 8d5868997c95f4758d4f53dfc913fa1142e2b728 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Thu, 9 Jan 2025 11:38:48 -0500 Subject: [PATCH 4/5] changelog entry --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index ac80c8b589..7e4aa8e53b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,7 @@ New Features methods to change active selection to all table items or clear all selected items without clearing the table. [#3381] +- Plugin API methods and attributes are now searchable from the plugin tray (and visible when API hints are enabled). [#3384] Cubeviz ^^^^^^^ From 66f0914d6b13ffdb22d4a1927f68c86f381a783e Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Thu, 9 Jan 2025 16:54:15 -0500 Subject: [PATCH 5/5] force expansion arrow to stay near top --- jdaviz/main_styles.vue | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/jdaviz/main_styles.vue b/jdaviz/main_styles.vue index 4512758dfc..53eca60131 100644 --- a/jdaviz/main_styles.vue +++ b/jdaviz/main_styles.vue @@ -59,6 +59,15 @@ div.output_wrapper { padding: 0px; } +.plugin-header { + /* ensure dropdown arrow aligns to the top for tall headers */ + align-items: start !important; +} + +.plugin-header .v-expansion-panel-header__icon { + margin-top: 4px; +} + .plugin-expansion-panel-content .row { /* override -12px margins */ margin-left: 0px;