.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2020 by Total Control Software License: wxWindows License .. include:: headings.inc .. _wx.ArtProvider: ========================================================================================================================================== |phoenix_title| **wx.ArtProvider** ========================================================================================================================================== :ref:`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 :ref:`wx.ArtProvider` for it instead. This way users can plug in their own :ref:`wx.ArtProvider` class and easily replace standard art with their own version. All that is needed is to derive a class from :ref:`wx.ArtProvider`, override either its :meth:`wx.ArtProvider.CreateBitmap` and/or its :meth:`wx.ArtProvider.CreateIconBundle` methods and register the provider with :meth:`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 :meth:`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 :meth:`wx.ArtProvider.GetBitmapBundle` or :meth:`wx.ArtProvider.GetIcon` . |phoenix_title| Identifying art resources ========================================= Every bitmap and icon bundle are known to :ref:`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 :ref:`Art Provider Sample `): .. include:: rest_substitutions\tables\wx.ArtProvider.1.rst Additionally, any string recognized by custom art providers registered using :meth:`wx.ArtProvider.Push` may be used. |phoenix_title| Clients ======================= The `client` is the entity that calls :ref:`wx.ArtProvider`'s :meth:`~wx.ArtProvider.GetBitmap` or :meth:`~wx.ArtProvider.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 :ref:`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 :ref:`wx.ArtProvider` – it is common that :meth:`wx.ArtProvider.GetBitmap` returns identical bitmap for different client values! .. note:: When building with ``NO_IMPLICIT_WXSTRING_ENCODING`` defined (see :ref:`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 :ref:`wx.ArtProvider` may return `wx.NullBitmap` or `wx.NullIcon` . The default theme is typically installed in ``/usr/share/icons/hicolor`` . .. seealso:: :ref:`Art Provider Sample ` for an example of :ref:`wx.ArtProvider` usage; :ref:`stock ID list ` | |class_hierarchy| Class Hierarchy ================================= .. raw:: html
Inheritance diagram for class ArtProvider:
| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~wx.ArtProvider.CreateBitmap` Derived art provider classes may override this method to create requested art resource. :meth:`~wx.ArtProvider.CreateIconBundle` This method is similar to :meth:`~ArtProvider.CreateBitmap` but can be used when a bitmap (or an icon) exists in several sizes. :meth:`~wx.ArtProvider.Delete` Delete the given `provider`. :meth:`~wx.ArtProvider.GetBitmap` Query registered providers for bitmap with given ``ID``. :meth:`~wx.ArtProvider.GetBitmapBundle` Query registered providers for a bundle of bitmaps with given ``ID``. :meth:`~wx.ArtProvider.GetDIPSizeHint` Returns a suitable size hint for the given `ArtClient` in DIPs. :meth:`~wx.ArtProvider.GetIcon` Same as :meth:`wx.ArtProvider.GetBitmap` , but return a :ref:`wx.Icon` object (or `wx.NullIcon` on failure). :meth:`~wx.ArtProvider.GetIconBundle` Query registered providers for icon bundle with given ``ID``. :meth:`~wx.ArtProvider.GetMessageBoxIcon` Helper used by several generic classes: return the icon corresponding to the standard ICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set) :meth:`~wx.ArtProvider.GetMessageBoxIconId` Helper used by :meth:`~ArtProvider.GetMessageBoxIcon` : return the art id corresponding to the standard ICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set) :meth:`~wx.ArtProvider.GetNativeDIPSizeHint` Returns native icon size for use specified by `client` hint in DIPs. :meth:`~wx.ArtProvider.GetNativeSizeHint` Returns native icon size for use specified by `client` hint. :meth:`~wx.ArtProvider.GetSizeHint` Returns a suitable size hint for the given `ArtClient`. :meth:`~wx.ArtProvider.HasNativeProvider` Returns ``True`` if the platform uses native icons provider that should take precedence over any customizations. :meth:`~wx.ArtProvider.Pop` Remove latest added provider and delete it. :meth:`~wx.ArtProvider.Push` Register new art provider and add it to the top of providers stack (i.e. :meth:`~wx.ArtProvider.PushBack` Register new art provider and add it to the bottom of providers stack. :meth:`~wx.ArtProvider.Remove` Remove a provider from the stack if it is on it. ================================================================================ ================================================================================ | |api| Class API =============== .. class:: wx.ArtProvider(Object) ArtProvider class is used to customize the look of wxWidgets application. .. method:: 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, :meth:`CreateBitmapBundle` should be overridden instead. Note that returned bitmaps are cached by :ref:`wx.ArtProvider` and it is therefore not necessary to optimize :meth:`CreateBitmap` for speed (e.g. you may create :ref:`wx.Bitmap` objects from XPMs here). :param `id`: ArtID unique identifier of the bitmap. :type `id`: wx.ArtID :param `client`: ArtClient identifier of the client (i.e. who is asking for the bitmap). This only serves as a hint. :type `client`: wx.ArtClient :param `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. :type `size`: wx.Size :rtype: :ref:`wx.Bitmap` .. note:: This is not part of :ref:`wx.ArtProvider`'s public API, use :meth:`wx.ArtProvider.GetBitmap` or :meth:`wx.ArtProvider.GetIconBundle` or :meth:`wx.ArtProvider.GetIcon` to query :ref:`wx.ArtProvider` for a resource. .. seealso:: :meth:`CreateIconBundle` .. method:: CreateIconBundle(self, id, client) This method is similar to :meth:`CreateBitmap` but can be used when a bitmap (or an icon) exists in several sizes. :param `id`: :type `id`: wx.ArtID :param `client`: :type `client`: wx.ArtClient :rtype: :ref:`wx.IconBundle` .. staticmethod:: Delete(provider) Delete the given `provider`. :param `provider`: :type `provider`: wx.ArtProvider :rtype: `bool` .. staticmethod:: 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 :meth:`GetBitmapBundle` . :param `id`: ArtID unique identifier of the bitmap. :type `id`: wx.ArtID :param `client`: ArtClient identifier of the client (i.e. who is asking for the bitmap). :type `client`: wx.ArtClient :param `size`: Size of the returned bitmap or DefaultSize if size doesn't matter. :type `size`: wx.Size :rtype: :ref:`wx.Bitmap` :returns: The bitmap if one of registered providers recognizes the ``ID`` or NullBitmap otherwise. .. staticmethod:: GetBitmapBundle(id, client=ART_OTHER, size=DefaultSize) Query registered providers for a bundle of bitmaps with given ``ID``. :param `id`: ArtID unique identifier of the bitmap. :type `id`: wx.ArtID :param `client`: ArtClient identifier of the client (i.e. who is asking for the bitmap). :type `client`: wx.ArtClient :param `size`: Default size for the returned bundle, i.e. the size of the bitmap in normal ``DPI`` (this implies that :meth:`wx.Window.FromDIP` must `not` be used with it). :type `size`: wx.Size :rtype: :ref:`wx.BitmapBundle` :returns: If any of the registered providers recognizes the ``ID`` in its :meth:`CreateBitmapBundle` , this bundle is returned. Otherwise, if any of providers returns a valid bitmap from :meth:`CreateBitmap` , the bundle containing only this bitmap is returned. Otherwise, an empty bundle is returned. .. versionadded:: 4.1/wxWidgets-3.1.6 .. staticmethod:: GetDIPSizeHint(client) Returns a suitable size hint for the given `ArtClient` in DIPs. Return the size used by the topmost :ref:`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. :param `client`: :type `client`: wx.ArtClient :rtype: :ref:`wx.Size` .. seealso:: :meth:`GetNativeDIPSizeHint` .. staticmethod:: GetIcon(id, client=ART_OTHER, size=DefaultSize) Same as :meth:`wx.ArtProvider.GetBitmap` , but return a :ref:`wx.Icon` object (or `wx.NullIcon` on failure). :param `id`: :type `id`: wx.ArtID :param `client`: :type `client`: wx.ArtClient :param `size`: :type `size`: wx.Size :rtype: :ref:`wx.Icon` .. staticmethod:: GetIconBundle(id, client=ART_OTHER) Query registered providers for icon bundle with given ``ID``. :param `id`: ArtID unique identifier of the icon bundle. :type `id`: wx.ArtID :param `client`: ArtClient identifier of the client (i.e. who is asking for the icon bundle). :type `client`: wx.ArtClient :rtype: :ref:`wx.IconBundle` :returns: The icon bundle if one of registered providers recognizes the ``ID`` or NullIconBundle otherwise. .. staticmethod:: 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) :param `flags`: :type `flags`: int :rtype: :ref:`wx.Icon` .. staticmethod:: GetMessageBoxIconId(flags) Helper used by :meth:`GetMessageBoxIcon` : return the art id corresponding to the standard ICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set) :param `flags`: :type `flags`: int :rtype: `wx.ArtID` .. staticmethod:: 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. :param `client`: :type `client`: wx.ArtClient :rtype: :ref:`wx.Size` .. versionadded:: 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. .. staticmethod:: GetNativeSizeHint(client, win=None) Returns native icon size for use specified by `client` hint. This function does the same thing as :meth:`GetNativeDIPSizeHint` , but uses `win` to convert the returned value to logical pixels. If `win` is ``None``, default ``DPI`` scaling (i.e. that of the primary display) is used. :param `client`: :type `client`: wx.ArtClient :param `win`: :type `win`: wx.Window :rtype: :ref:`wx.Size` .. versionadded:: 2.9.0 (`win` parameter is available only since 3.1.6) .. staticmethod:: GetSizeHint(client, win=None) Returns a suitable size hint for the given `ArtClient`. This function does the same thing as :meth:`GetDIPSizeHint` , but uses `win` to convert the returned value to logical pixels. If `win` is ``None``, default ``DPI`` scaling (i.e. that of the primary display) is used. Note that `win` parameter is only available since wxWidgets 3.1.6. :param `client`: :type `client`: wx.ArtClient :param `win`: :type `win`: wx.Window :rtype: :ref:`wx.Size` .. staticmethod:: 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 :meth:`Push` or :meth:`PushBack` . :rtype: `bool` .. versionadded:: 2.9.0 .. staticmethod:: Pop() Remove latest added provider and delete it. :rtype: `bool` .. staticmethod:: 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). :param `provider`: :type `provider`: wx.ArtProvider .. seealso:: :meth:`PushBack` .. staticmethod:: 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. :param `provider`: :type `provider`: wx.ArtProvider .. versionadded:: 2.9.0 .. seealso:: :meth:`Push` .. staticmethod:: Remove(provider) Remove a provider from the stack if it is on it. The provider is not deleted, unlike when using :meth:`Delete` . :param `provider`: :type `provider`: wx.ArtProvider :rtype: `bool`