#!/usr/bin/env python3 import gi gi.require_version('Gtk', '3.0') gi.require_version("WebKit2", "4.1") 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