<?xml version="1.0" standalone="no"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">

<refentry id="class-gdkcolor">
  <refnamediv>
    <refname>gtk.gdk.Color</refname>
    <refpurpose>an object holding color information</refpurpose>
  </refnamediv>

  <refsect1>
    <title>Synopsis</title>

    <classsynopsis language="python">
      <ooclass><classname>gtk.gdk.Color</classname></ooclass>
      <ooclass><classname>gobject.GBoxed</classname></ooclass>
      <constructorsynopsis language="python">
	<methodname><link
linkend="constructor-gdkcolor">gtk.gdk.Color</link></methodname>
	<methodparam><parameter
		       role="keyword">red</parameter>
	  <initializer>0</initializer></methodparam>
	<methodparam><parameter
		       role="keyword">green</parameter>
	  <initializer>0</initializer></methodparam>
	<methodparam><parameter
		       role="keyword">blue</parameter>
	  <initializer>0</initializer></methodparam>
	<methodparam><parameter
		       role="keyword">pixel</parameter>
	  <initializer>0</initializer></methodparam>
      </constructorsynopsis>
      
      <methodsynopsis language="python">
        <methodname><link linkend="method-gdkcolor--to-string">to_string</link></methodname>
        <methodparam></methodparam>
    </methodsynopsis>
    
    </classsynopsis>

    <programlisting>
<emphasis role="bold">Functions</emphasis>

<methodsynopsis language="python">
	<methodname><link linkend="function-gdk--color-parse">gtk.gdk.color_parse</link></methodname>
	<methodparam><parameter role="keyword">spec</parameter></methodparam>
      </methodsynopsis><methodsynopsis language="python">
      <methodname><link linkend="function-gdk--color-from-hsv">gtk.gdk.color_from_hsv</link></methodname>
      <methodparam><parameter role="keyword">hue</parameter></methodparam>
      <methodparam><parameter role="keyword">saturation</parameter></methodparam>
      <methodparam><parameter role="keyword">value</parameter></methodparam>
    </methodsynopsis></programlisting>

  </refsect1>

  <refsect1>
    <title>Attributes</title>

    <note>
      <para>Floating-point and HSV attributes are available in PyGTK 2.16 and above.</para>
    </note>

    <blockquote role="properties">
      <informaltable pgwide="1" frame="none">
	<tgroup cols="3">
	<?dbhtml cellpadding="5"?>
	  <colspec column="1" colwidth="1in"/>
	  <colspec column="2" colwidth="1in"/>
	  <colspec column="3" colwidth="4in"/>
	  <tbody>

	    <row valign="top">
	      <entry>"pixel"</entry>
	      <entry>Read-Write</entry>
	      <entry>The pixel value of the color</entry>
	    </row>

	    <row valign="top">
	      <entry>"red"</entry>
	      <entry>Read-Write</entry>
	      <entry>The value of the red component of the color</entry>
	    </row>

	    <row valign="top">
	      <entry>"green"</entry>
	      <entry>Read-Write</entry>
	      <entry>The value of the green component of the color</entry>
	    </row>

	    <row valign="top">
	      <entry>"blue"</entry>
	      <entry>Read-Write</entry>
	      <entry>The value of the blue component of the color</entry>
	    </row>

	    <row valign="top">
	      <entry>"red_float"</entry>
	      <entry>Read-Write</entry>
	      <entry>The value of the red component of the color as a float in the range 0.0--1.0</entry>
	    </row>

	    <row valign="top">
	      <entry>"green_float"</entry>
	      <entry>Read-Write</entry>
	      <entry>The value of the green component of the color as a float in the range 0.0--1.0</entry>
	    </row>

	    <row valign="top">
	      <entry>"blue_float"</entry>
	      <entry>Read-Write</entry>
	      <entry>The value of the blue component of the color as a float in the range 0.0--1.0</entry>
	    </row>

	    <row valign="top">
	      <entry>"hue"</entry>
	      <entry>Read</entry>
	      <entry>The hue (in HSV colorspace) of the color as a float in the range 0.0--1.0</entry>
	    </row>

	    <row valign="top">
	      <entry>"saturation"</entry>
	      <entry>Read</entry>
	      <entry>The saturation (in HSV colorspace) of the color as a float in the range 0.0--1.0</entry>
	    </row>

	    <row valign="top">
	      <entry>"value"</entry>
	      <entry>Read</entry>
	      <entry>The value (in HSV colorspace) of the color as a float in the range 0.0--1.0</entry>
	    </row>

	</tbody>
      </tgroup>
      </informaltable>
    </blockquote>

    <para>For details on how assignment to <literal>*_float</literal> attributes work,
      see <link linkend="constructor-gdkcolor">constructor documentation</link>.</para>
  </refsect1>

  <refsect1>
    <title>Description</title>

    <para>A <link
linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link>
contains the values of a color that may or may not be allocated. The red,
green and blue attributes are specified by an unsigned integer in the range
0-65535. The pixel value is an index into the colormap that has allocated
the <link
linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link>.
Typically a color is allocated by using the <link
linkend="method-gdkcolormap--alloc-color"><methodname>gdk.Colormap.alloc_color</methodname>()</link> 
method. Unallocated colors can be used to specify the color attributes of
<link linkend="class-gtkstyle"><classname>gtk.Style</classname></link>
objects since these colors will be allocated when an attempt is made to use
the <link linkend="class-gtkstyle"><classname>gtk.Style</classname></link>
object.</para>

    <para>
      Starting with PyGTK 2.14 <classname>gtk.gdk.Color</classname> objects are properly
      comparable.  By Python rules, colors (being mutable) are now unhashable.  If you
      need to use them as dictionary keys, use string representation instead.  You can
      convert string representation to <classname>gtk.gdk.Color</classname> objects using
      the constructor.
    </para>

    <para>
      Also beginning with PyGTK 2.14 <classname>gtk.gdk.Color</classname> objects have
      custom support for <function>str</function> and <function>repr</function> Python
      functions.  For any color it holds that:
    </para>

    <programlisting>
  color == eval(repr(color))
    </programlisting>

    <para>
      PyGTK 2.16 introduces several ways of using floating-point numbers for
      creating <link linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link>
      objects or setting their individual components.  In all cases it was decided to
      silently clamp input values to valid range, rather than being strict and e.g. raise
      an exception.  The rationale is that floating-point arithmetics are imprecise, so
      you could end with a computed value slightly larger than maximum or a little smaller
      than minimum valid value.  To simplify using new features, such "slightly off"
      values are just clamped without any warning.
    </para>

  </refsect1>

  <refsect1 id="constructor-gdkcolor">
    <title>Constructor</title>

    <programlisting><constructorsynopsis language="python">
	<methodname>gtk.gdk.Color</methodname>
	<methodparam><parameter
		       role="keyword">red</parameter>
	  <initializer>0</initializer></methodparam>
	<methodparam><parameter
		       role="keyword">green</parameter>
	  <initializer>0</initializer></methodparam>
	<methodparam><parameter
		       role="keyword">blue</parameter>
	  <initializer>0</initializer></methodparam>
	<methodparam><parameter
		       role="keyword">pixel</parameter>
	  <initializer>0</initializer></methodparam>
    </constructorsynopsis></programlisting>
    <programlisting><constructorsynopsis language="python">
	<methodname>gtk.gdk.Color</methodname>
	<methodparam><parameter
		       role="keyword">spec</parameter></methodparam>
      </constructorsynopsis></programlisting>
    <variablelist>
      <varlistentry>
	<term><parameter role="keyword">red</parameter>&nbsp;:</term>
	<listitem><simpara>The red color component in the range
0-65535</simpara></listitem>
      </varlistentry>
      <varlistentry>
	<term><parameter role="keyword">green</parameter>&nbsp;:</term>
	<listitem><simpara>The green color component in the range
0-65535</simpara></listitem>
      </varlistentry>
      <varlistentry>
	<term><parameter role="keyword">blue</parameter>&nbsp;:</term>
	<listitem><simpara>The blue color component in the range
