@@ -125,6 +125,19 @@ def text_to_qcolor(text):
125
125
color .setNamedColor (text )
126
126
return color
127
127
128
+ def is_matplotlib_color (value ):
129
+ """
130
+ Check if value is a color passed to us from matplotlib.
131
+ It could either be a valid color string or a 3-tuple of floats between 0. and 1.
132
+ """
133
+ if text_to_qcolor (value ).isValid ():
134
+ return True
135
+ if isinstance (value ,tuple ) and len (value )== 3 and all (map (lambda v : isinstance (v ,float ),value )):
136
+ for c in value :
137
+ if c < 0. or c > 1. :
138
+ return False
139
+ return True
140
+ return False
128
141
129
142
class ColorLayout (QHBoxLayout ):
130
143
"""Color-specialized QLineEdit layout"""
@@ -268,7 +281,7 @@ def setup(self):
268
281
continue
269
282
elif tuple_to_qfont (value ) is not None :
270
283
field = FontLayout (value , self )
271
- elif text_to_qcolor (value ). isValid ( ):
284
+ elif is_matplotlib_color (value ):
272
285
field = ColorLayout (QColor (value ), self )
273
286
elif isinstance (value , (str , unicode )):
274
287
field = QLineEdit (value , self )
@@ -329,7 +342,7 @@ def get(self):
329
342
continue
330
343
elif tuple_to_qfont (value ) is not None :
331
344
value = field .get_font ()
332
- elif isinstance (value , (str , unicode )):
345
+ elif isinstance (value , (str , unicode )) or is_matplotlib_color ( value ) :
333
346
value = unicode (field .text ())
334
347
elif isinstance (value , (list , tuple )):
335
348
index = int (field .currentIndex ())
0 commit comments