gtk.gdk.Color — an object holding color information
class gtk.gdk.Color(gobject.GBoxed): |
Functions
def gtk.gdk.color_parse(spec
)
|
A gtk.gdk.Color
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 gtk.gdk.Color
.
Typically a color is allocated by using the gdk.Colormap.alloc_color
()
method. Unallocated colors can be used to specify the color attributes of
gtk.Style
objects since these colors will be allocated when an attempt is made to use
the gtk.Style
object.
Starting with PyGTK 2.14 gtk.gdk.Color
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 gtk.gdk.Color
objects using
the constructor.
Also beginning with PyGTK 2.14 gtk.gdk.Color
objects have
custom support for str
and repr
Python
functions. For any color it holds that:
color == eval(repr(color))
gtk.gdk.Color(red
=0, green
=0, blue
=0, pixel
=0)
gtk.gdk.Color(spec
)
| The red color component in the range 0-65535 |
| The green color component in the range 0-65535 |
| The blue color component in the range 0-65535 |
| The index of the color when allocated in its colormap |
| String containing color specification |
Returns : | a new gtk.gdk.Color
object |
Second form of the constructor is available in PyGTK 2.14 and above.
Creates a new gtk.gdk.Color
object
with the color component values specified by red
,
green
and blue
(all default to
0) and using the pixel value specified by pixel
. The
value of pixel
will be overwritten when the color is
allocated.
Second form of the constructor is analogous to
gtk.gdk.color_parse
.
def to_string()
Returns : | a string |
This method is available in PyGTK 2.12 and above.
The to_string
() 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.
Starting with PyGTK 2.14 you can also
use str(color)
code. However, that can return a
shorter (3, 6 or 12 hexadecimal digits) string if shorter version means
the same for the constructor.
def gtk.gdk.color_parse(spec
)
| a string containing a color specification |
Returns : | a gtk.gdk.Color
object |
The gtk.gdk.color_parse
() method returns
the gtk.gdk.Color
specified by spec
. The format of
spec
is a string containing the specification of the
color either as a name (e.g. "navajowhite") as specified in the X11
rgb.txt
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 gtk.gdk.Color
is
not allocated.
This function raise the ValueError (TypeError prior to PyGTK 2.4) exception if unable to parse the color specification