示例#1
0
def _run(command, options, interactive=None):
    if interactive is None:
        interactive = options['--interactive']

    if interactive:
        code_globals['options'] = options
        repl = Repl(
            buche,
            reader,
            code_globals=code_globals,
            address="/repl",
            log_address="/"
        )
        buche.command_template(content=str(hrepr(repl)))

    buche.master.send({
        "command": "redirect",
        "from": "/stdout",
        "to": "/"
    })

    try:
        res = command(Options(options))
        code_globals['res'] = res
    except InferenceError as e:
        print_inference_error(e)
    except Exception as e:
        buche(e, interactive=True)

    if interactive:
        repl.start(nodisplay=True)
示例#2
0
def pytest_sessionstart(session):
    global _capture
    _capture = session.config.pluginmanager.get_plugin('capturemanager')
    buche.command_template(src=template_path)
    buche(
        H.script("""
        function tippy(x, y) {
            f = () => tippy(x, y);
            setTimeout(f, 1000);
        }
        """,
                 type="text/javascript"))
    scripts = [
        "https://unpkg.com/popper.js@1/dist/umd/popper.min.js",
        "https://unpkg.com/tippy.js@4"
    ]
    for s in scripts:
        buche(H.script(type="text/javascript", src=s))
    buche(H.span())
示例#3
0
文件: demo.py 项目: breuleux/pybuche
from buche import buche, H

# You don't have to set a template, but if you do, it must be the
# very first command you emit, before any printing.
# You can also give `src=<path-to-file>` instead of `content=...`
buche.command_template(content=H.div['my-template'](address="/"))

# Use this command to add styles, stylesheets, scripts, etc.
buche.command_resource(content=H.style(
    """
    .my-template {
        background-color: #eee;
        padding: 5px;
        display: flex;
        flex-direction: column;
        align-items: start;
    }
    """
))

# Display simple HTML
buche.html.h3('Welcome!')

# Display objects
buche(1234)
buche([x * x for x in range(100)])
buche.dict(avocado="green", banana="yellow", cherry="red")

# Open automatically creates an address for an element
div1 = buche.open.div(style="border: 3px solid red")