#!/usr/bin/python3
# vim:tabstop=2:softtabstop=0:shiftwidth=2:syntax=sh
#=============================================================================|
#                *** PROPRIETARY RIGHTS NOTICE ***                            |
#   This material contains proprietary information of MULI Holdings P/L,      |
#   Wahroonga, NSW, Australia and/or its licensor, embodying                  |
#   "CONFIDENTIAL INFORMATION" ideas and expressions, no part of which may    |
#   be reproduced or transmitted without permission of MULI Management P/L.   |
#      ***  COPYRIGHT  1982 - 2021  ***  MULI Holdings P/L  ***               |
#                          All rights reserved.                               |
#=============================================================================|
#=.
#=> N-000	ChaoMa	27.07.17	Initial version
#=> V15-000	BrowCh	22.03.21	add stock_id arg for tool button
#=>                         	added web_context and tls policy
#=.
#############################################################

from gi import require_version
require_version('Gtk', '3.0')
require_version('WebKit2', '4.0')

from gi.repository import Gtk
from gi.repository import WebKit2
import sys

uri = sys.argv[1]
web = WebKit2.WebView()
web_context = web.get_context()
web_context.set_tls_errors_policy(WebKit2.TLSErrorsPolicy.IGNORE)
web.load_uri(uri)
web.connect("notify::title",
            lambda view, _: window.set_title(view.get_title()))


scroller = Gtk.ScrolledWindow()
scroller.add(web)

back_button = Gtk.ToolButton(stock_id=Gtk.STOCK_GO_BACK)
back_button.connect("clicked", lambda _: web.go_back())

forward_button = Gtk.ToolButton(stock_id=Gtk.STOCK_GO_FORWARD)
forward_button.connect("clicked", lambda _: web.go_forward())

hbox = Gtk.HBox()
hbox.pack_start(back_button, False, True, 0)
hbox.pack_start(forward_button, False, True, 0)

vbox = Gtk.VBox()
vbox.pack_start(hbox, False, True, 0)
vbox.pack_start(scroller, True, True, 0)

window = Gtk.Window()
window.set_default_size(1400, 900)
window.set_position(Gtk.WindowPosition.CENTER)
window.connect("destroy", lambda _: Gtk.main_quit())
window.add(vbox)

window.show_all()
Gtk.main()
