Skip to content

Commit

Permalink
working on ThemeManager
Browse files Browse the repository at this point in the history
  • Loading branch information
brifordwylie committed Dec 4, 2024
1 parent 9e7ea80 commit 94c847f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/sageworks/utils/theme_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,17 @@ def set_theme(self, theme_name: str):
pio.templates.default = "custom_template"

# Update current theme and log
self.current_theme = theme_name
self.current_theme = {"name": theme_name, "plotly_template": template}
self.log.info(f"Theme set to '{theme_name}'")

def get_current_theme(self) -> str:
def get_current_theme(self) -> dict:
"""Get the name of the current theme."""
return self.current_theme

def get_current_template(self) -> dict:
"""Get the current Plotly template."""
return self.current_theme["plotly_template"]

def get_current_css_files(self) -> list[str]:
"""
Get the list of CSS files for the current theme.
Expand All @@ -115,10 +119,11 @@ def get_current_css_files(self) -> list[str]:
list[str]: List of CSS files for the current theme.
"""
# Bootstrap CDN and dbc.min.css
base_css = [self.bootstrap_themes[self.current_theme], self.dbc_css]
theme_name = self.current_theme["name"]
base_css = [self.bootstrap_themes[theme_name], self.dbc_css]

# Use Flask route for custom.css if it exists
theme = self.available_themes[self.current_theme]
theme = self.available_themes[theme_name]
custom_css = ["/custom.css"] if theme["custom_css"] else []

return base_css + custom_css
Expand All @@ -130,6 +135,7 @@ def register_css_route(self, app):
Args:
app: The Dash app (to access the Flask server).
"""

@app.server.route("/custom.css")
def serve_custom_css():
theme = self.available_themes[self.current_theme]
Expand All @@ -154,4 +160,4 @@ def _reload_css(self, css_file: Path):

theme_manager.set_theme("light")
print("Theme switched to:", theme_manager.get_current_theme())
print("CSS Files for Current Theme:", theme_manager.get_current_css_files())
print("CSS Files for Current Theme:", theme_manager.get_current_css_files())

0 comments on commit 94c847f

Please sign in to comment.