1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from muntjac.addon.colorpicker.color import Color
17
18 from muntjac.ui.abstract_component import AbstractComponent
19 from muntjac.ui.window import ICloseListener
20
21 from muntjac.addon.colorpicker.color_change_event import ColorChangeEvent
22 from muntjac.addon.colorpicker.color_selector import IColorSelector
23
24
26 """The listener interface for receiving colorChange events. The class that
27 is interested in processing a colorChange event implements this
28 interface, and the object created with that class is registered with a
29 component using the component's C{addColorChangeListener} method. When
30 the colorChange event occurs, that object's appropriate
31 method is invoked.
32
33 @see: L{ColorChangeEvent}
34 """
35
37 raise NotImplementedError
38
39
40 _COLOR_CHANGE_METHOD = getattr(IColorChangeListener, 'colorChanged')
41
42
43 -class ColorPicker(AbstractComponent, ICloseListener, IColorSelector,
44 IColorChangeListener):
45 """ColorPicker
46
47 @author: John Ahlroos / ITMill Oy
48 @author: Richard Lincoln
49 """
50
51 CLIENT_WIDGET = None
52
53 TYPE_MAPPING = 'com.vaadin.addon.colorpicker.ColorPicker'
54
55 - def __init__(self, caption='Colors', initialColor=None):
56 """Instantiates a new color picker.
57
58 @param caption:
59 the caption
60 @param initialColor:
61 the initial color
62 """
63 self.buttonStyle = str(ButtonStyle.BUTTON_NORMAL)
64
65 self.popupStyle = PopupStyle.POPUP_NORMAL
66
67 self.buttonCaption = ''
68
69
70 self._window = None
71
72
73 self._parent_window = None
74
75
76 self._popupStatus = False
77
78 self._positionX = 0
79 self._positionY = 0
80
81 self.rgbVisible = True
82 self.hsvVisible = True
83 self.swatchesVisible = True
84 self.historyVisible = True
85 self.textfieldVisible = True
86
87 if initialColor is None:
88 initialColor = Color(0, 0, 0)
89
90
91 self.color = initialColor
92 self.caption = caption
93
94 super(ColorPicker, self).__init__()
95
96
102
103
106
107
109 """Sets the position of the popup window
110
111 @param x:
112 the x-coordinate
113 @param y:
114 the y-coordinate
115 """
116 self._positionX = x
117 self._positionY = y
118 if self._window is not None:
119 self._window.setPositionX(x)
120 self._window.setPositionY(y)
121
122
131
132
133 - def addCallback(self, callback, eventType=None, *args):
141
142
150
151
161
162
163 - def paintContent(self, target):
164 target.addAttribute('red', '%.2x' % self.color.getRed())
165 target.addAttribute('green', '%.2x' % self.color.getGreen())
166 target.addAttribute('blue', '%.2x' % self.color.getBlue())
167 target.addAttribute('alpha', self.color.getAlpha())
168 target.addAttribute('popup', self._popupStatus)
169 target.addAttribute('btnstyle', self.buttonStyle)
170 target.addAttribute('btncaption', self.buttonCaption)
171
172
223
224
229
230
239
240
244
245
253
254
275
276
285
286
288 """Set the visibility of the RGB Tab
289
290 @param visible:
291 The visibility
292 """
293 if not visible and not self.hsvVisible and not self.swatchesVisible:
294 raise ValueError('Cannot hide all tabs.')
295
296 self.rgbVisible = visible
297 if self._window is not None:
298 self._window.setRGBTabVisible(visible)
299
300
302 """Set the visibility of the HSV Tab
303
304 @param visible:
305 The visibility
306 """
307 if not visible and not self.rgbVisible and not self.swatchesVisible:
308 raise ValueError('Cannot hide all tabs.')
309
310 self.hsvVisible = visible
311 if self._window is not None:
312 self._window.setHSVTabVisible(visible)
313
314
316 """Set the visibility of the Swatches Tab
317
318 @param visible:
319 The visibility
320 """
321 if not visible and not self.hsvVisible and not self.rgbVisible:
322 raise ValueError('Cannot hide all tabs.')
323
324 self.swatchesVisible = visible
325 if self._window is not None:
326 self._window.setSwatchesTabVisible(visible)
327
328
329 - def setHistoryVisibility(self, visible):
330 """Sets the visibility of the Color History
331
332 @param visible:
333 The visibility
334 """
335 self.historyVisible = visible
336 if self._window is not None:
337 self._window.setHistoryVisible(visible)
338
339
340 - def setTextfieldVisibility(self, visible):
341 """Sets tje visibility of the CSS color code text field
342
343 @param visible:
344 The visibility
345 """
346 self.textfieldVisible = visible
347 if self._window is not None:
348 self._window.setPreviewVisible(visible)
349
350
352 """Interface for converting 2d-coordinates to a Color"""
353
355 """Calculate color from coordinates
356
357 @param c_or_x:
358 the c or the x-coordinate
359 @param y
360 the y-coordinate
361
362 @return the integer array with the coordinates or the color
363 """
364 raise NotImplementedError
365
366
379
380 ButtonStyle.BUTTON_NORMAL = ButtonStyle('normal')
381 ButtonStyle.BUTTON_AREA = ButtonStyle('area')
382
383
396
397 PopupStyle.POPUP_NORMAL = PopupStyle('normal')
398 PopupStyle.POPUP_SIMPLE = PopupStyle('simple')
399