예제 #1
0
async def start_new_game(q: Q):
    q.client.game = Game(q.user.player.player_id)
    q.user.player.games[q.client.game.game_id] = q.client.game

    q.page['starting_game'] = ui.form_card(
        box='4 4 3 3',
        items=[
            ui.text_l('I am thinking of a number between 1 and 100'),
            ui.text_m('can you guess what it is?'),
            ui.text_xs('Рађ'),
            ui.slider(
                name='guess',
                label='your guess',
                min=1,
                max=100,
                value=100,
                trigger=True,
            ),
            ui.text_xs('Рађ'),
            ui.buttons(
                items=[
                    ui.button(name='quit_game', label='Quit', primary=True)
                ],
                justify='center',
            ),
        ],
    )
    await q.page.save()
예제 #2
0
async def show_issue(q: Q, issue_id: str):
    issue = issue_lookup[issue_id]
    issue.views += 1

    q.client.active_issue_id = issue_id

    q.page['form'] = ui.form_card(
        box='1 1 4 -1',
        items=[
            ui.text_xl(f'Issue {issue.id}'),
            ui.text(issue.text),
            ui.text_xs(f'({issue.views} views)'),
            ui.buttons([
                ui.button(
                    name='close_issue'
                    if issue.status == 'Open' else 'reopen_issue',
                    label="Close Issue"
                    if issue.status == 'Open' else "Reopen Issue",
                    primary=True,
                ),
                ui.button(name='back', label='Back'),
            ]),
        ])

    await q.page.save()
예제 #3
0
def get_user_input_items(sales_data, user_inputs, progress=False):
    return [
        ui.text_l('**Select Area of Interest**'),
        ui.dropdown(
            name='stores',
            label='Store IDs',
            values=[str(x) for x in user_inputs.stores],
            choices=[ui.choice(name=str(x), label=str(x)) for x in sales_data.stores_unique],
            tooltip='Select the Stores to include in the prediction',
            trigger=True,
        ),
        ui.text_xs('⠀'),
        ui.dropdown(
            name='departments',
            label='Product IDs',
            values=[str(x) for x in user_inputs.departments],
            choices=[ui.choice(name=str(x), label=str(x)) for x in sales_data.departments_unique],
            tooltip='Select the Products to include in the prediction',
            trigger=True,
        ),
        ui.frame(content=' ', height="40px"),
        ui.text_l('**Generate Sales Forecast**'),
        ui.slider(
            name='n_forecast_weeks',
            label='Number of Weeks',
            min=0,
            max=len(sales_data.prediction_dates) - 1,
            step=1,
            value=user_inputs.n_forecast_weeks,
            trigger=True,
            tooltip='Select the number of weeks into the future to predict'
        ),
        ui.text_xs('⠀'),
        ui.button(
            name='reset',
            label='Reset',
            primary=True,
            tooltip='Click to reset all values to defaults'
        ),
        ui.text_xs('⠀'),
        ui.progress(label='', caption='', visible=progress),
    ]
예제 #4
0
async def make_welcome_card(q):
    q.page['hello'] = ui.form_card(
        box='4 4 3 3',
        items=[
            ui.text_l(f'Hello {q.user.player.first.title()},'),
            ui.text_xs('Рађ'),
            ui.text_m('Do you want to play a guessing game?'),
            ui.text_xs('Рађ'),
            ui.buttons(
                items=[
                    ui.button('start_game', label='Play', primary=True),
                    ui.button('leaderboard',
                              label='View Scores',
                              primary=False),
                ],
                justify='center',
            ),
        ],
    )
    await q.page.save()
