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 |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 61 | def constant_red_generator(numchips, red, green, blue): |
| 62 | seq = constant(numchips) |
| 63 | return map(None, [red] * numchips, seq, seq) |
| 64 | |
| 65 | # green variations, red+blue = magenta constant |
| 66 | def constant_green_generator(numchips, red, green, blue): |
| 67 | seq = constant(numchips) |
| 68 | return map(None, seq, [green] * numchips, seq) |
| 69 | |
| 70 | # blue variations, red+green = yellow constant |
| 71 | def constant_blue_generator(numchips, red, green, blue): |
| 72 | seq = constant(numchips) |
| 73 | return map(None, seq, seq, [blue] * numchips) |
| 74 | |
| 75 | # red variations, green+blue = cyan constant |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 76 | def constant_cyan_generator(numchips, red, green, blue): |
| 77 | seq = constant(numchips) |
| 78 | return map(None, seq, [green] * numchips, [blue] * numchips) |
| 79 | |
| 80 | # green variations, red+blue = magenta constant |
| 81 | def constant_magenta_generator(numchips, red, green, blue): |
| 82 | seq = constant(numchips) |
| 83 | return map(None, [red] * numchips, seq, [blue] * numchips) |
| 84 | |
| 85 | # blue variations, red+green = yellow constant |
| 86 | def constant_yellow_generator(numchips, red, green, blue): |
| 87 | seq = constant(numchips) |
| 88 | return map(None, [red] * numchips, [green] * numchips, seq) |
| 89 | |
| 90 | |
| 91 | |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 92 | class LeftArrow: |
| 93 | _ARROWWIDTH = 30 |
| 94 | _ARROWHEIGHT = 15 |
| 95 | _YOFFSET = 13 |
| 96 | _TEXTYOFFSET = 1 |
| 97 | _TAG = ('leftarrow',) |
| 98 | |
| 99 | def __init__(self, canvas, x): |
| 100 | self._canvas = canvas |
| 101 | self.__arrow, self.__text = self._create(x) |
| 102 | self.move_to(x) |
| 103 | |
| 104 | def _create(self, x): |
| 105 | arrow = self._canvas.create_line( |
| 106 | x, self._ARROWHEIGHT + self._YOFFSET, |
| 107 | x, self._YOFFSET, |
| 108 | x + self._ARROWWIDTH, self._YOFFSET, |
| 109 | arrow='first', |
| 110 | width=3.0, |
| 111 | tags=self._TAG) |
| 112 | text = self._canvas.create_text( |
| 113 | x + self._ARROWWIDTH + 13, |
| 114 | self._ARROWHEIGHT - self._TEXTYOFFSET, |
Barry Warsaw | 35ae864 | 1998-02-13 21:28:47 +0000 | [diff] [blame] | 115 | tags=self._TAG, |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 116 | text='128') |
| 117 | return arrow, text |
| 118 | |
| 119 | def _x(self): |
| 120 | coords = self._canvas.coords(self._TAG) |
| 121 | assert coords |
| 122 | return coords[0] |
| 123 | |
| 124 | def move_to(self, x): |
| 125 | deltax = x - self._x() |
| 126 | self._canvas.move(self._TAG, deltax, 0) |
| 127 | |
Barry Warsaw | 35ae864 | 1998-02-13 21:28:47 +0000 | [diff] [blame] | 128 | def set_text(self, text): |
| 129 | self._canvas.itemconfigure(self.__text, text=text) |
| 130 | |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 131 | |
| 132 | class RightArrow(LeftArrow): |
| 133 | _TAG = ('rightarrow',) |
| 134 | |
| 135 | def _create(self, x): |
| 136 | arrow = self._canvas.create_line( |
| 137 | x, self._YOFFSET, |
| 138 | x + self._ARROWWIDTH, self._YOFFSET, |
| 139 | x + self._ARROWWIDTH, self._ARROWHEIGHT + self._YOFFSET, |
| 140 | arrow='last', |
| 141 | width=3.0, |
| 142 | tags=self._TAG) |
| 143 | text = self._canvas.create_text( |
Barry Warsaw | 35ae864 | 1998-02-13 21:28:47 +0000 | [diff] [blame] | 144 | x - self._ARROWWIDTH + 15, # TBD: kludge |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 145 | self._ARROWHEIGHT - self._TEXTYOFFSET, |
Barry Warsaw | 84f52e0 | 1998-10-06 23:04:55 +0000 | [diff] [blame] | 146 | justify=RIGHT, |
Barry Warsaw | 35ae864 | 1998-02-13 21:28:47 +0000 | [diff] [blame] | 147 | text='128', |
| 148 | tags=self._TAG) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 149 | return arrow, text |
| 150 | |
| 151 | def _x(self): |
| 152 | coords = self._canvas.bbox(self._TAG) |
| 153 | assert coords |
| 154 | return coords[2] - 6 # TBD: kludge |
| 155 | |
| 156 | |
| 157 | |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 158 | class StripWidget: |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 159 | _CHIPHEIGHT = 50 |
| 160 | _CHIPWIDTH = 10 |
| 161 | _NUMCHIPS = 40 |
| 162 | |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 163 | def __init__(self, switchboard, |
Barry Warsaw | ca07ba0 | 1998-10-22 03:25:59 +0000 | [diff] [blame] | 164 | master = None, |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 165 | chipwidth = _CHIPWIDTH, |
| 166 | chipheight = _CHIPHEIGHT, |
| 167 | numchips = _NUMCHIPS, |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 168 | generator = None, |
| 169 | axis = None, |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 170 | label = '', |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 171 | uwdvar = None, |
| 172 | hexvar = None): |
Barry Warsaw | 5177c48 | 1998-09-28 21:01:55 +0000 | [diff] [blame] | 173 | # instance variables |
| 174 | self.__generator = generator |
| 175 | self.__axis = axis |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 176 | self.__numchips = numchips |
Barry Warsaw | 5177c48 | 1998-09-28 21:01:55 +0000 | [diff] [blame] | 177 | assert self.__axis in (0, 1, 2) |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 178 | self.__uwd = uwdvar |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 179 | self.__hexp = hexvar |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 180 | # the last chip selected |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 181 | self.__lastchip = None |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 182 | self.__sb = switchboard |
Barry Warsaw | 5177c48 | 1998-09-28 21:01:55 +0000 | [diff] [blame] | 183 | |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 184 | canvaswidth = numchips * (chipwidth + 1) |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 185 | canvasheight = chipheight + 43 # TBD: Kludge |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 186 | |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 187 | # create the canvas and pack it |
Barry Warsaw | ca07ba0 | 1998-10-22 03:25:59 +0000 | [diff] [blame] | 188 | canvas = self.__canvas = Canvas(master, |
| 189 | width=canvaswidth, |
| 190 | height=canvasheight, |
| 191 | ## borderwidth=2, |
| 192 | ## relief=GROOVE |
| 193 | ) |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 194 | |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 195 | canvas.pack() |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 196 | canvas.bind('<ButtonPress-1>', self.__select_chip) |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 197 | canvas.bind('<ButtonRelease-1>', self.__select_chip) |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 198 | canvas.bind('<B1-Motion>', self.__select_chip) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 199 | |
Barry Warsaw | 4c2fab5 | 1998-02-18 16:22:22 +0000 | [diff] [blame] | 200 | # Load a proc into the Tcl interpreter. This is used in the |
| 201 | # set_color() method to speed up setting the chip colors. |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 202 | canvas.tk.eval(TCLPROC) |
Barry Warsaw | 4c2fab5 | 1998-02-18 16:22:22 +0000 | [diff] [blame] | 203 | |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 204 | # create the color strip |
| 205 | chips = self.__chips = [] |
| 206 | x = 1 |
| 207 | y = 30 |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 208 | tags = ('chip',) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 209 | for c in range(self.__numchips): |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 210 | color = 'grey' |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 211 | rect = canvas.create_rectangle( |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 212 | x, y, x+chipwidth, y+chipheight, |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 213 | fill=color, outline=color, |
| 214 | tags=tags) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 215 | x = x + chipwidth + 1 # for outline |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 216 | chips.append(color) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 217 | |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 218 | # create the strip label |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 219 | self.__label = canvas.create_text( |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 220 | 3, y + chipheight + 8, |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 221 | text=label, |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 222 | anchor=W) |
| 223 | |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 224 | # create the arrow and text item |
| 225 | chipx = self.__arrow_x(0) |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 226 | self.__leftarrow = LeftArrow(canvas, chipx) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 227 | |
| 228 | chipx = self.__arrow_x(len(chips) - 1) |
Barry Warsaw | 4435d5a | 1998-02-18 17:00:24 +0000 | [diff] [blame] | 229 | self.__rightarrow = RightArrow(canvas, chipx) |
Barry Warsaw | 9d882bc | 1998-02-12 19:51:57 +0000 | [diff] [blame] | 230 | |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 231 | def __arrow_x(self, chipnum): |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 232 | coords = self.__canvas.coords(chipnum+1) |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 233 | assert coords |
| 234 | x0, y0, x1, y1 = coords |
| 235 | return (x1 + x0) / 2.0 |
| 236 | |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 237 | # Invoked when one of the chips is clicked. This should just tell the |
| 238 | # switchboard to set the color on all the output components |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 239 | def __select_chip(self, event=None): |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 240 | x = event.x |
| 241 | y = event.y |
| 242 | canvas = self.__canvas |
| 243 | chip = canvas.find_overlapping(x, y, x, y) |
| 244 | if chip and (1 <= chip[0] <= self.__numchips): |
| 245 | color = self.__chips[chip[0]-1] |
| 246 | red, green, blue = ColorDB.rrggbb_to_triplet(color) |
| 247 | etype = int(event.type) |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 248 | if (etype == BTNUP or self.__uwd.get()): |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 249 | # update everyone |
| 250 | self.__sb.update_views(red, green, blue) |
| 251 | else: |
| 252 | # just track the arrows |
| 253 | self.__trackarrow(chip[0], (red, green, blue)) |
Barry Warsaw | bc68930 | 1998-02-17 03:09:40 +0000 | [diff] [blame] | 254 | |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 255 | def __trackarrow(self, chip, rgbtuple): |
| 256 | # invert the last chip |
| 257 | if self.__lastchip is not None: |
| 258 | color = self.__canvas.itemcget(self.__lastchip, 'fill') |
| 259 | self.__canvas.itemconfigure(self.__lastchip, outline=color) |
| 260 | self.__lastchip = chip |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 261 | # get the arrow's text |
| 262 | coloraxis = rgbtuple[self.__axis] |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 263 | if self.__hexp.get(): |
| 264 | # hex |
| 265 | text = hex(coloraxis) |
| 266 | else: |
| 267 | # decimal |
| 268 | text = repr(coloraxis) |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 269 | # move the arrow, and set it's text |
| 270 | if coloraxis <= 128: |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 271 | # use the left arrow |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 272 | self.__leftarrow.set_text(text) |
| 273 | self.__leftarrow.move_to(self.__arrow_x(chip-1)) |
| 274 | self.__rightarrow.move_to(-100) |
| 275 | else: |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 276 | # use the right arrow |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 277 | self.__rightarrow.set_text(text) |
| 278 | self.__rightarrow.move_to(self.__arrow_x(chip-1)) |
| 279 | self.__leftarrow.move_to(-100) |
| 280 | # and set the chip's outline |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 281 | brightness = ColorDB.triplet_to_brightness(rgbtuple) |
Barry Warsaw | 26f4b5d | 1998-09-28 22:52:02 +0000 | [diff] [blame] | 282 | if brightness <= 128: |
Barry Warsaw | f67a50c | 1998-02-18 00:05:59 +0000 | [diff] [blame] | 283 | outline = 'white' |
| 284 | else: |
| 285 | outline = 'black' |
| 286 | self.__canvas.itemconfigure(chip, outline=outline) |
Barry Warsaw | 70787ed | 1998-03-16 23:08:53 +0000 | [diff] [blame] | 287 | |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 288 | |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 289 | def update_yourself(self, red, green, blue): |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 290 | assert self.__generator |
| 291 | i = 1 |
| 292 | chip = 0 |
| 293 | chips = self.__chips = [] |
| 294 | tclcmd = [] |
| 295 | tk = self.__canvas.tk |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 296 | # get the red, green, and blue components for all chips |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 297 | for t in self.__generator(self.__numchips, red, green, blue): |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 298 | rrggbb = ColorDB.triplet_to_rrggbb(t) |
| 299 | chips.append(rrggbb) |
| 300 | tred, tgreen, tblue = t |
| 301 | if tred <= red and tgreen <= green and tblue <= blue: |
| 302 | chip = i |
| 303 | i = i + 1 |
| 304 | # call the raw tcl script |
| 305 | colors = string.join(chips) |
| 306 | tk.eval('setcolor %s {%s}' % (self.__canvas._w, colors)) |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 307 | # move the arrows around |
Barry Warsaw | 6a3ea74 | 1998-09-28 20:58:06 +0000 | [diff] [blame] | 308 | self.__trackarrow(chip, (red, green, blue)) |
Barry Warsaw | ee6d8a5 | 1998-03-17 15:59:26 +0000 | [diff] [blame] | 309 | |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 310 | def set(self, label, generator): |
| 311 | self.__canvas.itemconfigure(self.__label, text=label) |
| 312 | self.__generator = generator |
| 313 | |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 314 | |
| 315 | class StripViewer: |
Barry Warsaw | ca07ba0 | 1998-10-22 03:25:59 +0000 | [diff] [blame] | 316 | def __init__(self, switchboard, master=None): |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 317 | self.__sb = switchboard |
Barry Warsaw | 8a09e1c | 1998-10-20 20:45:46 +0000 | [diff] [blame] | 318 | optiondb = switchboard.optiondb() |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 319 | # create a frame inside the master. |
| 320 | frame = Frame(master, relief=RAISED, borderwidth=1) |
| 321 | frame.grid(row=1, column=0, columnspan=2, sticky='NSEW') |
| 322 | # create the options to be used later |
Barry Warsaw | 8a09e1c | 1998-10-20 20:45:46 +0000 | [diff] [blame] | 323 | uwd = self.__uwdvar = BooleanVar() |
| 324 | uwd.set(optiondb.get('UPWHILEDRAG', 0)) |
| 325 | hexp = self.__hexpvar = BooleanVar() |
| 326 | hexp.set(optiondb.get('HEXSTRIP', 0)) |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 327 | # create the red, green, blue strips inside their own frame |
| 328 | frame1 = Frame(frame) |
| 329 | frame1.pack(expand=YES, fill=BOTH) |
| 330 | self.__reds = StripWidget(switchboard, frame1, |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 331 | generator=constant_cyan_generator, |
| 332 | axis=0, |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 333 | label='Red Variations', |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 334 | uwdvar=uwd, hexvar=hexp) |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 335 | |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 336 | self.__greens = StripWidget(switchboard, frame1, |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 337 | generator=constant_magenta_generator, |
| 338 | axis=1, |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 339 | label='Green Variations', |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 340 | uwdvar=uwd, hexvar=hexp) |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 341 | |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 342 | self.__blues = StripWidget(switchboard, frame1, |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 343 | generator=constant_yellow_generator, |
| 344 | axis=2, |
Barry Warsaw | d344165 | 1998-10-01 03:08:07 +0000 | [diff] [blame] | 345 | label='Blue Variations', |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 346 | uwdvar=uwd, hexvar=hexp) |
| 347 | |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 348 | # create a frame to contain the controls |
| 349 | frame2 = Frame(frame) |
| 350 | frame2.pack(expand=YES, fill=BOTH) |
| 351 | frame2.columnconfigure(0, weight=20) |
| 352 | frame2.columnconfigure(2, weight=20) |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 353 | |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 354 | padx = 8 |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 355 | |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 356 | # create the black button |
| 357 | blackbtn = Button(frame2, |
Barry Warsaw | f5e9857 | 1999-04-27 15:56:02 +0000 | [diff] [blame] | 358 | text='Black', |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 359 | command=self.__toblack) |
| 360 | blackbtn.grid(row=0, column=0, rowspan=2, sticky=W, padx=padx) |
| 361 | |
| 362 | # create the controls |
| 363 | uwdbtn = Checkbutton(frame2, |
| 364 | text='Update while dragging', |
| 365 | variable=uwd) |
| 366 | uwdbtn.grid(row=0, column=1, sticky=W) |
| 367 | hexbtn = Checkbutton(frame2, |
| 368 | text='Hexadecimal', |
| 369 | variable=hexp, |
| 370 | command=self.__togglehex) |
| 371 | hexbtn.grid(row=1, column=1, sticky=W) |
| 372 | |
| 373 | # XXX: ignore this feature for now; it doesn't work quite right yet |
| 374 | |
| 375 | ## gentypevar = self.__gentypevar = IntVar() |
| 376 | ## self.__variations = Radiobutton(frame, |
| 377 | ## text='Variations', |
| 378 | ## variable=gentypevar, |
| 379 | ## value=0, |
| 380 | ## command=self.__togglegentype) |
| 381 | ## self.__variations.grid(row=0, column=1, sticky=W) |
| 382 | ## self.__constants = Radiobutton(frame, |
| 383 | ## text='Constants', |
| 384 | ## variable=gentypevar, |
| 385 | ## value=1, |
| 386 | ## command=self.__togglegentype) |
| 387 | ## self.__constants.grid(row=1, column=1, sticky=W) |
| 388 | |
| 389 | # create the white button |
| 390 | whitebtn = Button(frame2, |
Barry Warsaw | f5e9857 | 1999-04-27 15:56:02 +0000 | [diff] [blame] | 391 | text='White', |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 392 | command=self.__towhite) |
| 393 | whitebtn.grid(row=0, column=2, rowspan=2, sticky=E, padx=padx) |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 394 | |
Barry Warsaw | 0dc9c92 | 1998-09-28 22:42:44 +0000 | [diff] [blame] | 395 | def update_yourself(self, red, green, blue): |
| 396 | self.__reds.update_yourself(red, green, blue) |
| 397 | self.__greens.update_yourself(red, green, blue) |
| 398 | self.__blues.update_yourself(red, green, blue) |
Barry Warsaw | 5b67839 | 1998-10-06 16:13:35 +0000 | [diff] [blame] | 399 | |
| 400 | def __togglehex(self, event=None): |
| 401 | red, green, blue = self.__sb.current_rgb() |
| 402 | self.update_yourself(red, green, blue) |
Barry Warsaw | 8a09e1c | 1998-10-20 20:45:46 +0000 | [diff] [blame] | 403 | |
Barry Warsaw | ef30092 | 1998-12-15 01:04:38 +0000 | [diff] [blame] | 404 | def __togglegentype(self, event=None): |
| 405 | which = self.__gentypevar.get() |
| 406 | if which == 0: |
| 407 | self.__reds.set(label='Red Variations', |
| 408 | generator=constant_cyan_generator) |
| 409 | self.__greens.set(label='Green Variations', |
| 410 | generator=constant_magenta_generator) |
| 411 | self.__blues.set(label='Blue Variations', |
| 412 | generator=constant_yellow_generator) |
| 413 | elif which == 1: |
| 414 | self.__reds.set(label='Red Constant', |
| 415 | generator=constant_red_generator) |
| 416 | self.__greens.set(label='Green Constant', |
| 417 | generator=constant_green_generator) |
| 418 | self.__blues.set(label='Blue Constant', |
| 419 | generator=constant_blue_generator) |
| 420 | else: |
| 421 | assert 0 |
| 422 | self.__sb.update_views_current() |
| 423 | |
| 424 | def __toblack(self, event=None): |
| 425 | self.__sb.update_views(0, 0, 0) |
| 426 | |
| 427 | def __towhite(self, event=None): |
| 428 | self.__sb.update_views(255, 255, 255) |
| 429 | |
Barry Warsaw | 8a09e1c | 1998-10-20 20:45:46 +0000 | [diff] [blame] | 430 | def save_options(self, optiondb): |
| 431 | optiondb['UPWHILEDRAG'] = self.__uwdvar.get() |
| 432 | optiondb['HEXSTRIP'] = self.__hexpvar.get() |