Gtk.Image¶
Example¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1)
- Structs:
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
|||
r/w |
|||
r/w |
|||
r/w/en |
|||
r/w |
|||
r/w/en |
|||
r/w |
|||
r |
|||
r/w/en |
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class Gtk.Image(**kwargs)¶
- Bases:
- Abstract:
No
The
GtkImage
widget displays an image.An example
Gtk.Image
Various kinds of object can be displayed as an image; most typically, you would load a
GdkTexture
from a file, using the convenience function [ctor`Gtk`.Image.new_from_file], for instance:``c GtkWidget *image = gtk_image_new_from_file (“myfile.png”); ``
If the file isn’t loaded successfully, the image will contain a “broken image” icon similar to that used in many web browsers.
If you want to handle errors in loading the file yourself, for example by displaying an error message, then load the image with [ctor`Gdk`.Texture.new_from_file], then create the
GtkImage
with [ctor`Gtk`.Image.new_from_paintable].Sometimes an application will want to avoid depending on external data files, such as image files. See the documentation of
GResource
inside GIO, for details. In this case, [property`Gtk`.Image:resource], [ctor`Gtk`.Image.new_from_resource], and [method`Gtk`.Image.set_from_resource] should be used.GtkImage
displays its image as an icon, with a size that is determined by the application. See [class`Gtk`.Picture] if you want to show an image at is actual size.- CSS nodes
GtkImage
has a single CSS node with the nameimage
. The style classes.normal-icons
or.large-icons
may appear, depending on the [property`Gtk`.Image:icon-size] property.- Accessibility
GtkImage
uses theGTK_ACCESSIBLE_ROLE_IMG
role.- classmethod new()[source]¶
- Returns:
a newly created
GtkImage
widget.- Return type:
Creates a new empty
GtkImage
widget.
- classmethod new_from_file(filename)[source]¶
- Parameters:
filename (
str
) – a filename- Returns:
a new
GtkImage
- Return type:
Creates a new
GtkImage
displaying the file filename.If the file isn’t found or can’t be loaded, the resulting
GtkImage
will display a “broken image” icon. This function never returnsNone
, it always returns a validGtkImage
widget.If you need to detect failures to load the file, use [ctor`Gdk`.Texture.new_from_file] to load the file yourself, then create the
GtkImage
from the texture.The storage type (see [method`Gtk`.Image.get_storage_type]) of the returned image is not defined, it will be whatever is appropriate for displaying the file.
- classmethod new_from_gicon(icon)[source]¶
- Parameters:
icon (
Gio.Icon
) – an icon- Returns:
a new
GtkImage
displaying the themed icon- Return type:
Creates a
GtkImage
displaying an icon from the current icon theme.If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.
- classmethod new_from_icon_name(icon_name)[source]¶
- Parameters:
- Returns:
a new
GtkImage
displaying the themed icon- Return type:
Creates a
GtkImage
displaying an icon from the current icon theme.If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.
- classmethod new_from_paintable(paintable)[source]¶
- Parameters:
paintable (
Gdk.Paintable
orNone
) – aGdkPaintable
- Returns:
a new
GtkImage
- Return type:
Creates a new
GtkImage
displaying paintable.The
GtkImage
does not assume a reference to the paintable; you still need to unref it if you own references.GtkImage
will add its own reference rather than adopting yours.The
GtkImage
will track changes to the paintable and update its size and contents in response to it.
- classmethod new_from_pixbuf(pixbuf)[source]¶
- Parameters:
pixbuf (
GdkPixbuf.Pixbuf
orNone
) – aGdkPixbuf
- Returns:
a new
GtkImage
- Return type:
Creates a new
GtkImage
displaying pixbuf.The
GtkImage
does not assume a reference to the pixbuf; you still need to unref it if you own references.GtkImage
will add its own reference rather than adopting yours.This is a helper for [ctor`Gtk`.Image.new_from_paintable], and you can’t get back the exact pixbuf once this is called, only a texture.
Note that this function just creates an
GtkImage
from the pixbuf. TheGtkImage
created will not react to state changes. Should you want that, you should use [ctor`Gtk`.Image.new_from_icon_name].Deprecated since version 4.12: Use [ctor`Gtk`.Image.new_from_paintable] and [ctor`Gdk`.Texture.new_for_pixbuf] instead
- classmethod new_from_resource(resource_path)[source]¶
- Parameters:
resource_path (
str
) – a resource path- Returns:
a new
GtkImage
- Return type:
Creates a new
GtkImage
displaying the resource file resource_path.If the file isn’t found or can’t be loaded, the resulting
GtkImage
will display a “broken image” icon. This function never returnsNone
, it always returns a validGtkImage
widget.If you need to detect failures to load the file, use [ctor`GdkPixbuf`.Pixbuf.new_from_file] to load the file yourself, then create the
GtkImage
from the pixbuf.The storage type (see [method`Gtk`.Image.get_storage_type]) of the returned image is not defined, it will be whatever is appropriate for displaying the file.
- get_gicon()[source]¶
-
Gets the
GIcon
being displayed by theGtkImage
.The storage type of the image must be
Gtk.ImageType.EMPTY
orGtk.ImageType.GICON
(see [method`Gtk`.Image.get_storage_type]). The caller of this function does not own a reference to the returnedGIcon
.
- get_icon_name()[source]¶
-
Gets the icon name and size being displayed by the
GtkImage
.The storage type of the image must be
Gtk.ImageType.EMPTY
orGtk.ImageType.ICON_NAME
(see [method`Gtk`.Image.get_storage_type]). The returned string is owned by theGtkImage
and should not be freed.
- get_icon_size()[source]¶
- Returns:
the image size used by icons
- Return type:
Gets the icon size used by the self when rendering icons.
- get_paintable()[source]¶
- Returns:
the displayed paintable
- Return type:
Gets the image
GdkPaintable
being displayed by theGtkImage
.The storage type of the image must be
Gtk.ImageType.EMPTY
orGtk.ImageType.PAINTABLE
(see [method`Gtk`.Image.get_storage_type]). The caller of this function does not own a reference to the returned paintable.
- get_pixel_size()[source]¶
- Returns:
the pixel size used for named icons.
- Return type:
Gets the pixel size used for named icons.
- get_storage_type()[source]¶
- Returns:
image representation being used
- Return type:
Gets the type of representation being used by the
GtkImage
to store image data.If the
GtkImage
has no image data, the return value will beGtk.ImageType.EMPTY
.
- set_from_file(filename)[source]¶
-
Sets a
GtkImage
to show a file.See [ctor`Gtk`.Image.new_from_file] for details.
- set_from_gicon(icon)[source]¶
- Parameters:
icon (
Gio.Icon
) – an icon
Sets a
GtkImage
to show aGIcon
.See [ctor`Gtk`.Image.new_from_gicon] for details.
- set_from_icon_name(icon_name)[source]¶
-
Sets a
GtkImage
to show a named icon.See [ctor`Gtk`.Image.new_from_icon_name] for details.
- set_from_paintable(paintable)[source]¶
- Parameters:
paintable (
Gdk.Paintable
orNone
) – aGdkPaintable
Sets a
GtkImage
to show aGdkPaintable
.See [ctor`Gtk`.Image.new_from_paintable] for details.
- set_from_pixbuf(pixbuf)[source]¶
- Parameters:
pixbuf (
GdkPixbuf.Pixbuf
orNone
) – aGdkPixbuf
orNULL
Sets a
GtkImage
to show aGdkPixbuf
.See [ctor`Gtk`.Image.new_from_pixbuf] for details.
Note: This is a helper for [method`Gtk`.Image.set_from_paintable], and you can’t get back the exact pixbuf once this is called, only a paintable.
Deprecated since version 4.12: Use [method`Gtk`.Image.set_from_paintable] instead
- set_from_resource(resource_path)[source]¶
-
Sets a
GtkImage
to show a resource.See [ctor`Gtk`.Image.new_from_resource] for details.
- set_icon_size(icon_size)[source]¶
- Parameters:
icon_size (
Gtk.IconSize
) – the new icon size
Suggests an icon size to the theme for named icons.
Property Details¶
- Gtk.Image.props.file¶
-
The
GFile
to display.
- Gtk.Image.props.gicon¶
-
The
GIcon
displayed in theGtk.Image
.For themed icons, If the icon theme is changed, the image will be updated automatically.
- Gtk.Image.props.icon_name¶
-
The name of the icon in the icon theme.
If the icon theme is changed, the image will be updated automatically.
- Gtk.Image.props.icon_size¶
- Name:
icon-size
- Type:
- Default Value:
- Flags:
The symbolic size to display icons at.
- Gtk.Image.props.paintable¶
- Name:
paintable
- Type:
- Default Value:
- Flags:
The
GdkPaintable
to display.
- Gtk.Image.props.pixel_size¶
- Name:
pixel-size
- Type:
- Default Value:
-1
- Flags:
The size in pixels to display icons at.
If set to a value != -1, this property overrides the [property`Gtk`.Image:icon-size] property for images of type
GTK_IMAGE_ICON_NAME
.
- Gtk.Image.props.resource¶
-
A path to a resource file to display.
- Gtk.Image.props.storage_type¶
- Name:
storage-type
- Type:
- Default Value:
- Flags:
The representation being used for image data.
- Gtk.Image.props.use_fallback¶
- Name:
use-fallback
- Type:
- Default Value:
- Flags:
Whether the icon displayed in the
GtkImage
will use standard icon names fallback.The value of this property is only relevant for images of type
Gtk.ImageType.ICON_NAME
andGtk.ImageType.GICON
.