File indexing completed on 2024-06-16 05:08:38

0001 #!/usr/bin/env python3
0002 
0003 # SPDX-FileCopyrightText: 2023 Fushan Wen <qydwhotmail@gmail.com>
0004 # SPDX-License-Identifier: MIT
0005 
0006 import gi
0007 
0008 gi.require_version('Gtk', '4.0')
0009 from gi.repository import GLib, Gtk
0010 
0011 
0012 class TestWindow(Gtk.ApplicationWindow):
0013 
0014     def __init__(self, _app: Gtk.Application) -> None:
0015         super().__init__(application=_app, title="Test Window")
0016 
0017         self.button = Gtk.Button(label="Active Window")
0018         self.button.connect("clicked", self.on_button_clicked)
0019         self.set_child(self.button)
0020         self.connect("notify::is-active", self.on_is_active_changed)
0021 
0022         GLib.timeout_add_seconds(60, self.close)
0023 
0024     def on_button_clicked(self, widget) -> None:
0025         self.close()
0026 
0027     def on_is_active_changed(self, instance, param) -> None:
0028         if self.is_active():
0029             self.button.set_label("Active Window")
0030         else:
0031             self.button.set_label("Inactive Window")
0032 
0033 
0034 def on_activate(_app: Gtk.Application) -> None:
0035     win = TestWindow(_app)
0036     win.present()
0037 
0038 
0039 if __name__ == "__main__":
0040     app = Gtk.Application(application_id='org.kde.testwindow')
0041     app.connect('activate', on_activate)
0042     app.run(None)