Ejemplo n.º 1
0
def test_page_url_conflict():
    page_one = Page('one', core.Container())
    page_two = Page('two', core.Container(), url='/one')

    app = Dazzler(__name__)
    with pytest.raises(PageConflictError) as context:
        app.add_page(page_one, page_two)

    assert context.value.args[0] == 'Duplicate page url: two@/one'
Ejemplo n.º 2
0
async def test_middleware(start_visit, browser):
    page = Page(__name__, layout=layout, url='/')

    @page.bind(Trigger('cookie-setter', 'clicks'))
    async def on_cookie(ctx: BindingContext):
        cookie = ctx.request.cookies.get('dummy')
        await ctx.set_aspect('cookie-output', children=cookie)

    app = Dazzler(__name__)
    app.middlewares.append(DummyMiddleware())
    app.add_page(page)

    await start_visit(app)

    await browser.wait_for_text_to_equal('#request-output', 'dummy')
    await browser.click('#cookie-setter')
    await browser.wait_for_text_to_equal('#cookie-output', 'dummy-cookie')
Ejemplo n.º 3
0
def session_app():
    app = Dazzler(__name__)
    app.config.session.duration = 3
    app.config.secret_key = uuid.uuid4().hex

    page = Page(__name__,
                core.Container(
                    [core.Container(identity='session-output', clicks=1)]),
                url='/')

    @page.bind(Trigger('session-output', 'clicks'))
    async def on_session(ctx: BindingContext):
        await ctx.set_aspect('session-output', children=ctx.session.session_id)

    app.add_page(page)

    return app
Ejemplo n.º 4
0
async def test_link(start_visit, browser):
    from tests.components.pages.link import page, other_page

    app = Dazzler(__name__)
    app.add_page(page, other_page)
    await start_visit(app)

    await browser.get('http://127.0.0.1:8150/link')

    link = await browser.wait_for_element_by_id('internal')
    await app.executor.execute(link.click)

    external = await browser.wait_for_element_by_id('external')
    external.click()

    await asyncio.sleep(0.1)

    assert 'https://www.google.com/' in browser.driver.current_url
Ejemplo n.º 5
0
async def test_auth_from_configs(start_visit, browser):
    app = Dazzler(__name__)
    app.config.authentication.enable = True
    app.config.session.backend = 'Redis'
    app.config.authentication.authenticator = \
        'tests.test_dazzler_auth:DummyAuthenticator'

    page = Page(__name__,
                core.Container('my-page', identity='content'),
                require_login=True,
                url='/')
    app.add_page(page)

    await start_visit(app)
    await browser.get('http://localhost:8150/')

    await proceed_login(browser, 'AgentSmith', 'SuperSecret1')
    await browser.wait_for_text_to_equal('#content', 'my-page')
Ejemplo n.º 6
0
def start_page(start_visit):  # pylint: disable=redefined-outer-name
    app = Dazzler(__name__)

    async def _start_page(page, debug=False):
        page.url = '/'
        app.add_page(page)
        await start_visit(app, debug=debug)

    return _start_page
Ejemplo n.º 7
0
async def test_session(start_visit, browser, backend):
    app = Dazzler(__name__)
    app.config.session.enable = False
    app.config.session.duration = 3
    app.middlewares.append(SessionMiddleware(app, backend=backend(app)))

    page = Page(__name__,
                url='/',
                layout=core.Container([
                    core.Button('Click', identity='session-click'),
                    core.Container(identity='session-output'),
                    core.Button('Remove session', identity='remove-session'),
                ]))

    @page.bind(Trigger('session-click', 'clicks'))
    async def on_session(ctx: BindingContext):
        session = ctx.request['session']

        clicks = await session.get('clicks') or 0
        clicks += 1
        await session.set('clicks', clicks)

        await ctx.set_aspect('session-output', children=f'Clicked {clicks}')

    @page.bind(Trigger('remove-session', 'clicks'))
    async def on_remove(ctx: BindingContext):
        session = ctx.request['session']
        await session.delete('clicks')

    app.add_page(page)

    await start_visit(app)

    for i in range(1, 4):
        await browser.get('http://localhost:8150/')
        await browser.click('#session-click')
        await browser.wait_for_text_to_equal('#session-output', f'Clicked {i}')

    # Delete session item
    await browser.click('#remove-session')
    await browser.click('#session-click')
    await browser.wait_for_text_to_equal('#session-output', 'Clicked 1')
