Next / Previous / Contents / TCC Help System / NM Tech homepage

Abstract

Describes the implementation of huey, a graphical application for selecting colors and fonts, using the Python programming language and the Tkinter widget set.

This publication is available in Web form and also as a PDF document. Please forward any comments to tcc-doc@nmt.edu.

Table of Contents

1. Introduction
1.1. Files discussed in this publication
2. References
3. Design notes
4. Code prologue
4.1. Imports
4.2. Manifest constants
5. main(): The main program
6. class Color: A specific color
6.1. Color.__init__(): Constructor
6.2. Color.__standardize(): Standardize color component representation
6.3. Color.__str__(): Convert to a string
6.4. Color.__cmp__(): Compare two colors
7. class ColorModel: Base class for color models
7.1. ColorModel.__init__(): Constructor
7.2. ColorModel.paramsToColor()
7.3. ColorModel.colorToParams()
7.4. ColorModel.normalize(): Normalize an integer color parameter
7.5. ColorModel.discretize(): Discretize an integer color parameter
8. class HSVModel: Hue-saturation-value color model
8.1. HSVModel.__init__(): Constructor
8.2. HSVModel.paramsToColor()
8.3. HSVModel.colorToParams()
9. class RGBModel: Red-green-blue color model
9.1. RGBModel.__init_(): Constructor
9.2. RGBModel.paramsToColor()
9.3. RGBModel.colorToParams()
10. class CMYModel: Cyan-magenta-yellow color model
10.1. CMYModel.__init__()
10.2. CMYModel.paramsToColor()
10.3. CMYModel.colorToParams()
11. class Application: The outermost frame
11.1. Application.__init__(): Constructor
11.2. Application.__createWidgets(): Set up the widgets
11.3. Application.__nameHandler(): Name picker handler
11.4. Application.__adjustHandler(): Adjuster handler
12. class MenuBar: General controls
12.1. MenuBar.__init__(): Constructor
12.2. MenuBar.__createHelp(): Create the Help menu
12.3. MenuBar.__cascadeNamePicker()
12.4. MenuBar.__helpTyping()
12.5. MenuBar.__helpPicking()
12.6. MenuBar.__cascadeAdjuster()
12.7. MenuBar.__helpReadout()
12.8. MenuBar.__helpModelSelector()
12.9. MenuBar.__helpHSV()
12.10. MenuBar.__helpRGB()
12.11. MenuBar.__helpCMY()
12.12. MenuBar.__helpSliders()
12.13. MenuBar.__cascadeViewing()
12.14. MenuBar.__helpSwatch()
12.15. MenuBar.__cascadeFonts()
12.16. MenuBar.__helpFontFamily()
12.17. MenuBar.__helpFontSize()
12.18. MenuBar.__helpFontStyle()
12.19. MenuBar.__helpImporting()
12.20. MenuBar.__helpAuthor()
12.21. MenuBar.__dialog(): Pop up a dialog widget
13. class NamePicker: Select colors by name
13.1. NamePicker.__init(): Constructor
13.2. NamePicker.__createWidgets(): Create all widgets
13.3. NamePicker.__entryHandler(): Handler for the Enter key
13.4. NamePicker.__setByName(): Try to convert a color name to a color
13.5. NamePicker.__pickListHandler(): Somebody clicked on a color
14. class PickList: The color names pick list
14.1. PickList class constants
14.2. PickList: Default color list
14.3. PickList.lookupName(): Convert a color name to a color value
14.4. PickList.__init__(): Constructor
14.5. PickList.__addColors(): Populate the color list
14.6. PickList.__findColorsFile(): Read the rgb.txt file
14.7. PickList.__readColorsFile(): Process the rgb.txt file
14.8. PickList.__readColorLine(): Process one line from rgb.txt
14.9. PickList.__convert8(): Convert an 8-bit number
14.10. PickList.__useDefaultColors(): Set up a default color list
14.11. PickList.__cleanColorMap(): Remove redundant colors
14.12. PickList.__nameCleaner(): Remove redundant color names
14.13. PickList.__anglicize(): Convert “gray” to “grey”
14.14. PickList.__lowerize(): Convert intercapitalized names to lowercase
14.15. PickList.__purgeName(): Remove one redundant color name
14.16. PickList.__pickHandler(): Someone clicked on a color name
15. class Adjuster: Color adjustment and color model selection
15.1. Manifest constants
15.2. Adjuster.set(): Change the color
15.3. Adjuster.textColor(): Return the current text color
15.4. Adjuster.bgColor(): Return the current text color
15.5. Adjuster.isText(): Which color is being displayed?
15.6. Adjuster.__init__(): Constructor
15.7. Adjuster.__createWidgets(): Create internal widgets
15.8. Adjuster.__readoutHandler(): Change between text and background colors
15.9. Adjuster.__modelHandler(): Change the current color model
15.10. Adjuster.__sliderHandler(): Handler for slider changes
16. class ColorReadout: Text and background color readouts
16.1. ColorReadout.isText(): Which color are we displaying?
16.2. ColorReadout.set(): Change the displayed color
16.3. ColorReadout.internalSet()
16.4. ColorReadout.textColor(): Return the current text color
16.5. ColorReadout.bgColor(): Return the current background color
16.6. ColorReadout.__init__(): Constructor
16.7. ColorReadout.__createWidgets()
16.8. ColorReadout.__radioHandler(): Radiobutton state change handler
16.9. ColorReadout.__fixNames(): Prevent user modification of the Entry widgets
17. class ModelSelector: Widgets to select a color model
17.1. ModelSelector: Constants
17.2. ModelSelector.getModel(): Return the current model
17.3. ModelSelector.__init__(): Constructor
17.4. ModelSelector.__createWidgets()
17.5. ModelSelector.__radioHandler(): Handler for radiobutton action
18. class ColorSliders: Color model parameter sliders
18.1. ColorSliders.setModel(): Display a new color model
18.2. ColorSliders.setColor(): Change the displayed color
18.3. ColorSliders.__init__(): Constructor
18.4. ColorSliders.__createWidgets()
18.5. ColorSliders.__sliderHandler(): Handler for a parameter change
19. class ParamSlider: Scale widget for a color model parameter
19.1. ParamSlider.get(): Retrieve the current parameter value
19.2. ParamSlider.setModel(): Change the color model
19.3. ParamSlider.setColor(): Change the current color
19.4. ParamSlider.__init__(): Constructor
19.5. ParamSlider.__createWidgets()
19.6. ParamSlider.__plusHandler(): Increment the parameter
19.7. ParamSlider.__minusHandler(): Decrement the parameter
19.8. ParamSlider.__scaleHandler(): Somebody dragged the scale
20. class Swatch: Font and color samples
20.1. Class constants
20.2. Swatch.setTextColor()
20.3. Swatch.setBgColor()
20.4. Swatch.__init__(): Constructor
20.5. Swatch.__createWidgets()
20.6. Swatch.__fontHandler(): Handle a font change
21. Code epilogue