Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions src/Library/demos/Actions/main.blp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ Adw.StatusPage demo {
uri: "https://gjs.guide/guides/gio/actions-and-menus.html";
}

LinkButton {
label: _("PyGObjects Documentation");
uri: "https://pygobject.readthedocs.io";
}

LinkButton {
label: _("GTK Documentation");
uri: "https://docs.gtk.org/gtk4/actions.html";
Expand Down
79 changes: 79 additions & 0 deletions src/Library/demos/Actions/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import gi

gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1")
from gi.repository import Gtk, Adw, GLib, Gio
import workbench

demo: Adw.StatusPage = workbench.builder.get_object("demo")

demo_group = Gio.SimpleActionGroup()
demo.insert_action_group("demo", demo_group)

# Action with no state or parameters
simple_action = Gio.SimpleAction(name="simple")

simple_action.connect(
"activate", lambda action, _: print(
f"{action.get_name()} action activated"
),
)

demo_group.add_action(simple_action)

# Action with parameter
bookmarks_action = Gio.SimpleAction(
name="open-bookmarks",
parameter_type=GLib.VariantType("s"),
)

bookmarks_action.connect(
"activate",
lambda action, parameter: print(
f"{action.get_name()} activated with {parameter.unpack()}"
),
)

demo_group.add_action(bookmarks_action)

# Action with state
toggle_action = Gio.SimpleAction(
name="toggle",
# Boolean actions dont need parameters for activation
state=GLib.Variant.new_boolean(False),
)

toggle_action.connect(
"notify::state",
lambda action, _: print(
f"{action.get_name()} action set to {action.get_state().unpack()}"
),
)

demo_group.add_action(toggle_action)

# Action with state and parameter
scale_action = Gio.SimpleAction(
name="scale",
state=GLib.Variant.new_string("100%"),
parameter_type=GLib.VariantType("s"),
)

scale_action.connect(
"notify::state",
lambda action, _: print(
f"{action.get_name()} action set to {action.get_state().unpack()}"
),
)

demo_group.add_action(scale_action)

text: Gtk.Label = workbench.builder.get_object("text")

alignment_action = Gio.PropertyAction(
name="text-align",
object=text,
property_name="halign",
)

demo_group.add_action(alignment_action)
1 change: 1 addition & 0 deletions src/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ ${getBlueprintVersion()}
"Onkar https://github.com/onkarrai06",
"Sabrina Meindlhumer https://github.com/m-sabrina",
"Urtsi Santsi <[email protected]>",
"Roland Lötscher https://github.com/rolandlo",
// Add yourself as
// "John Doe",
// or
Expand Down