1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 Color options, these classes will display a text box.
19 """
20
21 import gtk
22
23 from screenlets.options import _
24 from base import Option
25
27 """An Option for color options."""
29 """Import (r, g, b, a) from comma-separated string."""
30
31 strvalue = strvalue.lstrip('(')
32 strvalue = strvalue.rstrip(')')
33 strvalue = strvalue.strip()
34
35 tmpval = strvalue.split(',')
36 outval = []
37 for f in tmpval:
38
39 outval.append(float(f.strip()))
40 return outval
41
43 """Export r, g, b, a to comma-separated string."""
44 l = len(value)
45 outval = ''
46 for i in xrange(l):
47 if type(value[i]) == float:
48 outval += "%0.5f" % value[i]
49 else:
50 outval += str(value[i])
51 if i < l-1:
52 outval += ','
53 return outval
54
60
62 """Set the color value as required."""
63 self.value = value
64
69
71 """Turn a colour array into a colour widget"""
72 result = gtk.ColorButton(gtk.gdk.Color(
73 int(colour[0]*65535), int(colour[1]*65535), int(colour[2]*65535)))
74 result.set_use_alpha(True)
75 result.set_alpha(int(colour[3]*65535))
76 result.connect("color-set", self.has_changed)
77 return result
78
80 """Turn a colour widget into a colour array"""
81 colour = widget.get_color()
82 return (
83 colour.red/65535.0,
84 colour.green/65535.0,
85 colour.blue/65535.0,
86 widget.get_alpha()/65535.0
87 )
88
89
91 """Allow a list of colours to be created"""
93 """Importing multiple colours"""
94 result = []
95 for col in value.split(';'):
96 if col:
97 result.append(super(ColorsOption, self).on_import(col))
98 return result
99
101 """Exporting multiple colours"""
102 result = ""
103 for col in value:
104 result += super(ColorsOption, self).on_export(col)+';'
105 return result
106
122
124 """Remove a colour box from the array when right clicked"""
125 if event.button == 3:
126 if len(self.widget.get_children()) > 2:
127 self.widget.remove(widget)
128 self.has_changed(widget)
129
140
148