Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using non-SVG icons in toolbar #465

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions glue_jupyter/common/toolbar_vuetify.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from mimetypes import guess_type
import os
import ipyvuetify as v
import traitlets
Expand Down Expand Up @@ -70,14 +71,21 @@
def add_tool(self, tool):
self.tools[tool.tool_id] = tool
# TODO: we should ideally just incorporate this check into icon_path directly.
ext = os.path.splitext(tool.icon)[1][1:] or "svg"
if os.path.exists(tool.icon):
path = tool.icon
else:
path = icon_path(tool.icon, icon_format='svg')
path = icon_path(tool.icon, icon_format=ext)

format = guess_type(path)[0]
image_prefix = "image/"
if format is None or not format.startswith(image_prefix):
raise ValueError(f"Invalid or unknown image MIME type for: {path}")

Check warning on line 83 in glue_jupyter/common/toolbar_vuetify.py

View check run for this annotation

Codecov / codecov/patch

glue_jupyter/common/toolbar_vuetify.py#L83

Added line #L83 was not covered by tests
format = format[len(image_prefix):]
self.tools_data = {
**self.tools_data,
tool.tool_id: {
'tooltip': tool.tool_tip,
'img': read_icon(path, 'svg+xml')
'img': read_icon(path, format)
}
}