.. 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.GetBitmap`   or :meth:`wx.ArtProvider.GetIcon` . 



|phoenix_title| Identifying art resources
=========================================

Every bitmap and icon bundle are known to :ref:`wx.ArtProvider`  under an unique ``ID`` that is used when requesting a resource from it. The ``ID`` is represented by the :ref:`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 <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 <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 <http://library.gnome.org/devel/gtk/stable/gtk-Stock-Items.html>`_. 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 <http://freedesktop.org/Standards/icon-theme-spec>`_. Note that themes are not guaranteed to contain all icons, so :ref:`wx.ArtProvider`  may return :ref:`wx.NullBitmap`  or :ref:`wx.NullIcon`. The default theme is typically installed in  ``/usr/share/icons/hicolor`` .  







.. seealso:: :ref:`Art Provider Sample <art provider sample>`  for an example of :ref:`wx.ArtProvider`  usage; :ref:`stock ID list <stock id list>`    







|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>ArtProvider</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.ArtProvider_inheritance.png" alt="Inheritance diagram of ArtProvider" usemap="#dummy" class="inheritance"/></center>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.ArtProvider.html" title="wx.ArtProvider" alt="" coords="5,83,124,112"/> <area shape="rect" id="node2" href="wx.Object.html" title="wx.Object" alt="" coords="21,5,108,35"/> </map> 
   </p>
   </div>

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.ArtProvider.CreateBitmap`                                             Derived art provider classes must 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.GetIcon`                                                  Same as :meth:`wx.ArtProvider.GetBitmap` , but return a :ref:`wx.Icon`  object (or :ref:`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.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 must override this method to create requested art resource.                  

      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``.                  




      :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:: GetIcon(id, client=ART_OTHER, size=DefaultSize)

      Same as :meth:`wx.ArtProvider.GetBitmap` , but return a :ref:`wx.Icon`  object (or :ref:`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: :ref:`wx.ArtID`








   .. staticmethod:: 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. 

                


      :param `client`: 
      :type `client`: wx.ArtClient




      :rtype: :ref:`wx.Size`







      .. versionadded:: 2.9.0 
     







      .. 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:: 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 :meth:`GetNativeSizeHint` , otherwise return the size from the topmost :ref:`wx.ArtProvider`. `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
      :param `platform_default`: 
      :type `platform_default`: bool




      :rtype: :ref:`wx.Size`







      .. seealso:: :meth:`GetNativeSizeHint`     








   .. 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`







