- Phoenix-port of `wx.lib.colourutils.py`, no unittest as I have no idea about which unittest can make any sense for this module. Documentation updated to Phoenix standards.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72110 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Andrea Gavana
2012-07-15 20:51:09 +00:00
parent 68f6b1cfc9
commit 4f6b6ff7ee

View File

@@ -1,6 +1,18 @@
#----------------------------------------------------------------------
# Name: colourutils.py
# Purpose: Some useful colour-related utility functions.
#
# Author: Cody Precord
#
# Created: 13-March-2001
# RCS-ID: $Id: colourutils.py 72102 2012-07-15 15:01:29Z AG $
# Copyright: (c) 2001 by Total Control Software
# Licence: wxWindows license
# Tags: phoenix-port, documented
#----------------------------------------------------------------------
""" """
Some useful colour-related utility functions. Some useful colour-related utility functions.
""" """
__author__ = "Cody Precord <cprecord@editra.org>" __author__ = "Cody Precord <cprecord@editra.org>"
@@ -21,20 +33,33 @@ if wx.Platform == '__WXMAC__':
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
def AdjustAlpha(colour, alpha): def AdjustAlpha(colour, alpha):
"""Adjust the alpha of a given colour""" """
Adjust the alpha of a given colour
:param integer `alpha`: the new value for the colour alpha channel (between 0
and 255).
:rtype: :class:`Colour`
:returns: A new :class:`Colour` with the alpha channel specified as input
"""
return wx.Colour(colour.Red(), colour.Green(), colour.Blue(), alpha) return wx.Colour(colour.Red(), colour.Green(), colour.Blue(), alpha)
def AdjustColour(color, percent, alpha=wx.ALPHA_OPAQUE): def AdjustColour(color, percent, alpha=wx.ALPHA_OPAQUE):
""" """
Brighten/Darken input colour by percent and adjust alpha Brighten/darken input colour by `percent` and adjust alpha
channel if needed. Returns the modified color. channel if needed. Returns the modified color.
:param Colour `color`: color object to adjust :param Colour `color`: color object to adjust;
:param integer `percent`: percent to adjust +(brighten) or -(darken) :param integer `percent`: percent to adjust +(brighten) or -(darken);
:keyword `alpha`: amount to adjust alpha channel :param integer `alpha`: amount to adjust alpha channel.
:rtype: :class:`Colour`
:returns: A new darkened/lightened :class:`Colour` with the alpha channel
specified as input
""" """
radj, gadj, badj = [ int(val * (abs(percent) / 100.)) radj, gadj, badj = [ int(val * (abs(percent) / 100.))
for val in color.Get() ] for val in color.Get() ]
@@ -54,10 +79,12 @@ def BestLabelColour(color, bw=False):
Get the best color to use for the label that will be drawn on Get the best color to use for the label that will be drawn on
top of the given color. top of the given color.
:param Colour `color`: background color that text will be drawn on :param Colour `color`: background color that text will be drawn on;
:keyword `bw`: If True, only return black or white :param bool `bw`: If ``True``, only return black or white.
:rtype: :class:`Colour`
""" """
avg = sum(color.Get()) / 3 avg = sum(color.Get()) / 3
if avg > 192: if avg > 192:
txt_color = wx.BLACK txt_color = wx.BLACK
@@ -71,12 +98,14 @@ def BestLabelColour(color, bw=False):
else: txt_color = AdjustColour(color, 95) else: txt_color = AdjustColour(color, 95)
return txt_color return txt_color
def GetHighlightColour():
"""Get the default highlight color
:return: :class:`Colour`
def GetHighlightColour():
""" """
Gets the default highlight color.
:rtype: :class:`Colour`
"""
if wx.Platform == '__WXMAC__': if wx.Platform == '__WXMAC__':
if CARBON: if CARBON:
if wx.VERSION < (2, 9, 0, 0, ''): if wx.VERSION < (2, 9, 0, 0, ''):