Handy.Avatar

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Buildable->Gtk.Widget Gtk.DrawingArea Gtk.DrawingArea Handy.Avatar Handy.Avatar Gtk.DrawingArea->Handy.Avatar Gtk.Widget->Gtk.DrawingArea

Subclasses:

None

Methods

Inherited:

Gtk.DrawingArea (1), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10)

Structs:

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

class

new (size, text, show_initials)

draw_to_pixbuf (size, scale_factor)

draw_to_pixbuf_async (size, scale_factor, cancellable, callback, *user_data)

draw_to_pixbuf_finish (async_result)

get_icon_name ()

get_loadable_icon ()

get_show_initials ()

get_size ()

get_text ()

set_icon_name (icon_name)

set_image_load_func (load_image, *user_data)

set_loadable_icon (icon)

set_show_initials (show_initials)

set_size (size)

set_text (text)

Virtual Methods

Inherited:

Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10)

Properties

Inherited:

Gtk.Widget (39)

Name

Type

Flags

Short Description

icon-name

str

r/w/en

The name of the icon from the icon theme

loadable-icon

Gio.LoadableIcon

r/w/en

The loadable icon used to load the avatar

show-initials

bool

r/w/en

Whether to show the initials

size

int

r/w/en

The size of the avatar

text

str

r/w/en

The text used to generate the color and the initials

Style Properties

Inherited:

Gtk.Widget (17)

Signals

Inherited:

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

Fields

Inherited:

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

Class Details

class Handy.Avatar(**kwargs)
Bases:

Gtk.DrawingArea

Abstract:

No

Structure:

Handy.AvatarClass

A widget displaying an image, with a generated fallback.

HdyAvatar is a widget to display a round avatar.

A provided image is made round before displaying, if no image is given this widget generates a round fallback with the initials of the [property`Avatar`:py:data::text<Handy.Avatar.props.text>] on top of a colored background.

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

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

Use [method`Avatar`.set_loadable_icon] or [property`Avatar`:py:data::loadable-icon<Handy.Avatar.props.loadable_icon>] to set a custom image.

CSS nodes

HdyAvatar has a single CSS node with name avatar.

New in version 1.0.

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 HdyAvatar

Return type:

Gtk.Widget

Creates a new HdyAvatar.

New in version 1.0.

draw_to_pixbuf(size, scale_factor)
Parameters:
  • size (int) – the size of the pixbuf

  • scale_factor (int) – the scale factor

Returns:

the pixbuf

Return type:

GdkPixbuf.Pixbuf

Renders self into a [class`GdkPixbuf`.Pixbuf] at size and scale_factor.

This can be used to export the fallback avatar.

New in version 1.2.

draw_to_pixbuf_async(size, scale_factor, cancellable, callback, *user_data)
Parameters:
  • size (int) – the size of the pixbuf

  • scale_factor (int) – the scale factor

  • cancellable (Gio.Cancellable or None) – a cancellable

  • callback (Gio.AsyncReadyCallback or None) – a [callback`Gio`.AsyncReadyCallback] to call when the avatar is generated

  • user_data (object or None) – the data to pass to callback function

Renders asynchronously self into a pixbuf at size and scale_factor.

This can be used to export the fallback avatar.

New in version 1.2.

draw_to_pixbuf_finish(async_result)
Parameters:

async_result (Gio.AsyncResult) – a [iface`Gio`.AsyncResult]

Returns:

the resulting pixbuf

Return type:

GdkPixbuf.Pixbuf

Finishes an asynchronous draw of an avatar to a pixbuf.

New in version 1.2.

get_icon_name()
Returns:

the icon name

Return type:

str or None

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

New in version 1.0.

get_loadable_icon()
Returns:

the [iface`Gio`.LoadableIcon]

Return type:

Gio.LoadableIcon or None

Gets the [iface`Gio`.LoadableIcon] set via [method`Avatar`.set_loadable_icon].

New in version 1.2.

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.

New in version 1.0.

get_size()
Returns:

the size of the avatar

Return type:

int

Gets the size of the avatar.

New in version 1.0.

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.

New in version 1.0.

set_icon_name(icon_name)
Parameters:

icon_name (str or None) – the name of the icon from the icon theme

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

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

New in version 1.0.

set_image_load_func(load_image, *user_data)
Parameters:

A callback which is called when the custom image needs to be reloaded.

It will be called on [property`Avatar`:py:data::size<Handy.Avatar.props.size>] or [property`Gtk`.Widget:scale-factor] changes.

New in version 1.0.

Deprecated since version 1.2: use [method`Avatar`.set_loadable_icon] instead.

set_loadable_icon(icon)
Parameters:

icon (Gio.LoadableIcon or None) – a [iface`Gio`.LoadableIcon]

Sets the [iface`Gio`.LoadableIcon] to use as an avatar.

The previous avatar is displayed till the new avatar is loaded, to immediately remove the custom avatar set the loadable-icon to NULL.

The [iface`Gio`.LoadableIcon] set via this function is preferred over a set [callback`AvatarImageLoadFunc`].

New in version 1.2.

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.

New in version 1.0.

set_size(size)
Parameters:

size (int) – the size to be used for the avatar

Sets the size of the avatar.

New in version 1.0.

set_text(text)
Parameters:

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

Set the text used to generate the fallback initials color.

New in version 1.0.

Property Details

Handy.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, the avatar-default-symbolic icon will be used. If the name doesn’t match a valid icon, it is an error and no icon will be displayed. If the icon theme is changed, the image will be updated automatically.

New in version 1.0.

Handy.Avatar.props.loadable_icon
Name:

loadable-icon

Type:

Gio.LoadableIcon

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

A [iface`Gio`.LoadableIcon] used to load the avatar.

New in version 1.2.

Handy.Avatar.props.show_initials
Name:

show-initials

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether to show the initials or the fallback icon on the generated avatar.

New in version 1.0.

Handy.Avatar.props.size
Name:

size

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The avatar size of the avatar.

New in version 1.0.

Handy.Avatar.props.text
Name:

text

Type:

str

Default Value:

None

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<Handy.Avatar.props.show_initials>] is FALSE.

New in version 1.0.