#!/usr/bin/env python
#
# $Id: colormath.py,v 1.3 2001/11/03 11:05:22 doughellmann Exp $
#
# Copyright 2001 Doug Hellmann.
#
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Doug
# Hellmann not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
"""Functions to compute color shadows, light and dark.
"""
__rcs_info__ = {
#
# Creation Information
#
'module_name' : '$RCSfile: colormath.py,v $',
'rcs_id' : '$Id: colormath.py,v 1.3 2001/11/03 11:05:22 doughellmann Exp $',
'creator' : 'Doug Hellmann <doug@hellfly.net>',
'project' : 'PmwContribD',
'created' : 'Sat, 05-May-2001 13:56:44 EDT',
#
# Current Information
#
'author' : '$Author: doughellmann $',
'version' : '$Revision: 1.3 $',
'date' : '$Date: 2001/11/03 11:05:22 $',
}
#
# Import system modules
#
#
# Import Local modules
#
#
# Module
#
def checkRGBRange(value, maxBits=16):
"""Make sure the RGB value represents no more than maxBits value.
The computeColorTriplet function is a bit sloppy with math, and
uses this function to clean up values before returning them.
"""
minval=0
maxval=pow(2, maxBits) - 1
#print '\t %d = %04x => ' % (value, value),
if value < minval:
newval = minval
elif value > maxval:
newval = maxval
else:
newval = value
#print '%04x = %d' % (newval, newval)
return newval
def computeColorTriplet(widget, baseColor):
"""Compute a set of three colors, given a baseColor.
Returns (baseColor, lightColor, darkColor).
"""
#print 'computing colors for %s' % baseColor
baseColorRGB = widget.winfo_rgb(baseColor)
baseColorHex = '#%04x%04x%04x' % baseColorRGB
lightColorRGB = (checkRGBRange(baseColorRGB[0] * 1.2),
checkRGBRange(baseColorRGB[1] * 1.2),
checkRGBRange(baseColorRGB[2] * 1.2))
lightColor = '#%04x%04x%04x' % lightColorRGB
darkColorRGB = (checkRGBRange(baseColorRGB[0] * 0.6),
checkRGBRange(baseColorRGB[1] * 0.6),
checkRGBRange(baseColorRGB[2] * 0.6))
darkColor = '#%04x%04x%04x' % darkColorRGB
triplet = (baseColorHex, lightColor, darkColor)
#print triplet
return triplet
|