From b715b32cb44e0115748a89372ee2a476a95de5e9 Mon Sep 17 00:00:00 2001 From: Mario Buikhuizen Date: Fri, 1 Dec 2023 19:30:42 +0100 Subject: [PATCH] fix: sub popout elements are missing styles (#2580) * fix: sub popout elements are missing styles * rename set_style_template_file to _add_style * docs updates to point to main_styles --------- Co-authored-by: Kyle Conroy --- docs/dev/ui_style_guide.rst | 2 + jdaviz/app.py | 18 +- jdaviz/app.vue | 265 +----------------- .../default/plugins/line_lists/line_lists.vue | 2 +- jdaviz/core/launcher.py | 2 +- jdaviz/core/marks.py | 2 +- jdaviz/core/template_mixin.py | 11 +- jdaviz/main_styles.vue | 262 +++++++++++++++++ jdaviz/style_registry.py | 47 ++++ 9 files changed, 335 insertions(+), 276 deletions(-) create mode 100644 jdaviz/main_styles.vue create mode 100644 jdaviz/style_registry.py diff --git a/docs/dev/ui_style_guide.rst b/docs/dev/ui_style_guide.rst index d507f70f25..e970b72da2 100644 --- a/docs/dev/ui_style_guide.rst +++ b/docs/dev/ui_style_guide.rst @@ -8,6 +8,8 @@ Tray Plugins In order to be consistent with layout, styling, and spacing, UI development on plugins should try to adhere to the following principles: +* CSS intended to be applied app-wide should live in ``main_styles.vue`` so that they are available + to all popout instances via ``PopoutStyleWrapper`` (exists on anything that inherits ``TemplateMixin``). * Any tray plugin should utilize ```` as the outer-container (which provides consistent styling rules). If the plugin makes use of active status (live-preview marks or viewer callbacks), then also pass `` :uses_active_status="uses_active_status" @plugin-ping="plugin_ping($event)"``. diff --git a/jdaviz/app.py b/jdaviz/app.py index 4117876481..92b419e3ee 100644 --- a/jdaviz/app.py +++ b/jdaviz/app.py @@ -43,13 +43,13 @@ from ipyvuetify import VuetifyTemplate from jdaviz import __version__ +from jdaviz import style_registry from jdaviz.core.config import read_configuration, get_configuration from jdaviz.core.events import (LoadDataMessage, NewViewerMessage, AddDataMessage, SnackbarMessage, RemoveDataMessage, AddDataToViewerMessage, RemoveDataFromViewerMessage, ViewerAddedMessage, ViewerRemovedMessage, ViewerRenamedMessage) -from jdaviz.core.style_widget import StyleWidget from jdaviz.core.registries import (tool_registry, tray_registry, viewer_registry, data_parser_registry) from jdaviz.core.tools import ICON_DIR @@ -154,6 +154,9 @@ def to_unit(self, data, cid, values, original_units, target_units): ipyvue.register_component_from_file('g-viewer-tab', "container.vue", __file__) +style_registry.instance.add((__file__, 'main_styles.vue')) + + class ApplicationState(State): """ The application state object contains all the current front-end state, @@ -252,6 +255,7 @@ class Application(VuetifyTemplate, HubListener): vdocs = Unicode("").tag(sync=True) docs_link = Unicode("").tag(sync=True) popout_button = Any().tag(sync=True, **widget_serialization) + style_registry_instance = Any().tag(sync=True, **widget_serialization) def __init__(self, configuration=None, *args, **kwargs): super().__init__(*args, **kwargs) @@ -259,6 +263,7 @@ def __init__(self, configuration=None, *args, **kwargs): self._verbosity = 'warning' self._history_verbosity = 'info' self.popout_button = PopoutButton(self) + self.style_registry_instance = style_registry.instance # Generate a state object for this application to maintain the state of # the user interface. @@ -407,19 +412,18 @@ def history_verbosity(self, val): raise ValueError(f'Invalid verbosity: {val}') self._history_verbosity = val - def set_style_template_file(self, path): + def _add_style(self, path): """ - Sets the path to a vue file containing a diff --git a/jdaviz/configs/default/plugins/line_lists/line_lists.vue b/jdaviz/configs/default/plugins/line_lists/line_lists.vue index ecf8a82c65..039489ab21 100644 --- a/jdaviz/configs/default/plugins/line_lists/line_lists.vue +++ b/jdaviz/configs/default/plugins/line_lists/line_lists.vue @@ -30,7 +30,7 @@ Shift spectral lines according to a specific redshift. Only enabled if at least one line is plotted. - + +export default { + created() { + this.$vuetify.theme.themes.light = { + toolbar: "#153A4B", + primary: "#00617E", + secondary: "#007DA4", + accent: "#C75109", + turquoise: "#007BA1", + lightblue: "#E3F2FD", // matches highlighted row in MOS table + spinner: "#163C4C", + error: '#FF5252', + info: '#2196F3', + success: '#4CAF50', + warning: '#FFC107', + gray: '#F8F8F8', + }; + this.$vuetify.theme.themes.dark = { + toolbar: "#153A4B", + primary: "#00617E", + secondary: "#007DA4", + accent: "#C75109", + turquoise: "#007BA1", + lightblue: "#E3F2FD", + spinner: "#ACE1FF", + error: '#FF5252', + info: '#2196F3', + success: '#4CAF50', + warning: '#FFC107', + gray: '#141414', + }; + }, +} + + + diff --git a/jdaviz/style_registry.py b/jdaviz/style_registry.py new file mode 100644 index 0000000000..ce03f2aa48 --- /dev/null +++ b/jdaviz/style_registry.py @@ -0,0 +1,47 @@ +from traitlets import Any, Dict, Instance, default +from ipywidgets import widget_serialization +from ipyvuetify import VuetifyTemplate + +from jdaviz.core.style_widget import StyleWidget + + +class StyleRegistry(VuetifyTemplate): + style_widgets = Dict(default_value={}).tag(sync=True, **widget_serialization) + + @default("template") + def _template(self): + return """ + + """ + + def add(self, path): + if hash(path) in self.style_widgets: + return + self.style_widgets = {**self.style_widgets, hash(path): StyleWidget(path)} + + +instance = StyleRegistry() + + +class PopoutStyleWrapper(VuetifyTemplate): + content = Any().tag(sync=True, **widget_serialization) + style_registry_instance = Instance( + StyleRegistry, + default_value=instance + ).tag(sync=True, **widget_serialization) + + @default("template") + def _template(self): + return """ + + """