Barry Warsaw | 4638c5b | 1998-10-02 16:20:14 +0000 | [diff] [blame] | 1 | """Strip viewer and related widgets. |
| 2 | |
| 3 | The classes in this file implement the StripViewer shown in the top two thirds |
| 4 | of the main Pynche window. It consists of three StripWidgets which display |
| 5 | the variations in red, green, and blue respectively of the currently selected |
| 6 | r/g/b color value. |
| 7 | |
| 8 | Each StripWidget shows the color variations that are reachable by varying an |
| 9 | axis of the currently selected color. So for example, if the color is |
| 10 | |
| 11 | (R,G,B)=(127,163,196) |
| 12 | |
| 13 | then the Red variations show colors from (0,163,196) to (255,163,196), the |
| 14 | Green variations show colors from (127,0,196) to (127,255,196), and the Blue |
| 15 | variations show colors from (127,163,0) to (127,163,255). |
| 16 | |
| 17 | The selected color is always visible in all three StripWidgets, and in fact |
| 18 | each StripWidget highlights the selected color, and has an arrow pointing to |
| 19 | the selected chip, which includes the value along that particular axis. |
| 20 | |
| 21 | Clicking on any chip in any StripWidget selects that color, and updates all |
| 22 | arrows and other windows. By toggling on Update while dragging, Pynche will |
| 23 | select the color under the cursor while you drag it, but be forewarned that |
| 24 | this can be slow. |
| 25 | """ |
| 26 | |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 27 | import string |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 28 | from Tkinter import * |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 29 | import ColorDB |
| 30 | |
Barry Warsaw | 4c2fab5 | 1998-02-18 16:22:22 +0000 | [diff] [blame] | 31 | # Load this script into the Tcl interpreter and call it in |
| 32 | # StripWidget.set_color(). This is about as fast as it can be with the |
| 33 | # current _tkinter.c interface, which doesn't support Tcl Objects. |
| 34 | TCLPROC = '''\ |
| 35 | proc setcolor {canv colors} { |
| 36 | set i 1 |
| 37 | foreach c $colors { |
| 38 | $canv itemconfigure $i -fill $c -outline $c |
| 39 | incr i |
| 40 | } |
| 41 | } |
| 42 | ''' |
| 43 | |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 44 | # Tcl event types |
| 45 | BTNDOWN = 4 |
| 46 | BTNUP = 5 |
| 47 | BTNDRAG = 6 |
| 48 | |
Barry Warsaw | 4c2fab5 | 1998-02-18 16:22:22 +0000 | [diff] [blame] | 49 | |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 50 | def constant(numchips): |
| 51 | step = 255.0 / (numchips - 1) |
| 52 | start = 0.0 |
| 53 | seq = [] |
| 54 | while numchips > 0: |
| 55 | seq.append(int(start)) |
| 56 | start = start + step |
| 57 | numchips = numchips - 1 |
| 58 | return seq |
| 59 | |
| 60 | # red variations, green+blue = cyan constant |
| 61 | def constant_cyan_generator(numchips, red, green, blue): |
| 62 | seq = constant(numchips) |
| 63 | return map(None, seq, [green] * numchips, [blue] * numchips) |
| 64 | |
| 65 | # green variations, red+blue = magenta constant |
| 66 | def constant_magenta_generator(numchips, red, green, blue): |
| 67 | seq = constant(numchips) |
| 68 | return map(None, [red] * numchips, seq, [blue] * numchips) |
| 69 | |
| 70 | # blue variations, red+green = yellow constant |
| 71 | def constant_yellow_generator(numchips, red, green, blue): |
| 72 | seq = constant(numchips) |
| 73 | return map(None, [red] * numchips, [green] * numchips, seq) |
| 74 | |
| 75 | |
| 76 | |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 77 | |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 78 | class LeftArrow: |
| 79 | _ARROWWIDTH = 30 |
| 80 | _ARROWHEIGHT = 15 |
| 81 | _YOFFSET = 13 |
| 82 | _TEXTYOFFSET = 1 |
| 83 | _TAG = ('leftarrow',) |
| 84 | |
| 85 | def __init__(self, canvas, x): |
| 86 | self._canvas = canvas |
| 87 | self.__arrow, self.__text = self._create(x) |
| 88 | self.move_to(x) |
| 89 | |
| 90 | def _create(self, x): |
| 91 | arrow = self._canvas.create_line( |
| 92 | x, self._ARROWHEIGHT + self._YOFFSET, |
| 93 | x, self._YOFFSET, |
| 94 | x + self._ARROWWIDTH, self._YOFFSET, |
| 95 | arrow='first', |
| 96 | width=3.0, |
| 97 | tags=self._TAG) |
| 98 | text = self._canvas.create_text( |
| 99 | x + self._ARROWWIDTH + 13, |
| 100 | self._ARROWHEIGHT - self._TEXTYOFFSET, |
Barry Warsaw | 35ae864 | 1998-02-13 21:28:47 +0000 | [diff] [blame] | 101 | tags=self._TAG, |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 102 | text='128') |
| 103 | return arrow, text |
| 104 | |
| 105 | def _x(self): |
| 106 | coords = self._canvas.coords(self._TAG) |
| 107 | assert coords |
| 108 | return coords[0] |
| 109 | |
| 110 | def move_to(self, x): |
| 111 | deltax = x - self._x() |
| 112 | self._canvas.move(self._TAG, deltax, 0) |
| 113 | |
Barry Warsaw | 35ae864 | 1998-02-13 21:28:47 +0000 | [diff] [blame] | 114 | def set_text(self, text): |
| 115 | self._canvas.itemconfigure(self.__text, text=text) |
| 116 | |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 117 | |
| 118 | class RightArrow(LeftArrow): |
| 119 | _TAG = ('rightarrow',) |
| 120 | |
| 121 | def _create(self, x): |
| 122 | arrow = self._canvas.create_line( |
| 123 | x, self._YOFFSET, |
| 124 | x + self._ARROWWIDTH, self._YOFFSET, |
| 125 | x + self._ARROWWIDTH, self._ARROWHEIGHT + self._YOFFSET, |
| 126 | arrow='last', |
| 127 | width=3.0, |
| 128 | tags=self._TAG) |
| 129 | text = self._canvas.create_text( |
Barry Warsaw | 35ae864 | 1998-02-13 21:28:47 +0000 | [diff] [blame] | 130 | x - self._ARROWWIDTH + 15, # TBD: kludge |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 131 | self._ARROWHEIGHT - self._TEXTYOFFSET, |
Barry Warsaw | 35ae864 | 1998-02-13 21:28:47 +0000 | [diff] [blame] | 132 | text='128', |
| 133 | tags=self._TAG) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 134 | return arrow, text |
| 135 | |
| 136 | def _x(self): |
| 137 | coords = self._canvas.bbox(self._TAG) |
| 138 | assert coords |
| 139 | return coords[2] - 6 # TBD: kludge |
| 140 | |
| 141 | |
| 142 | |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 143 | class StripWidget: |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 144 | _CHIPHEIGHT = 50 |
| 145 | _CHIPWIDTH = 10 |
| 146 | _NUMCHIPS = 40 |
| 147 | |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 148 | def __init__(self, switchboard, |
| 149 | parent = None, |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 150 | chipwidth = _CHIPWIDTH, |
| 151 | chipheight = _CHIPHEIGHT, |
| 152 | numchips = _NUMCHIPS, |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 153 | generator = None, |
| 154 | axis = None, |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 155 | label = '', |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 156 | uwdvar = None, |
| 157 | hexvar = None): |
Barry Warsaw | 5177c48 | 1998-09-28 21:01:55 +0000 | [diff] [blame] | 158 | # instance variables |
| 159 | self.__generator = generator |
| 160 | self.__axis = axis |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 161 | self.__numchips = numchips |
Barry Warsaw | 5177c48 | 1998-09-28 21:01:55 +0000 | [diff] [blame] | 162 | assert self.__axis in (0, 1, 2) |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 163 | self.__uwd = uwdvar |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 164 | self.__hexp = hexvar |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 165 | # the last chip selected |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 166 | self.__lastchip = None |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 167 | self.__sb = switchboard |
Barry Warsaw | 5177c48 | 1998-09-28 21:01:55 +0000 | [diff] [blame] | 168 | |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 169 | canvaswidth = numchips * (chipwidth + 1) |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 170 | canvasheight = chipheight + 43 # TBD: Kludge |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 171 | |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 172 | # create the canvas and pack it |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 173 | canvas = self.__canvas = Canvas( |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 174 | parent, |
| 175 | width=canvaswidth, |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 176 | height=canvasheight, |
| 177 | ## borderwidth=2, |
| 178 | ## relief=GROOVE |
| 179 | ) |
| 180 | |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 181 | canvas.pack() |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 182 | canvas.bind('<ButtonPress-1>', self.__select_chip) |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 183 | canvas.bind('<ButtonRelease-1>', self.__select_chip) |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 184 | canvas.bind('<B1-Motion>', self.__select_chip) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 185 | |
Barry Warsaw | 4c2fab5 | 1998-02-18 16:22:22 +0000 | [diff] [blame] | 186 | # Load a proc into the Tcl interpreter. This is used in the |
| 187 | # set_color() method to speed up setting the chip colors. |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 188 | canvas.tk.eval(TCLPROC) |
Barry Warsaw | 4c2fab5 | 1998-02-18 16:22:22 +0000 | [diff] [blame] | 189 | |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 190 | # create the color strip |
| 191 | chips = self.__chips = [] |
| 192 | x = 1 |
| 193 | y = 30 |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 194 | tags = ('chip',) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 195 | for c in range(self.__numchips): |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 196 | color = 'grey' |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 197 | rect = canvas.create_rectangle( |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 198 | x, y, x+chipwidth, y+chipheight, |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 199 | fill=color, outline=color, |
| 200 | tags=tags) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 201 | x = x + chipwidth + 1 # for outline |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 202 | chips.append(color) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 203 | |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 204 | # create the strip label |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 205 | self.__label = canvas.create_text( |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 206 | 3, y + chipheight + 8, |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 207 | text=label, |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 208 | anchor=W) |
| 209 | |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 210 | # create the arrow and text item |
| 211 | chipx = self.__arrow_x(0) |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 212 | self.__leftarrow = LeftArrow(canvas, chipx) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 213 | |
| 214 | chipx = self.__arrow_x(len(chips) - 1) |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 215 | self.__rightarrow = RightArrow(canvas, chipx) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 216 | |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 217 | def __arrow_x(self, chipnum): |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 218 | coords = self.__canvas.coords(chipnum+1) |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 219 | assert coords |
| 220 | x0, y0, x1, y1 = coords |
| 221 | return (x1 + x0) / 2.0 |
| 222 | |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 223 | # Invoked when one of the chips is clicked. This should just tell the |
| 224 | # switchboard to set the color on all the output components |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 225 | def __select_chip(self, event=None): |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 226 | x = event.x |
| 227 | y = event.y |
| 228 | canvas = self.__canvas |
| 229 | chip = canvas.find_overlapping(x, y, x, y) |
| 230 | if chip and (1 <= chip[0] <= self.__numchips): |
| 231 | color = self.__chips[chip[0]-1] |
| 232 | red, green, blue = ColorDB.rrggbb_to_triplet(color) |
| 233 | etype = int(event.type) |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 234 | if (etype == BTNUP or self.__uwd.get()): |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 235 | # update everyone |
| 236 | self.__sb.update_views(red, green, blue) |
| 237 | else: |
| 238 | # just track the arrows |
| 239 | self.__trackarrow(chip[0], (red, green, blue)) |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 240 | |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 241 | def __trackarrow(self, chip, rgbtuple): |
| 242 | # invert the last chip |
| 243 | if self.__lastchip is not None: |
| 244 | color = self.__canvas.itemcget(self.__lastchip, 'fill') |
| 245 | self.__canvas.itemconfigure(self.__lastchip, outline=color) |
| 246 | self.__lastchip = chip |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 247 | # get the arrow's text |
| 248 | coloraxis = rgbtuple[self.__axis] |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 249 | if self.__hexp.get(): |
| 250 | # hex |
| 251 | text = hex(coloraxis) |
| 252 | else: |
| 253 | # decimal |
| 254 | text = repr(coloraxis) |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 255 | # move the arrow, and set it's text |
| 256 | if coloraxis <= 128: |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 257 | # use the left arrow |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 258 | self.__leftarrow.set_text(text) |
| 259 | self.__leftarrow.move_to(self.__arrow_x(chip-1)) |
| 260 | self.__rightarrow.move_to(-100) |
| 261 | else: |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 262 | # use the right arrow |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 263 | self.__rightarrow.set_text(text) |
| 264 | self.__rightarrow.move_to(self.__arrow_x(chip-1)) |
| 265 | self.__leftarrow.move_to(-100) |
| 266 | # and set the chip's outline |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 267 | brightness = ColorDB.triplet_to_brightness(rgbtuple) |
Barry Warsaw | 26f4b5d | 1998-09-28 22:52:02 +0000 | [diff] [blame] | 268 | if brightness <= 128: |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 269 | outline = 'white' |
| 270 | else: |
| 271 | outline = 'black' |
| 272 | self.__canvas.itemconfigure(chip, outline=outline) |
Barry Warsaw | 70787ed | 1998-03-16 23:08:53 +0000 | [diff] [blame] | 273 | |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 274 | |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 275 | def update_yourself(self, red, green, blue): |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 276 | assert self.__generator |
| 277 | i = 1 |
| 278 | chip = 0 |
| 279 | chips = self.__chips = [] |
| 280 | tclcmd = [] |
| 281 | tk = self.__canvas.tk |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 282 | # get the red, green, and blue components for all chips |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 283 | for t in self.__generator(self.__numchips, red, green, blue): |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 284 | rrggbb = ColorDB.triplet_to_rrggbb(t) |
| 285 | chips.append(rrggbb) |
| 286 | tred, tgreen, tblue = t |
| 287 | if tred <= red and tgreen <= green and tblue <= blue: |
| 288 | chip = i |
| 289 | i = i + 1 |
| 290 | # call the raw tcl script |
| 291 | colors = string.join(chips) |
| 292 | tk.eval('setcolor %s {%s}' % (self.__canvas._w, colors)) |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 293 | # move the arrows around |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 294 | self.__trackarrow(chip, (red, green, blue)) |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 295 | |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 296 | |
| 297 | class StripViewer: |
| 298 | def __init__(self, switchboard, parent=None): |
| 299 | self.__sb = switchboard |
Barry Warsaw | d7d4725 | 1998-09-29 17:36:43 +0000 | [diff] [blame] | 300 | # create a frame inside the parent |
Barry Warsaw | 65f0b6b | 1998-10-01 14:26:04 +0000 | [diff] [blame] | 301 | self.__frame = Frame(parent) #, relief=GROOVE, borderwidth=2) |
| 302 | self.__frame.grid(row=1, column=0, columnspan=2, sticky='EW') |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 303 | uwd = BooleanVar() |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 304 | hexp = BooleanVar() |
Barry Warsaw | d7d4725 | 1998-09-29 17:36:43 +0000 | [diff] [blame] | 305 | self.__reds = StripWidget(switchboard, self.__frame, |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 306 | generator=constant_cyan_generator, |
| 307 | axis=0, |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 308 | label='Red Variations', |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 309 | uwdvar=uwd, hexvar=hexp) |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 310 | |
Barry Warsaw | d7d4725 | 1998-09-29 17:36:43 +0000 | [diff] [blame] | 311 | self.__greens = StripWidget(switchboard, self.__frame, |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 312 | generator=constant_magenta_generator, |
| 313 | axis=1, |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 314 | label='Green Variations', |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 315 | uwdvar=uwd, hexvar=hexp) |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 316 | |
Barry Warsaw | d7d4725 | 1998-09-29 17:36:43 +0000 | [diff] [blame] | 317 | self.__blues = StripWidget(switchboard, self.__frame, |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 318 | generator=constant_yellow_generator, |
| 319 | axis=2, |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 320 | label='Blue Variations', |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 321 | uwdvar=uwd, hexvar=hexp) |
| 322 | |
| 323 | frame = self.__frame1 = Frame(self.__frame) |
| 324 | frame.pack() |
| 325 | |
| 326 | self.__uwd = Checkbutton(frame, |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 327 | text='Update while dragging', |
| 328 | variable=uwd) |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 329 | self.__uwd.grid(row=0, column=0, sticky=W) |
| 330 | |
| 331 | self.__hex = Checkbutton(frame, |
| 332 | text='Hexadecimal', |
| 333 | variable=hexp, |
| 334 | command=self.__togglehex) |
| 335 | self.__hex.grid(row=1, column=0, sticky=W) |
| 336 | |
Barry Warsaw | 65f0b6b | 1998-10-01 14:26:04 +0000 | [diff] [blame] | 337 | self.__div = Frame(self.__frame, |
| 338 | height=2, |
| 339 | borderwidth=2, |
| 340 | relief=RAISED) |
| 341 | self.__div.pack(expand=1, fill=X) |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 342 | |
| 343 | def update_yourself(self, red, green, blue): |
| 344 | self.__reds.update_yourself(red, green, blue) |
| 345 | self.__greens.update_yourself(red, green, blue) |
| 346 | self.__blues.update_yourself(red, green, blue) |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 347 | |
| 348 | def __togglehex(self, event=None): |
| 349 | red, green, blue = self.__sb.current_rgb() |
| 350 | self.update_yourself(red, green, blue) |