Last active
July 18, 2024 21:13
-
-
Save sarcasticadmin/8f791c46c1af75261dfe844f60c3a642 to your computer and use it in GitHub Desktop.
leveraging python3 gtk and webkit with nix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} }: | |
with pkgs; | |
mkShell { | |
# Nixpkgs in include in shell | |
buildInputs = [ | |
gobject-introspection | |
python3Packages.pygobject3 | |
gtk3 | |
webkitgtk | |
glib-networking # Needed for TLS | |
]; | |
# Environment tweaks | |
shellHook = '' | |
# required for https://www.reddit.com/r/NixOS/comments/k1lt7c/comment/gdpphid/ | |
export GIO_MODULE_DIR=${glib-networking}/lib/gio/modules/ | |
# per https://github.com/tauri-apps/tauri/issues/4315#issuecomment-1207804495 | |
export WEBKIT_DISABLE_COMPOSITING_MODE=1 | |
''; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# vim:fenc=utf-8 | |
# | |
# Copyright (C) 2015-2016 Adrian Perez <[email protected]> | |
# Copyright (C) 2016 Nathan Hoad <[email protected]> | |
# | |
# Distributed under terms of the MIT license. | |
# Original src: https://github.com/aperezdc/webkit2gtk-python-webextension-example/blob/ec83c18d1926de3fcce9794b1c048102bc2f73d2/browse-with-extension | |
# | |
# The idea was for the to potentially replace the reg.py python2 gtk and webkit scripts used at SCaLE | |
# https://github.com/socallinuxexpo/scale-network/tree/d695fc5f1121b4715a0b602508e4d0fe600a8d39/pi/scripts | |
import gi | |
gi.require_version("WebKit2", "4.0") | |
from gi.repository import WebKit2, Gtk | |
from os import path | |
import sys | |
mydir = path.abspath(path.dirname(__file__)) | |
print("Extension directory:", mydir) | |
ctx = WebKit2.WebContext.get_default() | |
wnd = Gtk.Window() | |
web = WebKit2.WebView.new_with_context(ctx) | |
wnd.connect("destroy", Gtk.main_quit) | |
wnd.add(web) | |
wnd.set_default_size(1152, 800) | |
wnd.show_all() | |
def on_load_changed(webview, event): | |
if event == WebKit2.LoadEvent.FINISHED: | |
wnd.set_title(webview.get_title()) | |
else: | |
wnd.set_title("Loading... {:0.1f}%" | |
.format(webview.get_estimated_load_progress())) | |
def on_load_failed(webview, event, url, error): | |
print("Error loading", url, "-", error) | |
web.connect("load-changed", on_load_changed) | |
web.connect("load-failed", on_load_failed) | |
if len(sys.argv) > 1: | |
web.load_uri(sys.argv[1]) | |
else: | |
# Duck Duck Go | |
web.load_uri("http://ddg.gg") | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment