1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from muntjac.ui.abstract_component import AbstractComponent
17
18 from muntjac.addon.colorpicker.color_change_event import ColorChangeEvent
19 from muntjac.addon.colorpicker.color_picker import IColorChangeListener
20 from muntjac.addon.colorpicker.color_selector import IColorSelector
21
22
23 _COLOR_CHANGE_METHOD = getattr(IColorChangeListener, 'colorChanged')
24
25
27 """The Class ColorPickerGradient.
28
29 @author: John Ahlroos
30 @author: Richard Lincoln
31 """
32
33 CLIENT_WIDGET = None
34
35 TYPE_MAPPING = 'com.vaadin.addon.colorpicker.ColorPickerGradient'
36
38 """Instantiates a new color picker gradient.
39
40 @param id:
41 the id
42 @param converter:
43 the converter
44 """
45 super(ColorPickerGradient, self).__init__()
46
47
48 self._id = Id
49
50
51 self._converter = converter
52
53
54 self._color = None
55
56
57 self._x = 0
58
59
60 self._y = 0
61
62
63 self._backgroundColor = None
64
65 self.requestRepaint()
66
67
69 self._color = c
70 coords = self._converter.calculate(c)
71 self._x = coords[0]
72 self._y = coords[1]
73 self.requestRepaint()
74
75
76 - def paintContent(self, target):
77 target.addAttribute('cssid', self._id)
78
79 if self._color is not None:
80 target.addAttribute('cursorX', self._x)
81 target.addAttribute('cursorY', self._y)
82
83 if self._backgroundColor is not None:
84 bgRed = '%.2x' % self._backgroundColor.getRed()
85
86 bgGreen = '%.2x' % self._backgroundColor.getGreen()
87
88 bgBlue = '%.2x' % self._backgroundColor.getBlue()
89
90 target.addAttribute('bgColor', '#' + bgRed + bgGreen + bgBlue)
91
92
94 if 'cursorX' in variables and 'cursorY' in variables:
95 self._x = variables['cursorX']
96 self._y = variables['cursorY']
97 self._color = self._converter.calculate(self._x, self._y)
98 self.fireColorChanged(self._color)
99
100
109
110
111 - def addCallback(self, callback, eventType=None, *args):
120
121
129
130
141
142
144 """Sets the background color.
145
146 @param color:
147 the new background color
148 """
149 self._backgroundColor = color
150 self.requestRepaint()
151
152
155
156
158 """Notifies the listeners that the color has changed
159
160 @param color:
161 The color which it changed to
162 """
163 self.fireEvent(ColorChangeEvent(self, color))
164