Esempio n. 1
0
    def display_jupyter_cell(height=600, width=900, force_create_backend=False):
        if Viewer.backend == 'meshcat' and Viewer._is_notebook():
            from IPython.core.display import HTML, display as ipython_display

            if Viewer._backend_obj is None:
                if force_create_backend:
                    Viewer._create_meshcat_backend()
                else:
                    raise ValueError("No meshcat backend available and 'force_create_backend' is set to False.")

            viewer_url = Viewer._backend_obj.url()
            if Viewer.port_forwarding is not None:
                url_port_pattern = '(?<=:)[0-9]+(?=/)'
                port_localhost = int(re.search(url_port_pattern, viewer_url).group())
                if port_localhost in Viewer.port_forwarding.keys():
                    viewer_url = re.sub(url_port_pattern, str(Viewer.port_forwarding[port_localhost]), viewer_url)
                else:
                    print("Port forwarding defined but no port mapping associated with {port_localhost}.")

            jupyter_html = f'\n<div style="height: {height}px; width: {width}px; overflow-x: auto; overflow-y: hidden; resize: both">\
                             \n<iframe src="{viewer_url}" style="width: 100%; height: 100%; border: none">\
                             </iframe>\n</div>\n'

            ipython_display(HTML(jupyter_html))
        else:
            raise ValueError("Display in a Jupyter cell is only available using 'meshcat' backend and within a Jupyter notebook.")
Esempio n. 2
0
File: util.py Progetto: SRHerzog/ut
def disp_html(html):
    if not isinstance(html, basestring):
        try:
            html = html.renderContents()
        except AttributeError or TypeError:
            pass
    try:
        html_disp = disp_html_fun(html)
    except BaseException as e:
        html_disp = "failed<p>" + e.message
    ipython_display(html_disp)
Esempio n. 3
0
File: util.py Progetto: yz-/ut
def disp_html(html):
    if not isinstance(html, basestring):
        try:
            html = html.renderContents()
        except AttributeError or TypeError:
            pass
    try:
        html_disp = disp_html_fun(html)
    except BaseException as e:
        html_disp = "failed<p>" + e.message
    ipython_display(html_disp)
Esempio n. 4
0
def display_patterns(patterns: List[Pattern]):
    html_text = display_html(patterns)
    return ipython_display(html_text)