Exemplo n.º 1
0
def test_setting_and_getting_id_generators():
    h.set_id_generator(h.id_generator_sequential)
    id_gen = h.id_generator()
    id_ = next(id_gen)
    assert id_.startswith(h.PYBLOQS_ID_PREFIX)

    h.set_id_generator(h.id_generator_uuid)
    id_gen = h.id_generator()
    id_ = next(id_gen)
    assert not id_.startswith(h.PYBLOQS_ID_PREFIX)
Exemplo n.º 2
0
def interactive(verbose=True):
    """Inject Highcharts JS into Jupyter notebook to use pybloqs.plot functions inside notebooks."""
    from IPython.core.display import display_html
    from pybloqs.html import set_id_generator, id_generator_uuid

    set_id_generator(id_generator_uuid)

    stream = StringIO()

    stream.write(JScript("block-core", encode=False).write())
    stream.write(JScript("jsinflate", encode=False).write())
    add_highcharts_shim_to_stream(stream, HIGHCHARTS_ALL)

    display_html(stream.getvalue(), raw=True)

    if verbose:
        stream.write("<div>Interactive mode initialized successfully</div>")
Exemplo n.º 3
0
def interactive(verbose=True):
    """
    Enables interactive usage of block layout content.
    """
    from IPython.core.display import display, HTML, display_html
    from pybloqs.static import write_interactive
    from pybloqs.html import set_id_generator, id_generator_uuid

    set_id_generator(id_generator_uuid)

    stream = StringIO()

    write_interactive(stream)

    if verbose:
        stream.write("<div>Interactive mode initialized successfully</div>")

    # Send the scripts to the frontend
    display_html(stream.getvalue(), raw=True)