From 2781aace787f000fbd5d07d55c402c39c89d8dba Mon Sep 17 00:00:00 2001 From: Urtsi Santsi Date: Mon, 30 Oct 2023 10:29:08 +0200 Subject: [PATCH 1/2] Library: Port 'Toasts' to Python --- src/Library/demos/Toasts/main.py | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/Library/demos/Toasts/main.py diff --git a/src/Library/demos/Toasts/main.py b/src/Library/demos/Toasts/main.py new file mode 100644 index 000000000..6bfcfb8dc --- /dev/null +++ b/src/Library/demos/Toasts/main.py @@ -0,0 +1,54 @@ +import gi + +gi.require_version("Gtk", "4.0") +gi.require_version("GLib", "2.0") +gi.require_version("Gio", "2.0") +gi.require_version("Adw", "1") +from gi.repository import Gtk, GLib, Gio, Adw +import workbench + +overlay: Adw.ToastOverlay = workbench.builder.get_object("overlay") + +button_simple: Gtk.Button = workbench.builder.get_object("button_simple") + + +def simple(_): + toast = Adw.Toast( + title="Toasts are delicious!", + timeout=1, + ) + toast.connect("dismissed", lambda _: button_simple.set_sensitive(True)) + overlay.add_toast(toast) + button_simple.set_sensitive(False) + + +button_simple.connect("clicked", simple) + + +def advanced(_): + message_id = "42" + toast = Adw.Toast( + title="Message sent", + button_label="Undo", + action_name="win.undo", + action_target=GLib.Variant.new_string(message_id), + priority=Adw.ToastPriority.HIGH, + ) + overlay.add_toast(toast) + + +workbench.builder.get_object("button_advanced").connect("clicked", advanced) + +action_console = Gio.SimpleAction( + name="undo", + parameter_type=GLib.VariantType("s"), +) + + +def on_activate(_self, target): + value = target.unpack() + print(f"undo ${value}") + + +action_console.connect("activate", on_activate) +workbench.window.add_action(action_console) From ff83cc0ead432952c3bc16f889e122f29bfea333 Mon Sep 17 00:00:00 2001 From: Urtsi Santsi Date: Sat, 4 Nov 2023 00:43:07 +0200 Subject: [PATCH 2/2] Remove redundant 'requre_version' --- src/Library/demos/Toasts/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Library/demos/Toasts/main.py b/src/Library/demos/Toasts/main.py index 6bfcfb8dc..476df08dd 100644 --- a/src/Library/demos/Toasts/main.py +++ b/src/Library/demos/Toasts/main.py @@ -1,8 +1,6 @@ import gi gi.require_version("Gtk", "4.0") -gi.require_version("GLib", "2.0") -gi.require_version("Gio", "2.0") gi.require_version("Adw", "1") from gi.repository import Gtk, GLib, Gio, Adw import workbench