Classes de estilo#

Background#

Adw style class background

Adw style class background#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe background."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe background',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.button = Gtk.Button.new_with_label(label='Lorem Ipsum')
        self.button.add_css_class(css_class='background')
        vbox.append(child=self.button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'background' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='background')
        else:
            self.button.add_css_class(css_class='background')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class background."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    button = Gtk.Template.Child(name='button')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'background' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='background')
        else:
            self.button.add_css_class(css_class='background')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs background</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkButton" id="button">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="background"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs background';
  default-width: 683;
  default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
        [end]
        MenuButton {
          icon-name: 'open-menu-symbolic';
          menu-model: primary_menu;
        }
      }
      content:
      Box {
        orientation: vertical;
        margin-top: 12;
        margin-end: 12;
        margin-bottom: 12;
        margin-start: 12;
        spacing: 12;

        Button button {
          label: 'Lorem Ipsum';
          styles [
            'background',
          ]
        }

        Button {
          label: 'Add/Remove class';
          vexpand: true;
          valign: end;
          clicked => $on_button_clicked();
        }
      }

      ;
    }

    ;
  }
      ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Body#

Adw style class body

Adw style class body#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe body."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe body',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.label = Gtk.Label.new(str='Lorem Ipsum')
        self.label.add_css_class(css_class='title-1')
        vbox.append(child=self.label)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'body' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='body')
        else:
            self.label.add_css_class(css_class='body')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class body."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    label = Gtk.Template.Child(name='label')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'body' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='body')
        else:
            self.label.add_css_class(css_class='body')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs body</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <child>
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="title-1"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </child>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs body';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label label {
        label: 'Lorem Ipsum';
        styles [
          'title-1',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
}
menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
  ;
}

Boxed-list#

Adw style class boxed-list

Adw style class boxed-list#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class boxed-list."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe boxed-list',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.list_box = Gtk.ListBox.new()
        self.list_box.set_selection_mode(mode=Gtk.SelectionMode.NONE)
        self.list_box.add_css_class(css_class='boxed-list')
        vbox.append(child=self.list_box)

        for _ in range(2):
            adw_action_row = Adw.ActionRow.new()
            adw_action_row.set_title(title='Lorem Ipsum')
            self.list_box.append(child=adw_action_row)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'boxed-list' in self.list_box.get_css_classes():
            self.list_box.remove_css_class(css_class='boxed-list')
        else:
            self.list_box.add_css_class(css_class='boxed-list')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class boxed-list."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    list_box = Gtk.Template.Child(name='list_box')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'boxed-list' in self.list_box.get_css_classes():
            self.list_box.remove_css_class(css_class='boxed-list')
        else:
            self.list_box.add_css_class(css_class='boxed-list')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs boxed-list</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkListBox" id="list_box">
                    <property name="selection-mode">0</property>
                    <style>
                      <class name="boxed-list"/>
                    </style>
                    <child>
                      <object class="AdwActionRow">
                        <property name="title">Lorem Ipsum</property>
                      </object>
                    </child>
                    <child>
                      <object class="AdwActionRow">
                        <property name="title">Lorem Ipsum</property>
                      </object>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs boxed-list';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Gtk.ListBox list_box {
        selection-mode: none;
        styles [
            'boxed-list',
        ]

        Adw.ActionRow {
          title: 'Lorem Ipsum';
        }

        Adw.ActionRow {
          title: 'Lorem Ipsum';
        }
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}
menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Caption#

Adw style class caption

Adw style class caption#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe caption."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe caption',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.label = Gtk.Label.new(str='Lorem Ipsum')
        self.label.add_css_class(css_class='caption')
        vbox.append(child=self.label)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'caption' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='caption')
        else:
            self.label.add_css_class(css_class='caption')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class caption."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    label = Gtk.Template.Child(name='label')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'caption' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='caption')
        else:
            self.label.add_css_class(css_class='caption')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs caption</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="caption"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs caption';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label label {
        label: 'Lorem Ipsum';
        styles [
          'caption',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}
menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Caption-heading#

Adw style class caption-heading

