1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
|
# This is a redirection file that determines what constitutes a color trait
# in Chaco, and what constitutes the standard colors.
from __future__ import absolute_import
import sys
from traits.etsconfig.api import ETSConfig
from traits.api import List, Str, Trait, Tuple, TraitError
# Color definitions
transparent_color = (0.0, 0.0, 0.0, 0.0)
color_table = {"aliceblue": (0.941, 0.973, 1.000, 1.0),
"antiquewhite": (0.980, 0.922, 0.843, 1.0),
"aqua": (0.000, 1.000, 1.000, 1.0),
"aquamarine": (0.498, 1.000, 0.831, 1.0),
"azure": (0.941, 1.000, 1.000, 1.0),
"beige": (0.961, 0.961, 0.863, 1.0),
"bisque": (1.000, 0.894, 0.769, 1.0),
"black": (0.000, 0.000, 0.000, 1.0),
"blanchedalmond": (1.000, 0.922, 0.804, 1.0),
"blue": (0.000, 0.000, 1.000, 1.0),
"blueviolet": (0.541, 0.169, 0.886, 1.0),
"brown": (0.647, 0.165, 0.165, 1.0),
"burlywood": (0.871, 0.722, 0.529, 1.0),
"cadetblue": (0.373, 0.620, 0.627, 1.0),
"chartreuse": (0.498, 1.000, 0.000, 1.0),
"chocolate": (0.824, 0.412, 0.118, 1.0),
"coral": (1.000, 0.498, 0.314, 1.0),
"cornflowerblue": (0.392, 0.584, 0.929, 1.0),
"cornsilk": (1.000, 0.973, 0.863, 1.0),
"crimson": (0.863, 0.078, 0.235, 1.0),
"cyan": (0.000, 1.000, 1.000, 1.0),
"darkblue": (0.000, 0.000, 0.545, 1.0),
"darkcyan": (0.000, 0.545, 0.545, 1.0),
"darkgoldenrod": (0.722, 0.525, 0.043, 1.0),
"darkgray": (0.663, 0.663, 0.663, 1.0),
"darkgreen": (0.000, 0.392, 0.000, 1.0),
"darkgrey": (0.663, 0.663, 0.663, 1.0),
"darkkhaki": (0.741, 0.718, 0.420, 1.0),
"darkmagenta": (0.545, 0.000, 0.545, 1.0),
"darkolivegreen": (0.333, 0.420, 0.184, 1.0),
"darkorange": (1.000, 0.549, 0.000, 1.0),
"darkorchid": (0.600, 0.196, 0.800, 1.0),
"darkred": (0.545, 0.000, 0.000, 1.0),
"darksalmon": (0.914, 0.588, 0.478, 1.0),
"darkseagreen": (0.561, 0.737, 0.561, 1.0),
"darkslateblue": (0.282, 0.239, 0.545, 1.0),
"darkslategray": (0.184, 0.310, 0.310, 1.0),
"darkslategrey": (0.184, 0.310, 0.310, 1.0),
"darkturquoise": (0.000, 0.808, 0.820, 1.0),
"darkviolet": (0.580, 0.000, 0.827, 1.0),
"deeppink": (1.000, 0.078, 0.576, 1.0),
"deepskyblue": (0.000, 0.749, 1.000, 1.0),
"dimgray": (0.412, 0.412, 0.412, 1.0),
"dimgrey": (0.412, 0.412, 0.412, 1.0),
"dodgerblue": (0.118, 0.565, 1.000, 1.0),
"firebrick": (0.698, 0.133, 0.133, 1.0),
"floralwhite": (1.000, 0.980, 0.941, 1.0),
"forestgreen": (0.133, 0.545, 0.133, 1.0),
"fuchsia": (1.000, 0.000, 1.000, 1.0),
"gainsboro": (0.863, 0.863, 0.863, 1.0),
"ghostwhite": (0.973, 0.973, 1.000, 1.0),
"gold": (1.000, 0.843, 0.000, 1.0),
"goldenrod": (0.855, 0.647, 0.125, 1.0),
"gray": (0.502, 0.502, 0.502, 1.0),
"green": (0.000, 0.502, 0.000, 1.0),
"greenyellow": (0.678, 1.000, 0.184, 1.0),
"grey": (0.502, 0.502, 0.502, 1.0),
"honeydew": (0.941, 1.000, 0.941, 1.0),
"hotpink": (1.000, 0.412, 0.706, 1.0),
"indianred": (0.804, 0.361, 0.361, 1.0),
"indigo": (0.294, 0.000, 0.510, 1.0),
"ivory": (1.000, 1.000, 0.941, 1.0),
"khaki": (0.941, 0.902, 0.549, 1.0),
"lavender": (0.902, 0.902, 0.980, 1.0),
"lavenderblush": (1.000, 0.941, 0.961, 1.0),
"lawngreen": (0.486, 0.988, 0.000, 1.0),
"lemonchiffon": (1.000, 0.980, 0.804, 1.0),
"lightblue": (0.678, 0.847, 0.902, 1.0),
"lightcoral": (0.941, 0.502, 0.502, 1.0),
"lightcyan": (0.878, 1.000, 1.000, 1.0),
"lightgoldenrodyellow": (0.980, 0.980, 0.824, 1.0),
"lightgray": (0.827, 0.827, 0.827, 1.0),
"lightgreen": (0.565, 0.933, 0.565, 1.0),
"lightgrey": (0.827, 0.827, 0.827, 1.0),
"lightpink": (1.000, 0.714, 0.757, 1.0),
"lightsalmon": (1.000, 0.627, 0.478, 1.0),
"lightseagreen": (0.125, 0.698, 0.667, 1.0),
"lightskyblue": (0.529, 0.808, 0.980, 1.0),
"lightslategray": (0.467, 0.533, 0.600, 1.0),
"lightslategrey": (0.467, 0.533, 0.600, 1.0),
"lightsteelblue": (0.690, 0.769, 0.871, 1.0),
"lightyellow": (1.000, 1.000, 0.878, 1.0),
"lime": (0.000, 1.000, 0.000, 1.0),
"limegreen": (0.196, 0.804, 0.196, 1.0),
"linen": (0.980, 0.941, 0.902, 1.0),
"magenta": (1.000, 0.000, 1.000, 1.0),
"maroon": (0.502, 0.000, 0.000, 1.0),
"mediumaquamarine": (0.400, 0.804, 0.667, 1.0),
"mediumblue": (0.000, 0.000, 0.804, 1.0),
"mediumorchid": (0.729, 0.333, 0.827, 1.0),
"mediumpurple": (0.576, 0.439, 0.859, 1.0),
"mediumseagreen": (0.235, 0.702, 0.443, 1.0),
"mediumslateblue": (0.482, 0.408, 0.933, 1.0),
"mediumspringgreen": (0.000, 0.980, 0.604, 1.0),
"mediumturquoise": (0.282, 0.820, 0.800, 1.0),
"mediumvioletred": (0.780, 0.082, 0.522, 1.0),
"midnightblue": (0.098, 0.098, 0.439, 1.0),
"mintcream": (0.961, 1.000, 0.980, 1.0),
"mistyrose": (1.000, 0.894, 0.882, 1.0),
"moccasin": (1.000, 0.894, 0.710, 1.0),
"navajowhite": (1.000, 0.871, 0.678, 1.0),
"navy": (0.000, 0.000, 0.502, 1.0),
"oldlace": (0.992, 0.961, 0.902, 1.0),
"olive": (0.502, 0.502, 0.000, 1.0),
"olivedrab": (0.420, 0.557, 0.137, 1.0),
"orange": (1.000, 0.647, 0.000, 1.0),
"orangered": (1.000, 0.271, 0.000, 1.0),
"orchid": (0.855, 0.439, 0.839, 1.0),
"palegoldenrod": (0.933, 0.910, 0.667, 1.0),
"palegreen": (0.596, 0.984, 0.596, 1.0),
"paleturquoise": (0.686, 0.933, 0.933, 1.0),
"palevioletred": (0.859, 0.439, 0.576, 1.0),
"papayawhip": (1.000, 0.937, 0.835, 1.0),
"peachpuff": (1.000, 0.855, 0.725, 1.0),
"peru": (0.804, 0.522, 0.247, 1.0),
"pink": (1.000, 0.753, 0.796, 1.0),
"plum": (0.867, 0.627, 0.867, 1.0),
"powderblue": (0.690, 0.878, 0.902, 1.0),
"purple": (0.502, 0.000, 0.502, 1.0),
"red": (1.000, 0.000, 0.000, 1.0),
"rosybrown": (0.737, 0.561, 0.561, 1.0),
"royalblue": (0.255, 0.412, 0.882, 1.0),
"saddlebrown": (0.545, 0.271, 0.075, 1.0),
"salmon": (0.980, 0.502, 0.447, 1.0),
"sandybrown": (0.957, 0.643, 0.376, 1.0),
"seagreen": (0.180, 0.545, 0.341, 1.0),
"seashell": (1.000, 0.961, 0.933, 1.0),
"sienna": (0.627, 0.322, 0.176, 1.0),
"silver": (0.753, 0.753, 0.753, 1.0),
"skyblue": (0.529, 0.808, 0.922, 1.0),
"slateblue": (0.416, 0.353, 0.804, 1.0),
"slategray": (0.439, 0.502, 0.565, 1.0),
"slategrey": (0.439, 0.502, 0.565, 1.0),
"snow": (1.000, 0.980, 0.980, 1.0),
"springgreen": (0.000, 1.000, 0.498, 1.0),
"steelblue": (0.275, 0.510, 0.706, 1.0),
"tan": (0.824, 0.706, 0.549, 1.0),
"teal": (0.000, 0.502, 0.502, 1.0),
"thistle": (0.847, 0.749, 0.847, 1.0),
"tomato": (1.000, 0.388, 0.278, 1.0),
"turquoise": (0.251, 0.878, 0.816, 1.0),
"violet": (0.933, 0.510, 0.933, 1.0),
"wheat": (0.961, 0.871, 0.702, 1.0),
"white": (1.000, 1.000, 1.000, 1.0),
"whitesmoke": (0.961, 0.961, 0.961, 1.0),
"yellow": (1.000, 1.000, 0.000, 1.0),
"yellowgreen": (0.604, 0.804, 0.196, 1.0),
# Several aliases for transparent
"clear": transparent_color,
"transparent": transparent_color,
"none": transparent_color,
# Placeholders for system- and toolkit-specific UI colors; the
# toolkit-dependent code below will fill these with the appropriate
# values. These hardcoded defaults are for the Windows Classic
# theme.
"sys_window" : (0.83137, 0.81569, 0.78431, 1.0),
}
if not ETSConfig.toolkit:
# Force Traits to decide on its toolkit if it hasn't already
from traitsui.toolkit import toolkit as traits_toolkit
traits_toolkit()
if ETSConfig.toolkit == 'wx':
import wx
from traitsui.wx.color_editor \
import ToolkitEditorFactory as StandardColorEditorFactory
# Version dependent imports (ColourPtr not defined in wxPython 2.8):
try:
ColourPtr = wx.ColourPtr
except:
class ColourPtr ( object ): pass
# Mostly copied from traits/ui/wx/color_trait.py
def convert_from_wx_color(obj, name, value):
if isinstance(value, ColourPtr) or isinstance(value, wx.Colour):
return (value.Red()/255.0, value.Green()/255.0, value.Blue()/255.0, 1.0)
elif type(value) is int:
num = int( value )
return ((num >> 16)/255.0, ((num>>8) & 0xFF)/255.0, (num & 0xFF)/255.0, 1.0)
elif type(value) in (list, tuple):
if len(value) == 3:
return (value[0]/255.0, value[1]/255.0, value[2]/255.0, 1.0)
elif len(value) == 4:
return value
else:
raise TraitError
else:
raise TraitError
convert_from_wx_color.info = ('a wx.Colour instance, an integer which in hex is of '
'the form 0xRRGGBB, where RR is red, GG is green, '
'and BB is blue, a list/tuple of (r,g,b) or (r,g,b,a)')
# Set the system color
from traitsui.wx.constants import WindowColor
color_table["sys_window"] = (WindowColor.Red()/255.0,
WindowColor.Green()/255.0,
WindowColor.Blue()/255.0,
1.0)
class ColorEditorFactory(StandardColorEditorFactory):
def to_wx_color(self, editor):
if self.mapped:
retval = getattr( editor.object, editor.name + '_' )
else:
retval = getattr( editor.object, editor.name )
if isinstance(retval, tuple):
retval = wx.Colour(int(255*retval[0]), int(255*retval[1]),
int(255*retval[2]))
return retval
def from_wx_color ( self, color ):
""" Gets the application equivalent of a wxPython value.
"""
return convert_from_wx_color(self, 'color', color)
def str_color(self, color):
if isinstance( color, ( wx.Colour, ColourPtr ) ):
return "(%d,%d,%d)" % ( color.Red(), color.Green(), color.Blue() )
elif isinstance(color, tuple):
fmt = "(" + ",".join(["%0.3f"]*len(color)) + ")"
return fmt % color
return color
ColorTrait = Trait("black", Tuple, List, color_table,
convert_from_wx_color, editor=ColorEditorFactory)
elif ETSConfig.toolkit == 'qt4':
from pyface.qt import QtGui
from traitsui.qt4.color_editor \
import ToolkitEditorFactory as StandardColorEditorFactory
def convert_from_pyqt_color(obj, name, value):
if isinstance(value, QtGui.QColor):
return value.getRgbF()
elif type(value) is int:
num = int(value)
return ((num >> 16)/255.0, ((num>>8) & 0xFF)/255.0, (num & 0xFF)/255.0, 1.0)
elif type(value) in (list, tuple):
if len(value) == 3:
return (value[0]/255.0, value[1]/255.0, value[2]/255.0, 1.0)
elif len(value) == 4:
return value
else:
raise TraitError
else:
raise TraitError
convert_from_pyqt_color.info = ("a QtGui.Color instance, an SVG color "
"name, an integer which in hex is of the form 0xRRGGBB, where RR "
"is red, GG is green, and BB is blue, a list/tuple of (r,g,b) or "
"(r,g,b,a)")
window_color = QtGui.QApplication.palette().window().color()
color_table["sys_window"] = (window_color.red()/255.0,
window_color.green()/255.0,
window_color.blue()/255.0,
1.0)
class ColorEditorFactory(StandardColorEditorFactory):
def to_qt4_color(self, editor):
if self.mapped:
retval = getattr(editor.object, editor.name + '_')
else:
retval = getattr(editor.object, editor.name)
if isinstance(retval, tuple):
col = QtGui.QColor()
col.setRgbF(*retval)
retval = col
return retval
def str_color(self, color):
if isinstance(color, QtGui.QColor):
color = color.getRgbF()
if isinstance(color, tuple):
fmt = "(" + ",".join(["%0.3f"] * len(color)) + ")"
color = fmt % color
return color
ColorTrait = Trait("black", Tuple, List, color_table,
convert_from_pyqt_color, editor=ColorEditorFactory)
else:
ColorTrait = Trait("black", Tuple, List, Str, color_table)
ColorEditorFactory = None
black_color_trait = ColorTrait("black")
white_color_trait = ColorTrait("white")
transparent_color_trait = ColorTrait("transparent")
# EOF
|