0-65535</simpara></listitem>
      </varlistentry>
      <varlistentry>
	<term><parameter role="keyword">pixel</parameter>&nbsp;:</term>
	<listitem><simpara>The index of the color when allocated in its
colormap</simpara></listitem>
      </varlistentry>
      <varlistentry>
	<term><parameter role="keyword">spec</parameter>&nbsp;:</term>
	<listitem><simpara>String containing color specification</simpara></listitem>
      </varlistentry>
      <varlistentry>
	<term><emphasis>Returns</emphasis>&nbsp;:</term>
	<listitem><simpara>a new <link
linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link>
object</simpara></listitem>
      </varlistentry>
    </variablelist>

    <note>
      <para>Second form of the constructor is available in PyGTK 2.14 and above.</para>
    </note>

    <note>
      <para><parameter>red</parameter>, <parameter>green</parameter>
      and <parameter>blue</parameter> can be floating-point numbers since PyGTK
      2.16.</para>
    </note>

    <para>Creates a new <link
linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link> object
with the color component values specified by <parameter>red</parameter>,
<parameter>green</parameter> and <parameter>blue</parameter> (all default to
0) and using the pixel value specified by <parameter>pixel</parameter>. The
value of <parameter>pixel</parameter> will be overwritten when the color is
allocated.</para>

    <para>Second form of the constructor is analogous to
      <link linkend="function-gdk--color-parse"><function>gtk.gdk.color_parse</function></link>.</para>

    <para>Starting with PyGTK 2.16, <parameter>red</parameter>, <parameter>green</parameter> and
      <parameter>blue</parameter> parameters can also be floating-point numbers in the
      range 0.0--1.0.  Either all specified values must be integers or floats -- mixing is
      not allowed as this would be too error-prone.  Values outside the valid range
      0.0--1.0 are clamped, so e.g. 3.14 is the same as 1.0.</para>

    <para>Note that internally values are still stored as integers, so values of
      corresponding <literal>*_float</literal> attribute will not necessarily be the same
      as the value used as argument for the constructor.  They will be as close as
      permitted by 16-bit color component storage used by <classname>GdkColor</classname>
      though.</para>

    <para>All of the following expressions create a bright green color:</para>

    <programlisting>
  gtk.gdk.Color(0, 65535, 0)
  gtk.gdk.Color(green=1.0)
  gtk.gdk.Color('#0f0')
    </programlisting>

  </refsect1>
  
    <refsect1>
        <title>Methods</title>

        <refsect2 id="method-gdkcolor--to-string">
            <title>gtk.gdk.Color.to_string</title>

            <programlisting><methodsynopsis language="python">
                <methodname>to_string</methodname>
                <methodparam></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
                <varlistentry>
                    <term><emphasis>Returns</emphasis>&nbsp;:</term>
                        <listitem><simpara>a string</simpara></listitem>
                </varlistentry>
            </variablelist>

            <note>
                <para>This method is available in PyGTK 2.12 and above.</para>
            </note>

            <para>
                The <methodname>to_string</methodname>() method returns a textual
                specification of color in the hexadecimal form #rrrrggggbbbb,
                where r, g and b are hex digits representing the red,
                green and blue components respectively.
            </para>

            <note>
                <para>Starting with PyGTK 2.14 you can also
                use <literal>str(color)</literal> code.  However, that can return a
                shorter (3, 6 or 12 hexadecimal digits) string if shorter version means
                the same for the constructor.</para>
            </note>
        </refsect2>
    </refsect1>

  <refsect1>
    <title>Functions</title>

    <refsect2 id="function-gdk--color-parse">
      <title>gtk.gdk.color_parse</title>

      <programlisting><methodsynopsis language="python">
	  <methodname>gtk.gdk.color_parse</methodname>
	  <methodparam><parameter role="keyword">spec</parameter></methodparam>
	</methodsynopsis></programlisting>

      <variablelist>
	<varlistentry>
	  <term><parameter role="keyword">spec</parameter>&nbsp;:</term>
	  <listitem><simpara>a string containing a color
