Ejemplo n.º 1
0
def print_source(obj):
    source = format_source(obj)
    if is_jupyter():
        from IPython.display import display, Code
        display(source)
    else:
        print(source)
Ejemplo n.º 2
0
def source_repr(obj):
    source = format_source(obj)
    if is_jupyter():
        display(source)
        return ''
    else:
        return source
Ejemplo n.º 3
0
def source_repr(obj):
    source = format_source(obj)
    if is_jupyter():
        from IPython.display import display, Code
        display(source)
        return ''
    else:
        return source
Ejemplo n.º 4
0
 def __init__(self,
              grid,
              bounding_box=([0, 0], [1, 1]),
              codim=2,
              backend=None,
              block=False):
     assert grid.reference_element in (triangle, square)
     assert grid.dim == 2
     assert codim in (0, 2)
     backend = backend or ('jupyter' if is_jupyter() else None)
     self.__auto_init(locals())
Ejemplo n.º 5
0
def format_source(obj):
    source = getsource(obj)

    if is_jupyter():
        from IPython.display import display, Code
        return Code(source, language='python')
    else:
        try:
            from pygments import highlight
            from pygments.lexers import PythonLexer
            from pygments.formatters import Terminal256Formatter
            return highlight(source, PythonLexer(), Terminal256Formatter())
        except ImportError:
            return source
Ejemplo n.º 6
0
def print_source(obj):
    source = format_source(obj)
    if is_jupyter():
        display(source)
    else:
        print(source)
Ejemplo n.º 7
0
 def __init__(self, grid, codim=1, block=False, backend=None):
     assert isinstance(grid, OnedGrid)
     assert codim in (0, 1)
     backend = backend or ('jupyter' if is_jupyter() else None)
     self.__auto_init(locals())