##// END OF EJS Templates
Merge pull request #9250 from Carreau/pygpartial-1...
Matthias Bussonnier -
r22111:f31e6001 merge
parent child Browse files
Show More
@@ -0,0 +1,26 b''
1 #*****************************************************************************
2 # Copyright (C) 2016 The IPython Team <ipython-dev@scipy.org>
3 #
4 # Distributed under the terms of the BSD License. The full license is in
5 # the file COPYING, distributed as part of this software.
6 #*****************************************************************************
7 from __future__ import absolute_import
8
9 """
10 Color managing related utilities
11 """
12
13 import pygments
14
15 from traitlets.config import Configurable
16 from traitlets import Unicode
17
18
19 available_themes = lambda : [s for s in pygments.styles.get_all_styles()]+['NoColor','LightBG','Linux']
20
21 class Colorable(Configurable):
22 """
23 A subclass of configurable for all the classes that have a `default_scheme`
24 """
25 default_style=Unicode('lightbg', config=True)
26
@@ -42,6 +42,7 b' from IPython.utils.wildcard import list_namespace'
42 from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable
42 from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable
43 from IPython.utils.py3compat import cast_unicode, string_types, PY3
43 from IPython.utils.py3compat import cast_unicode, string_types, PY3
44 from IPython.utils.signatures import signature
44 from IPython.utils.signatures import signature
45 from IPython.utils.colorable import Colorable
45
46
46 # builtin docstrings to ignore
47 # builtin docstrings to ignore
47 _func_call_docstring = types.FunctionType.__call__.__doc__
48 _func_call_docstring = types.FunctionType.__call__.__doc__
@@ -365,13 +366,15 b' def find_source_lines(obj):'
365 return lineno
366 return lineno
366
367
367
368
368 class Inspector:
369 class Inspector(Colorable):
369 def __init__(self, color_table=InspectColors,
370 def __init__(self, color_table=InspectColors,
370 code_color_table=PyColorize.ANSICodeColors,
371 code_color_table=PyColorize.ANSICodeColors,
371 scheme='NoColor',
372 scheme='NoColor',
372 str_detail_level=0):
373 str_detail_level=0,
374 parent=None, config=None):
375 super(Inspector, self).__init__(parent=parent, config=config)
373 self.color_table = color_table
376 self.color_table = color_table
374 self.parser = PyColorize.Parser(code_color_table,out='str')
377 self.parser = PyColorize.Parser(out='str', parent=self, style=scheme)
375 self.format = self.parser.format
378 self.format = self.parser.format
376 self.str_detail_level = str_detail_level
379 self.str_detail_level = str_detail_level
377 self.set_active_scheme(scheme)
380 self.set_active_scheme(scheme)
@@ -85,6 +85,7 b' Inheritance diagram:'
85 # the file COPYING, distributed as part of this software.
85 # the file COPYING, distributed as part of this software.
86 #*****************************************************************************
86 #*****************************************************************************
87
87
88 from __future__ import absolute_import
88 from __future__ import unicode_literals
89 from __future__ import unicode_literals
89 from __future__ import print_function
90 from __future__ import print_function
90
91
@@ -125,6 +126,8 b' from IPython.utils import ulinecache'
125 from IPython.utils.data import uniq_stable
126 from IPython.utils.data import uniq_stable
126 from logging import info, error
127 from logging import info, error
127
128
129 import IPython.utils.colorable as colorable
130
128 # Globals
131 # Globals
129 # amount of space to put line numbers before verbose tracebacks
132 # amount of space to put line numbers before verbose tracebacks
130 INDENT_SIZE = 8
133 INDENT_SIZE = 8
@@ -476,15 +479,16 b' def find_recursion(etype, value, records):'
476
479
477 #---------------------------------------------------------------------------
480 #---------------------------------------------------------------------------
478 # Module classes
481 # Module classes
479 class TBTools(object):
482 class TBTools(colorable.Colorable):
480 """Basic tools used by all traceback printer classes."""
483 """Basic tools used by all traceback printer classes."""
481
484
482 # Number of frames to skip when reporting tracebacks
485 # Number of frames to skip when reporting tracebacks
483 tb_offset = 0
486 tb_offset = 0
484
487
485 def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None):
488 def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None, parent=None, config=None):
486 # Whether to call the interactive pdb debugger after printing
489 # Whether to call the interactive pdb debugger after printing
487 # tracebacks or not
490 # tracebacks or not
491 super(TBTools, self).__init__(parent=parent, config=config)
488 self.call_pdb = call_pdb
492 self.call_pdb = call_pdb
489
493
490 # Output stream to write to. Note that we store the original value in
494 # Output stream to write to. Note that we store the original value in
@@ -590,9 +594,9 b' class ListTB(TBTools):'
590 Because they are meant to be called without a full traceback (only a
594 Because they are meant to be called without a full traceback (only a
591 list), instances of this class can't call the interactive pdb debugger."""
595 list), instances of this class can't call the interactive pdb debugger."""
592
596
593 def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None):
597 def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None, parent=None):
594 TBTools.__init__(self, color_scheme=color_scheme, call_pdb=call_pdb,
598 TBTools.__init__(self, color_scheme=color_scheme, call_pdb=call_pdb,
595 ostream=ostream)
599 ostream=ostream, parent=parent)
596
600
597 def __call__(self, etype, value, elist):
601 def __call__(self, etype, value, elist):
598 self.ostream.flush()
602 self.ostream.flush()
@@ -54,6 +54,8 b' except AttributeError:'
54 from IPython.utils.coloransi import TermColors, InputTermColors ,ColorScheme, ColorSchemeTable
54 from IPython.utils.coloransi import TermColors, InputTermColors ,ColorScheme, ColorSchemeTable
55 from IPython.utils.py3compat import PY3
55 from IPython.utils.py3compat import PY3
56
56
57 from .colorable import Colorable
58
57 if PY3:
59 if PY3:
58 from io import StringIO
60 from io import StringIO
59 else:
61 else:
@@ -148,15 +150,18 b' LightBGColors = ColorScheme('
148 ANSICodeColors = ColorSchemeTable([NoColor,LinuxColors,LightBGColors],
150 ANSICodeColors = ColorSchemeTable([NoColor,LinuxColors,LightBGColors],
149 _scheme_default)
151 _scheme_default)
150
152
151 class Parser:
153 class Parser(Colorable):
152 """ Format colored Python source.
154 """ Format colored Python source.
153 """
155 """
154
156
155 def __init__(self, color_table=None,out = sys.stdout):
157 def __init__(self, color_table=None, out = sys.stdout, parent=None, style=None):
156 """ Create a parser with a specified color table and output channel.
158 """ Create a parser with a specified color table and output channel.
157
159
158 Call format() to process code.
160 Call format() to process code.
159 """
161 """
162
163 super(Parser, self).__init__(parent=parent)
164
160 self.color_table = color_table and color_table or ANSICodeColors
165 self.color_table = color_table and color_table or ANSICodeColors
161 self.out = out
166 self.out = out
162
167
General Comments 0
You need to be logged in to leave comments. Login now