File: color_trait.py

package info (click to toggle)
python-traitsui 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 13,292 kB
  • sloc: python: 39,867; makefile: 120; sh: 5
file content (140 lines) | stat: -rw-r--r-- 5,246 bytes parent folder | download | duplicates (3)
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
#------------------------------------------------------------------------------
#
#  Copyright (c) 2005, Enthought, Inc.
#  All rights reserved.
#
#  This software is provided without warranty under the terms of the BSD
#  license included in enthought/LICENSE.txt and may be redistributed only
#  under the conditions described in the aforementioned license.  The license
#  is also available online at http://www.enthought.com/licenses/BSD.txt
#
#  Thanks for using Enthought open source!
#
#  Author: David C. Morrill
#  Date:   02/14/2005
#
#------------------------------------------------------------------------------

""" Trait definition for a null-based (i.e., no UI) color.
"""

#-------------------------------------------------------------------------------
#  Imports:
#-------------------------------------------------------------------------------

from __future__ import absolute_import

from traits.api import Trait, TraitError

#-------------------------------------------------------------------------------
#  Convert a number into a wxColour object:
#-------------------------------------------------------------------------------

def convert_to_color ( object, name, value ):
    """ Converts a number into a wxColour object.
    """
    if type( value ) is int:
        return value & 0xFFFFFF

    elif isinstance( value, tuple ):
        return (value[0]/255., value[1]/255., value[2]/255.)

    raise TraitError

convert_to_color.info = ('an integer which in hex is of the form 0xRRGGBB, '
                         'where RR is red, GG is green, and BB is blue')

#-------------------------------------------------------------------------------
#  Standard colors:
#-------------------------------------------------------------------------------

standard_colors = {
    'aquamarine':          0x70DB93,
    'black':               0x000000,
    'blue':                0x0000FF,
    'blue violet':         0x9F5F9F,
    'brown':               0xA52A2A,
    'cadet blue':          0x5F9F9F,
    'coral':               0xFF7F00,
    'cornflower blue':     0x42426F,
    'cyan':                0x00FFFF,
    'dark grey':           0x2F2F2F,
    'dark green':          0x2F4F2F,
    'dark olive green':    0x4F4F2F,
    'dark orchid':         0x9932CC,
    'dark slate blue':     0x6B238E,
    'dark slate grey':     0x2F4F4F,
    'dark turquoise':      0x7093DB,
    'dim grey':            0x545454,
    'firebrick':           0x8E2323,
    'forest green':        0x238E23,
    'gold':                0xCC7F32,
    'goldenrod':           0xDBDB70,
    'grey':                0x808080,
    'green':               0x00FF00,
    'green yellow':        0x93DB70,
    'indian red':          0x4F2F2F,
    'khaki':               0x9F9F5F,
    'light blue':          0xBFD8D8,
    'light grey':          0xC0C0C0,
    'light steel':         0x000000,
    'blue':                0x0000FF,
    'lime green':          0x32CC32,
    'magenta':             0xFF00FF,
    'maroon':              0x8E236B,
    'medium aquamarine':   0x32CC99,
    'medium blue':         0x3232CC,
    'medium forest green': 0x6B8E23,
    'medium goldenrod':    0xEAEAAD,
    'medium orchid':       0x9370DB,
    'medium sea green':    0x426F42,
    'medium slate blue':   0x7F00FF,
    'medium spring green': 0x7FFF00,
    'medium turquoise':    0x70DBDB,
    'medium violet red':   0xDB7093,
    'midnight blue':       0x2F2F4F,
    'navy':                0x23238E,
    'orange':              0xCC3232,
    'orange red':          0xFF007F,
    'orchid':              0xDB70DB,
    'pale green':          0x8FBC8F,
    'pink':                0xBC8FEA,
    'plum':                0xEAADEA,
    'purple':              0xB000FF,
    'red':                 0xFF0000,
    'salmon':              0x6F4242,
    'sea green':           0x238E6B,
    'sienna':              0x8E6B23,
    'sky blue':            0x3299CC,
    'slate blue':          0x007FFF,
    'spring green':        0x00FF7F,
    'steel blue':          0x236B8E,
    'tan':                 0xDB9370,
    'thistle':             0xD8BFD8,
    'turquoise':           0xADEAEA,
    'violet':              0x4F2F4F,
    'violet red':          0xCC3299,
    'wheat':               0xD8D8BF,
    'white':               0xFFFFFF,
    'yellow':              0xFFFF00,
    'yellow green':        0x99CC32
}

#-------------------------------------------------------------------------------
#  Define 'null' specific color traits:
#-------------------------------------------------------------------------------

### Note: Declare the editor to be a function which returns the ColorEditor
# class from traits ui to avoid circular import issues. For backwards
# compatibility with previous Traits versions, the 'editors' folder in Traits
# project declares 'from api import *' in its __init__.py. The 'api' in turn
# can contain classes that have a Color trait which lead to this file getting
# imported. This leads to a circular import when declaring a Color trait.
def get_color_editor(*args, **traits):
    from ..api import ColorEditor
    return ColorEditor(*args, **traits)

# Color traits
NullColor = Trait( 'white', convert_to_color, standard_colors,
                   editor = get_color_editor )