1 # Copyright (C) 2008 Samuel Abels, http://debain.org
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2, as
5 # published by the Free Software Foundation.
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License
13 # along with this program; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 ########################
18 # Explicit converters.
19 ########################
21 return gtk
.gdk
.color_parse(name
)
24 red
= (i
>> 24) & 0xff
25 green
= (i
>> 16) & 0xff
26 blue
= (i
>> 8) & 0xff
27 return gtk
.gdk
.Color(red
* 256, green
* 256, blue
* 256)
30 red
= color
[0] * 65535.0
31 green
= color
[1] * 65535.0
32 blue
= color
[2] * 65535.0
33 return gtk
.gdk
.Color(red
, green
, blue
)
36 red
= color
[0] * 65535.0
37 green
= color
[1] * 65535.0
38 blue
= color
[2] * 65535.0
39 value
= color
[3] * 65535.0 # not supported by gdk.Color
40 return gtk
.gdk
.Color(red
, green
, blue
)
43 return (color
.red
/ 256 << 24) \
44 |
(color
.green
/ 256 << 16) \
45 |
(color
.blue
/ 256 << 8) \
49 return (color
.red
/ 65535.0, color
.green
/ 65535.0, color
.blue
/ 65535.0)
52 return (color
.red
/ 65535.0, color
.green
/ 65535.0, color
.blue
/ 65535.0, 1)
54 ########################
55 # Automatic converters.
56 ########################
58 if isinstance(color
, gtk
.gdk
.Color
):
60 elif type(color
) == type(0) or type(color
) == type(0l):
62 elif type(color
) == type(''):
64 elif type(color
) == type(()) and len(color
) == 3:
66 elif type(color
) == type(()) and len(color
) == 4:
67 return rgba2gdk(color
)
69 raise TypeError('%s is not a known color type' % type(color
))
72 return gdk2int(to_gdk(color
))
75 return gdk2rgb(to_gdk(color
))
78 return gdk2rgba(to_gdk(color
))