summaryrefslogtreecommitdiff
path: root/docs/reference/pygtk-gdkcolor.xml
blob: 60d3ab533eddda49dce10cafd109c4dba2685758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?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></programlisting>

  </refsect1>

  <refsect1>
    <title>Attributes</title>

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

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

  </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>

  </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>

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

  </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>

  </refsect1>

</refentry>