예제 #1
0
def main():
    from bowtie import App
    app = App(title='Network DownScaler')

    app.add(sine_plot)

    app.add_sidebar(upload)
    app.subscribe(upload_listener, upload.on_upload)

    app.add_sidebar(scale_factor_input)
    app.subscribe(update_scale_factor, scale_factor_input.on_change)

    app.add_sidebar(mark)

    #app.add_sidebar(text)
    #app.subscribe(write, text.on_change)

    app.add_sidebar(run_button)
    app.subscribe(button_listener, run_button.on_click)

    app.add_sidebar(freq_slider)
    app.subscribe(slider_listener, freq_slider.on_change)

    app.add_sidebar(dropdown_src)
    app.add_sidebar(dropdown_dst)

    app.subscribe(dropdown_src_listener, dropdown_src.on_change)
    app.subscribe(dropdown_dst_listener, dropdown_dst.on_change)

    return app
예제 #2
0
def components(build_reset, monkeypatch):
    """App with all components."""
    controllers, visuals, htmls = create_components()

    app = App(__name__, rows=len(visuals), sidebar=True)
    for controller in controllers:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[controller._uuid] == controller
        app.add_sidebar(controller)

    for vis in visuals:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[vis._uuid] == vis
        app.add(vis)

    for htm in htmls:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[htm._uuid] == htm
        app.add_sidebar(htm)

    assert len(COMPONENT_REGISTRY) == len(controllers) + 2 * len(visuals) + len(htmls)

    # pylint: disable=protected-access
    app._build()

    # run second time to make sure nothing weird happens with subsequent builds
    app._build()

    with server_check(app) as server:
        yield server
예제 #3
0
def components(build_reset, monkeypatch):
    """App with all components."""
    controllers, visuals, htmls = create_components()

    app = App(__name__, rows=len(visuals), sidebar=True)
    for controller in controllers:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[controller._uuid] == controller
        app.add_sidebar(controller)

    for vis in visuals:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[vis._uuid] == vis
        app.add(vis)

    for htm in htmls:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[htm._uuid] == htm
        app.add_sidebar(htm)

    assert len(
        COMPONENT_REGISTRY) == len(controllers) + 2 * len(visuals) + len(htmls)

    # pylint: disable=protected-access
    app._build()

    # run second time to make sure nothing weird happens with subsequent builds
    app._build()

    with server_check(app) as server:
        yield server
예제 #4
0
def multiple_views(build_path, monkeypatch):
    """Create multiple views app."""
    monkeypatch.setattr(App, '_sourcefile',
                        lambda self: 'bowtie.tests.test_multiple')

    app = App()
    view1 = View()  # pylint: disable=unused-variable
    assert view1._uuid == 2  # pylint: disable=protected-access
    view2 = View()
    view2.add(table)
    app.add_route(view2, 'view2')

    app.add(table)
    app.add_sidebar(ctrl)
    app.add_sidebar(ctrl2)
    app.subscribe(callback, ctrl.on_change)
    app.subscribe(callback, ctrl2.on_click)

    app._build()  # pylint: disable=protected-access

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)
    yield
    server.kill()
예제 #5
0
def components(build_path, monkeypatch):
    """App with all components."""
    monkeypatch.setattr(App, '_sourcefile',
                        lambda self: 'bowtie.tests.test_components')

    controllers, visuals = create_components()

    app = App(rows=len(visuals))
    for controller in controllers:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[controller._uuid] == controller
        app.add_sidebar(controller)

    for vis in visuals:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[vis._uuid] == vis
        app.add(vis)

    # pylint: disable=protected-access
    app._build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)
    yield
    server.kill()
예제 #6
0
def test_components(chrome_driver, build_path):
    """Tests plotly."""

    app = App(rows=len(visuals), directory=build_path)
    for controller in controllers:
        app.add_sidebar(controller)

    for vis in visuals:
        app.add(vis)
    app.build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)

    chrome_driver.get('http://localhost:9991')
    chrome_driver.implicitly_wait(5)

    logs = chrome_driver.get_log('browser')
    for log in logs:
        if log['level'] == 'SEVERE':
            raise Exception(log['message'])

    server.kill()
