MCPcopy Create free account
hub / github.com/ipython/ipython / ColorSchemeTable

Class ColorSchemeTable

IPython/utils/coloransi.py:126–187  ·  view source on GitHub ↗

General class to handle tables of color schemes. It's basically a dict of color schemes with a couple of shorthand attributes and some convenient methods. active_scheme_name -> obvious active_colors -> actual color table of the active scheme

Source from the content-addressed store, hash-verified

124 return ColorScheme(name, self.colors.dict())
125
126class ColorSchemeTable(dict):
127 """General class to handle tables of color schemes.
128
129 It's basically a dict of color schemes with a couple of shorthand
130 attributes and some convenient methods.
131
132 active_scheme_name -> obvious
133 active_colors -> actual color table of the active scheme"""
134
135 def __init__(self, scheme_list=None, default_scheme=''):
136 """Create a table of color schemes.
137
138 The table can be created empty and manually filled or it can be
139 created with a list of valid color schemes AND the specification for
140 the default active scheme.
141 """
142
143 # create object attributes to be set later
144 self.active_scheme_name = ''
145 self.active_colors = None
146
147 if scheme_list:
148 if default_scheme == '':
149 raise ValueError('you must specify the default color scheme')
150 for scheme in scheme_list:
151 self.add_scheme(scheme)
152 self.set_active_scheme(default_scheme)
153
154 def copy(self):
155 """Return full copy of object"""
156 return ColorSchemeTable(self.values(),self.active_scheme_name)
157
158 def add_scheme(self,new_scheme):
159 """Add a new color scheme to the table."""
160 if not isinstance(new_scheme,ColorScheme):
161 raise ValueError('ColorSchemeTable only accepts ColorScheme instances')
162 self[new_scheme.name] = new_scheme
163
164 def set_active_scheme(self,scheme,case_sensitive=0):
165 """Set the currently active scheme.
166
167 Names are by default compared in a case-insensitive way, but this can
168 be changed by setting the parameter case_sensitive to true."""
169
170 scheme_names = list(self.keys())
171 if case_sensitive:
172 valid_schemes = scheme_names
173 scheme_test = scheme
174 else:
175 valid_schemes = [s.lower() for s in scheme_names]
176 scheme_test = scheme.lower()
177 try:
178 scheme_idx = valid_schemes.index(scheme_test)
179 except ValueError:
180 raise ValueError('Unrecognized color scheme: ' + scheme + \
181 '\nValid schemes: '+str(scheme_names).replace("'', ",''))
182 else:
183 active = scheme_names[scheme_idx]

Callers 3

PyColorize.pyFile · 0.90
exception_colorsFunction · 0.90
copyMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected