Revision: 5030
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5030&view=rev
Author: efiring
Date: 2008-04-07 11:48:02 -0700 (Mon, 07 Apr 2008)
Log Message:
-----------
improve color validation in rc handling
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/rcsetup.py
trunk/matplotlib/matplotlibrc.template
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2008-04-04 15:02:48 UTC (rev 5029)
+++ trunk/matplotlib/CHANGELOG 2008-04-07 18:48:02 UTC (rev 5030)
@@ -1,6 +1,9 @@
+2008-04-07 Improve color validation in rc handling, suggested
+ by Lev Givon - EF
+
2008-04-02 Allow to use both linestyle definition arguments, '-' and
- 'solid' etc. in plots/collections - MM
-
+ 'solid' etc. in plots/collections - MM
+
2008-03-27 Fix saving to Unicode filenames with Agg backend
(other backends appear to already work...)
(Thanks, Christopher Barker) - MGD
Modified: trunk/matplotlib/lib/matplotlib/rcsetup.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/rcsetup.py 2008-04-04 15:02:48 UTC (rev
5029)
+++ trunk/matplotlib/lib/matplotlib/rcsetup.py 2008-04-07 18:48:02 UTC (rev
5030)
@@ -10,6 +10,7 @@
import os
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
+from matplotlib.colors import is_color_like
class ValidateInStrings:
def __init__(self, key, valid, ignorecase=False):
@@ -122,37 +123,35 @@
return [int(val) for val in s]
-
def validate_color(s):
'return a valid color arg'
- if s.lower() == 'none': return 'None'
- if len(s)==1 and s.isalpha(): return s
- if s.find(',')>=0: # looks like an rgb
+ if s.lower() == 'none':
+ return 'None'
+ if is_color_like(s):
+ return s
+ stmp = '#' + s
+ if is_color_like(stmp):
+ return stmp
+ # If it is still valid, it must be a tuple.
+ colorarg = s
+ msg = ''
+ if s.find(',')>=0:
# get rid of grouping symbols
- s = ''.join([ c for c in s if c.isdigit() or c=='.' or c==','])
- vals = s.split(',')
+ stmp = ''.join([ c for c in s if c.isdigit() or c=='.' or c==','])
+ vals = stmp.split(',')
if len(vals)!=3:
- raise ValueError('Color tuples must be length 3')
+ msg = '\nColor tuples must be length 3'
+ else:
+ try:
+ colorarg = [float(val) for val in vals]
+ except ValueError:
+ msg = '\nCould not convert all entries to floats'
- try: return [float(val) for val in vals]
- except ValueError:
- raise ValueError('Could not convert all entries "%s" to floats'%s)
+ if not msg and is_color_like(colorarg):
+ return colorarg
- if s.replace('.', '').isdigit(): # looks like scalar (grayscale)
- return s
+ raise ValueError('%s does not look like a color arg%s'%(s, msg))
- if len(s)==6 and s.isalnum(): # looks like hex
- return '#' + s
-
- if len(s)==7 and s.startswith('#') and s[1:].isalnum():
- return s
-
- if s.isalpha():
- #assuming a color name, hold on
- return s
-
- raise ValueError('%s does not look like color arg'%s)
-
def validate_stringlist(s):
'return a list'
if type(s) is str:
Modified: trunk/matplotlib/matplotlibrc.template
===================================================================
--- trunk/matplotlib/matplotlibrc.template 2008-04-04 15:02:48 UTC (rev
5029)
+++ trunk/matplotlib/matplotlibrc.template 2008-04-07 18:48:02 UTC (rev
5030)
@@ -19,7 +19,7 @@
# Colors: for the color values below, you can either use
# - a matplotlib color string, such as r, k, or b
# - an rgb tuple, such as (1.0, 0.5, 0.0)
-# - a hex string, such as ff00ff (no '#' symbol)
+# - a hex string, such as ff00ff or #ff00ff
# - a scalar grayscale intensity such as 0.75
# - a legal html color name, eg red, blue, darkslategray
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Register now and save $200. Hurry, offer ends at 11:59 p.m.,
Monday, April 7! Use priority code J8TLD2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins