1998-10-02 13:20:14 -03:00
|
|
|
|
"""Strip viewer and related widgets.
|
|
|
|
|
|
2004-07-18 03:16:08 -03:00
|
|
|
|
The classes in this file implement the StripViewer shown in the top two thirds
|
1998-10-02 13:20:14 -03:00
|
|
|
|
of the main Pynche window. It consists of three StripWidgets which display
|
|
|
|
|
the variations in red, green, and blue respectively of the currently selected
|
|
|
|
|
r/g/b color value.
|
|
|
|
|
|
|
|
|
|
Each StripWidget shows the color variations that are reachable by varying an
|
|
|
|
|
axis of the currently selected color. So for example, if the color is
|
|
|
|
|
|
|
|
|
|
(R,G,B)=(127,163,196)
|
|
|
|
|
|
|
|
|
|
then the Red variations show colors from (0,163,196) to (255,163,196), the
|
|
|
|
|
Green variations show colors from (127,0,196) to (127,255,196), and the Blue
|
|
|
|
|
variations show colors from (127,163,0) to (127,163,255).
|
|
|
|
|
|
|
|
|
|
The selected color is always visible in all three StripWidgets, and in fact
|
|
|
|
|
each StripWidget highlights the selected color, and has an arrow pointing to
|
|
|
|
|
the selected chip, which includes the value along that particular axis.
|
|
|
|
|
|
|
|
|
|
Clicking on any chip in any StripWidget selects that color, and updates all
|
|
|
|
|
arrows and other windows. By toggling on Update while dragging, Pynche will
|
|
|
|
|
select the color under the cursor while you drag it, but be forewarned that
|
|
|
|
|
this can be slow.
|
|
|
|
|
"""
|
|
|
|
|
|
2010-08-02 19:08:58 -03:00
|
|
|
|
from tkinter import *
|
1998-02-12 15:51:57 -04:00
|
|
|
|
import ColorDB
|
|
|
|
|
|
1998-02-18 12:22:22 -04:00
|
|
|
|
# Load this script into the Tcl interpreter and call it in
|
|
|
|
|
# StripWidget.set_color(). This is about as fast as it can be with the
|
|
|
|
|
# current _tkinter.c interface, which doesn't support Tcl Objects.
|
|
|
|
|
TCLPROC = '''\
|
|
|
|
|
proc setcolor {canv colors} {
|
|
|
|
|
set i 1
|
|
|
|
|
foreach c $colors {
|
|
|
|
|
$canv itemconfigure $i -fill $c -outline $c
|
2003-10-24 17:09:23 -03:00
|
|
|
|
incr i
|
1998-02-18 12:22:22 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
'''
|
|
|
|
|
|
1998-03-17 11:59:26 -04:00
|
|
|
|
# Tcl event types
|
|
|
|
|
BTNDOWN = 4
|
|
|
|
|
BTNUP = 5
|
|
|
|
|
BTNDRAG = 6
|
|
|
|
|
|
2001-07-10 18:44:24 -03:00
|
|
|
|
SPACE = ' '
|
1998-02-18 12:22:22 -04:00
|
|
|
|
|
2001-07-10 18:44:24 -03:00
|
|
|
|
|
|
|
|
|
|
1998-09-28 19:42:44 -03:00
|
|
|
|
def constant(numchips):
|
|
|
|
|
step = 255.0 / (numchips - 1)
|
|
|
|
|
start = 0.0
|
|
|
|
|
seq = []
|
|
|
|
|
while numchips > 0:
|
2003-10-24 17:09:23 -03:00
|
|
|
|
seq.append(int(start))
|
|
|
|
|
start = start + step
|
|
|
|
|
numchips = numchips - 1
|
1998-09-28 19:42:44 -03:00
|
|
|
|
return seq
|
|
|
|
|
|
1998-12-14 21:04:38 -04:00
|
|
|
|
# red variations, green+blue = cyan constant
|
|
|
|
|
def constant_red_generator(numchips, red, green, blue):
|
|
|
|
|
seq = constant(numchips)
|
2010-08-02 19:08:58 -03:00
|
|
|
|
return list(zip([red] * numchips, seq, seq))
|
1998-12-14 21:04:38 -04:00
|
|
|
|
|
|
|
|
|
# green variations, red+blue = magenta constant
|
|
|
|
|
def constant_green_generator(numchips, red, green, blue):
|
|
|
|
|
seq = constant(numchips)
|
2010-08-02 19:08:58 -03:00
|
|
|
|
return list(zip(seq, [green] * numchips, seq))
|
1998-12-14 21:04:38 -04:00
|
|
|
|
|
|
|
|
|
# blue variations, red+green = yellow constant
|
|
|
|
|
def constant_blue_generator(numchips, red, green, blue):
|
|
|
|
|
seq = constant(numchips)
|
2010-08-02 19:08:58 -03:00
|
|
|
|
return list(zip(seq, seq, [blue] * numchips))
|
1998-12-14 21:04:38 -04:00
|
|
|
|
|
1998-09-28 19:42:44 -03:00
|
|
|
|
# red variations, green+blue = cyan constant
|
|
|
|
|
def constant_cyan_generator(numchips, red, green, blue):
|
|
|
|
|
seq = constant(numchips)
|
2010-08-02 19:08:58 -03:00
|
|
|
|
return list(zip(seq, [green] * numchips, [blue] * numchips))
|
1998-09-28 19:42:44 -03:00
|
|
|
|
|
|
|
|
|
# green variations, red+blue = magenta constant
|
|
|
|
|
def constant_magenta_generator(numchips, red, green, blue):
|
|
|
|
|
seq = constant(numchips)
|
2010-08-02 19:08:58 -03:00
|
|
|
|
return list(zip([red] * numchips, seq, [blue] * numchips))
|
1998-09-28 19:42:44 -03:00
|
|
|
|
|
|
|
|
|
# blue variations, red+green = yellow constant
|
|
|
|
|
def constant_yellow_generator(numchips, red, green, blue):
|
|
|
|
|
seq = constant(numchips)
|
2010-08-02 19:08:58 -03:00
|
|
|
|
return list(zip([red] * numchips, [green] * numchips, seq))
|
1998-09-28 19:42:44 -03:00
|
|
|
|
|
|
|
|
|
|
1998-02-17 20:05:59 -04:00
|
|
|
|
|
1998-02-12 15:51:57 -04:00
|
|
|
|
class LeftArrow:
|
|
|
|
|
_ARROWWIDTH = 30
|
|
|
|
|
_ARROWHEIGHT = 15
|
|
|
|
|
_YOFFSET = 13
|
|
|
|
|
_TEXTYOFFSET = 1
|
|
|
|
|
_TAG = ('leftarrow',)
|
|
|
|
|
|
|
|
|
|
def __init__(self, canvas, x):
|
2003-10-24 17:09:23 -03:00
|
|
|
|
self._canvas = canvas
|
|
|
|
|
self.__arrow, self.__text = self._create(x)
|
|
|
|
|
self.move_to(x)
|
1998-02-12 15:51:57 -04:00
|
|
|
|
|
|
|
|
|
def _create(self, x):
|
2003-10-24 17:09:23 -03:00
|
|
|
|
arrow = self._canvas.create_line(
|
|
|
|
|
x, self._ARROWHEIGHT + self._YOFFSET,
|
|
|
|
|
x, self._YOFFSET,
|
|
|
|
|
x + self._ARROWWIDTH, self._YOFFSET,
|
|
|
|
|
arrow='first',
|
|
|
|
|
width=3.0,
|
|
|
|
|
tags=self._TAG)
|
|
|
|
|
text = self._canvas.create_text(
|
|
|
|
|
x + self._ARROWWIDTH + 13,
|
|
|
|
|
self._ARROWHEIGHT - self._TEXTYOFFSET,
|
|
|
|
|
tags=self._TAG,
|
|
|
|
|
text='128')
|
|
|
|
|
return arrow, text
|
1998-02-12 15:51:57 -04:00
|
|
|
|
|
|
|
|
|
def _x(self):
|
2010-08-02 19:08:58 -03:00
|
|
|
|
coords = list(self._canvas.coords(self._TAG))
|
2003-10-24 17:09:23 -03:00
|
|
|
|
assert coords
|
|
|
|
|
return coords[0]
|
1998-02-12 15:51:57 -04:00
|
|
|
|
|
|
|
|
|
def move_to(self, x):
|
2003-10-24 17:09:23 -03:00
|
|
|
|
deltax = x - self._x()
|
|
|
|
|
self._canvas.move(self._TAG, deltax, 0)
|
1998-02-12 15:51:57 -04:00
|
|
|
|
|
1998-02-13 17:28:47 -04:00
|
|
|
|
def set_text(self, text):
|
2003-10-24 17:09:23 -03:00
|
|
|
|
self._canvas.itemconfigure(self.__text, text=text)
|
1998-02-13 17:28:47 -04:00
|
|
|
|
|
1998-02-12 15:51:57 -04:00
|
|
|
|
|
|
|
|
|
class RightArrow(LeftArrow):
|
|
|
|
|
_TAG = ('rightarrow',)
|
|
|
|
|
|
|
|
|
|
def _create(self, x):
|
2003-10-24 17:09:23 -03:00
|
|
|
|
arrow = self._canvas.create_line(
|
|
|
|
|
x, self._YOFFSET,
|
|
|
|
|
x + self._ARROWWIDTH, self._YOFFSET,
|
|
|
|
|
x + self._ARROWWIDTH, self._ARROWHEIGHT + self._YOFFSET,
|
|
|
|
|
arrow='last',
|
|
|
|
|
width=3.0,
|
|
|
|
|
tags=self._TAG)
|
|
|
|
|
text = self._canvas.create_text(
|
|
|
|
|
x - self._ARROWWIDTH + 15, # BAW: kludge
|
|
|
|
|
self._ARROWHEIGHT - self._TEXTYOFFSET,
|
1998-10-06 20:04:55 -03:00
|
|
|
|
justify=RIGHT,
|
2003-10-24 17:09:23 -03:00
|
|
|
|
text='128',
|
|
|
|
|
tags=self._TAG)
|
|
|
|
|
return arrow, text
|
1998-02-12 15:51:57 -04:00
|
|
|
|
|
|
|
|
|
def _x(self):
|
2010-08-02 19:08:58 -03:00
|
|
|
|
coords = list(self._canvas.coords(self._TAG))
|
2003-10-24 17:09:23 -03:00
|
|
|
|
assert coords
|
2006-01-01 17:48:54 -04:00
|
|
|
|
return coords[0] + self._ARROWWIDTH
|
1998-02-12 15:51:57 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-09-28 17:58:06 -03:00
|
|
|
|
class StripWidget:
|
1998-02-12 15:51:57 -04:00
|
|
|
|
_CHIPHEIGHT = 50
|
|
|
|
|
_CHIPWIDTH = 10
|
|
|
|
|
_NUMCHIPS = 40
|
|
|
|
|
|
1998-09-28 17:58:06 -03:00
|
|
|
|
def __init__(self, switchboard,
|
Many changes to support a second mode of operation. Pynche can now be
run either as a standalone application (by running pynche or
pynche.pyw), or as a modal dialog inside another application. This
can be done by importing pyColorChooser and running askcolor(). The
API for this is the same as the tkColorChooser.askcolor() API, namely:
When `Okay' is hit, askcolor() returns ((r, g, b), "name"). When
`Cancel' is hit, askcolor() returns (None, None).
Note the following differences:
1. pyColorChooser.askcolor() takes an optional keyword `master'
which if set tells Pynche to run as a modal dialog. `master'
is a Tkinter parent window. Without the `master' keyword
Pynche runs standalone.
2. in pyColorChooser.askcolor() will return a Tk/X11 color name as
"name" if there is an exact match, otherwise it will return a
color spec, e.g. "#rrggbb". tkColorChooser can't return a
color name.
There are also some UI differences when running standalone vs. modal.
When modal, there is no "File" menu, but instead there are "Okay" and
"Cancel" buttons.
The implementation of all this is a bit of a hack, but it seems to
work moderately well. I'm not guaranteeing the pyColorChooser.Chooser
class has the same semantics as the tkColorChooser.Chooser class.
1998-10-22 00:25:59 -03:00
|
|
|
|
master = None,
|
1998-09-28 19:42:44 -03:00
|
|
|
|
chipwidth = _CHIPWIDTH,
|
|
|
|
|
chipheight = _CHIPHEIGHT,
|
|
|
|
|
numchips = _NUMCHIPS,
|
1998-09-28 17:58:06 -03:00
|
|
|
|
generator = None,
|
|
|
|
|
axis = None,
|
1998-10-01 00:08:07 -03:00
|
|
|
|
label = '',
|
1998-10-06 13:13:35 -03:00
|
|
|
|
uwdvar = None,
|
|
|
|
|
hexvar = None):
|
1998-09-28 18:01:55 -03:00
|
|
|
|
# instance variables
|
2003-10-24 17:09:23 -03:00
|
|
|
|
self.__generator = generator
|
|
|
|
|
self.__axis = axis
|
1998-09-28 19:42:44 -03:00
|
|
|
|
self.__numchips = numchips
|
2003-10-24 17:09:23 -03:00
|
|
|
|
assert self.__axis in (0, 1, 2)
|
|
|
|
|
self.__uwd = uwdvar
|
1998-10-06 13:13:35 -03:00
|
|
|
|
self.__hexp = hexvar
|
1998-09-28 17:58:06 -03:00
|
|
|
|
# the last chip selected
|
1998-03-17 11:59:26 -04:00
|
|
|
|
self.__lastchip = None
|
1998-09-28 17:58:06 -03:00
|
|
|
|
self.__sb = switchboard
|
2004-07-18 03:16:08 -03:00
|
|
|
|
|
2003-10-24 17:09:23 -03:00
|
|
|
|
canvaswidth = numchips * (chipwidth + 1)
|
|
|
|
|
canvasheight = chipheight + 43 # BAW: Kludge
|
1998-02-12 15:51:57 -04:00
|
|
|
|
|
2003-10-24 17:09:23 -03:00
|
|
|
|
# create the canvas and pack it
|
|
|
|
|
canvas = self.__canvas = Canvas(master,
|
Many changes to support a second mode of operation. Pynche can now be
run either as a standalone application (by running pynche or
pynche.pyw), or as a modal dialog inside another application. This
can be done by importing pyColorChooser and running askcolor(). The
API for this is the same as the tkColorChooser.askcolor() API, namely:
When `Okay' is hit, askcolor() returns ((r, g, b), "name"). When
`Cancel' is hit, askcolor() returns (None, None).
Note the following differences:
1. pyColorChooser.askcolor() takes an optional keyword `master'
which if set tells Pynche to run as a modal dialog. `master'
is a Tkinter parent window. Without the `master' keyword
Pynche runs standalone.
2. in pyColorChooser.askcolor() will return a Tk/X11 color name as
"name" if there is an exact match, otherwise it will return a
color spec, e.g. "#rrggbb". tkColorChooser can't return a
color name.
There are also some UI differences when running standalone vs. modal.
When modal, there is no "File" menu, but instead there are "Okay" and
"Cancel" buttons.
The implementation of all this is a bit of a hack, but it seems to
work moderately well. I'm not guaranteeing the pyColorChooser.Chooser
class has the same semantics as the tkColorChooser.Chooser class.
1998-10-22 00:25:59 -03:00
|
|
|
|
width=canvaswidth,
|
|
|
|
|
height=canvasheight,
|
|
|
|
|
## borderwidth=2,
|
|
|
|
|
## relief=GROOVE
|
|
|
|
|
)
|
1998-02-16 23:09:40 -04:00
|
|
|
|
|
2003-10-24 17:09:23 -03:00
|
|
|
|
canvas.pack()
|
|
|
|
|
canvas.bind('<ButtonPress-1>', self.__select_chip)
|
|
|
|
|
canvas.bind('<ButtonRelease-1>', self.__select_chip)
|
|
|
|
|
canvas.bind('<B1-Motion>', self.__select_chip)
|
|
|
|
|
|
|
|
|
|
# Load a proc into the Tcl interpreter. This is used in the
|
|
|
|
|
# set_color() method to speed up setting the chip colors.
|
|
|
|
|
canvas.tk.eval(TCLPROC)
|
|
|
|
|
|
|
|
|
|
# create the color strip
|
|
|
|
|
chips = self.__chips = []
|
|
|
|
|
x = 1
|
|
|
|
|
y = 30
|
|
|
|
|
tags = ('chip',)
|
|
|
|
|
for c in range(self.__numchips):
|
|
|
|
|
color = 'grey'
|
|
|
|
|
canvas.create_rectangle(
|
|
|
|
|
x, y, x+chipwidth, y+chipheight,
|
|
|
|
|
fill=color, outline=color,
|
|
|
|
|
tags=tags)
|
|
|
|
|
x = x + chipwidth + 1 # for outline
|
|
|
|
|
chips.append(color)
|
|
|
|
|
|
|
|
|
|
# create the strip label
|
|
|
|
|
self.__label = canvas.create_text(
|
|
|
|
|
3, y + chipheight + 8,
|
|
|
|
|
text=label,
|
|
|
|
|
anchor=W)
|
|
|
|
|
|
|
|
|
|
# create the arrow and text item
|
|
|
|
|
chipx = self.__arrow_x(0)
|
|
|
|
|
self.__leftarrow = LeftArrow(canvas, chipx)
|
|
|
|
|
|
|
|
|
|
chipx = self.__arrow_x(len(chips) - 1)
|
|
|
|
|
self.__rightarrow = RightArrow(canvas, chipx)
|
1998-02-12 15:51:57 -04:00
|
|
|
|
|
1998-02-16 23:09:40 -04:00
|
|
|
|
def __arrow_x(self, chipnum):
|
2003-10-24 17:09:23 -03:00
|
|
|
|
coords = self.__canvas.coords(chipnum+1)
|
|
|
|
|
assert coords
|
|
|
|
|
x0, y0, x1, y1 = coords
|
|
|
|
|
return (x1 + x0) / 2.0
|
1998-02-16 23:09:40 -04:00
|
|
|
|
|
1998-09-28 19:42:44 -03:00
|
|
|
|
# Invoked when one of the chips is clicked. This should just tell the
|
|
|
|
|
# switchboard to set the color on all the output components
|
1998-02-16 23:09:40 -04:00
|
|
|
|
def __select_chip(self, event=None):
|
1998-09-28 19:42:44 -03:00
|
|
|
|
x = event.x
|
|
|
|
|
y = event.y
|
|
|
|
|
canvas = self.__canvas
|
|
|
|
|
chip = canvas.find_overlapping(x, y, x, y)
|
|
|
|
|
if chip and (1 <= chip[0] <= self.__numchips):
|
|
|
|
|
color = self.__chips[chip[0]-1]
|
|
|
|
|
red, green, blue = ColorDB.rrggbb_to_triplet(color)
|
|
|
|
|
etype = int(event.type)
|
1998-10-01 00:08:07 -03:00
|
|
|
|
if (etype == BTNUP or self.__uwd.get()):
|
1998-09-28 19:42:44 -03:00
|
|
|
|
# update everyone
|
|
|
|
|
self.__sb.update_views(red, green, blue)
|
|
|
|
|
else:
|
|
|
|
|
# just track the arrows
|
|
|
|
|
self.__trackarrow(chip[0], (red, green, blue))
|
1998-02-16 23:09:40 -04:00
|
|
|
|
|
1998-03-17 11:59:26 -04:00
|
|
|
|
def __trackarrow(self, chip, rgbtuple):
|
|
|
|
|
# invert the last chip
|
|
|
|
|
if self.__lastchip is not None:
|
|
|
|
|
color = self.__canvas.itemcget(self.__lastchip, 'fill')
|
|
|
|
|
self.__canvas.itemconfigure(self.__lastchip, outline=color)
|
|
|
|
|
self.__lastchip = chip
|
2003-10-24 17:09:23 -03:00
|
|
|
|
# get the arrow's text
|
|
|
|
|
coloraxis = rgbtuple[self.__axis]
|
1998-10-06 13:13:35 -03:00
|
|
|
|
if self.__hexp.get():
|
|
|
|
|
# hex
|
|
|
|
|
text = hex(coloraxis)
|
|
|
|
|
else:
|
|
|
|
|
# decimal
|
|
|
|
|
text = repr(coloraxis)
|
2005-07-22 18:49:32 -03:00
|
|
|
|
# move the arrow, and set its text
|
2003-10-24 17:09:23 -03:00
|
|
|
|
if coloraxis <= 128:
|
|
|
|
|
# use the left arrow
|
|
|
|
|
self.__leftarrow.set_text(text)
|
|
|
|
|
self.__leftarrow.move_to(self.__arrow_x(chip-1))
|
|
|
|
|
self.__rightarrow.move_to(-100)
|
|
|
|
|
else:
|
|
|
|
|
# use the right arrow
|
|
|
|
|
self.__rightarrow.set_text(text)
|
|
|
|
|
self.__rightarrow.move_to(self.__arrow_x(chip-1))
|
|
|
|
|
self.__leftarrow.move_to(-100)
|
|
|
|
|
# and set the chip's outline
|
1998-09-28 17:58:06 -03:00
|
|
|
|
brightness = ColorDB.triplet_to_brightness(rgbtuple)
|
2003-10-24 17:09:23 -03:00
|
|
|
|
if brightness <= 128:
|
|
|
|
|
outline = 'white'
|
|
|
|
|
else:
|
|
|
|
|
outline = 'black'
|
|
|
|
|
self.__canvas.itemconfigure(chip, outline=outline)
|
1998-03-16 19:08:53 -04:00
|
|
|
|
|
1998-03-17 11:59:26 -04:00
|
|
|
|
|
1998-09-28 17:58:06 -03:00
|
|
|
|
def update_yourself(self, red, green, blue):
|
2003-10-24 17:09:23 -03:00
|
|
|
|
assert self.__generator
|
|
|
|
|
i = 1
|
|
|
|
|
chip = 0
|
|
|
|
|
chips = self.__chips = []
|
|
|
|
|
tk = self.__canvas.tk
|
1998-09-28 17:58:06 -03:00
|
|
|
|
# get the red, green, and blue components for all chips
|
1998-09-28 19:42:44 -03:00
|
|
|
|
for t in self.__generator(self.__numchips, red, green, blue):
|
1998-03-17 11:59:26 -04:00
|
|
|
|
rrggbb = ColorDB.triplet_to_rrggbb(t)
|
|
|
|
|
chips.append(rrggbb)
|
|
|
|
|
tred, tgreen, tblue = t
|
|
|
|
|
if tred <= red and tgreen <= green and tblue <= blue:
|
|
|
|
|
chip = i
|
|
|
|
|
i = i + 1
|
|
|
|
|
# call the raw tcl script
|
2001-07-10 18:44:24 -03:00
|
|
|
|
colors = SPACE.join(chips)
|
1998-03-17 11:59:26 -04:00
|
|
|
|
tk.eval('setcolor %s {%s}' % (self.__canvas._w, colors))
|
|
|
|
|
# move the arrows around
|
1998-09-28 17:58:06 -03:00
|
|
|
|
self.__trackarrow(chip, (red, green, blue))
|
1998-03-17 11:59:26 -04:00
|
|
|
|
|
1998-12-14 21:04:38 -04:00
|
|
|
|
def set(self, label, generator):
|
|
|
|
|
self.__canvas.itemconfigure(self.__label, text=label)
|
|
|
|
|
self.__generator = generator
|
|
|
|
|
|
1998-09-28 19:42:44 -03:00
|
|
|
|
|
|
|
|
|
class StripViewer:
|
Many changes to support a second mode of operation. Pynche can now be
run either as a standalone application (by running pynche or
pynche.pyw), or as a modal dialog inside another application. This
can be done by importing pyColorChooser and running askcolor(). The
API for this is the same as the tkColorChooser.askcolor() API, namely:
When `Okay' is hit, askcolor() returns ((r, g, b), "name"). When
`Cancel' is hit, askcolor() returns (None, None).
Note the following differences:
1. pyColorChooser.askcolor() takes an optional keyword `master'
which if set tells Pynche to run as a modal dialog. `master'
is a Tkinter parent window. Without the `master' keyword
Pynche runs standalone.
2. in pyColorChooser.askcolor() will return a Tk/X11 color name as
"name" if there is an exact match, otherwise it will return a
color spec, e.g. "#rrggbb". tkColorChooser can't return a
color name.
There are also some UI differences when running standalone vs. modal.
When modal, there is no "File" menu, but instead there are "Okay" and
"Cancel" buttons.
The implementation of all this is a bit of a hack, but it seems to
work moderately well. I'm not guaranteeing the pyColorChooser.Chooser
class has the same semantics as the tkColorChooser.Chooser class.
1998-10-22 00:25:59 -03:00
|
|
|
|
def __init__(self, switchboard, master=None):
|
1998-09-28 19:42:44 -03:00
|
|
|
|
self.__sb = switchboard
|
1998-10-20 17:45:46 -03:00
|
|
|
|
optiondb = switchboard.optiondb()
|
1998-12-14 21:04:38 -04:00
|
|
|
|
# create a frame inside the master.
|
|
|
|
|
frame = Frame(master, relief=RAISED, borderwidth=1)
|
|
|
|
|
frame.grid(row=1, column=0, columnspan=2, sticky='NSEW')
|
|
|
|
|
# create the options to be used later
|
1998-10-20 17:45:46 -03:00
|
|
|
|
uwd = self.__uwdvar = BooleanVar()
|
|
|
|
|
uwd.set(optiondb.get('UPWHILEDRAG', 0))
|
|
|
|
|
hexp = self.__hexpvar = BooleanVar()
|
|
|
|
|
hexp.set(optiondb.get('HEXSTRIP', 0))
|
1998-12-14 21:04:38 -04:00
|
|
|
|
# create the red, green, blue strips inside their own frame
|
|
|
|
|
frame1 = Frame(frame)
|
|
|
|
|
frame1.pack(expand=YES, fill=BOTH)
|
|
|
|
|
self.__reds = StripWidget(switchboard, frame1,
|
1998-09-28 19:42:44 -03:00
|
|
|
|
generator=constant_cyan_generator,
|
|
|
|
|
axis=0,
|
1998-10-01 00:08:07 -03:00
|
|
|
|
label='Red Variations',
|
1998-10-06 13:13:35 -03:00
|
|
|
|
uwdvar=uwd, hexvar=hexp)
|
1998-09-28 19:42:44 -03:00
|
|
|
|
|
1998-12-14 21:04:38 -04:00
|
|
|
|
self.__greens = StripWidget(switchboard, frame1,
|
1998-09-28 19:42:44 -03:00
|
|
|
|
generator=constant_magenta_generator,
|
|
|
|
|
axis=1,
|
1998-10-01 00:08:07 -03:00
|
|
|
|
label='Green Variations',
|
1998-10-06 13:13:35 -03:00
|
|
|
|
uwdvar=uwd, hexvar=hexp)
|
1998-09-28 19:42:44 -03:00
|
|
|
|
|
1998-12-14 21:04:38 -04:00
|
|
|
|
self.__blues = StripWidget(switchboard, frame1,
|
1998-09-28 19:42:44 -03:00
|
|
|
|
generator=constant_yellow_generator,
|
|
|
|
|
axis=2,
|
1998-10-01 00:08:07 -03:00
|
|
|
|
label='Blue Variations',
|
1998-10-06 13:13:35 -03:00
|
|
|
|
uwdvar=uwd, hexvar=hexp)
|
|
|
|
|
|
1998-12-14 21:04:38 -04:00
|
|
|
|
# create a frame to contain the controls
|
|
|
|
|
frame2 = Frame(frame)
|
|
|
|
|
frame2.pack(expand=YES, fill=BOTH)
|
|
|
|
|
frame2.columnconfigure(0, weight=20)
|
|
|
|
|
frame2.columnconfigure(2, weight=20)
|
|
|
|
|
|
|
|
|
|
padx = 8
|
|
|
|
|
|
|
|
|
|
# create the black button
|
|
|
|
|
blackbtn = Button(frame2,
|
1999-04-27 12:56:02 -03:00
|
|
|
|
text='Black',
|
1998-12-14 21:04:38 -04:00
|
|
|
|
command=self.__toblack)
|
|
|
|
|
blackbtn.grid(row=0, column=0, rowspan=2, sticky=W, padx=padx)
|
|
|
|
|
|
|
|
|
|
# create the controls
|
|
|
|
|
uwdbtn = Checkbutton(frame2,
|
|
|
|
|
text='Update while dragging',
|
|
|
|
|
variable=uwd)
|
|
|
|
|
uwdbtn.grid(row=0, column=1, sticky=W)
|
|
|
|
|
hexbtn = Checkbutton(frame2,
|
|
|
|
|
text='Hexadecimal',
|
|
|
|
|
variable=hexp,
|
|
|
|
|
command=self.__togglehex)
|
|
|
|
|
hexbtn.grid(row=1, column=1, sticky=W)
|
|
|
|
|
|
|
|
|
|
# create the white button
|
|
|
|
|
whitebtn = Button(frame2,
|
1999-04-27 12:56:02 -03:00
|
|
|
|
text='White',
|
1998-12-14 21:04:38 -04:00
|
|
|
|
command=self.__towhite)
|
|
|
|
|
whitebtn.grid(row=0, column=2, rowspan=2, sticky=E, padx=padx)
|
1998-10-06 13:13:35 -03:00
|
|
|
|
|
1998-09-28 19:42:44 -03:00
|
|
|
|
def update_yourself(self, red, green, blue):
|
|
|
|
|
self.__reds.update_yourself(red, green, blue)
|
|
|
|
|
self.__greens.update_yourself(red, green, blue)
|
|
|
|
|
self.__blues.update_yourself(red, green, blue)
|
1998-10-06 13:13:35 -03:00
|
|
|
|
|
|
|
|
|
def __togglehex(self, event=None):
|
|
|
|
|
red, green, blue = self.__sb.current_rgb()
|
|
|
|
|
self.update_yourself(red, green, blue)
|
1998-10-20 17:45:46 -03:00
|
|
|
|
|
1998-12-14 21:04:38 -04:00
|
|
|
|
def __toblack(self, event=None):
|
|
|
|
|
self.__sb.update_views(0, 0, 0)
|
|
|
|
|
|
|
|
|
|
def __towhite(self, event=None):
|
|
|
|
|
self.__sb.update_views(255, 255, 255)
|
|
|
|
|
|
1998-10-20 17:45:46 -03:00
|
|
|
|
def save_options(self, optiondb):
|
|
|
|
|
optiondb['UPWHILEDRAG'] = self.__uwdvar.get()
|
|
|
|
|
optiondb['HEXSTRIP'] = self.__hexpvar.get()
|