Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/webkit_load_status.py
blob: 1d6649f432d57979936300007fcf67345cf1efc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from gi.repository import Gtk
from gi.repository import WebKit
from gi.repository import GObject


class MyWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="WebKit load-status FAILED")
        self.set_default_size(1000, 500)
        self.connect("delete-event", Gtk.main_quit)

        webview = WebKit.WebView()
        webview.connect('notify::load-status', self.__load_status_changed_cb)
        webview.connect('load-error', self.__load_error_cb)
        webview.load_uri('http://www.google.com')

        self.add(webview)
        self.show_all()

    def __load_error_cb(self, web_view, web_frame, uri, web_error):
        print '### WEB_ERROR_CODE:', web_error.code

    def __load_status_changed_cb(self, widget, param):
        status = widget.get_load_status()
        if status is WebKit.LoadStatus.COMMITTED:
            GObject.timeout_add(40, self.__stop_loading, widget)
        print '### STATUS:', status
        print '### URI:', widget.props.uri

    def __stop_loading(self, webview):
        print 'WebKit.WebView.stop_loading'
        webview.stop_loading()


if __name__ == '__main__':
    win = MyWindow()
    Gtk.main()