specification</simpara></listitem>
	</varlistentry>
        <varlistentry>
          <term><emphasis>Returns</emphasis>&nbsp;:</term>
          <listitem><simpara>a <link
linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link>
object</simpara></listitem>
        </varlistentry>
      </variablelist>

      <para>The <function>gtk.gdk.color_parse</function>() method returns
the <link
linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link>
specified by <parameter>spec</parameter>. The format of
<parameter>spec</parameter> is a string containing the specification of the
color either as a name (e.g. "navajowhite") as specified in the X11
<filename>rgb.txt</filename> file or as a hexadecimal string (e.g.
"#FF0078"). The hexadecimal string must start with '#' and must contain 3
sets of hexadecimal digits of the same length (i.e. 1, 2 ,3 or 4 digits).
For example the following specify the same color value: "#F0A", "#FF00AA",
"#FFF000AAA" and "#FFFF0000AAAA". The <link
linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link> is
<emphasis>not</emphasis> allocated.</para>

      <para>This function raise the ValueError (TypeError prior to PyGTK
2.4) exception if unable to parse the color specification</para>

    </refsect2>

    <refsect2 id="function-gdk--color-from-hsv">
      <title>gtk.gdk.color_from_hsv</title>

      <programlisting><methodsynopsis language="python">
	  <methodname>gtk.gdk.color_from_hsv</methodname>
	  <methodparam><parameter role="keyword">hue</parameter></methodparam>
	  <methodparam><parameter role="keyword">saturation</parameter></methodparam>
	  <methodparam><parameter role="keyword">value</parameter></methodparam>
	</methodsynopsis></programlisting>

      <variablelist>
	<varlistentry>
	  <term><parameter role="keyword">hue</parameter>&nbsp;:</term>
	  <listitem><simpara>Hue of the desired color as a float in range
	      0.0--1.0</simpara></listitem>
	</varlistentry>
	<varlistentry>
	  <term><parameter role="keyword">saturation</parameter>&nbsp;:</term>
	  <listitem><simpara>Saturation of the desired color as a float in range
	      0.0--1.0</simpara></listitem>
	</varlistentry>
	<varlistentry>
	  <term><parameter role="keyword">value</parameter>&nbsp;:</term>
	  <listitem><simpara>Value of the desired color as a float in range
	      0.0--1.0</simpara></listitem>
	</varlistentry>
        <varlistentry>
          <term><emphasis>Returns</emphasis>&nbsp;:</term>
          <listitem><simpara>a <link linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link>
              object</simpara></listitem>
        </varlistentry>
      </variablelist>

      <note>
        <para>This function is available in PyGTK 2.16 and above.</para>
      </note>

      <para>The <function>gtk.gdk.color_from_hsv</function>() method returns
        the <link linkend="class-gdkcolor"><classname>gtk.gdk.Color</classname></link>
        specified by the HSV parameters.  All three parameters are mandatory and should be
        floats from 0.0 to 1.0.  The range requirement, however, is not strict, see
        below.</para>

      <para>As hue goes from 0 to 1 color goes roughly as red → yellow → green → cyan →
        blue → magenta → red.  Because of the "circular" nature, this parameter wraps
        around, so only fractional part matters.  E.g. -4.2 or 1.8 are the same as 0.8.
        Saturation determines how intense a color is, with 0.0 meaning pure gray and 1.0
        -- fully intense color.  Value determines how light a color is, with 0.0 standing
        for fully black and 1.0 for completely white color.  Both saturation and value are
        clamped to valid range (see rationale at the top of the page).</para>

      <para>Note that internal storage is still integers, so values of
        corresponding <literal>hue</literal>, <literal>saturation</literal>
        and <literal>value</literal> attributes of the returned object will not
        necessarily be equal to the value used as argument for this functions.  They will
        be as close as permitted by 16-bit color component storage used
        by <classname>GdkColor</classname> though.</para>

      <para>For more details read about <ulink url="http://en.wikipedia.org/wiki/HSL_and_HSV">HSV
          colorspace</ulink>.</para>
    </refsect2>

  </refsect1>

</refentry>
