Name

gtk.Image — A widget displaying an image

Synopsis

class gtk.Image(gtk.Misc):
    gtk.Image()
def set_from_pixmap(pixmap, mask)
def set_from_image(gdk_image, mask)
def set_from_file(filename)
def set_from_pixbuf(pixbuf)
def set_from_stock(stock_id, size)
def set_from_icon_set(icon_set, size)
def set_from_animation(animation)
def get_storage_type()
def get_pixmap(pixmap, mask)
def get_image(gdk_image, mask)
def get_pixbuf()
def get_stock(stock_id, size)
def get_icon_set(icon_set, size)
def get_animation()
Functions

    def gtk.image_new_from_stock(stock_id, size)
def gtk.image_new_from_icon_set(icon_set, size)
def gtk.image_new_from_animation(animation)

Ancestry

+-- gobject.GObject
  +-- gtk.Object
    +-- gtk.Widget
      +-- gtk.Misc
        +-- gtk.Image

Properties

"pixbuf"Read-Writea gtk.gdk.Pixbuf to display
"pixmap"Read-Writea gtk.gdk.Pixmap to display
"image"Read-Writea gtk.gdk.Image to display
"mask"Read-Writea bitmap gtk.gdk.Pixmap to use with a gtk.gdk.Image or a gtk.gdk.Pixmap
"file"Writea filename containing the image data
"stock"Read-Writethe stock ID for a stock image to display.
"icon-set"Read-Writethe gtk.IconSet to display
"icon-size"Read-Writethe size to use for a stock icon or icon set.
"pixbuf-animation"Read-Writethe gtk.gdk.PixbufAnimation to display
"storage-type"Readthe type of the image data; 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

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.

Constructor

    gtk.Image()
Returns :a newly created gtk.Image widget.

Creates a new empty gtk.Image widget.

Methods

gtk.Image.set_from_pixmap

    def set_from_pixmap(pixmap, mask)
pixmap :a gtk.gdk.Pixmap
mask :a bitmap gtk.gdk.Pixmap or None

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)
gdk_image :a gtk.gdk.Image or None
mask :a bitmap gtk.gdk.Pixmap or None

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)
pixbuf :a gtk.gdk.Pixbuf or None

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_stock

    def set_from_stock(stock_id, size)
stock_id :a stock icon name
size :a stock icon size

The set_from_stock() method sets the image data from the stock item identified by stock_id. Sample stock icon names are gtk.STOCK_OPEN and gtk.STOCK_OK. 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. 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.

The stock icons are:

gtk.STOCK_DIALOG_INFO
gtk.STOCK_DIALOG_WARNING
gtk.STOCK_DIALOG_ERROR
gtk.STOCK_DIALOG_QUESTION
gtk.STOCK_DND
gtk.STOCK_DND_MULTIPLE
gtk.STOCK_ADD
gtk.STOCK_APPLY
gtk.STOCK_BOLD
gtk.STOCK_CANCEL
gtk.STOCK_CDROM
gtk.STOCK_CLEAR
gtk.STOCK_CLOSE
gtk.STOCK_CONVERT
gtk.STOCK_COPY
gtk.STOCK_CUT
gtk.STOCK_DELETE
gtk.STOCK_EXECUTE
gtk.STOCK_FIND
gtk.STOCK_FIND_AND_REPLACE
gtk.STOCK_FLOPPY
gtk.STOCK_GOTO_BOTTOM
gtk.STOCK_GOTO_FIRST
gtk.STOCK_GOTO_LAST
gtk.STOCK_GOTO_TOP
gtk.STOCK_GO_BACK
gtk.STOCK_GO_DOWN
gtk.STOCK_GO_FORWARD
gtk.STOCK_GO_UP
gtk.STOCK_HELP
gtk.STOCK_HOME
gtk.STOCK_INDEX
gtk.STOCK_ITALIC
gtk.STOCK_JUMP_TO
gtk.STOCK_JUSTIFY_CENTER
gtk.STOCK_JUSTIFY_FILL
gtk.STOCK_JUSTIFY_LEFT
gtk.STOCK_JUSTIFY_RIGHT
gtk.STOCK_MISSING_IMAGE
gtk.STOCK_NEW
gtk.STOCK_NO
gtk.STOCK_OK
gtk.STOCK_OPEN
gtk.STOCK_PASTE
gtk.STOCK_PREFERENCES
gtk.STOCK_PRINT
gtk.STOCK_PRINT_PREVIEW
gtk.STOCK_PROPERTIES
gtk.STOCK_QUIT
gtk.STOCK_REDO
gtk.STOCK_REFRESH
gtk.STOCK_REMOVE
gtk.STOCK_REVERT_TO_SAVED
gtk.STOCK_SAVE
gtk.STOCK_SAVE_AS
gtk.STOCK_SELECT_COLOR
gtk.STOCK_SELECT_FONT
gtk.STOCK_SORT_ASCENDING
gtk.STOCK_SORT_DESCENDING
gtk.STOCK_SPELL_CHECK
gtk.STOCK_STOP
gtk.STOCK_STRIKETHROUGH
gtk.STOCK_UNDELETE
gtk.STOCK_UNDERLINE
gtk.STOCK_UNDO
gtk.STOCK_YES
gtk.STOCK_ZOOM_100
gtk.STOCK_ZOOM_FIT
gtk.STOCK_ZOOM_IN
gtk.STOCK_ZOOM_OUT

gtk.Image.set_from_icon_set

    def set_from_icon_set(icon_set, size)
icon_set :a gtk.IconSet
size :a stock icon 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)
animation :the gtk.gdk.PixbufAnimation

The set_from_animation() method sets the image data from animation.

gtk.Image.get_storage_type

    def 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

    def 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

    def get_image()
Returns :a tuple containing a gtk.gdk.Image and a mask bitmap

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

    def 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

    def 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

    def 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

    def 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)
animation :a gtk.gdk.PixbufAnimation object
Returns :a new gtk.Image object

The gtk.image_new_from_animation() function returns a new gtk.Image object containing the gtk.gdk.PixbufAnimation specified by animation.