Skip to content

Commit

Permalink
Merge pull request #465 from Carifio24/other-icon-types
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog authored Aug 16, 2024
2 parents 8434cb4 + 93005e7 commit f0a47fd
Showing 1 changed file with 10 additions and 2 deletions.
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 _on_change_active_tool(self, change):
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}")
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)
}
}

0 comments on commit f0a47fd

Please sign in to comment.