Pastery

gnome-shell-qrcode-tester.py +

 1import os 2import subprocess 3import sys 4import gi 5 6if 'QRCODE_TESTER_SELF_RUN' not in os.environ: 7    ARCH_TRIPLET = subprocess.check_output( 8        ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).decode().strip() 910    os.environ['GI_TYPELIB_PATH'] = ':'.join([11        f'/usr/lib/{ARCH_TRIPLET}/gnome-shell',12        f'/usr/lib/gnome-shell',13        f'/usr/lib/{ARCH_TRIPLET}/mutter-14',14        f'/usr/lib/{ARCH_TRIPLET}/girepository-1.0',15        os.getenv('GI_TYPELIB_PATH', ''),16    ])17    os.environ['LD_LIBRARY_PATH'] = ':'.join([18        f'/usr/lib/{ARCH_TRIPLET}/gnome-shell',19        f'/usr/lib/gnome-shell',20        f'/usr/lib/{ARCH_TRIPLET}/mutter-14',21        f'/usr/lib/{ARCH_TRIPLET}/girepository-1.0',22        os.getenv('LD_LIBRARY_PATH', ''),23    ])2425    os.environ['QRCODE_TESTER_SELF_RUN'] = "1"26    os.execv(sys.executable, [sys.executable] + sys.argv)2728gi.require_version('Shell', '14')29gi.require_version('Meta', '14')30gi.require_version('Gtk', '4.0')3132from gi.repository import Gtk, Shell, Meta3334os.environ["XDG_RUNTIME_DIR"] = "/tmp/mutter-tester"3536SIZE = 3503738image = Gtk.Image.new()3940def on_activate(app):41    win = Gtk.ApplicationWindow(application=app)42    win.set_default_size(SIZE, SIZE)43    image.set_from_icon_name('start-here')44    win.set_child(image)45    win.present()4647def on_generate_cb(generator, res):48    icon = generator.generate_qr_code_finish(res)49    print("finished", icon)50    image.set_from_gicon(icon)51    image.set_pixel_size(SIZE)5253app = Gtk.Application()54app.connect('activate', on_activate)5556ctx = Meta.create_context("tester")57ctx.set_plugin_name("libdefault")58ctx.configure([sys.argv[0], "--wayland", "--headless"])59ctx.setup()60qrcode_generator = Shell.QrCodeGenerator.new()61qrcode_generator.generate_qr_code(url="https://bugs.launchpad.net/ubuntu/+source/gnome-shell",62                                  width=SIZE, height=SIZE,63                                  callback=on_generate_cb)6465app.run(None)
New paste