This class is a compound widget that has two functions:
It displays the current text and background colors in #RRGGBB form.
It has radiobuttons that allow the user to select whether the color sliders are displaying the text color or the background color.
Here is the class interface:
# - - - - - c l a s s C o l o r R e a d o u t
class ColorReadout(Frame):
"""Displays text and background colors, and switches between them.
Exports:
ColorReadout ( parent, bg, fg, callback=None ):
[ (parent is a Frame) and
(bg is a background color as a Color) and
(fg is a foreground color as a Color) and
(callback is a function or None) ->
parent := parent with a new ColorReadout widget
added but not gridded, initially displaying
the background color, which will call
callback() whenever the user changes
between text to bg color ]
The next two methods return the current text and
background colors, respectively; see
Section 16.4, “ColorReadout.textColor(): Return the
current text color” and
Section 16.5, “ColorReadout.bgColor(): Return the
current background color”.
.textColor():
[ return self's current text color as a Color instance ]
.bgColor:
[ return self's current background color as a Color instance ]
The .set() method changes the currently
displayed color; see Section 16.2, “ColorReadout.set(): Change the displayed
color”.
.set ( color ):
[ if self is currently displaying the text color ->
self's text color := color
else ->
self's background color := color
In any case ->
call self.__callback(color) ]
To determine whether the user has selected text or
background color, call this method; see Section 16.1, “ColorReadout.isText(): Which color are we
displaying?”.
.isText():
[ if self is currently displaying the text color ->
return True
else -> return False ]
Here is the layout of the internal widgets, and the internal attributes that control them.
Contained widgets:
.__rgbLabel: [ text label '#RRGGBB' ]
.__textColorName:
[ an Entry widget displaying self.__textColorVar ]
.__bgColorName:
[ an Entry widget displaying self.__bgColorVar ]
.__textRadio: [ a Radiobutton selecting text color ]
.__bgRadio: [ a Radiobutton selecting background color ]
Grid plan:
0 1
+--------------+-------------------+
0 | | .__rgbLabel |
+--------------+-------------------+
1 | .__bgRadio | .__bgColorName |
+--------------+-------------------+
2 | .__textRadio | .__textColorName |
+--------------+-------------------+
State/Internals:
.__callback: [ as passed to constructor, read-only ]
.__isTextVar:
[ an IntVar that is 1 if displaying text color,
0 if displaying background color ]
.__bgColor:
[ self's current background color as a Color instance ]
.__bgColorVar:
[ a StringVar displaying self.__bgColor as #RRGGBB ]
.__textColor:
[ self's current text color as a Color instance ]
.__textColorVar:
[ a StringVar displaying self.__textColor as #RRGGBB ]
"""