Skip to content
This repository was archived by the owner on Sep 28, 2026. It is now read-only.
Merged
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
41 changes: 41 additions & 0 deletions demos/View Switcher/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import gi

gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1")

from gi.repository import Gtk, Adw

import workbench

notifications_page: Adw.ViewStackPage = workbench.builder.get_object("page3")
notification_list: Gtk.ListBox = workbench.builder.get_object("notification_list")

notifications_count = 5
# object.props.<property_name> can be used also instead of get and set functions
notifications_page.props.badge_number = notifications_count


def on_button_clicked(button: Gtk.Button, *_):
notifications_page.props.badge_number -= 1
notification_list.remove(button.get_ancestor(Adw.ActionRow))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

# get_ancestor method gets the most recent parent of the type provided

if notifications_page.props.badge_number == 0:
notifications_page.props.needs_attention = False


for i in range(notifications_count):
notification_row = Adw.ActionRow(title="Notification", selectable=False)

button = Gtk.Button(
halign=Gtk.Align.CENTER,
valign=Gtk.Align.CENTER,
margin_top=10,
margin_bottom=10,
icon_name="check-plain-symbolic",
)

button.connect("clicked", on_button_clicked)

notification_row.add_suffix(button)
notification_list.append(notification_row)