コード例 #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)
コード例 #2
0
ファイル: rw.py プロジェクト: lengxupa/hublib
    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)
コード例 #3
0
ファイル: rw.py プロジェクト: lengxupa/hublib
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)
コード例 #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))
コード例 #5
0
ファイル: notebook.py プロジェクト: enthought/mayavi
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))
コード例 #6
0
ファイル: rw.py プロジェクト: lengxupa/hublib
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)
コード例 #7
0
ファイル: notebook.py プロジェクト: amalss18/mayavi
    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)))
コード例 #8
0
ファイル: notebook.py プロジェクト: amalss18/mayavi
    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))
コード例 #9
0
ファイル: notebook.py プロジェクト: amalss18/mayavi
 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
コード例 #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*"
    )
コード例 #11
0
ファイル: widget.py プロジェクト: ka2hyeon/allweather
 def display(self):
     for key, widget in self.widgets.items():
         idisplay(widget)