-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb-browser
More file actions
executable file
·49 lines (42 loc) · 1.46 KB
/
Copy pathweb-browser
File metadata and controls
executable file
·49 lines (42 loc) · 1.46 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
#! /usr/bin/python3
"""Basic web browser using Pywebview"""
from venv_tool import activate
activate(dist_packages=True)
from argparse import ArgumentParser, RawDescriptionHelpFormatter
import webview
import webview.menu as wm
parser = ArgumentParser(
description = __doc__,
formatter_class = RawDescriptionHelpFormatter,
)
parser.add_argument("--gui-toolkit", default="qt", help="Select gtk or qt (defaults to qt)")
parser.add_argument("--width", type=int, default=1200, help="Set window width")
parser.add_argument("--height", type=int, default=900, help="Set window height")
parser.add_argument("--x", type=int, default=None, help="Set window X coordinate")
parser.add_argument("--y", type=int, default=None, help="Set window Y coordinate")
parser.add_argument("--debug", action="store_true", help="Enabling devtools, verbose logging")
parser.add_argument("url", help="URL of site to open")
options = parser.parse_args()
print("options:", options)
window = webview.create_window(
title = "Web Browser",
url = options.url,
width = options.width,
height = options.height,
x = options.x,
y = options.y,
)
def on_loaded(window):
window.title = window.dom.get_elements("title")[0].text
window.events.loaded += on_loaded
menu = (
wm.Menu("Navigation", [
wm.MenuAction("Back", lambda: window.run_js("history.back()")),
wm.MenuAction("Forward", lambda: window.run_js("history.forward()")),
]),
)
webview.start(
debug = options.debug,
gui = options.gui_toolkit,
menu = menu,
)