Forum Archive

How to load a local .gif into ui.webview()?

donnieh

I want to use aui.webview()to show an image instead of using aui.imageview()(for the purposes of playing .gif animations).

How do you open the .gif if it is not a url but a local file? Do I useWebView.load_html(html)?

omz

You can construct a file:// URL from the image path, and load it using load_url:

import urlparse
import urllib
import os
import ui

# Change this:
img_path = os.path.abspath('Examples/Misc/animation.gif')

img_url = urlparse.urljoin('file:', urllib.pathname2url(img_path))

webview = ui.WebView()
webview.load_url(img_url)
webview.present()
donnieh

Thank you @omz . That was very helpful.

JonB

You actually don't need file://, if you use os.abspath

w.load_url(os.path.abspath('a.gif'))