Adw.Avatar

g Adw.Avatar Adw.Avatar GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget Gtk.Widget->Adw.Avatar

Subclasses:

None

Methods

Inherited:

Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new (size, text, show_initials)

draw_to_texture (scale_factor)

get_custom_image ()

get_icon_name ()

get_show_initials ()

get_size ()

get_text ()

set_custom_image (custom_image)

set_icon_name (icon_name)

set_show_initials (show_initials)

set_size (size)

set_text (text)

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)

Properties

Inherited:

Gtk.Widget (34), Gtk.Accessible (1)

Name

Type

Flags

Short Description

custom-image

Gdk.Paintable

r/w/en

icon-name

str

r/w/en

show-initials

bool

r/w/en

size

int

r/w/en

text

str

r/w/en

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Class Details

class Adw.Avatar(**kwargs)
Bases:

Gtk.Widget

Abstract:

No

Structure:

Adw.AvatarClass

A widget displaying an image, with a generated fallback.

<picture> <source srcset=”avatar-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”avatar.png” alt=”avatar”> </picture>

AdwAvatar is a widget that shows a round avatar.

AdwAvatar generates an avatar with the initials of the [property`Avatar`:py:data::text<Adw.Avatar.props.text>] on top of a colored background.

The color is picked based on the hash of the [property`Avatar`:py:data::text<Adw.Avatar.props.text>].

If [property`Avatar`:py:data::show-initials<Adw.Avatar.props.show_initials>] is set to FALSE, [property`Avatar`:py:data::icon-name<Adw.Avatar.props.icon_name>] or avatar-default-symbolic is shown instead of the initials.

Use [property`Avatar`:py:data::custom-image<Adw.Avatar.props.custom_image>] to set a custom image.

CSS nodes

AdwAvatar has a single CSS node with name avatar.

classmethod new(size, text, show_initials)
Parameters:
  • size (int) – The size of the avatar

  • text (str or None) – the text used to get the initials and color

  • show_initials (bool) – whether to use initials instead of an icon as fallback

Returns:

the newly created AdwAvatar

Return type:

Gtk.Widget

Creates a new AdwAvatar.

draw_to_texture(scale_factor)
Parameters:

scale_factor (int) – The scale factor

Returns:

the texture

Return type:

Gdk.Texture

Renders self into a [class`Gdk`.Texture] at scale_factor.

This can be used to export the fallback avatar.

get_custom_image()
Returns:

the custom image

Return type:

Gdk.Paintable or None

Gets the custom image paintable.

get_icon_name()
Returns:

the icon name

Return type:

str or None

Gets the name of an icon to use as a fallback.

get_show_initials()
Returns:

whether initials are used instead of an icon as fallback

Return type:

bool

Gets whether initials are used instead of an icon on the fallback avatar.

get_size()
Returns:

the size of the avatar

Return type:

int

Gets the size of the avatar.

get_text()
Returns:

the text used to generate the fallback initials and color

Return type:

str or None

Gets the text used to generate the fallback initials and color.

set_custom_image(custom_image)
Parameters:

custom_image (Gdk.Paintable or None) – a custom image

Sets the custom image paintable.

Custom image is displayed instead of initials or icon.

set_icon_name(icon_name)
Parameters:

icon_name (str or None) – the icon name

Sets the name of an icon to use as a fallback.

If no name is set, avatar-default-symbolic will be used.

set_show_initials(show_initials)
Parameters:

show_initials (bool) – whether to use initials instead of an icon as fallback

Sets whether to use initials instead of an icon on the fallback avatar.

See [property`Avatar`:py:data::icon-name<Adw.Avatar.props.icon_name>] for how to change the fallback icon.

set_size(size)
Parameters:

size (int) – The size of the avatar

Sets the size of the avatar.

set_text(text)
Parameters:

text (str or None) – the text used to get the initials and color

Sets the text used to generate the fallback initials and color.

It’s only used to generate the color if [property`Avatar`:py:data::show-initials<Adw.Avatar.props.show_initials>] is FALSE.

Property Details

Adw.Avatar.props.custom_image
Name:

custom-image

Type:

Gdk.Paintable

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

A custom image paintable.

Custom image is displayed instead of initials or icon.

Adw.Avatar.props.icon_name
Name:

icon-name

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The name of an icon to use as a fallback.

If no name is set, avatar-default-symbolic will be used.

Adw.Avatar.props.show_initials
Name:

show-initials

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether initials are used instead of an icon on the fallback avatar.

See [property`Avatar`:py:data::icon-name<Adw.Avatar.props.icon_name>] for how to change the fallback icon.

Adw.Avatar.props.size
Name:

size

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The size of the avatar.

Adw.Avatar.props.text
Name:

text

Type:

str

Default Value:

''

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Sets the text used to generate the fallback initials and color.

It’s only used to generate the color if [property`Avatar`:py:data::show-initials<Adw.Avatar.props.show_initials>] is FALSE.