Icon#
- class Icon(*args, **kwargs)#
Implementations: BytesIcon, Emblem, EmblemedIcon, FileIcon, ThemedIcon
GIcon is a very minimal interface for icons. It provides functions
for checking the equality of two icons, hashing of icons and
serializing an icon to and from strings.
GIcon does not provide the actual pixmap for the icon as this is out
of GIO’s scope, however implementations of GIcon may contain the name
of an icon (see ThemedIcon), or the path to an icon
(see LoadableIcon).
To obtain a hash of a GIcon, see hash.
To check if two GIcons are equal, see equal.
For serializing a GIcon, use serialize and
deserialize.
If you want to consume GIcon (for example, in a toolkit) you must
be prepared to handle at least the three following cases:
LoadableIcon, ThemedIcon and EmblemedIcon.
It may also make sense to have fast-paths for other cases (like handling
`GdkPixbuf <https://docs.gtk.org/gdk-pixbuf/class.Pixbuf.html>`__ directly,
for example) but all compliant GIcon implementations outside of GIO must
implement LoadableIcon.
If your application or library provides one or more GIcon
implementations you need to ensure that your new implementation also
implements LoadableIcon. Additionally, you must provide an
implementation of serialize that gives a result that is
understood by deserialize, yielding one of the built-in
icon types.
Methods#
- class Icon
- classmethod deserialize() Icon | None#
Deserializes a
Iconpreviously serialized usingserialize().Added in version 2.38.
- equal(icon2: Icon | None = None) bool#
Checks if two icons are equal.
- Parameters:
icon2 – pointer to the second
Icon.
- classmethod new_for_string() Icon#
Generate a
Iconinstance fromstr. This function can fail ifstris not valid - seeto_string()for discussion.If your application or library provides one or more
Iconimplementations you need to ensure that eachTypeis registered with the type system prior to callingnew_for_string().Added in version 2.20.
- serialize() Variant | None#
Serializes a
Iconinto aVariant. An equivalentIconcan be retrieved back by callingdeserialize()on the returned value. As serialization will avoid using raw icon data when possible, it only makes sense to transfer theVariantbetween processes on the same machine, (as opposed to over the network), and within the same file system namespace.Added in version 2.38.
- to_string() str | None#
Generates a textual representation of
iconthat can be used for serialization such as when passingiconto a different process or saving it to persistent storage. Usenew_for_string()to geticonback from the returned string.The encoding of the returned string is proprietary to
Iconexcept in the following two casesIf
iconis aFileIcon, the returned string is a native path (such as/path/to/my icon.png) without escaping if theFileforiconis a native file. If the file is not native, the returned string is the result ofget_uri()(such assftp://path/to/my%20icon.png).If
iconis aThemedIconwith exactly one name and no fallbacks, the encoding is simply the name (such asnetwork-server).
Added in version 2.20.
Virtual Methods#
- class Icon
- do_equal(icon2: Icon | None = None) bool#
Checks if two icons are equal.
- Parameters:
icon2 – pointer to the second
Icon.
- do_serialize() Variant | None#
Serializes a
Iconinto aVariant. An equivalentIconcan be retrieved back by callingdeserialize()on the returned value. As serialization will avoid using raw icon data when possible, it only makes sense to transfer theVariantbetween processes on the same machine, (as opposed to over the network), and within the same file system namespace.Added in version 2.38.