예제 #7
0
def main():
    from bowtie import App
    app = App(debug=True)
    app.add_sidebar(sigma)
    app.add(mainplot)
    app.schedule(0.1, walk)
    return app
예제 #8
0
def construct():
    from bowtie import App
    app = App(debug=True)
    app.add_sidebar(sigma)
    app.add(mainplot)
    app.schedule(0.1, walk)

    app.build()
예제 #9
0
파일: test_cache.py 프로젝트: ylwb/bowtie
def dummy(build_reset, monkeypatch):
    """Create basic app."""
    app = App(__name__)
    app.add(button)
    app.subscribe(button.on_click)(click)
    app._build()  # pylint: disable=protected-access

    with server_check(app) as server:
        yield server
예제 #10
0
파일: test_cache.py 프로젝트: jwkvam/bowtie
def dummy(build_reset, monkeypatch):
    """Create basic app."""
    app = App(__name__)
    app.add(button)
    app.subscribe(button.on_click)(click)
    app._build()  # pylint: disable=protected-access

    with server_check(app) as server:
        yield server
예제 #11
0
def test_build(build_path):
    """Tests the build process."""
    reset_uuid()
    ctrl = Nouislider()
    viz = Plotly()

    app = App(directory=build_path)
    app.add_sidebar(ctrl)
    app.add(viz)
    app.subscribe(callback, ctrl.on_change)
    app.build()
예제 #12
0
def test_used(buttons):
    """Test cell usage checks."""

    app = App(rows=2, columns=2)
    for i in range(3):
        app.add(buttons[i])

    app[0, 0] = buttons[3]
    app[0:1, 1] = buttons[3]
    app[1, 0:1] = buttons[3]
    app[1, 1] = buttons[3]
예제 #13
0
파일: test_cache.py 프로젝트: zz38/bowtie
def dummy(build_path, monkeypatch):
    """Create basic app."""
    monkeypatch.setattr(App, '_sourcefile', lambda self: 'bowtie.tests.test_cache')

    app = App()
    app.add(button)
    app.subscribe(click, button.on_click)
    # pylint: disable=protected-access
    app._build()

    with server_check(build_path) as server:
        yield server
예제 #14
0
파일: test_compile.py 프로젝트: ylwb/bowtie
def test_build(build_reset, monkeypatch):
    """Tests the build process."""
    reset_uuid()
    ctrl = Nouislider()
    viz = Plotly()

    app = App(__name__, sidebar=True)
    app.add_sidebar(ctrl)
    app.add(viz)
    app.subscribe(ctrl.on_change)(callback)
    # pylint: disable=protected-access
    app._build()
예제 #15
0
파일: test_editor.py 프로젝트: rdiaz18/vue
def markdown(build_reset, monkeypatch):
    """Create markdown and text widgets."""
    app = App(__name__, sidebar=True)
    app.add(mark)
    app.add_sidebar(side)
    app.add_sidebar(text)
    app.subscribe(text.on_change)(write)
    # pylint: disable=protected-access
    app._build()

    with server_check(app) as server:
        yield server
예제 #16
0
def markdown(build_reset, monkeypatch):
    """Create markdown and text widgets."""
    app = App(__name__, sidebar=True)
    app.add(mark)
    app.add_sidebar(side)
    app.add_sidebar(text)
    app.subscribe(text.on_change)(write)
    # pylint: disable=protected-access
    app._build()

    with server_check(app) as server:
        yield server
예제 #17
0
def plotly(build_reset, monkeypatch):
    """Create plotly app."""
    app = App(__name__, sidebar=True)
    app.add(viz)
    app.add_sidebar(ctrl)
    app.add_sidebar(ctrl_range)
    app.add_sidebar(ctrl2)
    app.subscribe(ctrl.on_change)(app.subscribe(ctrl2.on_click)(callback))
    # pylint: disable=protected-access
    app._build()

    with server_check(app) as server:
        yield server
