Ejemplo n.º 1
0
def pretty_print(*args, fontsize=11, **kwargs):
    """https://stackoverflow.com/questions/8924173/how-do-i-print-bold-text-in-python/8930747"""
    if isnotebook():
        idisplay(iMarkdown(f'<span style="font-size:{fontsize}pt">'+fmt(*args, isnotebook=True)+'</span>'))
    else:
        # TODO: check if os is linux else just remove ;)
        print(fmt(*args), **kwargs)
Ejemplo n.º 2
0
    def save(self, name, value, display=False):
        if not name in self.out:
            raise ValueError('\"%s\" not in output schema!' % name)
        otype = self.out[name]['type']

        if otype == 'Image':
            if type(value) is str:
                # filename
                value = Image(value)
            if type(value) is Image:
                if display:
                    idisplay(value)
                data, _metadata = IPython.core.formatters.format_display_data(
                    value)
                pm.record(name, data)
                return

        if display:
            idisplay(value)

        if otype == 'Array' and type(value) is np.ndarray:
            sval = json.dumps(value, cls=plotly.utils.PlotlyJSONEncoder)
            pm.record(name, sval)
            return

        pm.record(name, value)
Ejemplo n.º 3
0
def save(name, value, display=False):
    if display:
        idisplay(value)

    if type(value) is np.ndarray:
        sval = json.dumps(value, cls=plotly.utils.PlotlyJSONEncoder)
        pm.record(name, sval)
        return

    if type(value) is Video or type(value) is Image:
        data, _metadata = IPython.core.formatters.format_display_data(value)
        pm.record(name, data)
        return

    pm.record(name, value)
Ejemplo n.º 4
0
def _ipython_display_(self):
    """Method for displaying elements on the Jupyter notebook.
    """
    from IPython.display import HTML
    from IPython.display import display as idisplay

    if hasattr(self, 'render_window'):
        scene = self
    elif hasattr(self, 'scene'):
        scene = self.scene
    if _backend == 'png':
        return idisplay(HTML(scene_to_png(scene)))
    elif _backend == 'x3d':
        return idisplay(HTML(scene_to_x3d(scene)))
    elif _backend == 'ipy':
        return idisplay(scene_to_ipy(scene))
Ejemplo n.º 5
0
def _ipython_display_(self):
    """Method for displaying elements on the Jupyter notebook.
    """
    from IPython.display import HTML
    from IPython.display import display as idisplay

    if hasattr(self, 'render_window'):
        scene = self
    elif hasattr(self, 'scene'):
        scene = self.scene
    if _backend == 'png':
        return idisplay(HTML(scene_to_png(scene)))
    elif _backend == 'x3d':
        return idisplay(HTML(scene_to_x3d(scene)))
    elif _backend == 'ipy':
        return idisplay(scene_to_ipy(scene))
Ejemplo n.º 6
0
def rdisplay(nb, name):
    data = nb.data[name]
    if type(data) is str:
        try:
            data = json.loads(data)
        except:
            pass
    try:
        if 'image/jpeg' in data \
            or 'image/png' in data \
            or 'image/gif' in data \
            or 'text/html' in data:
            idisplay(data, raw=True)
            return
    except:
        pass

    idisplay(data)
Ejemplo n.º 7
0
    def display(self, obj):
        from IPython.display import HTML
        from IPython.display import display as idisplay
        if hasattr(obj, 'render_window'):
            scene = obj
        elif hasattr(obj, 'scene'):
            scene = obj.scene

        return idisplay(HTML(self.scene_to_x3d(scene)))
Ejemplo n.º 8
0
    def display(self, obj):
        from IPython.display import display as idisplay

        if hasattr(obj, 'render_window'):
            scene = obj
        elif hasattr(obj, 'scene'):
            scene = obj.scene

        return idisplay(self._widget_manager.scene_to_ipy(scene))
Ejemplo n.º 9
0
 def display(self, obj):
     from IPython.display import display as idisplay
     scene = get_scene(obj)
     if scene is not None:
         actors = get_all_actors(scene)
         self._update_pipeline(actors)
         # Works around bug in released itkwidgets-0.32.1.
         # Can remove when this PR is merged and in a release:
         # https://github.com/InsightSoftwareConsortium/itkwidgets/pull/438
         kw = dict(
             actors=actors, geometries=[], geometry_colors=[],
             geometry_opacities=[], point_sets=[], point_set_colors=[],
             point_set_opacities=[]
         )
         return idisplay(self._view(**kw))
     else:
         return obj
Ejemplo n.º 10
0
        to_print = "".join(to_print)
    if isnotebook: to_print = to_print.replace("\n", "<br>")
    return to_print

########################################################################################################################
########################################################################################################################

def print_multicol(lst, line_len=220):
    max_len = (max(len(i) for i in lst) + 1)
    n_cols = max(line_len//max_len, 1)
    divisions = list(zip(*[lst[i::n_cols] for i in range(n_cols)]))
    for elems in zip(divisions):
        print("".join([i.ljust(max_len) for i in elems[0]]))


if isnotebook():
    from IPython.display import Markdown
    display = lambda x: pretty_print(x) if isinstance(x, str) else idisplay(x)
else:
    import pprint
    pp = pprint.PrettyPrinter(indent=2)
    display = lambda x: pretty_print((pp.pformat(x) if not isinstance(x, str) else x).strip("'").strip('"'))
    Markdown = lambda *args: " ".join([(i if not i.startswith("#") else "**"+i.strip("# ")+"**") for i in args])
#such that I can do `from misc_util.pretty_print import Markdown, display`


if __name__ == "__main__":
    pretty_print(
        "Hello this is **bold** and **this is too**, __and this underlined__, __**and this both**__ and *r*this is red*r*"
    )
Ejemplo n.º 11
0
 def display(self):
     for key, widget in self.widgets.items():
         idisplay(widget)