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

fix: resolve image urls #136

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions ovos_bus_client/apis/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,21 @@ def show_text(self, text: str, title: Optional[str] = None,
self.show_page("SYSTEM_TextFrame", override_idle,
override_animations)

def _resolve_url(self, url: str) -> str:
if not url.startswith("http") and not os.path.isfile(url):
GUI_CACHE_PATH = get_xdg_cache_save_path('ovos_gui')
gui_cache = f"{GUI_CACHE_PATH}/{self.skill_id}/{url}"
if os.path.isfile(gui_cache):
LOG.debug(f"Resolved image: {gui_cache}")
return gui_cache
else:
for framework in self.ui_directories:
gui_cache = f"{GUI_CACHE_PATH}/{self.skill_id}/{framework}/{url}"
if os.path.isfile(gui_cache):
LOG.debug(f"Resolved image: {gui_cache}")
return gui_cache
return url

JarbasAl marked this conversation as resolved.
Show resolved Hide resolved
def show_image(self, url: str, caption: Optional[str] = None,
title: Optional[str] = None,
fill: str = None, background_color: str = None,
Expand All @@ -557,6 +572,10 @@ def show_image(self, url: str, caption: Optional[str] = None,
True: Disables showing all platform skill animations.
False: 'Default' always show animations.
"""
url = self._resolve_url(url)
if not os.path.isfile(url):
LOG.error(f"Provided image file does not exist! '{url}'")
return
self["image"] = url
self["title"] = title
self["caption"] = caption
Expand Down Expand Up @@ -589,6 +608,10 @@ def show_animated_image(self, url: str, caption: Optional[str] = None,
True: Disables showing all platform skill animations.
False: 'Default' always show animations.
"""
url = self._resolve_url(url)
if not os.path.isfile(url):
LOG.error(f"Provided image file does not exist! '{url}'")
return
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved
self["image"] = url
self["title"] = title
self["caption"] = caption
Expand Down
Loading