Ejemplo n.º 8
0
def auth_app():
    app = Dazzler(__name__)
    page = Page('test-auth',
                core.Container([
                    core.Html('h2', 'logged-in', identity='header'),
                    core.Container(identity='username-output'),
                    _auth.Logout('/auth/logout', identity='logout')
                ]),
                url='/',
                require_login=True)

    @page.bind(Trigger('header', 'children'))
    async def on_username(ctx):
        user = ctx.request['user']
        await ctx.set_aspect('username-output', children=user.username)

    app.add_page(page)
    app.config.session.backend = 'Redis'

    DazzlerAuth(app, DummyAuthenticator())

    return app
Ejemplo n.º 9
0
def setup(app):
    app.connect("autodoc-skip-member", skip)
    app.add_css_file('styles.css')

    # Generate components for docstrings.
    from dazzler import Dazzler

    dazz = Dazzler('dazzler')

    for source, output in (('../src/core/js/components',
                            '../dazzler/components/core'),
                           ('../src/extra/js/components',
                            '../dazzler/components/extra'),
                           ('../src/calendar/js/components',
                            '../dazzler/components/calendar'),
                           ('../src/markdown/js/components',
                            '../dazzler/components/markdown'),
                           ('../src/auth/js/components',
                            '../dazzler/components/auth')):
        dazz.start(['generate', source, output])

    dazz.start(['dump-configs', 'dazzler.toml'])
