Post

skWebView

A simple program to showcase the capabilities of the WebView widget in SimpleKivy.

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
39
import SimpleKivy.SimpleKivy as sk

layout=[
    [sk.Titlebar(size="y40")],
    [sk.In(k='url',hint_text='type an url address',size='y35',enable_events=True,on_event='on_text_validate')],
    [sk.BoxitH(
        sk.FlatRoundB('SimpleKivy',k='goto:https://ergocreate.github.io/simplekivy'),
        sk.FlatRoundB('ErgoCreate',k='goto:https://github.com/ErgoCreate'),
        sk.FlatRoundB('Google',k='goto:https://google.com'),
        sk.FlatRoundB('YouTube',k='goto:https://youtube.com'),
        size='y30',
        spacing=8
        )],
    [sk.WebView(k='web')]
]

def evman(app,ev):
    if ev=='__Start__':
        def on_loaded():
            app("url",text=app.ids.web.window.get_current_url())
        app.ids.web.window.events.loaded += on_loaded
    elif ev=='url':
        new_url=app.ids.url.text
        if not new_url.startswith('http'):
            new_url='https://'+new_url
            app('url',text=new_url)
        app.ids.web.window.load_url(new_url)
    elif ev[:5]=='goto:':
        app('url',text=ev[5:])
        app.trigger_event('url')

app=sk.MyApp(
    layout=layout,
    title='SKWeb',
    event_manager=evman,
    custom_titlebar=True,
    layout_args=dict(padding=8,spacing=8)
)
app.run()

This post is licensed under CC BY 4.0 by the author.