#!/usr/bin/env python3 """Controlled GTK progress fixture, with keyboard focus on a separate button.""" import sys import gi gi.require_version("Gtk", "3.0") from gi.repository import GLib, Gtk window = Gtk.Window(title="Progress probe") window.set_default_size(400, 200) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12) window.add(box) progress = Gtk.ProgressBar() progress.get_accessible().set_name("Download") box.pack_start(progress, False, False, 0) button = Gtk.Button(label="Keep focus") box.pack_start(button, False, False, 0) other = Gtk.Window(title="Other probe") other.set_default_size(400, 200) other.move(450, 0) other.add(Gtk.Entry()) window.show_all() other.show_all() window.present() button.grab_focus() def command_received(source, condition): line = sys.stdin.readline().strip() if not line: Gtk.main_quit() return False if line.startswith("hide "): progress.hide() progress.set_fraction(float(line.split()[1])) elif line == "show": progress.show() else: progress.set_fraction(float(line)) return True GLib.io_add_watch(sys.stdin, GLib.IO_IN | GLib.IO_HUP, command_received) GLib.idle_add(lambda: print("ready", flush=True)) Gtk.main()