Table Of Contents

Previous topic

ArchiveFSHandler

Next topic

AutoBufferedPaintDC

This Page

phoenix_title ArtProvider

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 ArtProvider for it instead. This way users can plug in their own ArtProvider class and easily replace standard art with their own version.

All that is needed is to derive a class from ArtProvider, override either its ArtProvider.CreateBitmap and/or its ArtProvider.CreateIconBundle methods and register the provider with 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 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 ArtProvider.GetBitmap or ArtProvider.GetIcon .

phoenix_title Identifying art resources

Every bitmap and icon bundle are known to ArtProvider under an unique ID that is used when requesting a resource from it. The ID is represented by the ArtID type and can have one of these predefined values (you can see bitmaps represented by these constants in the ):

  • ART_ERROR
  • ART_GOTO_LAST (since 2.9.2)
  • ART_FILE_SAVE_AS
  • ART_QUESTION
  • ART_PRINT
  • ART_DELETE
  • ART_WARNING
  • ART_HELP
  • ART_COPY
  • ART_INFORMATION
  • ART_TIP
  • ART_CUT
  • ART_ADD_BOOKMARK
  • ART_REPORT_VIEW
  • ART_PASTE
  • ART_DEL_BOOKMARK
  • ART_LIST_VIEW
  • ART_UNDO
  • ART_HELP_SIDE_PANEL
  • ART_NEW_DIR
  • ART_REDO
  • ART_HELP_SETTINGS
  • ART_FOLDER
  • ART_PLUS (since 2.9.2)
  • ART_HELP_BOOK
  • ART_FOLDER_OPEN
  • ART_MINUS (since 2.9.2)
  • ART_HELP_FOLDER
  • ART_GO_DIR_UP
  • ART_CLOSE
  • ART_HELP_PAGE
  • ART_EXECUTABLE_FILE
  • ART_QUIT
  • ART_GO_BACK
  • ART_NORMAL_FILE
  • ART_FIND
  • ART_GO_FORWARD
  • ART_TICK_MARK
  • ART_FIND_AND_REPLACE
  • ART_GO_UP
  • ART_CROSS_MARK
  • ART_HARDDISK
  • ART_GO_DOWN
  • ART_MISSING_IMAGE
  • ART_FLOPPY
  • ART_GO_TO_PARENT
  • ART_NEW
  • ART_CDROM
  • ART_GO_HOME
  • ART_FILE_OPEN
 
  • ART_GOTO_FIRST (since 2.9.2)
  • ART_FILE_SAVE
 

Additionally, any string recognized by custom art providers registered using ArtProvider.Push may be used.

phoenix_title Clients

The client is the entity that calls 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 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. ART_FILE_OPEN). Remember that this is really only a hint for ArtProvider – it is common that ArtProvider.GetBitmap returns identical bitmap for different client values!

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 ArtProvider may return NullBitmap or NullIcon . The default theme is typically installed in /usr/share/icons/hicolor .

See also

for an example of ArtProvider usage; stock ID list


class_hierarchy Inheritance Diagram

Inheritance diagram for class ArtProvider

Inheritance diagram of ArtProvider


method_summary Methods Summary

CreateBitmap Derived art provider classes must override this method to create requested art resource.
CreateIconBundle This method is similar to CreateBitmap but can be used when a bitmap (or an icon) exists in several sizes.
Delete Delete the given provider.
GetBitmap Query registered providers for bitmap with given ID.
GetIcon Same as ArtProvider.GetBitmap , but return a Icon object (or NullIcon on failure).
GetIconBundle Query registered providers for icon bundle with given ID.
GetNativeSizeHint Returns native icon size for use specified by client hint.
GetSizeHint Returns a suitable size hint for the given ArtClient.
HasNativeProvider Returns True if the platform uses native icons provider that should take precedence over any customizations.
Insert  
Pop Remove latest added provider and delete it.
Push Register new art provider and add it to the top of providers stack (i.e.
PushBack Register new art provider and add it to the bottom of providers stack.
Remove Remove a provider from the stack if it is on it.

api Class API



class ArtProvider(Object)

ArtProvider class is used to customize the look of wxWidgets application.


Methods



CreateBitmap(self, id, client, size)

Derived art provider classes must override this method to create requested art resource.

Note that returned bitmaps are cached by ArtProvider and it is therefore not necessary to optimize CreateBitmap for speed (e.g. you may create Bitmap objects from XPMs here).

Parameters:
  • id (string) – ArtID unique identifier of the bitmap.
  • client (string) – ArtClient identifier of the client (i.e. who is asking for the bitmap). This only servers as a hint.
  • size (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:

Bitmap

Note

This is not part of ArtProvider’s public API, use ArtProvider.GetBitmap or ArtProvider.GetIconBundle or ArtProvider.GetIcon to query ArtProvider for a resource.

See also

CreateIconBundle



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 (string) –
  • client (string) –
Return type:

IconBundle



static Delete(provider)

Delete the given provider.

Parameters:provider (ArtProvider) –
Return type:bool


static GetBitmap(id, client=ART_OTHER, size=DefaultSize)

Query registered providers for bitmap with given ID.

Parameters:
  • id (string) – ArtID unique identifier of the bitmap.
  • client (string) – ArtClient identifier of the client (i.e. who is asking for the bitmap).
  • size (Size) – Size of the returned bitmap or DefaultSize if size doesn’t matter.
Return type:

Bitmap

Returns:

The bitmap if one of registered providers recognizes the ID or NullBitmap otherwise.



static GetIcon(id, client=ART_OTHER, size=DefaultSize)

Same as ArtProvider.GetBitmap , but return a Icon object (or NullIcon on failure).

Parameters:
  • id (string) –
  • client (string) –
  • size (Size) –
Return type:

Icon



static GetIconBundle(id, client=ART_OTHER)

Query registered providers for icon bundle with given ID.

Parameters:
  • id (string) – ArtID unique identifier of the icon bundle.
  • client (string) – ArtClient identifier of the client (i.e. who is asking for the icon bundle).
Return type:

IconBundle

Returns:

The icon bundle if one of registered providers recognizes the ID or NullIconBundle otherwise.



static GetNativeSizeHint(client)

Returns native icon size for use specified by client hint.

If the platform has no commonly used default for this use or if client is not recognized, returns DefaultSize.

Parameters:client (string) –
Return type: Size

New in version 2.9.0.

Note

In some cases, a platform may have several appropriate native sizes (for example, ART_FRAME_ICON for frame icons). In that case, this method returns only one of them, picked reasonably.



static GetSizeHint(client, platform_default=False)

Returns a suitable size hint for the given ArtClient.

If platform_default is True, return a size based on the current platform using GetNativeSizeHint , otherwise return the size from the topmost ArtProvider. DefaultSize may be returned if the client doesn’t have a specified size, like ART_OTHER for example.

Parameters:
  • client (string) –
  • platform_default (bool) –
Return type:

Size



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 or PushBack .

Return type:bool

New in version 2.9.0.



static Insert(provider)
Parameters:provider (ArtProvider) –

Deprecated since version 2.9.4: Use PushBack instead.



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 (ArtProvider) –

See also

PushBack



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 (ArtProvider) –

New in version 2.9.0.

See also

Push



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 (ArtProvider) –
Return type:bool