예제 #18
0
def test_build(build_path, monkeypatch):
    """Tests the build process."""
    monkeypatch.setattr(App, '_sourcefile',
                        lambda self: 'bowtie.tests.test_compile')
    reset_uuid()
    ctrl = Nouislider()
    viz = Plotly()

    app = App()
    app.add_sidebar(ctrl)
    app.add(viz)
    app.subscribe(callback, ctrl.on_change)
    # pylint: disable=protected-access
    app._build()
예제 #19
0
def test_used(buttons):
    """Test cell usage checks."""

    app = App(rows=2, columns=2)
    for i in range(3):
        app.add(buttons[i])

    with pytest.raises(UsedCellsError):
        app[0, 0] = buttons[3]

    with pytest.raises(UsedCellsError):
        app[0:1, 1] = buttons[3]

    with pytest.raises(UsedCellsError):
        app[1, 0:1] = buttons[3]

    app[1, 1] = buttons[3]
예제 #20
0
def multiple_views(build_reset, monkeypatch):
    """Create multiple views app."""
    app = App(__name__, sidebar=True)
    view1 = View()  # pylint: disable=unused-variable
    assert view1._uuid == 2  # pylint: disable=protected-access
    view2 = View()
    view2.add(table)
    app.add_route(view2, 'view2')

    app.add(table)
    app.add_sidebar(ctrl)
    app.add_sidebar(ctrl2)
    app.subscribe(ctrl.on_change)(app.subscribe(ctrl2.on_click)(callback))

    app._build()  # pylint: disable=protected-access

    with server_check(app) as server:
        yield server
예제 #21
0
def multiple_views(build_reset, monkeypatch):
    """Create multiple views app."""
    app = App(__name__, sidebar=True)
    view1 = View()  # pylint: disable=unused-variable
    assert view1._uuid == 2  # pylint: disable=protected-access
    view2 = View()
    view2.add(table)
    app.add_route(view2, 'view2')

    app.add(table)
    app.add_sidebar(ctrl)
    app.add_sidebar(ctrl2)
    app.subscribe(ctrl.on_change)(app.subscribe(ctrl2.on_click)(callback))

    app._build()  # pylint: disable=protected-access

    with server_check(app) as server:
        yield server
예제 #22
0
파일: test_plotly.py 프로젝트: zz38/bowtie
def plotly(build_path, monkeypatch):
    """Create plotly app."""
    monkeypatch.setattr(App, '_sourcefile', lambda self: 'bowtie.tests.test_plotly')

    app = App()
    app.add(viz)
    app.add_sidebar(ctrl)
    app.add_sidebar(ctrl_range)
    app.add_sidebar(ctrl2)
    app.subscribe(callback, ctrl.on_change)
    app.subscribe(callback, ctrl2.on_click)
    # pylint: disable=protected-access
    app._build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(), os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'), env=env)

    time.sleep(5)
    yield
    server.kill()
예제 #23
0
def test_markdown(chrome_driver, build_path):
    """Test markdown and text widgets."""
    app = App(directory=build_path)
    app.add(mark)
    app.add_sidebar(side)
    app.add_sidebar(text)
    app.subscribe(write, text.on_change)
    app.build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)

    chrome_driver.get('http://*****:*****@style='grid-area: 1 / 2 / 2 / 3; position: relative;']")

    assert 'top' in output.text
    assert 'middle' in output.text
    assert 'link' in output.text

    txtctrl.send_keys('apple')
    time.sleep(1)

    assert 'apple' in output.text

    txtctrl.send_keys('banana')
    time.sleep(1)

    assert 'apple' in output.text
    assert 'banana' in output.text

    server.kill()
예제 #24
0
def markdown(build_path, monkeypatch):
    """Create markdown and text widgets."""
    monkeypatch.setattr(App, '_sourcefile',
                        lambda self: 'bowtie.tests.test_editor')

    app = App()
    app.add(mark)
    app.add_sidebar(side)
    app.add_sidebar(text)
    app.subscribe(write, text.on_change)
    # pylint: disable=protected-access
    app._build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)
    yield
    server.kill()
