-
-
Notifications
You must be signed in to change notification settings - Fork 90
library: Port Actions demo to Python #717
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link isn't specific to
Actions- it doesn't belong here.I will move it to the bookmarks menu. If there is PyGObject specific documentation for actions - let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Not really, just the API docs.