Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Can't get the WebView delegate methods to work (SOLVED)
-
I'm trying to do something when a webpage has finished loading, but it doesn't seem to work.
import ui, sound class MyWebViewDelegate (object): def webview_did_finish_load(webview): sound.play_effect('Ding_3') w = ui.WebView() w.frame = (0, 0, ui.get_screen_size()[0], ui.get_screen_size()[1]) w.delegate = MyWebViewDelegate() w.load_url('http://www.google.com') w.present()
Any ideas?
-
Sorry about this, the documentation is wrong. The first parameter of every method should be
self
. So your delegate class should look like this:class MyWebViewDelegate (object): def webview_did_finish_load(self, webview): sound.play_effect('Ding_3')
-
Thanks for clearing that up @omz! :) <br>
I should have understood that though :P -
Just curious..I was playing with this snippet and I find that some webpages call webview_did_finish_load more than once. How does this method determine that the load is finished and why do some webpages (e.g., https://twitter.com) trigger it more than once?
-
@ihf This is related to embedded iframes. Unfortunately, I forgot to implement a
loading
attribute that would allow you to check whether the view is still loading, so there's currently no way to work around this... -
Noted that it is a year later, and the documentation is still wrong.