Ejemplo n.º 10
0
def gen(target):
    brd = cu.Board(
        (90, 63),
        trace = cu.mil(6),
        space = cu.mil(6) * 2.0,
        via_hole = 0.3,
        via = 0.6,
        via_space = cu.mil(5),
        silk = cu.mil(6))
    brd.outline()
    brd.layers['GML'].union(sg.box(-9.8, 0, 0, 16))

    daz = Dazzler(brd.DC((28, 38)).left(90))
    if target == "pico":
        pico = Pico(brd.DC((70, 28)))
    elif target == "teensy":
        teensy = Teensy40(brd.DC((70, 28)))
        breakout(teensy)
    elif target == "feather":
        feather = Feather(brd.DC((70, 28)))
        breakout(feather)
    sd = SD(brd.DC((3, 12)).right(180))

    # ------------------------------ SD
    for nm in ("G1", "G2", "G3", "G4", "6"):
        sd.s(nm).w("r 90 f 1 -")
    sd.s("4").setname("VCC").w("r 90 f 2").wire()

    tt = [sd.s(c) for c in "1235789"]
    [t.left(90).forward(1) for t in tt]
    r0 = brd.enriver90(tt, 90).left(135).wire()

    tt = [daz.s(str(15 + i)) for i in range(7)]
    [t.w("o f .1") for t in tt]
    r1 = brd.enriver90(tt, 90).left(45).meet(r0)

    # ------------------------------ Wii
    def wii(i):
        y = 32.5 + 6 - i * 12
        return cu.WiiPlug(brd.DC((-5, y)).right(270)).escape()
    wii1 = wii(-1)
    wii2 = wii(1)
    wii1.w("r 90 f 2").wire()
    wii2.w("f 10 r 45 f 4 r 45").wire()
    wii = wii2.join(wii1, 0.5).wire()

    tt = [daz.s(str(i)) for i in (13, 12, 11, 10, 9, 8)]
    [t.w("i f 4") for t in tt]
    daz_i2cbus = brd.enriver90(tt, -90).wire()

    wii.w("f 9 r 90 f 3 /").meet(daz_i2cbus)

    # ------------------------------ Dazzler power
    daz.s("VCC").thermal(1).wire()
    for nm in ("GND", "GND1", "GND2"):
        daz.s(nm).inside().forward(2).wire(width = 0.5).w("-")

    daz_used = ("1", "2", "22", "23", "25", "26", "27", "28", "29", "PGM")
    tt = [daz.s(nm) for nm in daz_used]
    [p.w("i f 4").wire() for p in tt]
    daz.s("1").left(90)
    daz.s("2").forward(1).left(90)
    daz.s("PGM").right(90)
    cu.extend2(tt)
    b1 = brd.enriver90(tt[::-1], 90)

    if target == "pico":
        b1.w("l 90 f 2 r 45").wire()
        pico_used = (
            "GP0",
            "GP2", "GP3", "GP4", "GP5",
            "GP6", "GP7", "GP8", "GP9", "GP10"
        )
        tt = [pico.s(str(i)) for i in pico_used]
        [p.setlayer("GBL").w("r 180 f 2").wire() for p in tt]
        b0 = brd.enriver90(tt[::-1], -90).wire()

        b0.shuffle(b1, {         # Pico         Dazzler    
            "GP8": "1"  ,    # UART1 TX     CONSOLE IN 
            "GP9": "2"  ,    # UART1 RX     CONOLE OUT 
            "GP4": "22" ,    # SPI0 RX      MISO       
            "GP5": "25" ,    # GP5          GPU SEL    
            "GP6": "26" ,    # GP6          SD SEL     
            "GP7": "27" ,    # GP7          DAZZLER SEL
            "GP3": "28" ,    # SPI0 TX      MOSI       
            "GP2": "29" ,    # SPI0 SCK     SCK        
            "GP10":"PGM",    # GP10         PGM        
            "GP0": "23" ,    # UART0 TX     UART       
        }).w("f 9 l 45").meet(b1)
        daz.s("5V").setwidth(0.5).w("o f 1 l 90 f 7 r 90 f 14 r 90 f 2.5").goto(pico.s("VBUS")).wire()
    elif target == "teensy":
        b1.w("l 45 f 2 r 45").wire()
        teensy_used = (
            "1", "8", "9", "10", "11", "12",
            "13", "14", "15", "16"
        )
        tt = [teensy.s(str(i)) for i in teensy_used]
        [p.setlayer("GBL").w("l 90 f 2").wire() for p in tt]
        rv0 = brd.enriver90(tt[:6][::-1], -90).wire()
        rv1 = brd.enriver90(tt[6:][::-1], 90).wire()
        b0 = rv1.join(rv0, 1).forward(2).wire()
        b0.shuffle(b1, {    # Teensy       Dazzler
            "14": "1"  ,    # TX3          CONSOLE IN 
            "15": "2"  ,    # RX3          CONOLE OUT 
            "12": "22" ,    # MISO         MISO       
            "8" : "25" ,    # 8            GPU SEL    
            "9" : "26" ,    # 9            SD SEL     
            "10": "27" ,    # 10           DAZZLER SEL
            "11": "28" ,    # MOSI         MOSI       
            "13": "29" ,    # SCK          SCK        
            "16":"PGM" ,    # 16           PGM        
            "1" : "23" ,    # UART0 TX     UART       
        }).w("f 8").meet(b1)
        daz.s("5V").setwidth(0.5).w("o f 2 r 90 f 39 l 90 f 23").goto(teensy.s("VIN")).wire()
    elif target == "feather":
        mapping = {
#           Feather             Dazzler
            "SCK"   : "29" ,    # SCK        
            "MOSI"  : "28" ,    # MOSI       
            "MISO"  : "22" ,    # MISO       
            "TX"    : "23" ,    # UART       
            "D4"    : "25" ,    # GPU SEL    
            "D5"    : "26" ,    # SD SEL     
            "D6"    : "27" ,    # DAZZLER SEL
            "D9"    :"PGM" ,    # PGM        
            "D10"   : "2"  ,    # CONOLE OUT 
            "D12"   : "1"  ,    # CONSOLE IN 
        }
        b1.w("l 45 f 2 r 45").wire()
        used = mapping.keys()
        tt = [feather.s(str(i)) for i in used]
        [p.setlayer("GBL").w("l 90 f 2").wire() for p in tt]
        rv0 = brd.enriver90(tt[:5][::-1], -90).wire()
        rv1 = brd.enriver90(tt[5:][::-1], 90).wire()
        b0 = rv1.join(rv0, 1).forward(19).wire()
        b0.shuffle(b1, mapping).w("f 8").meet(b1)
        daz.s("5V").setwidth(0.5).w("o f 2 r 90 f 41 l 90 f 23").goto(feather.s("USB")).wire()

    if 1:
        im = Image.open("img/gameduino-mono.png")
        brd.logo(16, 4, im)

        im = Image.open("img/dazzler-logo.png")
        brd.logo(36, 4, im)

        if target == "pico":
            brd.logo(pico.center.xy[0], pico.center.xy[1] - 15, gentext("PICO"))
        else:
            brd.logo(70, 4, gentext(target))

        brd.logo(-5, 38.5 - 12, gentext("2").transpose(Image.ROTATE_270), scale = 0.9)
        brd.logo(-5, 38.5 + 12, gentext("1").transpose(Image.ROTATE_270), scale = 0.9)

        brd.logo(-4.8, 38.5, Image.open("img/oshw-logo-outline.png").transpose(Image.ROTATE_270), scale = 0.7)

        for i,s in enumerate(["(C) 2021", "EXCAMERA LABS", str(__VERSION__)]):
            brd.annotate(81, 60 - 1.5 * i, s)

    if 1:
        brd.fill_any("GTL", "VCC")
        brd.fill_any("GBL", "GL2")

    name = target + "_dazzler"
    brd.save(name)
    for n in brd.nets:
        print(n)
    svgout.write(brd, name + ".svg")