예제 #25
0
def test_all_used(buttons):
    """Test all cells are used."""

    app = App(rows=2, columns=2)
    for i in range(4):
        app.add(buttons[i])

    check_all_cells_used(app._root)

    app = App(rows=2, columns=2)
    app[0, 0] = buttons[0]
    app[0, 1] = buttons[1]
    app[1, 0] = buttons[2]
    app[1, 1] = buttons[3]

    check_all_cells_used(app._root)

    app.add(buttons[2])

    assert len(app[1, 1]) == 2

    app = App(rows=2, columns=2)
    app[0] = buttons[0]
    app[1, 0] = buttons[2]
    app[1, 1] = buttons[3]

    check_all_cells_used(app._root)

    app.add(buttons[2])
    assert len(app[1, 1]) == 2
예제 #26
0
def test_all_used(buttons):
    """Test all cells are used."""

    app = App(rows=2, columns=2)
    for i in range(4):
        app.add(buttons[i])

    assert list(app._root._used.values()) == 4 * [True]

    app = App(rows=2, columns=2)
    app[0, 0] = buttons[0]
    app[0, 1] = buttons[1]
    app[1, 0] = buttons[2]
    app[1, 1] = buttons[3]

    assert list(app._root._used.values()) == 4 * [True]

    with pytest.raises(NoUnusedCellsError):
        app.add(buttons[2])

    app = App(rows=2, columns=2)
    app[0] = buttons[0]
    app[1, 0] = buttons[2]
    app[1, 1] = buttons[3]

    assert list(app._root._used.values()) == 4 * [True]

    with pytest.raises(NoUnusedCellsError):
        app.add(buttons[2])
예제 #27
0
def test_plotly(chrome_driver, build_path):
    """Tests plotly."""

    app = App(directory=build_path)
    app.add(viz)
    app.add_sidebar(ctrl)
    app.add_sidebar(ctrl2)
    app.subscribe(callback, ctrl.on_change)
    app.subscribe(callback, ctrl2.on_click)
    app.build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)

    chrome_driver.get('http://localhost:9991')
    chrome_driver.implicitly_wait(5)

    assert chrome_driver.title == 'Bowtie App'

    button = chrome_driver.find_element_by_class_name('ant-btn')
    button.click()

    points = chrome_driver.find_elements_by_class_name('point')

    logs = chrome_driver.get_log('browser')
    for log in logs:
        if log['level'] == 'SEVERE':
            raise Exception(log['message'])

    assert len(points) == 4

    server.kill()
예제 #28
0
from bowtie import App
from bowtie.control import Nouislider
from bowtie.visual import Plotly
from bowtie import Pager, cache, command

import numpy as np
from numpy import random as rng
import plotlywrapper as pw

app = App(debug=True, sidebar=True)
pager = Pager()
sigma = Nouislider(start=0., minimum=0.1, maximum=50.)
mainplot = Plotly()

app.add_sidebar(sigma)
app.add(mainplot)


def initialize():
    cache.save('data', [0.] * 100)


@app.subscribe(pager)
def upgraph():
    data = cache.load('data')
    value = float(sigma.get())
    data.pop(0)
    data.append(value * rng.randn() + data[-1])
    mainplot.do_all(pw.line(data).to_json())
    cache.save('data', data)
예제 #29
0
from bowtie.control import Nouislider
from bowtie.visual import Plotly
from bowtie import Pager, cache, command

import numpy as np
from numpy import random as rng
import plotlywrapper as pw


app = App(debug=True, sidebar=True)
pager = Pager()
sigma = Nouislider(start=0., minimum=0.1, maximum=50.)
mainplot = Plotly()

app.add_sidebar(sigma)
app.add(mainplot)


def initialize():
    cache.save('data', [0.] * 100)


@app.subscribe(pager)
def upgraph():
    data = cache.load('data')
    value = float(sigma.get())
    data.pop(0)
    data.append(value * rng.randn() + data[-1])
    mainplot.do_all(pw.line(data).to_json())
    cache.save('data', data)