wx.ArtProvider¶
wx.ArtProvider class is used to customize the look of wxWidgets application.
When wxWidgets needs to display an icon or a bitmap (e.g. in the standard file dialog), it does not use a hard-coded resource but asks wx.ArtProvider for it instead. This way users can plug in their own wx.ArtProvider class and easily replace standard art with their own version.
All that is needed is to derive a class from wx.ArtProvider, override either its wx.ArtProvider.CreateBitmap
and/or its wx.ArtProvider.CreateIconBundle
methods and register the provider with wx.ArtProvider.Push
:
class MyProvider(wx.ArtProvider):
def CreateBitmap(self, id, client, size):
# Your implementation of CreateBitmap here
pass
# optionally override this one as well
def CreateIconBundle(self, id, client):
# Your implementation of CreateIconBundle here
pass
# Later on...
wx.ArtProvider.Push(MyProvider())
If you need bitmap images (of the same artwork) that should be displayed at different sizes you should probably consider overriding wx.ArtProvider.CreateIconBundle
and supplying icon bundles that contain different bitmap sizes.
There’s another way of taking advantage of this class: you can use it in your code and use platform native icons as provided by wx.ArtProvider.GetBitmapBundle
or wx.ArtProvider.GetIcon
.
Identifying art resources¶
Every bitmap and icon bundle are known to wx.ArtProvider under a unique ID
that is used when requesting a resource from it. The ID
is represented by the wx.ArtID type and can have one of these predefined values (you can see bitmaps represented by these constants in the Art Provider Sample):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Additionally, any string recognized by custom art providers registered using wx.ArtProvider.Push
may be used.
Clients¶
The client is the entity that calls wx.ArtProvider’s GetBitmap
or GetIcon
function. It is represented by ClientID type and can have one of these values:
ART_TOOLBAR
ART_MENU
ART_BUTTON
ART_FRAME_ICON
ART_CMN_DIALOG
ART_HELP_BROWSER
ART_MESSAGE_BOX
ART_OTHER
(used for all requests that don’t fit into any of the categories above)
Client ID
serve as a hint to
wx.ArtProvider that is supposed to help it to choose the best looking bitmap. For example it is often desirable to use slightly different icons in menus and toolbars even though they represent the same action (e.g. wx.ART_FILE_OPEN
). Remember that this is really only a hint for wx.ArtProvider – it is common that wx.ArtProvider.GetBitmap
returns identical bitmap for different client values!
Note
When building with NO_IMPLICIT_WXSTRING_ENCODING
defined (see String Overview for more details), you need to explicitly use ASCII_STR
around these constants.
Note
When running under GTK+ 2, GTK+ stock item IDs (e.g. "gtk-cdrom"
) may be used as well:
if wx.Platform == '__WXGTK__':
bmp = wx.ArtProvider.GetBitmap("gtk-cdrom", wx.ART_MENU)
For a list of the GTK+ stock items please refer to the GTK+ documentation page. It is also possible to load icons from the current icon theme by specifying their name (without extension and directory components). Icon themes recognized by GTK+ follow the freedesktop.org Icon Themes specification. Note that themes are not guaranteed to contain all icons, so wx.ArtProvider may return wx.NullBitmap
or wx.NullIcon
. The default theme is typically installed in /usr/share/icons/hicolor
.
See also
Art Provider Sample for an example of wx.ArtProvider usage; stock ID list
Class Hierarchy¶
Methods Summary¶
Derived art provider classes may override this method to create requested art resource. |
|
Override this method to create the requested art resources available in more than one size. |
|
This method is similar to |
|
Delete the given provider. |
|
Query registered providers for bitmap with given |
|
Query registered providers for a bundle of bitmaps with given |
|
Returns a suitable size hint for the given ArtClient in DIPs. |
|
Same as |
|
Query registered providers for icon bundle with given |
|
Helper used by several generic classes: return the icon corresponding to the standard ICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set) |
|
Helper used by |
|
Returns native icon size for use specified by client hint in DIPs. |
|
Returns native icon size for use specified by client hint. |
|
Returns a suitable size hint for the given ArtClient. |
|
Returns |
|
Remove latest added provider and delete it. |
|
Register new art provider and add it to the top of providers stack (i.e. |
|
Register new art provider and add it to the bottom of providers stack. |
|
Remove a provider from the stack if it is on it. |
Class API¶
- class wx.ArtProvider(Object)¶
ArtProvider class is used to customize the look of wxWidgets application.
Methods¶
- CreateBitmap(self, id, client, size)¶
Derived art provider classes may override this method to create requested art resource.
For bitmaps available in more than one size,
CreateBitmapBundle
should be overridden instead.Note that returned bitmaps are cached by wx.ArtProvider and it is therefore not necessary to optimize
CreateBitmap
for speed (e.g. you may create wx.Bitmap objects from XPMs here).- Parameters:
id (wx.ArtID) – ArtID unique identifier of the bitmap.
client (wx.ArtClient) – ArtClient identifier of the client (i.e. who is asking for the bitmap). This only serves as a hint.
size (wx.Size) – Preferred size of the bitmap. The function may return a bitmap of different dimensions, it will be automatically rescaled to meet client’s request.
- Return type:
Note
This is not part of wx.ArtProvider’s public API, use
wx.ArtProvider.GetBitmap
orwx.ArtProvider.GetIconBundle
orwx.ArtProvider.GetIcon
to query wx.ArtProvider for a resource.See also
- CreateBitmapBundle(self, id, client, size)¶
Override this method to create the requested art resources available in more than one size.
Unlike
CreateBitmap
, this method can be overridden to return the same bitmap in several (or all, ifwx.BitmapBundle.FromSVG
is used) sizes at once, which will allow selecting the size best suited for the current display resolution automatically.- Parameters:
id (wx.ArtID) – ArtID unique identifier of the bitmap.
client (wx.ArtClient) – ArtClient identifier of the client (i.e. who is asking for the bitmap). This only serves as a hint.
size (wx.Size) – Default size of the bitmaps returned by the bundle.
- Return type:
Added in version 4.1/wxWidgets-3.1.6.
- CreateIconBundle(self, id, client)¶
This method is similar to
CreateBitmap
but can be used when a bitmap (or an icon) exists in several sizes.- Parameters:
id (wx.ArtID)
client (wx.ArtClient)
- Return type:
- static Delete(provider)¶
Delete the given provider.
- Parameters:
provider (wx.ArtProvider)
- Return type:
bool
- static GetBitmap(id, client=ART_OTHER, size=DefaultSize)¶
Query registered providers for bitmap with given
ID
.Note that applications using wxWidgets 3.1.6 or later should prefer calling
GetBitmapBundle
.- Parameters:
id (wx.ArtID) – ArtID unique identifier of the bitmap.
client (wx.ArtClient) – ArtClient identifier of the client (i.e. who is asking for the bitmap).
size (wx.Size) – Size of the returned bitmap or DefaultSize if size doesn’t matter.
- Return type:
- Returns:
The bitmap if one of registered providers recognizes the
ID
or NullBitmap otherwise.
- static GetBitmapBundle(id, client=ART_OTHER, size=DefaultSize)¶
Query registered providers for a bundle of bitmaps with given
ID
.- Parameters:
id (wx.ArtID) – ArtID unique identifier of the bitmap.
client (wx.ArtClient) – ArtClient identifier of the client (i.e. who is asking for the bitmap).
size (wx.Size) – Default size for the returned bundle, i.e. the size of the bitmap in normal
DPI
(this implies thatwx.Window.FromDIP
must not be used with it).
- Return type:
- Returns:
If any of the registered providers recognizes the
ID
in itsCreateBitmapBundle
, this bundle is returned. Otherwise, if any of providers returns a valid bitmap fromCreateBitmap
, the bundle containing only this bitmap is returned. Otherwise, an empty bundle is returned.
Added in version 4.1/wxWidgets-3.1.6.
- static GetDIPSizeHint(client)¶
Returns a suitable size hint for the given ArtClient in DIPs.
Return the size used by the topmost wx.ArtProvider for the given client. DefaultSize may be returned if the client doesn’t have a specified size, like
wx.ART_OTHER
for example.- Parameters:
client (wx.ArtClient)
- Return type:
See also
- static GetIcon(id, client=ART_OTHER, size=DefaultSize)¶
Same as
wx.ArtProvider.GetBitmap
, but return a wx.Icon object (orwx.NullIcon
on failure).
- static GetIconBundle(id, client=ART_OTHER)¶
Query registered providers for icon bundle with given
ID
.- Parameters:
id (wx.ArtID) – ArtID unique identifier of the icon bundle.
client (wx.ArtClient) – ArtClient identifier of the client (i.e. who is asking for the icon bundle).
- Return type:
- Returns:
The icon bundle if one of registered providers recognizes the
ID
or NullIconBundle otherwise.
- static GetMessageBoxIcon(flags)¶
Helper used by several generic classes: return the icon corresponding to the standard ICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set)
- Parameters:
flags (int)
- Return type:
- static GetMessageBoxIconId(flags)¶
Helper used by
GetMessageBoxIcon
: return the art id corresponding to the standard ICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set)- Parameters:
flags (int)
- Return type:
wx.ArtID
- static GetNativeDIPSizeHint(client)¶
Returns native icon size for use specified by client hint in DIPs.
If the platform has no commonly used default for this use or if client is not recognized, returns DefaultSize.
- Parameters:
client (wx.ArtClient)
- Return type:
Added in version 4.1/wxWidgets-3.1.6.
Note
In some cases, a platform may have several appropriate native sizes (for example,
wx.ART_FRAME_ICON
for frame icons). In that case, this method returns only one of them, picked reasonably.
- static GetNativeSizeHint(client, win=None)¶
Returns native icon size for use specified by client hint.
This function does the same thing as
GetNativeDIPSizeHint
, but uses win to convert the returned value to logical pixels. If win isNone
, defaultDPI
scaling (i.e. that of the primary display) is used.Added in version 2.9.0: (win parameter is available only since 3.1.6)
- static GetSizeHint(client, win=None)¶
Returns a suitable size hint for the given ArtClient.
This function does the same thing as
GetDIPSizeHint
, but uses win to convert the returned value to logical pixels. If win isNone
, defaultDPI
scaling (i.e. that of the primary display) is used.Note that win parameter is only available since wxWidgets 3.1.6.
- static HasNativeProvider()¶
Returns
True
if the platform uses native icons provider that should take precedence over any customizations.This is
True
for any platform that has user-customizable icon themes, currently only wxGTK.A typical use for this method is to decide whether a custom art provider should be plugged in using
Push
orPushBack
.- Return type:
bool
Added in version 2.9.0.
- static Pop()¶
Remove latest added provider and delete it.
- Return type:
bool
- static Push(provider)¶
Register new art provider and add it to the top of providers stack (i.e.
it will be queried as the first provider).
- Parameters:
provider (wx.ArtProvider)
- Return type:
None
See also
- static PushBack(provider)¶
Register new art provider and add it to the bottom of providers stack.
In other words, it will be queried as the last one, after all others, including the default provider.
- Parameters:
provider (wx.ArtProvider)
- Return type:
None
Added in version 2.9.0.
See also
- static Remove(provider)¶
Remove a provider from the stack if it is on it.
The provider is not deleted, unlike when using
Delete
.- Parameters:
provider (wx.ArtProvider)
- Return type:
bool