1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from colorsys import hsv_to_rgb
17
18 from muntjac.addon.colorpicker.color import Color
19
20 from muntjac.ui.custom_component import CustomComponent
21 from muntjac.ui.vertical_layout import VerticalLayout
22 from muntjac.ui.select import Select
23
24 from muntjac.data.property import IValueChangeListener
25
26 from muntjac.addon.colorpicker.color_picker_grid import ColorPickerGrid
27 from muntjac.addon.colorpicker.color_selector import IColorSelector
31 """The Class ColorPickerSelect.
32
33 @author: John Ahlroos / ITMill Oy LTd 2010
34 @author: Richard Lincoln
35 """
36
73
74
76 """Creates the all colors.
77
78 @param rows:
79 the rows
80 @param columns:
81 the columns
82
83 @return: the color[][]
84 """
85 colors = [([None] * columns) for _ in range(rows)]
86
87 for row in range(rows):
88 for col in range(columns):
89
90
91 if row < rows - 1:
92
93
94 hue = col / columns
95 saturation = 1.0
96 value = 1.0
97
98
99 if row < rows / 2:
100 saturation = (row + 1.0) / rows / 2.0
101 else:
102 value = 1.0 - ((row - (rows / 2.0)) / rows / 2.0)
103
104 colors[row][col] = \
105 Color(*hsv_to_rgb(hue, saturation, value))
106 else:
107 hue = 0.0
108 saturation = 0.0
109 value = 1.0 - (col / columns)
110
111 colors[row][col] = \
112 Color(*hsv_to_rgb(hue, saturation, value))
113
114 return colors
115
116
118 """Creates the color.
119
120 @param color:
121 the color
122 @param rows:
123 the rows
124 @param columns:
125 the columns
126
127 @return: the color[][]
128 """
129 colors = [([None] * columns) for _ in range(rows)]
130 hsv = color.getHSV()
131
132 hue = hsv[0]
133 saturation = 1.0
134 value = 1.0
135
136 for row in range(rows):
137 for col in range(columns):
138
139 index = (row * columns) + col
140 saturation = 1.0
141 value = 1.0
142
143 if index <= (rows * columns) / 2:
144 saturation = index / (rows * columns) / 2.0
145 else:
146 index -= (rows * columns) / 2
147 value = 1.0 - (index / (rows * columns) / 2.0)
148
149 colors[row][col] = Color(*hsv_to_rgb(hue, saturation, value))
150
151 return colors
152
153
156
157
160
161
164
165
168
169
171 if self._grid is None:
172 return
173
174 if event.getProperty().getValue() == ColorRangePropertyId.ALL:
175 self._grid.setColorGrid(self.createAllColors(14, 10))
176
177 elif event.getProperty().getValue() == ColorRangePropertyId.RED:
178 self._grid.setColorGrid(self.createColor(Color(255, 0, 0), 14, 10))
179
180 elif event.getProperty().getValue() == ColorRangePropertyId.GREEN:
181 self._grid.setColorGrid(self.createColor(Color(0, 255, 0), 14, 10))
182
183 elif event.getProperty().getValue() == ColorRangePropertyId.BLUE:
184 self._grid.setColorGrid(self.createColor(Color(0, 0, 255), 14, 10))
185
188 """The Enum ColorRangePropertyId."""
189
190 ALL = None
191 RED = None
192 GREEN = None
193 BLUE = None
194
196 """Instantiates a new color range property id.
197
198 @param caption:
199 the caption
200 """
201 self._caption = caption
202
205
206 @classmethod
209
210
211 ColorRangePropertyId.ALL = ColorRangePropertyId('All colors')
212 ColorRangePropertyId.RED = ColorRangePropertyId('Red colors')
213 ColorRangePropertyId.GREEN = ColorRangePropertyId('Green colors')
214 ColorRangePropertyId.BLUE = ColorRangePropertyId('Blue colors')
215