1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#!/usr/bin/env python3
"""Test and show off the spinner methods.
PYTHON_ARGCOMPLETE_OK
"""
from time import sleep
from milc import cli
cli.milc_options(name='spinner', author='MILC', version='1.9.1')
@cli.argument('-n', '--name', help='Name to greet', default='World')
@cli.entrypoint('Show off spinners.')
def main(cli):
cli.log.info('No subcommand specified!')
cli.print_usage()
@cli.subcommand('Instaniated.')
def instaniated(cli):
spinner = cli.spinner(text='Loading', spinner='dots')
spinner.start()
sleep(2)
spinner.stop()
@cli.subcommand('Context Manager.')
def context_manager(cli):
with cli.spinner(text='Loading', spinner='dots'):
sleep(2)
@cli.spinner(text='Loading', spinner='dots')
def long_running_function():
sleep(2)
@cli.subcommand('Decorated Function.')
def decorated(cli):
long_running_function()
@cli.subcommand('Custom Spinner.')
def custom_spinner(cli):
my_spinner = {
'interval': 100,
'frames': [
'. ',
'.o ',
'.oO ',
'.oO0 ',
'.oO0() ',
'.oO0( )',
'.oO0() ',
'.oO0 ',
'.oO ',
'.o ',
'. ',
]
}
cli.add_spinner('my_spinner', my_spinner)
with cli.spinner(text='Loaded by dict', spinner=my_spinner):
sleep(2)
with cli.spinner(text='Loaded by name', spinner='my_spinner'):
sleep(2)
if __name__ == '__main__':
cli()
|