Ejemplo n.º 11
0
from dazzler import Dazzler
from dazzler.components import core
from dazzler.system import Page

app = Dazzler(__name__)


async def layout(_):
    return core.Container('Layout as function', identity='layout')


page = Page(
    __name__,
    url='/',
    layout=layout,
)
app.add_page(page)

if __name__ == '__main__':
    app.start('-v --debug=1 --port=5420'.split())
Ejemplo n.º 12
0
from dazzler import Dazzler

from tests.hot_reload import hot_reload_page

app = Dazzler(__name__)

app.config.session.backend = 'Redis'
app.config.development.reload_threshold = 0.1
app.add_page(hot_reload_page.page)

if __name__ == '__main__':
    app.start('--v --reload --debug')
Ejemplo n.º 13
0
from dazzler import Dazzler
from dazzler.components import core
from dazzler.system import Page

app = Dazzler(__name__)

for num in ('one', 'two', 'three', 'four'):
    page = Page(
        name=num,
        layout=core.Container(f'Page {num}', identity='content'),
        title=f'Page {num}',
    )

    app.add_page(page)


if __name__ == '__main__':
    app.start('-v --debug 1'.split())
Ejemplo n.º 14
0
from dazzler import Dazzler
from dazzler.system import Page

from dazzler.components import core

app = Dazzler(__name__)
app.config.requirements.prefer_external = True

app.add_page(Page('index', core.Container('foo'), url='/'))
Ejemplo n.º 15
0
    def escape(self, a=-45):
        tt = [t.copy().w("i") for t in self.pads][::-1]
        return self.board.enriver(tt, a)


if __name__ == "__main__":
    brd = cu.Board((50, 42),
                   trace=cu.mil(5),
                   space=cu.mil(5) * 2.0,
                   via_hole=0.3,
                   via=0.6,
                   via_space=cu.mil(5),
                   silk=cu.mil(6))

    daz = Dazzler(brd.DC((68.58 - 43.59, 26.5)).right(180))
    sd = SD(brd.DC((53.6, 16.5)).right(0))
    (lvl_in, lvl_out) = cu.M74LVC245(brd.DC((60, 37)).right(90)).escape()
    shield = ArduinoR3(brd.DC((0, 0)))
    cu.C0402(brd.DC((65, 39.0)), '0.1 uF').escape_2layer()
    cu.C0402(brd.DC((59, 27.5)), '0.1 uF').escape_2layer()

    R1 = cu.R0402(brd.DC((51.5, 46.0)).right(90), '4.7K')
    R2 = cu.R0402(brd.DC((53.0, 46.0)).right(90), '4.7K')
    R1.pads[0].w("o l 90 f 0.5 -")
    daz.s("PGM").w("o f 1 r 90 f 13 r 45 f 5.5 l 45 f 2").wire()
    daz.s("5V").copy().w(
        "i f 6 l 90 f 9.15 l 90 f 11.3 r 90 f 26.9 r 90 f 4").goto(
            R2.pads[0]).wire()

    def wii(i):
Ejemplo n.º 16
0
    26: "< SD SEL",
    27: "< DAZZLER SEL",
    28: "< MOSI",
    29: "< SCK",
}

if __name__ == "__main__":
    brd = cu.Board((76, 76),
                   trace=cu.mil(5),
                   space=cu.mil(5) * 2.0,
                   via_hole=0.3,
                   via=0.6,
                   via_space=cu.mil(5),
                   silk=cu.mil(6))

    daz = Dazzler(brd.DC((33, 25)).right(90))
    daz.labels()
    # cu.C0402(brd.DC((70, 20)).right(90), '0.1 uF').escape_2layer()

    tt = [daz.s(nm).copy().inside() for nm in ("2", "1")]
    uart0 = brd.enriver(tt, 45).wire()

    conn = dip.SIL(brd.DC((66.5, 38)).left(180), "29")
    [p.setname(str(i)) for (i, p) in enumerate(conn.pads, 1)]
    for p in conn.pads:
        p.copy().goxy(-3, 0).text(str(p.name))
        l = labels.get(int(p.name), "")
        if l:
            p.copy().goxy(1, 0).ltext(l)
    [p.left(90) for p in conn.pads]
    # connb0 = brd.enriver(conn.pads[0:14][::-1], 45).wire()
Ejemplo n.º 17
0
from dazzler import Dazzler

from tests.apps.pages import component_as_trigger, binding_return_trigger, \
    same_identity, component_as_aspect, storage, regex_bindings
from tests.components.pages import checklist, store, html, interval, \
    input_output, radio, link, viewport, progress, select, button, slider, \
    modal, textarea, table, grid, form, markdown, calendar, pager, extras, \
    login, list_box, treeview, dropdown, page_map, icons

