Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library: Port 'Toasts' to Python #732

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/Library/demos/Toasts/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import gi

gi.require_version("Gtk", "4.0")
gi.require_version("GLib", "2.0")
gi.require_version("Gio", "2.0")
UrtsiSantsi marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting this error here:

image

Is this because of #110?
The rest of the demo seems to work.