Ejemplo n.º 1
0
def main():
    with ProgressBar(
            title=HTML('<b>Example of many parallel tasks.</b>'),
            bottom_toolbar=HTML('<b>[Control-L]</b> clear  <b>[Control-C]</b> abort')) as pb:

        def run_task(label, total, sleep_time):
            for i in pb(range(total), label=label):
                time.sleep(sleep_time)

        threads = [
            threading.Thread(target=run_task, args=('First task', 50, .1)),
            threading.Thread(target=run_task, args=('Second task', 100, .1)),
            threading.Thread(target=run_task, args=('Third task', 8, 3)),
            threading.Thread(target=run_task, args=('Fourth task', 200, .1)),
            threading.Thread(target=run_task, args=('Fifth task', 40, .2)),
            threading.Thread(target=run_task, args=('Sixth task', 220, .1)),
            threading.Thread(target=run_task, args=('Seventh task', 85, .05)),
            threading.Thread(target=run_task, args=('Eight task', 200, .05)),
        ]

        for t in threads:
            t.daemon = True
            t.start()

        # Wait for the threads to finish. We use a timeout for the join() call,
        # because on Windows, join cannot be interrupted by Control-C or any other
        # signal.
        for t in threads:
            while t.is_alive():
                t.join(timeout=.5)
Ejemplo n.º 2
0
def main():
    with ProgressBar() as pb:
        # Two parallal tasks.
        def task_1():
            for i in pb(range(100)):
                time.sleep(.05)

        def task_2():
            for i in pb(range(150)):
                time.sleep(.08)

        # Start threads.
        t1 = threading.Thread(target=task_1)
        t2 = threading.Thread(target=task_2)
        t1.daemon = True
        t2.daemon = True
        t1.start()
        t2.start()

        # Wait for the threads to finish. We use a timeout for the join() call,
        # because on Windows, join cannot be interrupted by Control-C or any other
        # signal.
        for t in [t1, t2]:
            while t.is_alive():
                t.join(timeout=.5)
def main():
    with ProgressBar(
            title=HTML('<b>Example of many parallel tasks.</b>'),
            bottom_toolbar=HTML(
                '<b>[Control-L]</b> clear  <b>[Control-C]</b> abort')) as pb:

        def run_task(label, total, sleep_time):
            for i in pb(range(total), label=label):
                time.sleep(sleep_time)

        threads = []

        for i in range(160):
            label = 'Task %i' % i
            total = random.randrange(50, 200)
            sleep_time = random.randrange(5, 20) / 100.

            threads.append(
                threading.Thread(target=run_task,
                                 args=(label, total, sleep_time)))

        for t in threads:
            t.daemon = True
            t.start()

        # Wait for the threads to finish. We use a timeout for the join() call,
        # because on Windows, join cannot be interrupted by Control-C or any other
        # signal.
        for t in threads:
            while t.is_alive():
                t.join(timeout=.5)
Ejemplo n.º 4
0
def main():
    bottom_toolbar = HTML(
        ' <b>[f]</b> Print "f" <b>[q]</b> Abort  <b>[x]</b> Send Control-C.')

    # Create custom key bindings first.
    kb = KeyBindings()
    cancel = [False]

    @kb.add('f')
    def _(event):
        print('You pressed `f`.')

    @kb.add('q')
    def _(event):
        " Quit by setting cancel flag. "
        cancel[0] = True

    @kb.add('x')
    def _(event):
        " Quit by sending SIGINT to the main thread. "
        os.kill(os.getpid(), signal.SIGINT)

    # Use `patch_stdout`, to make sure that prints go above the
    # application.
    with patch_stdout():
        with ProgressBar(key_bindings=kb, bottom_toolbar=bottom_toolbar) as pb:
            for i in pb(range(800)):
                time.sleep(.01)

                if cancel[0]:
                    break
def main():
    title = HTML(
        'Downloading <style bg="yellow" fg="black">4 files...</style>')
    label = HTML('<ansired>some file</ansired>: ')

    with ProgressBar(title=title) as pb:
        for i in pb(range(800), label=label):
            time.sleep(.01)
Ejemplo n.º 6
0
def main():
    with ProgressBar(
            title='Scrolling task name (make sure the window is not too big).'
    ) as pb:
        for i in pb(
                range(800),
                label=
                'This is a very very very long task that requires horizontal scrolling ...'
        ):
            time.sleep(.01)
Ejemplo n.º 7
0
def main():
    with ProgressBar(
            title=HTML('<b fg="#aa00ff">Nested progress bars</b>'),
            bottom_toolbar=HTML(
                ' <b>[Control-L]</b> clear  <b>[Control-C]</b> abort')) as pb:

        for i in pb(range(6), label='Main task'):
            for j in pb(range(200),
                        label='Subtask <%s>' % (i + 1, ),
                        remove_when_done=True):
                time.sleep(.01)
