Lev, I'm sorry, but you went a little too far in the new version; color validation in rcsetup still needs much of the original code, but it can use is_color_like as a helper--not a replacement. validate_color has to handle 'None', and tuples that come in as strings.
I have committed a change to svn that I think takes care of the problem. It could be simplified, or it could be made more complex by adding more explanation of what is wrong with a given input, but I think it is adequate for now as-is. It should trap anything that would otherwise fail later. Eric Lev Givon wrote: > Received from Lev Givon on Sun, Apr 06, 2008 at 11:03:06PM EDT: >> Received from Eric Firing on Sun, Apr 06, 2008 at 10:40:44PM EDT: >>> Lev, >>> >>> Yes, you can post it here. It looks to me like just using >>> colors.is_color_like() as a last step would do it. Is that the way you >>> made the change? I haven't dealt much with the rc system, so I may be >>> missing something. >>> >> No, but your suggestion seems preferable to my patch (I essentially >> just improved several problematic clauses within validate_color and >> added a check against the color name dictionaries defined in >> matplotlib.color). There may be some issue complicating the import of >> the color module within rcsetup, though; I will have to check. > > The issue I alluded to affects the current stable version of > matplotlib owing to the numerix layer, but isn't a problem with the > svn version. The updated patch (made against revision 4913 of > rcsetup.py) is attached. > > L.G. > > > ------------------------------------------------------------------------ > > --- rcsetup.py.bak 2008-04-07 11:46:47.000000000 -0400 > +++ rcsetup.py 2008-04-07 12:33:06.000000000 -0400 > @@ -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): > @@ -125,34 +126,11 @@ > > 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 > - # get rid of grouping symbols > - s = ''.join([ c for c in s if c.isdigit() or c=='.' or c==',']) > - vals = s.split(',') > - if len(vals)!=3: > - raise ValueError('Color tuples must be length 3') > - > - try: return [float(val) for val in vals] > - except ValueError: > - raise ValueError('Could not convert all entries "%s" to > floats'%s) > - > - if s.replace('.', '').isdigit(): # looks like scalar (grayscale) > + if is_color_like(s): > return s > - > - 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) > - > + else: > + raise ValueError('%s does not look like color arg'%s) > + > def validate_stringlist(s): > 'return a list' > if type(s) is str: > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > 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-devel mailing list > Matplotlib-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel ------------------------------------------------------------------------- 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-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel