##// END OF EJS Templates
Merge pull request #12166 from Carreau/deprectaed-aliases-removed...
Matthias Bussonnier -
r25565:e6941b76 merge
parent child Browse files
Show More
@@ -1,184 +1,166 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 Color schemes for exception handling code in IPython.
4 4 """
5 5
6 6 import os
7 7 import warnings
8 8
9 9 #*****************************************************************************
10 10 # Copyright (C) 2005-2006 Fernando Perez <fperez@colorado.edu>
11 11 #
12 12 # Distributed under the terms of the BSD License. The full license is in
13 13 # the file COPYING, distributed as part of this software.
14 14 #*****************************************************************************
15 15
16 16 from IPython.utils.coloransi import ColorSchemeTable, TermColors, ColorScheme
17 17
18 18 def exception_colors():
19 19 """Return a color table with fields for exception reporting.
20 20
21 21 The table is an instance of ColorSchemeTable with schemes added for
22 22 'Neutral', 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled
23 23 in.
24 24
25 25 Examples:
26 26
27 27 >>> ec = exception_colors()
28 28 >>> ec.active_scheme_name
29 29 ''
30 30 >>> print(ec.active_colors)
31 31 None
32 32
33 33 Now we activate a color scheme:
34 34 >>> ec.set_active_scheme('NoColor')
35 35 >>> ec.active_scheme_name
36 36 'NoColor'
37 37 >>> sorted(ec.active_colors.keys())
38 38 ['Normal', 'caret', 'em', 'excName', 'filename', 'filenameEm', 'line',
39 39 'lineno', 'linenoEm', 'name', 'nameEm', 'normalEm', 'topline', 'vName',
40 40 'val', 'valEm']
41 41 """
42 42
43 43 ex_colors = ColorSchemeTable()
44 44
45 45 # Populate it with color schemes
46 46 C = TermColors # shorthand and local lookup
47 47 ex_colors.add_scheme(ColorScheme(
48 48 'NoColor',
49 49 # The color to be used for the top line
50 50 topline = C.NoColor,
51 51
52 52 # The colors to be used in the traceback
53 53 filename = C.NoColor,
54 54 lineno = C.NoColor,
55 55 name = C.NoColor,
56 56 vName = C.NoColor,
57 57 val = C.NoColor,
58 58 em = C.NoColor,
59 59
60 60 # Emphasized colors for the last frame of the traceback
61 61 normalEm = C.NoColor,
62 62 filenameEm = C.NoColor,
63 63 linenoEm = C.NoColor,
64 64 nameEm = C.NoColor,
65 65 valEm = C.NoColor,
66 66
67 67 # Colors for printing the exception
68 68 excName = C.NoColor,
69 69 line = C.NoColor,
70 70 caret = C.NoColor,
71 71 Normal = C.NoColor
72 72 ))
73 73
74 74 # make some schemes as instances so we can copy them for modification easily
75 75 ex_colors.add_scheme(ColorScheme(
76 76 'Linux',
77 77 # The color to be used for the top line
78 78 topline = C.LightRed,
79 79
80 80 # The colors to be used in the traceback
81 81 filename = C.Green,
82 82 lineno = C.Green,
83 83 name = C.Purple,
84 84 vName = C.Cyan,
85 85 val = C.Green,
86 86 em = C.LightCyan,
87 87
88 88 # Emphasized colors for the last frame of the traceback
89 89 normalEm = C.LightCyan,
90 90 filenameEm = C.LightGreen,
91 91 linenoEm = C.LightGreen,
92 92 nameEm = C.LightPurple,
93 93 valEm = C.LightBlue,
94 94
95 95 # Colors for printing the exception
96 96 excName = C.LightRed,
97 97 line = C.Yellow,
98 98 caret = C.White,
99 99 Normal = C.Normal
100 100 ))
101 101
102 102 # For light backgrounds, swap dark/light colors
103 103 ex_colors.add_scheme(ColorScheme(
104 104 'LightBG',
105 105 # The color to be used for the top line
106 106 topline = C.Red,
107 107
108 108 # The colors to be used in the traceback
109 109 filename = C.LightGreen,
110 110 lineno = C.LightGreen,
111 111 name = C.LightPurple,
112 112 vName = C.Cyan,
113 113 val = C.LightGreen,
114 114 em = C.Cyan,
115 115
116 116 # Emphasized colors for the last frame of the traceback
117 117 normalEm = C.Cyan,
118 118 filenameEm = C.Green,
119 119 linenoEm = C.Green,
120 120 nameEm = C.Purple,
121 121 valEm = C.Blue,
122 122
123 123 # Colors for printing the exception
124 124 excName = C.Red,
125 125 #line = C.Brown, # brown often is displayed as yellow
126 126 line = C.Red,
127 127 caret = C.Normal,
128 128 Normal = C.Normal,
129 129 ))
130 130
131 131 ex_colors.add_scheme(ColorScheme(
132 132 'Neutral',
133 133 # The color to be used for the top line
134 134 topline = C.Red,
135 135
136 136 # The colors to be used in the traceback
137 137 filename = C.LightGreen,
138 138 lineno = C.LightGreen,
139 139 name = C.LightPurple,
140 140 vName = C.Cyan,
141 141 val = C.LightGreen,
142 142 em = C.Cyan,
143 143
144 144 # Emphasized colors for the last frame of the traceback
145 145 normalEm = C.Cyan,
146 146 filenameEm = C.Green,
147 147 linenoEm = C.Green,
148 148 nameEm = C.Purple,
149 149 valEm = C.Blue,
150 150
151 151 # Colors for printing the exception
152 152 excName = C.Red,
153 153 #line = C.Brown, # brown often is displayed as yellow
154 154 line = C.Red,
155 155 caret = C.Normal,
156 156 Normal = C.Normal,
157 157 ))
158 158
159 159 # Hack: the 'neutral' colours are not very visible on a dark background on
160 160 # Windows. Since Windows command prompts have a dark background by default, and
161 161 # relatively few users are likely to alter that, we will use the 'Linux' colours,
162 162 # designed for a dark background, as the default on Windows.
163 163 if os.name == "nt":
164 164 ex_colors.add_scheme(ex_colors['Linux'].copy('Neutral'))
165 165
166 166 return ex_colors
167
168 class Deprec(object):
169
170 def __init__(self, wrapped_obj):
171 self.wrapped=wrapped_obj
172
173 def __getattr__(self, name):
174 val = getattr(self.wrapped, name)
175 warnings.warn("Using ExceptionColors global is deprecated and will be removed in IPython 6.0",
176 DeprecationWarning, stacklevel=2)
177 # using getattr after warnings break ipydoctest in weird way for 3.5
178 return val
179
180 # For backwards compatibility, keep around a single global object. Note that
181 # this should NOT be used, the factory function should be used instead, since
182 # these objects are stateful and it's very easy to get strange bugs if any code
183 # modifies the module-level object's state.
184 ExceptionColors = Deprec(exception_colors())
General Comments 0
You need to be logged in to leave comments. Login now