Description
The gtk.Image widget
displays an image. Various kinds of objects can be displayed as an image;
usually, you would load a gtk.gdk.Pixbuf
("pixel buffer") from a file, and then display it. The convenience method
set_from_file()
will read the file and automatically create a pixbuf that is added to the
gtk.Image
widget. 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 gtk.gdk.pixbuf_new_from_file(),
then add it to the gtk.Image with the
set_from_pixbuf()
method. The image file may contain an animation; if so, the gtk.Image will
display an animation (gtk.gdk.PixbufAnimation)
instead of a static image.
gtk.Image is a
subclass of gtk.Misc, which
implies that you can align it (center, left, right) and add padding to it,
using the gtk.Misc methods.
gtk.Image is a
"no window" widget (has no gtk.gdk.Window of
its own), so by default does not receive events. If you want to receive
events on the image, such as button clicks, place the image inside a gtk.EventBox, then
connect to the event signals on the event box.
Methods
gtk.Image.set_from_pixmap
def set_from_pixmap(pixmap, mask)
|
The set_from_pixmap() method sets the
image data from pixmap using
mask.
gtk.Image.set_from_image
def set_from_image(gdk_image, mask)
|
The set_from_image() method sets the
image data from image using
mask. A gtk.gdk.Image is a
client-side image buffer in the pixel format of the current display. If
image is None the current image
data will be removed.
gtk.Image.set_from_file
def set_from_file(filename)
|
filename : | a filename or
None |
The set_from_file() method sets the
image data from the contents of the file named
filename. If the file isn't found or can't be loaded,
the resulting gtk.Image will
display a "broken image" icon. This function never returns None, it always
returns a valid gtk.Image widget. If
the file contains an animation, the image will contain an animation. If
filename is None the current image
data will be removed.
If you need to detect failures to load the file, use gtk.gdk.pixbuf_new_from_file()
to load the file yourself, then create the gtk.Image from the
pixbuf. (Or for animations, use the gtk.gdk.PixbufAnimation()
constructor.
gtk.Image.set_from_pixbuf
def set_from_pixbuf(pixbuf)
|
The set_from_pixbuf() method sets the
image data using pixbuf. Note that this function just
creates an gtk.Image from
pixbuf. The gtk.Image created
will not react to state changes. Should you want that, you should use the
set_from_icon_set()
method If pixbuf is None the
current image data will be removed.
gtk.Image.set_from_icon_set
def set_from_icon_set(icon_set, size)
|
The set_from_icon_set() method sets the
image data from icon_set with the size specified by
size. Stock icon sizes are
gtk.ICON_SIZE_MENU,
gtk.ICON_SIZE_SMALL_TOOLBAR,
gtk.ICON_SIZE_LARGE_TOOLBAR,
gtk.ICON_SIZE_BUTTON,
gtk.ICON_SIZE_DND and
gtk.ICON_SIZE_DIALOG.
gtk.Image.set_from_animation
def set_from_animation(animation)
|
The set_from_animation() method sets
the image data from animation.
gtk.Image.get_storage_type
Returns : | the type of the image representation being
used |
The get_storage_type() method gets the
type of representation being used by the gtk.Image to store
image data. If the gtk.Image has no
image data, the return value will be gtk.IMAGE_EMPTY. The
image type is one of: gtk.IMAGE_EMPTY,
gtk.IMAGE_PIXMAP, gtk.IMAGE_IMAGE,
gtk.IMAGE_PIXBUF, gtk.IMAGE_STOCK,
gtk.IMAGE_ICON_SET or
gtk.IMAGE_ANIMATION.
gtk.Image.get_pixmap
Returns : | a tuple containing the pixmap (or
None) and the mask (or
None) |
The get_pixmap() method returns a tuple
containing the pixmap and mask being displayed by the gtk.Image. Either or
both the pixmap and mask may be None. If the storage type
of the image is not either gtk.IMAGE_EMPTY or
gtk.IMAGE_PIXMAP the ValueError exception will be
raised.
gtk.Image.get_image
The get_image() method returns a tuple
containing the gtk.gdk.Image and
mask being displayed by the gtk.Image. One or
both of the gtk.gdk.Image and
mask may be None. If the storage type of the image is not
either of gtk.IMAGE_EMPTY or
gtk.IMAGE_IMAGE the ValueError exception will be
raised.
gtk.Image.get_pixbuf
Returns : | the displayed pixbuf, or
None if the image is empty |
The get_pixbuf() method gets the gtk.gdk.Pixbuf being
displayed by the gtk.Image. The return
value may be None if no image data is set. If the storage type of the image
is not either gtk.IMAGE_EMPTY or
gtk.IMAGE_PIXBUF the ValueError exception will be
raised.
gtk.Image.get_stock
Returns : | a tuple containing the stock icon name and the
stock icon size of the image data |
The get_stock() method returns a tuple
containing the stock icon identifier (may be None) and
size being displayed by the gtk.Image. The size
will be one of: gtk.ICON_SIZE_MENU,
gtk.ICON_SIZE_SMALL_TOOLBAR,
gtk.ICON_SIZE_LARGE_TOOLBAR,
gtk.ICON_SIZE_BUTTON,
gtk.ICON_SIZE_DND or
gtk.ICON_SIZE_DIALOG. If the storage type of the image is
not either gtk.IMAGE_EMPTY or
gtk.IMAGE_STOCK the ValueError exception will be
raised.
gtk.Image.get_icon_set
Returns : | a tuple containing a gtk.IconSet and a
stock icon size |
The get_icon_set() method returns a
tuple containing the icon set (may be None) and size
being displayed by the gtk.Image. The size
will be one of: gtk.ICON_SIZE_MENU,
gtk.ICON_SIZE_SMALL_TOOLBAR,
gtk.ICON_SIZE_LARGE_TOOLBAR,
gtk.ICON_SIZE_BUTTON,
gtk.ICON_SIZE_DND or
gtk.ICON_SIZE_DIALOG. If the storage type of the image is
not either gtk.IMAGE_EMPTY or
gtk.IMAGE_ICON_SET the ValueError exception will be
raised.
gtk.Image.get_animation
Returns : | the displayed animation, or
None if the image is empty |
The get_animation() method gets the
gtk.gdk.PixbufAnimation
(may be None if there is no image data) being displayed by the gtk.Image. If the
storage type of the image is not either gtk.IMAGE_EMPTY
or gtk.IMAGE_ANIMATION the ValueError exception will be
raised.
Functions
gtk.image_new_from_stock
def gtk.image_new_from_stock(stock_id, size)
|
stock_id : | a stock icon name |
size : | an integer representing an icon
size |
Returns : | a new gtk.Image
displaying the stock icon |
The gtk.image_new_from_stock() function
returns a new gtk.Image displaying
the stock icon specified by stock_id with the
specified size. Sample stock icon names are
gtk.STOCK_OPEN, gtk.STOCK_OK - see the
set_from_stock()
method for detailed information on the PyGTK stock icons.
. Sample stock sizes are gtk.ICON_SIZE_MENU,
gtk.ICON_SIZE_SMALL_TOOLBAR - see the gtk.icon_size_lookup() function for more detail. If the stock icon name isn't
known, a "broken image" icon will be displayed instead. You can register
your own stock icon names, see the gtk.IconFactory.add_default()
and gtk.IconFactory.add()
methods.
gtk.image_new_from_icon_set
def gtk.image_new_from_icon_set(icon_set, size)
|
icon_set : | a gtk.IconSet
object |
size : | an integer representing an icon
size |
Returns : | a new gtk.Image
object |
The gtk.image_new_from_icon_set() function
returns a new gtk.Image created
from the gtk.IconSet
specified by icon_set with the specified
size. Sample stock sizes are
gtk.ICON_SIZE_MENU,
gtk.ICON_SIZE_SMALL_TOOLBAR - see the gtk.icon_size_lookup()
function for more detail. Instead of using this function, usually it's
better to create a gtk.IconFactory,
put your icon sets in the icon factory, add the icon factory to the list of
default factories with the add_default()
method, and then use the gtk.image_new_from_stock()
function. This will allow themes to override the icon you ship with your
application.
gtk.image_new_from_animation
def gtk.image_new_from_animation(animation)
|
The gtk.image_new_from_animation() function
returns a new gtk.Image object
containing the gtk.gdk.PixbufAnimation
specified by animation.