예제 #5
0
async def serve(q: Q):
    q.page['example'] = ui.form_card(box='1 1 4 10', items=[
        ui.text_xl(content='Extra-large text, for headings.'),
        ui.text_l(content='Large text, for sub-headings.'),
        ui.text_m(content='Body text, for paragraphs and other content.'),
        ui.text_s(content='Small text, for small print.'),
        ui.text_xs(content='Extra-small text, for really small print.'),
        ui.separator(label='A separator sections forms'),
        ui.progress(label='A progress bar'),
        ui.progress(label='A progress bar'),
        ui.message_bar(type='success', text='Message bar'),
        ui.textbox(name='textbox', label='Textbox'),
        ui.label(label='Checkboxes'),
        ui.checkbox(name='checkbox1', label='A checkbox'),
        ui.checkbox(name='checkbox1', label='Another checkbox'),
        ui.checkbox(name='checkbox1', label='Yet another checkbox'),
        ui.toggle(name='toggle', label='Toggle'),
        ui.choice_group(name='choice_group', label='Choice group', choices=[
            ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']
        ]),
        ui.checklist(name='checklist', label='Checklist', choices=[
            ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']
        ]),
        ui.dropdown(name='dropdown', label='Dropdown', choices=[
            ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']
        ]),
        ui.dropdown(name='dropdown', label='Multi-valued Dropdown', values=[], choices=[
            ui.choice(name=x, label=x) for x in ['Egg', 'Bacon', 'Spam']
        ]),
        ui.combobox(name='combobox', label='Combobox', choices=['Choice 1', 'Choice 2', 'Choice 3']),
        ui.slider(name='slider', label='Slider'),
        ui.range_slider(name='range_slider', label='Range slider', max=99),
        ui.spinbox(name='spinbox', label='Spinbox'),
        ui.date_picker(name='date_picker', label='Date picker'),
        ui.color_picker(name='color_picker', label='Color picker'),
        ui.buttons([
            ui.button(name='primary_button', label='Primary', primary=True),
            ui.button(name='standard_button', label='Standard'),
            ui.button(name='standard_disabled_button', label='Standard', disabled=True),
        ]),
        ui.file_upload(name='file_upload', label='File upload'),
        ui.table(name='table', columns=[
            ui.table_column(name='col1', label='Column 1'),
            ui.table_column(name='col2', label='Column 2'),
        ], rows=[
            ui.table_row(name='row1', cells=['Text A', 'Text B']),
            ui.table_row(name='row2', cells=['Text C', 'Text D']),
            ui.table_row(name='row3', cells=['Text E', 'Text F']),
        ]),
        ui.link(label='Link'),
        ui.tabs(name='tabs', items=[
            ui.tab(name='email', label='Mail', icon='Mail'),
            ui.tab(name='events', label='Events', icon='Calendar'),
            ui.tab(name='spam', label='Spam'),
        ]),
        ui.expander(name='expander', label='Expander'),
        ui.frame(path='https://example.com'),
        ui.markup(content=html),
        ui.template(
            content=menu,
            data=pack(dict(dishes=[
                dict(name='Spam', price='$2.00'),
                dict(name='Ham', price='$3.45'),
                dict(name='Eggs', price='$1.75'),
            ]))
        ),
        ui.picker(name='picker', label='Picker', choices=[
            ui.choice('choice1', label='Choice 1'),
            ui.choice('choice2', label='Choice 2'),
            ui.choice('choice3', label='Choice 3'),
        ]),
        ui.stepper(name='stepper', items=[
            ui.step(label='Step 1', icon='MailLowImportance'),
            ui.step(label='Step 2', icon='TaskManagerMirrored'),
            ui.step(label='Step 3', icon='Cafe'),
        ]),
        ui.visualization(
            plot=ui.plot([ui.mark(type='interval', x='=product', y='=price', y_min=0)]),
            data=data(fields='product price', rows=[(c, x) for c, x, _ in [f.next() for _ in range(n)]], pack=True),
        ),
        ui.vega_visualization(
            specification=spec,
            data=data(fields=["a", "b"], rows=[
                ["A", rnd()], ["B", rnd()], ["C", rnd()],
                ["D", rnd()], ["E", rnd()], ["F", rnd()],
                ["G", rnd()], ["H", rnd()], ["I", rnd()]
            ], pack=True),
        ),
        ui.button(name='show_inputs', label='Submit', primary=True),
    ])
    await q.page.save()
# Form / Text / Sizes
# Use text size variants to display formatted text using predefined font sizes.
# ---
from h2o_wave import site, ui

page = site['/demo']

page['example'] = ui.form_card(
    box='1 1 4 -1',
    items=[
        ui.separator('Separator'),
        ui.text_xl('Extra large text'),
        ui.text_l('Large text'),
        ui.text('Normal text'),
        ui.text_m('Medium text'),
        ui.text_s('Small text'),
        ui.text_xs('Extra small text'),

        # Using `ui.text()` with a `size` argument produces similar results:
        ui.separator('Separator'),
        ui.text('Extra large text', size=ui.TextSize.XL),
        ui.text('Large text', size=ui.TextSize.L),
        ui.text('Normal text'),
        ui.text('Medium text', size=ui.TextSize.M),
        ui.text('Small text', size=ui.TextSize.S),
        ui.text('Extra small text', size=ui.TextSize.XS),
    ],
)
page.save()
예제 #7
0
async def run_app(q: Q):
    if q.args.start_game:
        if q.args.submit_game:
            q.client.game.is_public = True
            q.app.games[q.client.game.game_id] = q.client.game
        del q.page['leaderboard']
        del q.page['hello']
        await start_new_game(q)
    elif q.args.quit_game:
        del q.page['starting_game']
        await make_welcome_card(q)
    elif q.args.guess:
        message = q.client.game.guess(q.args.guess)
        if message == 'You Got It!':
            q.page['starting_game'].items = [
                ui.text_l(
                    f'­ЪЈЁ ­ЪјЅ ­Ъјѓ You Got It, The number is **{q.client.game.number}**'
                ),
                ui.text_m(
                    f'You made **{len(q.client.game.guesses)}** guesses in'),
                ui.text_m(f'{q.client.game.game_time()}.'),
                ui.toggle(
                    name='submit_game',
                    label='Submit your game to Public Scoreboard',
                    trigger=False,
                ),
                ui.text_xs('Рађ'),
                ui.buttons(
                    items=[
                        ui.button(
                            name='leaderboard',
                            label='View Scores',
                            primary=True,
                        ),
                        ui.button(
                            name='start_game',
                            label='Play Again',
                            primary=False,
                        ),
                    ],
                    justify='center',
                ),
            ]
        else:
            previous_guesses = [str(x) for x in q.client.game.guesses]
            if len(previous_guesses) > 16:
                previous_guesses = previous_guesses[-16:]
                previous_guesses[0] = '...'
            guesses_str = ", ".join(previous_guesses)
            q.page['starting_game'].items = [
                ui.text_l(message),
                ui.text_m(guesses_str),
                ui.text_xs('Рађ'),
                ui.slider(
                    name='guess',
                    label='your guess',
                    min=1,
                    max=100,
                    value=q.args.guess,
                    trigger=True,
                ),
                ui.text_xs('Рађ'),
                ui.buttons(
                    items=[
                        ui.button(name='quit_game', label='Quit', primary=True)
                    ],
                    justify='center',
                ),
            ]
    elif q.args.leaderboard:
        if q.args.submit_game:
            q.client.game.is_public = True
            q.app.games[q.client.game.game_id] = q.client.game
        del q.page['starting_game']
        await show_leaderboard(q)
    elif q.args.private_leaderboard:
        await show_private_leaderboard(q)

    await q.page.save()