app = Dazzler(__name__)
app.config.session.backend = 'Redis'
app.config.development.reload_threshold = 5.0

pages = [
    component_as_trigger.page,
    binding_return_trigger.page,
    same_identity.page,
    component_as_aspect.page,
    input_output.page,
    interval.page,
    checklist.page,
    html.page,
    radio.page,
    store.page,
    link.page,
    link.other_page,
    viewport.page,
    progress.page,
    select.page,
    button.page,
    slider.page,
Ejemplo n.º 18
0
    ftdi_in = brd.river1(i).wire()

    # ------------------------------ PS/2
    # MD-60S from CUI, Future Electronics $1.10
    # 1: DATA  5: CLOCK
    ps2 = MD_60Sb(brd.DC((6.2, 10)).right(90))
    dc = [ps2.s("6"), ps2.s("1")]
    ps2.s("5").w("f 0 r 180 f 1 -")
    ps2.s("3").newpath().setlayer('GBL').w("r 45 f 3").wire()
    cu.extend2(dc)
    ps2b = brd.enriver90([t.w("f 4") for t in dc], -90).wire()

    print(ftdi_in.tt)
    zbus = zd.join(za, 0.5).join(ps2b).join(ftdi_in).wire()

    daz = Dazzler(brd.DC((73, 26)).right(0), "nosw")

    if 0:
        (lvl_a, lvl_d, lvl_b) = cu.M74LVC245(brd.DC(
            (60, 37)).right(45)).escape2()
        lvl_a.w("l 45 f 3").wire()
        lvl_d.setname("VCC").w("o f 0.5").wire()
        lvl_b.w("l 45 r 90 f 5 r 90")
        lvl_b.through()
        lvl_b.through()

    # ------------------------------ dazzler busses
    daz.s("VCC").thermal(1).wire()
    for nm in ("GND", "GND1", "GND2"):
        daz.s(nm).inside().forward(2).wire(width=0.5).w("-")
Ejemplo n.º 19
0
    for value in range(start, stop):
        await context.set_aspect(f'value-{value}', value=value)
        await asyncio.sleep(0.15)


async def trigger_output(context: BindingContext):
    value = context.trigger.value
    current = json.loads(context.states['output']['children'])
    current.append(value)
    await context.set_aspect(
        'output',
        children=json.dumps(current),
    )
    if value == 10:
        await context.set_aspect('done', children='done')


for i in range(1, 3):
    page.bind(Trigger(f'output-{i}', 'value'))(trigger_input)

for i in range(1, 11):
    page.bind(Trigger(f'value-{i}', 'value'),
              State('output', 'children'))(trigger_output)

if __name__ == '__main__':
    from dazzler import Dazzler

    app = Dazzler(__name__)
    app.add_page(page)
    app.start()
Ejemplo n.º 20
0
        p.setname(nm)
        p.copy().w("l 90 f 2").text(nm.upper())

    b_names = "d7 d6 d5 d4 d3 d2 d1 d0 iorq wr int clk m1 a0 a1 a2 a3 a4 a5 a6 a7".split(
    )
    b_names = "a0 a1 a2 a3 a4 a5 a6 a7".split()
    zsig = [bus.s(nm) for nm in b_names]
    for i, t in enumerate(zsig):
        t.setlayer('GTL').w("l 90 f 1")
    cu.extend2(zsig)
    zsig0 = brd.enriver90(zsig, -90)
    zsig0.wire()

    # PS/2 keyboard: MD-60S from CUI, Future Electronics $1.10

    daz = Dazzler(brd.DC((73, 26)).right(0))

    (lvl_a, lvl_d, lvl_b) = cu.M74LVC245(brd.DC((60, 37)).right(45)).escape2()
    lvl_a.w("l 45 f 3").wire()
    lvl_d.setname("VCC").w("o f 0.5").wire()
    lvl_b.w("l 45 r 90 f 5 r 90")
    lvl_b.through()
    lvl_b.through()
    """
    cu.C0402(brd.DC((65, 39.0)), '0.1 uF').escape_2layer()
    cu.C0402(brd.DC((59, 27.5)), '0.1 uF').escape_2layer()

    R1 = cu.R0402(brd.DC((51.5, 46.0)).right(90), '4.7K')
    R2 = cu.R0402(brd.DC((53.0, 46.0)).right(90), '4.7K')
    R1.pads[0].w("o l 90 f 0.5 -")
    daz.s("PGM").w("o f 1 r 90 f 13 r 45 f 5.5 l 45 f 2").wire()