2023-09-07 19:58:17 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2023-09-08 16:03:09 +08:00
|
|
|
import gi
|
2023-09-07 19:58:17 +08:00
|
|
|
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
gi.require_version("WebKit2", "4.1")
|
2023-09-08 16:03:09 +08:00
|
|
|
from gi.repository import Gtk, WebKit2
|
2023-09-07 19:58:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
def create_same_window(origin, req):
|
2023-09-08 15:06:42 +08:00
|
|
|
WebEngine = type(origin)
|
2023-09-07 19:58:17 +08:00
|
|
|
w, h = origin.window.get_size()
|
|
|
|
win = Gtk.Window()
|
|
|
|
win.set_default_size(w, h)
|
2023-09-08 15:06:42 +08:00
|
|
|
|
|
|
|
web = WebEngine(win, origin)
|
|
|
|
web.set_zoom_level(origin.get_zoom_level())
|
|
|
|
web.set_settings(origin.get_settings())
|
2023-09-07 19:58:17 +08:00
|
|
|
web.load_request(req)
|
|
|
|
|
|
|
|
win.add(web)
|
|
|
|
win.show_all()
|
2023-09-08 15:06:42 +08:00
|
|
|
|
2023-09-07 19:58:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_custom_window(origin, options):
|
|
|
|
WebEngine = type(origin)
|
|
|
|
_w, _h = origin.window.get_size()
|
|
|
|
w = options.get('width') or _w
|
|
|
|
h = options.get('height') or _h
|
|
|
|
win = Gtk.Window()
|
|
|
|
win.set_default_size(w, h)
|
|
|
|
|
|
|
|
wmclass = options.get('wmclass') or 'WebEngine Window'
|
|
|
|
win.set_wmclass(wmclass, 'WebEngine')
|
|
|
|
win.set_title(options.get('title') or 'WebEngine')
|
|
|
|
|
|
|
|
if options.get('frame') == False:
|
|
|
|
win.set_decorated(False)
|
|
|
|
|
|
|
|
if options.get('x') is not None and options.get('y') is not None:
|
|
|
|
win.move(options.get('x'), options.get('y'))
|
|
|
|
|
|
|
|
if options.get('always_on_top') == True:
|
|
|
|
win.set_keep_above(options['always_on_top'])
|
|
|
|
|
|
|
|
if options.get('resizable') == False:
|
|
|
|
win.set_resizable(False)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-08 15:06:42 +08:00
|
|
|
|
|
|
|
web = WebEngine(win, origin)
|
2023-09-07 19:58:17 +08:00
|
|
|
web.set_root(origin.root, True)
|
|
|
|
web.set_zoom_level(origin.get_zoom_level())
|
|
|
|
web.set_settings(origin.get_settings())
|
|
|
|
web.load(options.get('url'))
|
|
|
|
|
|
|
|
win.add(web)
|
|
|
|
win.show_all()
|
|
|
|
return web
|