예제 #8
0
async def show_private_leaderboard(q: Q):
    columns = [
        ui.table_column(
            name='game_id',
            label='Game #',
            sortable=False,
            searchable=False,
            max_width='150',
            data_type='string',
            link=False,
        ),
        ui.table_column(
            name='number',
            label='Number',
            sortable=True,
            max_width='90',
            data_type='number',
        ),
        ui.table_column(
            name='num_of_guesses',
            label='# of Guesses',
            sortable=True,
            max_width='120',
            data_type='number',
        ),
        ui.table_column(
            name='status',
            label='Status',
            sortable=False,
            filterable=True,
            max_width='90',
            data_type='string',
            cell_type=ui.icon_table_cell_type(),
        ),
        ui.table_column(
            name='game_time',
            label='Time (s)',
            sortable=True,
            max_width='150',
            data_type='number',
        ),
    ]
    scores = [
        ui.table_row(
            name=game.game_id,
            cells=[
                str(idx),
                str(game.number),
                str(len(game.guesses)),
                'MedalSolid' if game.status == 'done' else 'Running',
                str(game.time_seconds()),
            ],
        ) for idx, game in enumerate(q.user.player.games.values(), 1)
    ]
    leaderboard = ui.table(
        name='leaderboard',
        columns=columns,
        rows=scores,
        groupable=False,
        downloadable=False,
        resettable=False,
        height='600px',
    )
    del q.page['starting_game']
    q.page['leaderboard'] = ui.form_card(
        box='3 2 5 9',
        items=[
            ui.label('Scores from your games'),
            leaderboard,
            ui.text_xs('Рађ'),
            ui.buttons(
                items=[
                    ui.button(name='start_game', label='Play', primary=True),
                    ui.button(name='leaderboard',
                              label='Show all games',
                              primary=True),
                ],
                justify='center',
            ),
        ],
    )
    await q.page.save()
예제 #9
0
async def show_leaderboard(q: Q):
    columns = [
        ui.table_column(
            name='name',
            label='Name',
            sortable=True,
            searchable=False,
            max_width='230',
            data_type='string',
            link=False,
        ),
        ui.table_column(
            name='number',
            label='Number',
            sortable=True,
            max_width='100',
            data_type='number',
        ),
        ui.table_column(
            name='num_of_guesses',
            label='# of Guesses',
            sortable=True,
            max_width='120',
            data_type='number',
        ),
        ui.table_column(
            name='game_time',
            label='Time (s)',
            sortable=True,
            max_width='160',
            data_type='number',
        ),
    ]
    scores = [
        ui.table_row(
            name=game.game_id,
            cells=[
                q.app.players[game.player_id].name,
                str(game.number),
                str(len(game.guesses)),
                str(game.time_seconds()),
            ],
        ) for game in q.app.games.values()
    ]
    leaderboard = ui.table(
        name='leaderboard',
        columns=columns,
        rows=scores,
        groupable=False,
        downloadable=False,
        resettable=False,
        height='600px',
    )
    del q.page['starting_game']
    q.page['leaderboard'] = ui.form_card(
        box='3 2 5 9',
        items=[
            ui.label('Scores'),
            leaderboard,
            ui.text_xs('Рађ'),
            ui.buttons(
                items=[
                    ui.button(name='start_game', label='Play', primary=True),
                    ui.button(name='leaderboard',
                              label='Refresh',
                              primary=True),
                    ui.button(
                        name='private_leaderboard',
                        label='Show my games only',
                        primary=True,
                    ),
                ],
                justify='center',
            ),
        ],
    )
    await q.page.save()