phoenix_title wx.Icon

An icon is a small rectangular bitmap usually used for denoting a minimized application.

It differs from a wx.Bitmap in always having a mask associated with it for transparent drawing. On some platforms, icons and bitmaps are implemented identically, since there is no real distinction between a wx.Bitmap with a mask and an icon; and there is no specific icon format on some platforms (X-based applications usually standardize on XPMs for small bitmaps and icons). However, some platforms (such as Windows) make the distinction, so a separate class is provided.

Note

It is usually desirable to associate a pertinent icon with a frame. Icons can also be used for other purposes, for example with wx.TreeCtrl and wx.ListCtrl. Icons have different formats on different platforms therefore separate icons will usually be created for the different environments. Platform-specific methods for creating a wx.Icon structure are catered for, and this is an occasion where conditional compilation will probably be required. Note that a new icon must be created for every time the icon is to be used for a new window. In Windows, the icon will not be reloaded if it has already been used. An icon allocated to a frame will be deleted when the frame is deleted. For more information please see Bitmaps and Icons.

See also

Bitmaps and Icons, Supported Bitmap File Formats, wx.IconBundle, wx.DC.DrawIcon , wx.Cursor


class_hierarchy Class Hierarchy

Inheritance diagram for class Icon:

method_summary Methods Summary

__init__

Default constructor.

CopyFromBitmap

Copies bmp bitmap to this icon.

CreateFromHICON

MSW-only method to create a wx.Icon from a native icon handle.

GetDepth

Gets the colour depth of the icon.

GetHandle

GetHeight

Gets the height of the icon in physical pixels.

GetLogicalHeight

Gets the height of the icon in logical pixels.

GetLogicalSize

Gets the size of the icon in logical pixels.

GetLogicalWidth

Gets the width of the icon in logical pixels.

GetScaleFactor

Gets the scale factor of this icon.

GetSize

Gets the size of the icon in physical pixels.

GetWidth

Gets the width of the icon in physical pixels.

IsOk

Returns True if icon data is present.

LoadFile

Loads an icon from a file or resource.

SetDepth

SetHandle

SetHeight

SetWidth

__bool__

__nonzero__


property_summary Properties Summary

Depth

See GetDepth and SetDepth

Handle

See GetHandle and SetHandle

Height

See GetHeight and SetHeight

LogicalHeight

See GetLogicalHeight

LogicalSize

See GetLogicalSize

LogicalWidth

See GetLogicalWidth

ScaleFactor

See GetScaleFactor

Size

See GetSize

Width

See GetWidth and SetWidth


api Class API

class wx.Icon(GDIObject)

Possible constructors:

Icon()

Icon(icon)

Icon(name, type=BITMAP_TYPE_ANY, desiredWidth=-1, desiredHeight=-1)

Icon(loc)

Icon(bmp)

An icon is a small rectangular bitmap usually used for denoting a minimized application.


Methods

__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Default constructor.

Constructs an icon object with no data; an assignment or another member function such as LoadFile must be called subsequently.



__init__ (self, icon)

Copy constructor.

Parameters:

icon (wx.Icon) –



__init__ (self, name, type=BITMAP_TYPE_ANY, desiredWidth=-1, desiredHeight=-1)

Loads an icon from a file or resource.

Parameters:
  • name (string) – This can refer to a resource name or a filename under MS Windows and X. Its meaning is determined by the type parameter.

  • type (BitmapType) – May be one of the wx.BitmapType values and indicates which type of bitmap should be loaded. See the note in the class detailed description. Note that the ICON_DEFAULT_TYPE constant has different value under different wxWidgets ports. See the icon.h header for the value it takes for a specific port.

  • desiredWidth (int) – Specifies the desired width of the icon. This parameter only has an effect in Windows where icon resources can contain several icons of different sizes.

  • desiredHeight (int) – Specifies the desired height of the icon. This parameter only has an effect in Windows where icon resources can contain several icons of different sizes.