def main():
    custom_formatters = [
        formatters.Label(),
        formatters.Text(': [', style='class:percentage'),
        formatters.Percentage(),
        formatters.Text(']', style='class:percentage'),
        formatters.Text(' '),
        formatters.Bar(sym_a='#', sym_b='#', sym_c='.'),
        formatters.Text('  '),
    ]

    with ProgressBar(style=style, formatters=custom_formatters) as pb:
        for i in pb(range(1600), label='Installing'):
            time.sleep(.01)
async def interact() -> None:
    """
    The application interaction.

    This will run automatically in a prompt_toolkit_dev AppSession, which means
    that any prompt_toolkit_dev application (dialogs, prompts, etc...) will use the
    SSH channel for input and output.
    """
    prompt_session = PromptSession()

    # Alias 'print_formatted_text', so that 'print' calls go to the SSH client.
    print = print_formatted_text

    print(
        'We will be running a few prompt_toolkit_dev applications through this '
    )
    print('SSH connection.\n')

    # Simple progress bar.
    with ProgressBar() as pb:
        for i in pb(range(50)):
            await asyncio.sleep(.1)

    # Normal prompt.
    text = await prompt_session.prompt_async("(normal prompt) Type something: "
                                             )
    print("You typed", text)

    # Prompt with auto completion.
    text = await prompt_session.prompt_async(
        "(autocompletion) Type an animal: ", completer=animal_completer)
    print("You typed", text)

    # prompt with syntax highlighting.
    text = await prompt_session.prompt_async(
        "(HTML syntax highlighting) Type something: ",
        lexer=PygmentsLexer(HtmlLexer))
    print("You typed", text)

    # Show yes/no dialog.
    await prompt_session.prompt_async('Showing yes/no dialog... [ENTER]')
    await yes_no_dialog("Yes/no dialog", "Running over asyncssh").run_async()

    # Show input dialog
    await prompt_session.prompt_async('Showing input dialog... [ENTER]')
    await input_dialog("Input dialog", "Running over asyncssh").run_async()
Ejemplo n.º 10
0
def main():
    custom_formatters = [
        formatters.Label(),
        formatters.Text(' '),
        formatters.SpinningWheel(),
        formatters.Text(' '),
        formatters.Text(HTML('<tildes>~~~</tildes>')),
        formatters.Bar(sym_a='#', sym_b='#', sym_c='.'),
        formatters.Text(' left: '),
        formatters.TimeLeft(),
    ]
    with ProgressBar(title='Progress bar example with custom formatter.',
                     formatters=custom_formatters,
                     style=style) as pb:

        for i in pb(range(20), label='Downloading...'):
            time.sleep(1)
Ejemplo n.º 11
0
def main():
    custom_formatters = [
        formatters.Label(suffix=': '),
        formatters.Percentage(),
        formatters.Bar(start='|', end='|', sym_a=' ', sym_b=' ', sym_c=' '),
        formatters.Text(' '),
        formatters.Progress(),
        formatters.Text(' ['),
        formatters.TimeElapsed(),
        formatters.Text('<'),
        formatters.TimeLeft(),
        formatters.Text(', '),
        formatters.IterationsPerSecond(),
        formatters.Text('it/s]'),
    ]

    with ProgressBar(style=style, formatters=custom_formatters) as pb:
        for i in pb(range(1600), label='Installing'):
            time.sleep(.01)
Ejemplo n.º 12
0
def main():
    true_color = confirm('Yes true colors? (y/n) ')

    custom_formatters = [
        formatters.Label(),
        formatters.Text(' '),
        formatters.Rainbow(formatters.Bar()),
        formatters.Text(' left: '),
        formatters.Rainbow(formatters.TimeLeft()),
    ]

    if true_color:
        color_depth = ColorDepth.DEPTH_24_BIT
    else:
        color_depth = ColorDepth.DEPTH_8_BIT

    with ProgressBar(formatters=custom_formatters,
                     color_depth=color_depth) as pb:
        for i in pb(range(20), label='Downloading...'):
            time.sleep(1)
def main():
    with ProgressBar() as pb:
        for i in pb(range(800)):
            time.sleep(.01)
Ejemplo n.º 14
0
def main():
    with ProgressBar(style=style,
                     title='Progress bar example with custom styling.') as pb:
        for i in pb(range(1600), label='Downloading...'):
            time.sleep(.01)
Ejemplo n.º 15
0
def main():
    with ProgressBar() as pb:
        for i in pb(data()):
            time.sleep(.1)