python3-webengine-gtk3/usr/lib/python3/dist-packages/webengine/gtk3/_custom_window.py

67 lines
1.6 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
2023-09-08 16:03:09 +08:00
import gi
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
def create_same_window(origin, req):
WebEngine = type(origin)
w, h = origin.window.get_size()
win = Gtk.Window()
win.set_default_size(w, h)
web = WebEngine(win, origin)
web.set_zoom_level(origin.get_zoom_level())
web.set_settings(origin.get_settings())
web.load_request(req)
win.add(web)
win.show_all()
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('icon_path'):
win.set_icon_from_file(options['icon_path'])
if options.get('icon'):
win.set_icon_name(options['icon'])
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)
web = WebEngine(win, origin, options.get('uuid'))
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