See also

LoadFile



__init__ (self, loc)

Loads an icon from the specified location.

Parameters:

loc (wx.IconLocation) –



__init__ (self, bmp)

Construct an Icon from a Bitmap.





CopyFromBitmap(self, bmp)

Copies bmp bitmap to this icon.

Under MS Windows the bitmap must have mask colour set.

Parameters:

bmp (wx.Bitmap) –

See also

LoadFile



CreateFromHICON(self, hicon)

MSW-only method to create a wx.Icon from a native icon handle.

Return type:

bool



GetDepth(self)

Gets the colour depth of the icon.

A value of 1 indicates a monochrome icon.

Return type:

int



GetHandle(self)
Return type:

long



GetHeight(self)

Gets the height of the icon in physical pixels.

Return type:

int



GetLogicalHeight(self)

Gets the height of the icon in logical pixels.

See wx.Bitmap.GetLogicalHeight .

Return type:

float

New in version 4.1/wxWidgets-3.1.6.



GetLogicalSize(self)

Gets the size of the icon in logical pixels.

See wx.Bitmap.GetLogicalSize .

Return type:

wx.Size

New in version 4.1/wxWidgets-3.1.6.



GetLogicalWidth(self)

Gets the width of the icon in logical pixels.

See wx.Bitmap.GetLogicalWidth .

Return type:

float

New in version 4.1/wxWidgets-3.1.6.



GetScaleFactor(self)

Gets the scale factor of this icon.

See wx.Bitmap.GetScaleFactor .

Return type:

float

New in version 4.1/wxWidgets-3.1.6.



GetSize(self)

Gets the size of the icon in physical pixels.

Return type:

wx.Size

See also

GetLogicalSize



GetWidth(self)

Gets the width of the icon in physical pixels.

Return type:

int



IsOk(self)

Returns True if icon data is present.

Return type:

bool



LoadFile(self, name, type=BITMAP_TYPE_ANY, desiredWidth=-1, desiredHeight=-1)

Loads an icon from a file or resource.

Parameters:
  • name (string) – Either a filename or a Windows resource name. The meaning of name is determined by the type parameter.

  • type (BitmapType) – One of the wx.BitmapType values; see the note in the class detailed description. Note that the ICON_DEFAULT_TYPE constant has different value under different wxWidgets ports. See the icon.h header for the value it takes for a specific port.

  • desiredWidth (int) – Specifies the desired width of the icon. This parameter only has an effect in Windows where icon resources can contain several icons of different sizes.

  • desiredHeight (int) – Specifies the desired height of the icon. This parameter only has an effect in Windows where icon resources can contain several icons of different sizes.

Return type:

bool

Returns:

True if the operation succeeded, False otherwise.



SetDepth(self, depth)

Sets the depth member (does not affect the icon data).

Parameters:

depth (int) – Icon depth.

Deprecated

This function is deprecated since version 3.1.2, dimensions and depth can only be set at construction time.



SetHandle(self, handle)


SetHeight(self, height)

Sets the height member (does not affect the icon data).

Parameters:

height (int) – Icon height in pixels.

Deprecated

This function is deprecated since version 3.1.2, dimensions and depth can only be set at construction time.



SetWidth(self, width)

Sets the width member (does not affect the icon data).

Parameters:

width (int) – Icon width in pixels.

Deprecated

This function is deprecated since version 3.1.2, dimensions and depth can only be set at construction time.



__bool__(self)
Return type:

int



__nonzero__(self)
Return type:

int


Properties

Depth

See GetDepth and SetDepth



Handle

See GetHandle and SetHandle



Height

See GetHeight and SetHeight



LogicalHeight

See GetLogicalHeight



LogicalSize

See GetLogicalSize



LogicalWidth

See GetLogicalWidth



ScaleFactor

See GetScaleFactor



Size

See GetSize



Width

See GetWidth and SetWidth