.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2018 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.Palette:

==========================================================================================================================================
|phoenix_title|  **wx.Palette**
==========================================================================================================================================

A palette is a table that maps pixel values to ``RGB`` colours.          

It allows the colours of a low-depth bitmap, for example, to be mapped to the available colours in a display. The notion of palettes is becoming more and more obsolete nowadays and only the MSW port is still using a native palette. All other ports use generic code which is basically just an array of colours. 

It is likely that in the future the only use for palettes within wxWidgets will be for representing colour indices from images (such as ``GIF`` or ``PNG``). The image handlers for these formats have been modified to create a palette if there is such information in the original image file (usually 256 or less colour images). See :ref:`wx.Image`  for more information. 









         



.. seealso:: :meth:`wx.DC.SetPalette` , :ref:`wx.Bitmap`    







|

|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>Palette</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.Palette_inheritance.png" alt="Inheritance diagram of Palette" usemap="#dummy" class="inheritance"/></center>
   </div>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.Palette.html" title="wx.Palette" alt="" coords="15,160,101,189"/> <area shape="rect" id="node2" href="wx.GDIObject.html" title="wx.GDIObject" alt="" coords="5,83,112,112"/> <area shape="rect" id="node3" href="wx.Object.html" title="wx.Object" alt="" coords="17,5,99,35"/> </map> 
   </p>

|


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

================================================================================ ================================================================================
:meth:`~wx.Palette.__init__`                                                     Default constructor.
:meth:`~wx.Palette.Create`                                                       Creates a palette from 3 sequences of integers, one for each red, blue or green component.
:meth:`~wx.Palette.GetColoursCount`                                              Returns number of entries in palette.
:meth:`~wx.Palette.GetPixel`                                                     Returns a pixel value (index into the palette) for the given ``RGB`` values.
:meth:`~wx.Palette.GetRGB`                                                       Returns ``RGB`` values for a given palette index.
:meth:`~wx.Palette.IsOk`                                                         Returns ``True`` if palette data is present.
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.Palette.ColoursCount`                                                 See :meth:`~wx.Palette.GetColoursCount`
:attr:`~wx.Palette.RGB`                                                          See :meth:`~wx.Palette.GetRGB`
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.Palette(GDIObject)

   **Possible constructors**::

       Palette()
       
       Palette(palette)
       
       Palette(red, green, blue)
       
   
   A palette is a table that maps pixel values to ``RGB`` colours.



   .. method:: __init__(self, *args, **kw)



      |overload| Overloaded Implementations:

      **~~~**

      
      **__init__** `(self)`
      
      Default constructor.                   
      
      
      
      
      **~~~**

      
      **__init__** `(self, palette)`
      
      Copy constructor, uses :ref:`Reference Counting <reference counting>`.                  
      
      
      
      
      :param `palette`: A reference to the palette to copy.   
      :type `palette`: wx.Palette
      
      
      
      
                        
      
      
      
      
      **~~~**

      
      **__init__** `(self, red, green, blue)`
      
      Creates a palette from a set of sequences of integers,
      one for each red, green and blue color components.
      
      :param red: A sequence of integer values in the range 0..255 inclusive.
      :param green: A sequence of integer values in the range 0..255 inclusive.
      :param blue: A sequence of integer values in the range 0..255 inclusive.
      
      .. note:: All sequences must be the same length.  
      
      
      
      
      **~~~**






   .. method:: Create(self, red, green, blue)

      Creates a palette from 3 sequences of integers, one for each red, blue or green component.

      :param red: A sequence of integer values in the range 0..255 inclusive.
      :param green: A sequence of integer values in the range 0..255 inclusive.
      :param blue: A sequence of integer values in the range 0..255 inclusive.

      .. note:: All sequences must be the same length. 

      :rtype: `bool`








   .. method:: GetColoursCount(self)

      Returns number of entries in palette.                  

      :rtype: `int`








   .. method:: GetPixel(self, red, green, blue)

      Returns a pixel value (index into the palette) for the given ``RGB`` values.                  




      :param `red`: Red value.   
      :type `red`: int
      :param `green`: Green value.   
      :type `green`: int
      :param `blue`: Blue value.  
      :type `blue`: int










      :rtype: `int`



                  



      :returns: 

         The nearest palette index or  ``NOT_FOUND``   for unexpected errors.  







      .. seealso:: :meth:`GetRGB`     








   .. method:: GetRGB(self, pixel)

      Returns ``RGB`` values for a given palette index. 

      :rtype: `tuple`







      :returns: 

         ( `red`, `green`, `blue` ) 








   .. method:: IsOk(self)

      Returns ``True`` if palette data is present.                  

      :rtype: `bool`








   .. attribute:: ColoursCount

      See :meth:`~wx.Palette.GetColoursCount`


   .. attribute:: RGB

      See :meth:`~wx.Palette.GetRGB`