Adw style class caption-heading#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe caption-heading."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe caption-heading',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.label = Gtk.Label.new(str='Lorem Ipsum')
        self.label.add_css_class(css_class='caption-heading')
        vbox.append(child=self.label)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'caption-heading' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='caption-heading')
        else:
            self.label.add_css_class(css_class='caption-heading')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class caption-heading."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    label = Gtk.Template.Child(name='label')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'caption-heading' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='caption-heading')
        else:
            self.label.add_css_class(css_class='caption-heading')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs caption-heading</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="caption-heading"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs caption-heading';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label label {
        label: 'Lorem Ipsum';
        styles [
          'caption-heading',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Card#

Adw style class card

Adw style class card#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe card."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe card',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_homogeneous(homogeneous=True)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.label = Gtk.Label.new(str='Lorem Ipsum')
        self.label.add_css_class(css_class='card')
        vbox.append(child=self.label)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'card' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='card')
        else:
            self.label.add_css_class(css_class='card')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class card."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    label = Gtk.Template.Child(name='label')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'card' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='card')
        else:
            self.label.add_css_class(css_class='card')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs card</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="homogeneous">true</property>
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="card"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs card';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      homogeneous: true;
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label label {
        label: 'Lorem Ipsum';
        styles [
          'card',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}
menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Circular#

Adw style class circular

Adw style class circular#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe circular."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe circular',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.button = Gtk.Button.new_from_icon_name(
            icon_name='face-smile-big-symbolic',
        )
        self.button.set_halign(align=Gtk.Align.CENTER)
        self.button.set_hexpand(expand=False)
        self.button.add_css_class(css_class='circular')
        vbox.append(child=self.button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'circular' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='circular')
        else:
            self.button.add_css_class(css_class='circular')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class circular."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    button = Gtk.Template.Child(name='button')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'circular' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='circular')
        else:
            self.button.add_css_class(css_class='circular')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs circular</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkButton" id="button">
                    <property name="icon-name">face-smile-big-symbolic</property>
                    <property name="halign">3</property>
                    <property name="hexpand">false</property>
                    <style>
                      <class name="circular"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs circular';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Button button {
        icon-name: 'face-smile-big-symbolic';
        halign: center;
        hexpand: false;
        styles [
          'circular',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Colors#

Adw style class colors

Adw style class colors#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe colors."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe colors',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.label_accent = Gtk.Label.new(str='Lorem Ipsum')
        self.label_accent.add_css_class(css_class='accent')
        vbox.append(child=self.label_accent)

        self.label_success = Gtk.Label.new(str='Lorem Ipsum')
        self.label_success.add_css_class(css_class='success')
        vbox.append(child=self.label_success)

        self.label_warning = Gtk.Label.new(str='Lorem Ipsum')
        self.label_warning.add_css_class(css_class='warning')
        vbox.append(child=self.label_warning)

        self.label_error = Gtk.Label.new(str='Lorem Ipsum')
        self.label_error.add_css_class(css_class='error')
        vbox.append(child=self.label_error)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'accent' in self.label_accent.get_css_classes():
            self.label_accent.remove_css_class(css_class='accent')
            self.label_success.remove_css_class(css_class='success')
            self.label_warning.remove_css_class(css_class='warning')
            self.label_error.remove_css_class(css_class='error')

        else:
            self.label_accent.add_css_class(css_class='accent')
            self.label_success.add_css_class(css_class='success')
            self.label_warning.add_css_class(css_class='warning')
            self.label_error.add_css_class(css_class='error')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class colors."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    label_accent = Gtk.Template.Child(name='label_accent')
    label_success = Gtk.Template.Child(name='label_success')
    label_warning = Gtk.Template.Child(name='label_warning')
    label_error = Gtk.Template.Child(name='label_error')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'accent' in self.label_accent.get_css_classes():
            self.label_accent.remove_css_class(css_class='accent')
            self.label_success.remove_css_class(css_class='success')
            self.label_warning.remove_css_class(css_class='warning')
            self.label_error.remove_css_class(css_class='error')

        else:
            self.label_accent.add_css_class(css_class='accent')
            self.label_success.add_css_class(css_class='success')
            self.label_warning.add_css_class(css_class='warning')
            self.label_error.add_css_class(css_class='error')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs colors</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label_accent">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="accent"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkLabel" id="label_success">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="success"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkLabel" id="label_warning">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="warning"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkLabel" id="label_error">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="error"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs colors';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label label_accent {
        label: 'Lorem Ipsum';
        styles [
          'accent',
        ]
      }

      Label label_success {
        label: 'Lorem Ipsum';
        styles [
          'success',
        ]
      }

      Label label_warning {
        label: 'Lorem Ipsum';
        styles [
          'warning',
        ]
      }

      Label label_error {
        label: 'Lorem Ipsum';
        styles [
          'error',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Compact#

Adw style class compact

Adw style class compact#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe compact."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe compact',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.status_page = Adw.StatusPage.new()
        self.status_page.set_description(description='Lorem Ipsum.')
        self.status_page.set_icon_name(icon_name='face-smile-big-symbolic')
        self.status_page.set_title(title='Lorem Ipsum.')
        self.status_page.add_css_class(css_class='compact')
        vbox.append(child=self.status_page)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'compact' in self.status_page.get_css_classes():
            self.status_page.remove_css_class(css_class='compact')
        else:
            self.status_page.add_css_class(css_class='compact')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class compact."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    status_page = Gtk.Template.Child(name='status_page')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'compact' in self.status_page.get_css_classes():
            self.status_page.remove_css_class(css_class='compact')
        else:
            self.status_page.add_css_class(css_class='compact')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs compact</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="AdwStatusPage" id="status_page">
                    <property name="description">Lorem Ipsum.</property>
                    <property name="icon-name">face-smile-big-symbolic</property>
                    <property name="title">Lorem Ipsum.</property>
                    <style>
                      <class name="compact"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs compact';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Adw.StatusPage status_page {
        description: 'Lorem Ipsum.';
        icon-name: 'face-smile-big-symbolic';
        title: 'Lorem Ipsum.';
        styles [
          'compact',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Destructive-action#

Adw style class destructive-action

Adw style class destructive-action#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe destructive-action."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe destructive-action',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.button = Gtk.Button.new_with_label(label='Lorem Ipsum')
        self.button.add_css_class(css_class='destructive-action')
        vbox.append(child=self.button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'destructive-action' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='destructive-action')
        else:
            self.button.add_css_class(css_class='destructive-action')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class destructive-action."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    button = Gtk.Template.Child(name='button')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'destructive-action' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='destructive-action')
        else:
            self.button.add_css_class(css_class='destructive-action')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs destructive-action</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkButton" id="button">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="destructive-action"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs destructive-action';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Button button {
        label: 'Lorem Ipsum';
        styles [
          'destructive-action',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Devel#

Adw style class devel

Adw style class devel#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe devel."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe devel',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))
        self.add_css_class(css_class='devel')

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        self.adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=self.adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        self.adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        label = Gtk.Label.new(str='Lorem Ipsum')
        vbox.append(child=label)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'devel' in self.get_css_classes():
            self.remove_css_class(css_class='devel')
        else:
            self.add_css_class(css_class='devel')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class devel."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'devel' in self.get_css_classes():
            self.remove_css_class(css_class='devel')
        else:
            self.add_css_class(css_class='devel')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs devel</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <style>
      <class name="devel"/>
    </style>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel">
                    <property name="label">Lorem Ipsum</property>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs devel';
  default-width: 683;
  default-height: 384;
  styles [
    'devel',
  ]

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label {
        label: 'Lorem Ipsum';
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Dim-label#

Adw style class dim-label

Adw style class dim-label#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe dim-label."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe dim-label',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.label = Gtk.Label.new(str='Lorem Ipsum')
        self.label.add_css_class(css_class='dim-label')
        vbox.append(child=self.label)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'dim-label' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='dim-label')
        else:
            self.label.add_css_class(css_class='dim-label')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class dim-label."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    label = Gtk.Template.Child(name='label')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'dim-label' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='dim-label')
        else:
            self.label.add_css_class(css_class='dim-label')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs dim-label</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="dim-label"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs dim-label';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label label {
        label: 'Lorem Ipsum';
        styles [
          'dim-label',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Flat#

Adw style class flat

Adw style class flat#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe flat."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe flat',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.button = Gtk.Button.new_with_label(label='Lorem Ipsum')
        self.button.add_css_class(css_class='flat')
        vbox.append(child=self.button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'flat' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='flat')
        else:
            self.button.add_css_class(css_class='flat')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class flat."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    button = Gtk.Template.Child(name='button')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'flat' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='flat')
        else:
            self.button.add_css_class(css_class='flat')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs flat</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkButton" id="button">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="flat"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs flat';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Button button {
        label: 'Lorem Ipsum';
        styles [
          'flat',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Frame#

Adw style class frame

Adw style class frame#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe frame."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe frame',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.label = Gtk.Label.new(str='Lorem Ipsum')
        self.label.add_css_class(css_class='frame')
        vbox.append(child=self.label)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'frame' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='frame')
        else:
            self.label.add_css_class(css_class='frame')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class frame."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    label = Gtk.Template.Child(name='label')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'frame' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='frame')
        else:
            self.label.add_css_class(css_class='frame')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs frame</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="frame"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs frame';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label label {
        label: 'Lorem Ipsum';
        styles [
          'frame',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Heading#

Adw style class heading

Adw style class heading#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe heading."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe heading',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.label = Gtk.Label.new(str='Lorem Ipsum')
        self.label.add_css_class(css_class='heading')
        vbox.append(child=self.label)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'heading' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='heading')
        else:
            self.label.add_css_class(css_class='heading')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class heading."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    label = Gtk.Template.Child(name='label')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'heading' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='heading')
        else:
            self.label.add_css_class(css_class='heading')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs heading</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="heading"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs heading';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label label {
        label: 'Lorem Ipsum';
        styles [
          'heading',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Icon-dropshadow#

Adw style class icon-dropshadow

Adw style class icon-dropshadow#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe icon-dropshadow."""

import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


ICON = BASE_DIR.parent.parent.joinpath(
    'data', 'icons', 'icon-128x128.svg',
)


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe icon-dropshadow',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.image = Gtk.Image.new_from_file(filename=str(ICON))
        self.image.add_css_class(css_class='lowres-icon')
        vbox.append(child=self.image)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'icon-dropshadow' in self.image.get_css_classes():
            self.image.remove_css_class(css_class='icon-dropshadow')
        else:
            self.image.add_css_class(css_class='icon-dropshadow')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class icon-dropshadow."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')
ICON = BASE_DIR.parent.parent.parent.joinpath(
    'data', 'icons', 'icon-128x128.svg',
)








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    image = Gtk.Template.Child(name='image')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.image.set_from_file(filename=str(ICON))

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'icon-dropshadow' in self.image.get_css_classes():
            self.image.remove_css_class(css_class='icon-dropshadow')
        else:
            self.image.add_css_class(css_class='icon-dropshadow')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs icon-dropshadow</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkImage" id="image">
                    <style>
                      <class name="icon-dropshadow"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs icon-dropshadow';
  default-width: 683;
  default-height: 384;
  content: Adw.ToastOverlay {
    child: Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
        [end]
        MenuButton {
          icon-name: 'open-menu-symbolic';
          menu-model: primary_menu;
        }
      }
      content: Gtk.Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Image image {
        styles [
          'icon-dropshadow',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Inline#

Adw style class inline

Adw style class inline#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe inline."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe inline',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        toggle_button = Gtk.ToggleButton.new()
        toggle_button.set_icon_name(icon_name='system-search-symbolic')
        toggle_button.connect('toggled', self.on_button_search_clicked)
        adw_header_bar.pack_start(child=toggle_button)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        search_entry = Gtk.SearchEntry.new()
        search_entry.set_placeholder_text(text='Lorem Ipsum')
        search_entry.connect('search_changed', self.on_search_entry_changed)

        self.search_bar = Gtk.SearchBar.new()
        self.search_bar.connect_entry(entry=search_entry)
        self.search_bar.set_child(child=search_entry)
        self.search_bar.add_css_class(css_class='inline')
        vbox.append(child=self.search_bar)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_search_clicked(self, toggle_button):
        if self.search_bar.get_search_mode():
            self.search_bar.set_search_mode(search_mode=False)
        else:
            self.search_bar.set_search_mode(search_mode=True)

    def on_search_entry_changed(self, search_entry):
        print(search_entry.get_text())

    def on_button_clicked(self, button):
        if 'inline' in self.search_bar.get_css_classes():
            self.search_bar.remove_css_class(css_class='inline')
        else:
            self.search_bar.add_css_class(css_class='inline')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class inline."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    search_bar = Gtk.Template.Child(name='search_bar')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_search_clicked(self, toggle_button):
        if self.search_bar.get_search_mode():
            self.search_bar.set_search_mode(search_mode=False)
        else:
            self.search_bar.set_search_mode(search_mode=True)

    @Gtk.Template.Callback()
    def on_search_entry_changed(self, search_entry):
        print(search_entry.get_text())

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'inline' in self.search_bar.get_css_classes():
            self.search_bar.remove_css_class(css_class='inline')
        else:
            self.search_bar.add_css_class(css_class='inline')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs inline</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="start">
                  <object class="GtkToggleButton">
                    <property name="icon-name">system-search-symbolic</property>
                    <signal name="toggled" handler="on_button_search_clicked"/>
                  </object>
                </child>
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkSearchBar" id="search_bar">
                    <style>
                      <class name="inline"/>
                    </style>
                    <property name="child">
                      <object class="GtkSearchEntry">
                        <property name="activates-default">true</property>
                        <property name="placeholder-text">Lorem Ipsum</property>
                        <signal name="search-changed" handler="on_search_entry_changed"/>
                      </object>
                    </property>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs inline';
  default-width: 683;
  default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
        [start]
        ToggleButton {
          icon-name: 'system-search-symbolic';
          toggled => $on_button_search_clicked();
        }

        [end]
        MenuButton {
          icon-name: 'open-menu-symbolic';
          menu-model: primary_menu;
        }
      }
      content:
      Box {
        orientation: vertical;
        margin-top: 12;
        margin-end: 12;
        margin-bottom: 12;
        margin-start: 12;
        spacing: 12;

        SearchBar search_bar {
          styles [
            'inline',
          ]
          child:
            SearchEntry {
              activates-default: true;
              placeholder-text: 'Lorem Ipsum';
              search-changed => $on_search_entry_changed();
            }

            ;
        }

        Button {
          label: 'Add/Remove class';
          vexpand: true;
          valign: end;
          clicked => $on_button_clicked();
        }
      }

      ;
    }

    ;
  }

  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Linked#

Adw style class linked

Adw style class linked#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe linked."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe linked',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.hbox = Gtk.Box.new(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
        self.hbox.add_css_class(css_class='linked')
        vbox.append(child=self.hbox)

        for _ in range(3):
            button = Gtk.Button.new_with_label(label='Lorem Ipsum')
            self.hbox.append(child=button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'linked' in self.hbox.get_css_classes():
            self.hbox.remove_css_class(css_class='linked')
        else:
            self.hbox.add_css_class(css_class='linked')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class linked."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    hbox = Gtk.Template.Child(name='hbox')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'linked' in self.hbox.get_css_classes():
            self.hbox.remove_css_class(css_class='linked')
        else:
            self.hbox.add_css_class(css_class='linked')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs linked</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkBox" id="hbox">
                    <property name="orientation">0</property>
                    <property name="spacing">0</property>
                    <style>
                      <class name="linked"/>
                    </style>
                    <child>
                      <object class="GtkButton">
                        <property name="label">Lorem Ipsum</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkButton">
                        <property name="label">Lorem Ipsum</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkButton">
                        <property name="label">Lorem Ipsum</property>
                      </object>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs linked';
  default-width: 683;
  default-height: 384;
  content: Adw.ToastOverlay {
    child: Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
        [end]
        MenuButton {
          icon-name: 'open-menu-symbolic';
          menu-model: primary_menu;
        }
      }
      content: Gtk.Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Box hbox{
        orientation: horizontal;
        spacing: 0;
        styles [
          'linked',
        ]

        Button {
          label: 'Lorem Ipsum';
        }

        Button {
          label: 'Lorem Ipsum';
        }

        Button {
          label: 'Lorem Ipsum';
        }
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Lowres-icon#

Adw style class lowres-icon

Adw style class lowres-icon#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe lowres-icon."""

import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


ICON = BASE_DIR.parent.parent.joinpath(
    'data', 'icons', 'icon-32x32.svg',
)


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe lowres-icon',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.image = Gtk.Image.new_from_file(filename=str(ICON))
        self.image.add_css_class(css_class='lowres-icon')
        vbox.append(child=self.image)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'lowres-icon' in self.image.get_css_classes():
            self.image.remove_css_class(css_class='lowres-icon')
        else:
            self.image.add_css_class(css_class='lowres-icon')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class lowres-icon."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')
ICON = BASE_DIR.parent.parent.parent.joinpath(
    'data', 'icons', 'icon-128x128.svg',
)








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    image = Gtk.Template.Child(name='image')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.image.set_from_file(filename=str(ICON))

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'lowres-icon' in self.image.get_css_classes():
            self.image.remove_css_class(css_class='lowres-icon')
        else:
            self.image.add_css_class(css_class='lowres-icon')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs lowres-icon</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkImage" id="image">
                    <style>
                      <class name="lowres-icon"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs lowres-icon';
  default-width: 683;
  default-height: 384;
  content: Adw.ToastOverlay {
    child: Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
        [end]
        MenuButton {
          icon-name: 'open-menu-symbolic';
          menu-model: primary_menu;
        }
      }
      content: Gtk.Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Image image {
        styles [
          'lowres-icon',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}


Monospace#

Adw style class monospace

Adw style class monospace#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe monospace."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe monospace',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.label = Gtk.Label.new(str='Lorem Ipsum')
        self.label.add_css_class(css_class='monospace')
        vbox.append(child=self.label)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'monospace' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='monospace')
        else:
            self.label.add_css_class(css_class='monospace')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class monospace."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    label = Gtk.Template.Child(name='label')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'monospace' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='monospace')
        else:
            self.label.add_css_class(css_class='monospace')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs monospace</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="monospace"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs monospace';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label label {
        label: 'Lorem Ipsum';
        styles [
          'monospace',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}


Numeric#

Adw style class numeric

Adw style class numeric#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe numeric."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe numeric',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.label = Gtk.Label.new(str='Lorem Ipsum (0123456789)')
        self.label.add_css_class(css_class='numeric')
        vbox.append(child=self.label)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'numeric' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='numeric')
        else:
            self.label.add_css_class(css_class='numeric')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class numeric."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    label = Gtk.Template.Child(name='label')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'numeric' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='numeric')
        else:
            self.label.add_css_class(css_class='numeric')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs numeric</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label">
                    <property name="label">Lorem Ipsum (0123456789)</property>
                    <style>
                      <class name="numeric"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs numeric';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label label {
        label: 'Lorem Ipsum (0123456789)';
        styles [
          'numeric',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Opaque#

Adw style class opaque

Adw style class opaque#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe opaque."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe opaque',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.button = Gtk.Button.new_with_label(label='Lorem Ipsum')
        self.button.add_css_class(css_class='opaque')
        vbox.append(child=self.button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'opaque' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='opaque')
        else:
            self.button.add_css_class(css_class='opaque')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class opaque."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    button = Gtk.Template.Child(name='button')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'opaque' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='opaque')
        else:
            self.button.add_css_class(css_class='opaque')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs opaque</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkButton" id="button">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="opaque"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs opaque';
  default-width: 683;
  default-height: 384;
  content: Adw.ToastOverlay {
    child: Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
        [end]
        MenuButton {
          icon-name: 'open-menu-symbolic';
          menu-model: primary_menu;
        }
      }
      content: Gtk.Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Button button {
        label: 'Lorem Ipsum';
        styles [
          'opaque',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Osd#

Adw style class osd

Adw style class osd#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe osd."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe osd',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.button = Gtk.Button.new_with_label(label='Lorem Ipsum')
        self.button.add_css_class(css_class='osd')
        vbox.append(child=self.button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'osd' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='osd')
        else:
            self.button.add_css_class(css_class='osd')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class osd."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    button = Gtk.Template.Child(name='button')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'osd' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='osd')
        else:
            self.button.add_css_class(css_class='osd')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs osd</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkButton" id="button">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="osd"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs osd';
  default-width: 683;
  default-height: 384;
  content: Adw.ToastOverlay {
    child: Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
        [end]
        MenuButton {
          icon-name: 'open-menu-symbolic';
          menu-model: primary_menu;
        }
      }
      content: Gtk.Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Button button {
        label: 'Lorem Ipsum';
        styles [
          'osd',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Pill#

Adw style class pill

Adw style class pill#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe pill."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe pill',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.button = Gtk.Button.new_with_label(label='Lorem Ipsum')
        self.button.add_css_class(css_class='pill')
        vbox.append(child=self.button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'pill' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='pill')
        else:
            self.button.add_css_class(css_class='pill')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class pill."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    button = Gtk.Template.Child(name='button')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'pill' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='pill')
        else:
            self.button.add_css_class(css_class='pill')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs pill</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkButton" id="button">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="pill"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs pill';
  default-width: 683;
  default-height: 384;
  content: Adw.ToastOverlay {
    child: Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
        [end]
        MenuButton {
          icon-name: 'open-menu-symbolic';
          menu-model: primary_menu;
        }
      }
      content: Gtk.Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Button button {
        label: 'Lorem Ipsum';
        styles [
          'pill',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

property#

Adw style class property

Adw style class property#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class property."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe property',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        list_box = Gtk.ListBox.new()
        vbox.append(child=list_box)

        self.adw_action_row = Adw.ActionRow.new()
        self.adw_action_row.set_title(title='Lorem Ipsum')
        self.adw_action_row.set_subtitle(subtitle='Lorem Ipsum')
        self.adw_action_row.set_subtitle_selectable(subtitle_selectable=True)
        self.adw_action_row.add_css_class(css_class='property')
        list_box.append(child=self.adw_action_row)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'property' in self.adw_action_row.get_css_classes():
            self.adw_action_row.remove_css_class(css_class='property')
        else:
            self.adw_action_row.add_css_class(css_class='property')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class property."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    adw_action_row = Gtk.Template.Child(name='adw_action_row')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'property' in self.adw_action_row.get_css_classes():
            self.adw_action_row.remove_css_class(css_class='property')
        else:
            self.adw_action_row.add_css_class(css_class='property')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs property</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkListBox">
                    <child>
                      <object class="AdwActionRow" id="adw_action_row">
                        <property name="title">Lorem Ipsum</property>
                        <property name="subtitle">Lorem Ipsum</property>
                        <property name="subtitle-selectable">true</property>
                        <style>
                          <class name="property"/>
                        </style>
                      </object>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs property';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Gtk.ListBox {
        
        Adw.ActionRow adw_action_row {
          title: 'Lorem Ipsum';
          subtitle: 'Lorem Ipsum';
          subtitle-selectable: true;
          styles [
            'property',
          ]
        }
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Selection-mode#

Adw style class selection-mode

Adw style class selection-mode#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style selection-mode."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style selection-mode',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.check_button = Gtk.CheckButton.new_with_label(label='Lorem Ipsum')
        self.check_button.add_css_class(css_class='selection-mode')
        vbox.append(child=self.check_button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'selection-mode' in self.check_button.get_css_classes():
            self.check_button.remove_css_class(css_class='selection-mode')
        else:
            self.check_button.add_css_class(css_class='selection-mode')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style selection-mode."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    check_button = Gtk.Template.Child(name='check_button')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'selection-mode' in self.check_button.get_css_classes():
            self.check_button.remove_css_class(css_class='selection-mode')
        else:
            self.check_button.add_css_class(css_class='selection-mode')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs selection-mode</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkCheckButton" id="check_button">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="selection-mode"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs selection-mode';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      CheckButton check_button {
        label: 'Lorem Ipsum';
        styles [
          'selection-mode',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

    ;
  }
  ;
}
menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Spacer#

Adw style class spacer

Adw style class spacer#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe spacer."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe spacer',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        button = Gtk.Button.new_with_label(label='Lorem Ipsum')
        vbox.append(child=button)

        self.separator = Gtk.Separator.new(orientation=Gtk.Orientation.VERTICAL)
        self.separator.add_css_class(css_class='spacer')
        vbox.append(child=self.separator)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'spacer' in self.separator.get_css_classes():
            self.separator.remove_css_class(css_class='spacer')
        else:
            self.separator.add_css_class(css_class='spacer')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class spacer."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    separator = Gtk.Template.Child(name='separator')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'spacer' in self.separator.get_css_classes():
            self.separator.remove_css_class(css_class='spacer')
        else:
            self.separator.add_css_class(css_class='spacer')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs spacer</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkButton" id="button">
                    <property name="label">Lorem Ipsum</property>
                  </object>
                </child>
                <child>
                  <object class="GtkSeparator" id="separator">
                    <property name="orientation">1</property>
                    <style>
                      <class name="spacer"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs spacer';
  default-width: 683;
  default-height: 384;
  content: Adw.ToastOverlay {
    child: Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
        [end]
        MenuButton {
          icon-name: 'open-menu-symbolic';
          menu-model: primary_menu;
        }
      }
      content: Gtk.Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Button button {
        label: 'Lorem Ipsum';
      }

      Separator separator {
        orientation:vertical;
        styles [
          'spacer',
        ]
      }
      
      Button {
        label: 'Add/Remove class';
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Suggested-action#

Adw style class suggested-action

Adw style class suggested-action#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe suggested-action."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe suggested-action',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.button = Gtk.Button.new_with_label(label='Lorem Ipsum')
        self.button.add_css_class(css_class='suggested-action')
        vbox.append(child=self.button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'suggested-action' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='suggested-action')
        else:
            self.button.add_css_class(css_class='suggested-action')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class suggested-action."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    button = Gtk.Template.Child(name='button')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'suggested-action' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='suggested-action')
        else:
            self.button.add_css_class(css_class='suggested-action')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs suggested-action</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkButton" id="button">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="suggested-action"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs suggested-action';
  default-width: 683;
  default-height: 384;
  content: Adw.ToastOverlay {
    child: Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
        [end]
        MenuButton {
          icon-name: 'open-menu-symbolic';
          menu-model: primary_menu;
        }
      }
      content: Gtk.Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Button button {
        label: 'Lorem Ipsum';
        styles [
          'suggested-action',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Title#

Adw style class title

Adw style class title#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe title."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe title',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.label = Gtk.Label.new(str='Lorem Ipsum')
        self.label.add_css_class(css_class='title-1')
        vbox.append(child=self.label)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'title-1' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='title-1')
        else:
            self.label.add_css_class(css_class='title-1')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class title."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    label = Gtk.Template.Child(name='label')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'title-1' in self.label.get_css_classes():
            self.label.remove_css_class(css_class='title-1')
        else:
            self.label.add_css_class(css_class='title-1')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs title</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="title-1"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs title';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Label label {
        label: 'Lorem Ipsum';
        styles [
          'title-1',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

Toolbar#

Adw style class toolbar

Adw style class toolbar#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class toolbar."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe toolbar',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.hbox = Gtk.Box.new(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
        self.hbox.add_css_class(css_class='toolbar')
        vbox.append(child=self.hbox)

        for _ in range(3):
            button = Gtk.Button.new_from_icon_name(
                icon_name='document-open-symbolic',
            )
            self.hbox.append(child=button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'toolbar' in self.hbox.get_css_classes():
            self.hbox.remove_css_class(css_class='toolbar')
        else:
            self.hbox.add_css_class(css_class='toolbar')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class toolbar."""

import sys
import pathlib


import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    hbox = Gtk.Template.Child(name='hbox')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'toolbar' in self.hbox.get_css_classes():
            self.hbox.remove_css_class(css_class='toolbar')
        else:
            self.hbox.add_css_class(css_class='toolbar')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs toolbar</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkBox" id="hbox">
                    <property name="orientation">0</property>
                    <style>
                      <class name="toolbar"/>
                    </style>
                    <child>
                      <object class="GtkButton">
                        <property name="icon-name">document-open-symbolic</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkButton">
                        <property name="icon-name">document-open-symbolic</property>
                      </object>
                    </child>
                    <child>
                      <object class="GtkButton">
                        <property name="icon-name">document-open-symbolic</property>
                      </object>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs toolbar';
  default-width: 683;
default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
      [top]
      Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content:
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Box hbox {
        orientation: horizontal;
        styles [
            'toolbar',
          ]
        Button {
          icon-name: 'document-open-symbolic';
        }
        Button {
          icon-name: 'document-open-symbolic';
        }
        Button {
          icon-name: 'document-open-symbolic';
        }
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}

View#

Adw style class view

Adw style class view#

# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style classe view."""

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()


class ExampleWindow(Adw.ApplicationWindow):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.set_title(
            title='Python and GTK: PyGObject libadwaita style classe view',
        )
        self.set_default_size(width=int(1366 / 2), height=int(768 / 2))
        self.set_size_request(width=int(1366 / 3), height=int(768 / 3))

        adw_toast_overlay = Adw.ToastOverlay.new()
        self.set_content(content=adw_toast_overlay)

        adw_toolbar_view = Adw.ToolbarView.new()
        adw_toast_overlay.set_child(child=adw_toolbar_view)

        adw_header_bar = Adw.HeaderBar.new()
        adw_toolbar_view.add_top_bar(widget=adw_header_bar)

        menu_button_model = Gio.Menu()
        menu_button_model.append(
            label='Preferences',
            detailed_action='app.preferences',
        )

        menu_button = Gtk.MenuButton.new()
        menu_button.set_icon_name(icon_name='open-menu-symbolic')
        menu_button.set_menu_model(menu_model=menu_button_model)
        adw_header_bar.pack_end(child=menu_button)

        vbox = Gtk.Box.new(orientation=Gtk.Orientation.VERTICAL, spacing=12)
        vbox.set_margin_top(margin=12)
        vbox.set_margin_end(margin=12)
        vbox.set_margin_bottom(margin=12)
        vbox.set_margin_start(margin=12)
        adw_toolbar_view.set_content(content=vbox)

        self.button = Gtk.Button.new_with_label(label='Lorem Ipsum')
        self.button.add_css_class(css_class='view')
        vbox.append(child=self.button)

        button = Gtk.Button.new_with_label(label='Add/remove class')
        button.set_vexpand(expand=True)
        button.set_valign(align=Gtk.Align.END)
        button.connect('clicked', self.on_button_clicked)
        vbox.append(child=button)

    def on_button_clicked(self, button):
        if 'view' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='view')
        else:
            self.button.add_css_class(css_class='view')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    import sys

    app = ExampleApplication()
    app.run(sys.argv)
# -*- coding: utf-8 -*-
"""Python and GTK: PyGObject libadwaita style class suggested-action."""

import sys
import pathlib

import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk


UI = BASE_DIR.joinpath('MainWindow.ui')








Adw.init()


@Gtk.Template(filename=str(UI))
class ExampleWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'ExampleWindow'

    button = Gtk.Template.Child(name='button')

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback()
    def on_button_clicked(self, button):
        if 'view' in self.button.get_css_classes():
            self.button.remove_css_class(css_class='view')
        else:
            self.button.add_css_class(css_class='view')


class ExampleApplication(Adw.Application):

    def __init__(self):
        super().__init__(application_id='br.com.justcode.PyGObject',
                         flags=Gio.ApplicationFlags.FLAGS_NONE)

        self.create_action('quit', self.exit_app, ['<primary>q'])
        self.create_action('preferences', self.on_preferences_action)

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)
        win.present()

    def do_startup(self):
        Gtk.Application.do_startup(self)

    def do_shutdown(self):
        Gtk.Application.do_shutdown(self)

    def on_preferences_action(self, action, param):
        print('Action `app.preferences` was active.')

    def exit_app(self, action, param):
        self.quit()

    def create_action(self, name, callback, shortcuts=None):
        action = Gio.SimpleAction.new(name=name, parameter_type=None)
        action.connect('activate', callback)
        self.add_action(action=action)
        if shortcuts:
            self.set_accels_for_action(
                detailed_action_name=f'app.{name}',
                accels=shortcuts,
            )


if __name__ == '__main__':
    app = ExampleApplication()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="ExampleWindow" parent="AdwApplicationWindow">
    <property name="title">Python and GTK: PyGObject libadwaita style classs view</property>
    <property name="default-width">683</property>
    <property name="default-height">384</property>
    <property name="content">
      <object class="AdwToastOverlay">
        <property name="child">
          <object class="AdwToolbarView">
            <child type="top">
              <object class="AdwHeaderBar" id="header_bar">
                <child type="end">
                  <object class="GtkMenuButton">
                    <property name="icon-name">open-menu-symbolic</property>
                    <property name="menu-model">primary_menu</property>
                  </object>
                </child>
              </object>
            </child>
            <property name="content">
              <object class="GtkBox">
                <property name="orientation">1</property>
                <property name="margin-top">12</property>
                <property name="margin-end">12</property>
                <property name="margin-bottom">12</property>
                <property name="margin-start">12</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkButton" id="button">
                    <property name="label">Lorem Ipsum</property>
                    <style>
                      <class name="view"/>
                    </style>
                  </object>
                </child>
                <child>
                  <object class="GtkButton">
                    <property name="label">Add/Remove class</property>
                    <property name="vexpand">true</property>
                    <property name="valign">2</property>
                    <signal name="clicked" handler="on_button_clicked"/>
                  </object>
                </child>
              </object>
            </property>
          </object>
        </property>
      </object>
    </property>
  </template>
  <menu id="primary_menu">
    <section>
      <item>
        <attribute name="label" translatable="true">Preferences</attribute>
        <attribute name="action">app.preferences</attribute>
      </item>
    </section>
  </menu>
</interface>
using Gtk 4.0;
using Adw 1;

template $ExampleWindow : Adw.ApplicationWindow {
  title: 'Python and GTK: PyGObject libadwaita style classs view';
  default-width: 683;
  default-height: 384;

  content:
  Adw.ToastOverlay {
    child:
    Adw.ToolbarView {
    [top]
    Adw.HeaderBar header_bar {
      [end]
      MenuButton {
        icon-name: 'open-menu-symbolic';
        menu-model: primary_menu;
      }
    }
    content: 
    Box {
      orientation: vertical;
      margin-top: 12;
      margin-end: 12;
      margin-bottom: 12;
      margin-start: 12;
      spacing: 12;

      Button button {
        label: 'Lorem Ipsum';
        styles [
          'view',
        ]
      }

      Button {
        label: 'Add/Remove class';
        vexpand: true;
        valign: end;
        clicked => $on_button_clicked();
      }
    }

    ;
  }

  ;
  }
  ;
}

menu primary_menu {
  section {
    item {
      label: _('Preferences');
      action: 'app.preferences';
    }
  }
}