-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmini_browser.py
More file actions
65 lines (53 loc) · 1.82 KB
/
Copy pathmini_browser.py
File metadata and controls
65 lines (53 loc) · 1.82 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import toga
from toga.constants import CENTER, COLUMN, ROW
from toga.validators import StartsWith
class Graze(toga.App):
def startup(self):
self.main_window = toga.MainWindow()
self.webview = toga.WebView(on_webview_load=self.on_webview_loaded, flex=1)
self.url_input = toga.TextInput(
value="https://beeware.org/",
on_confirm=self.load_page,
flex=1,
validators=[StartsWith("http://"), StartsWith("https://")],
)
box = toga.Box(
children=[
toga.Box(
children=[
self.url_input,
toga.Button(
"Go",
on_press=self.load_page,
width=50,
margin_left=5,
),
],
direction=ROW,
align_items=CENTER,
margin=5,
),
self.webview,
],
direction=COLUMN,
)
self.main_window.content = box
self.webview.url = self.url_input.value
# Show the main window
self.main_window.show()
async def load_page(self, widget):
if self.url_input.is_valid:
self.webview.url = self.url_input.value
else:
await self.main_window.dialog(
toga.ErrorDialog(
"Invalid URL",
"Please enter a URL that starts with http:// or https:// and try again.",
)
)
def on_webview_loaded(self, widget):
self.url_input.value = self.webview.url
def main():
return Graze("Graze", "org.beeware.toga.examples.tutorial")
if __name__ == "__main__":
main().main_loop()