예제 #1
0
def test_kbi_safe_yaspin():
    sp = kbi_safe_yaspin()

    try:
        sp.start()

        handler = signal.getsignal(signal.SIGINT)
        # Handler function is wrapped into ``partial`` and
        # is accesible via ``func`` attribute.
        assert handler.func == sp._sigmap[signal.SIGINT]
    finally:
        sp.stop()
예제 #2
0
def get_random_spinner():
    spinner_choices = [
        Spinners.aesthetic,
        Spinners.pong,
        Spinners.dots2,
        Spinners.bouncingBar,
        Spinners.bouncingBall,
    ]
    color_choices = ['magenta', 'green', 'yellow', 'white']
    return kbi_safe_yaspin(
        random.choice(spinner_choices),
        color=random.choice(color_choices),
        side='left',
        reversal=True,
        timer=True,
    )
예제 #3
0
        ["sudo aplay -q /tmp/packet" + str(num_transmissions % 5) + ".wav"],
        shell=True,
        stdin=None,
        stdout=None,
        stderr=None,
        close_fds=True,
        start_new_session=True)


######################################################################
# UPDATE LOOP
######################################################################

# Make a fancy spinner for running in terminal
color = ("red", "white", "green", "blue")
spinner = kbi_safe_yaspin(text="")
spinner.start()

# initialize update info
num_updates = 0
num_transmissions = 0
last_update_time = time.time_ns()
start_time = last_update_time

# Update once a second, and transmit if it is the correct time to do so
while True:
    delta_time = time.time_ns() - last_update_time

    # once a second check
    if delta_time < 1e9:
        # go back to top of loop since it hasnt been a second yet
예제 #4
0
    if not counts['to_downloads']:
        print(f'Nothing to download! Add some tracks in {bold("mnt/d/#/Documents/music-i-liek.txt")} and try again')
        sys.exit()
    # Init counters
    downloaded_count = 0
    failed_count = 0
    skipped_count = 0

    #TODO: box listing constants key/val pairs
    print_silly_init_msg()

    while len(tracks) > 0:
        track = tracks[0]

        # TODO hide cursor during this
        with kbi_safe_yaspin() as sp:
            def err_hook(msg, critical=False): 
                color = red if critical else yellow
                sp.text = spinner_text % (color(msg[0]), color(msg[1]))
                sleep(1.5)

            metadata = get_metadata(track)
            nth_dl  = '{current:>{total_strlen}}/{total}'.format(current=downloaded_count+1, total=counts['to_downloads'], total_strlen=len(str(counts['to_downloads'])))
            #TODO: this to a function that takes Artist - Track and ouputs cyan<bold<Artist> Track>
            track_pretty = colored(metadata["artist"], "cyan", attrs=["bold"]) + ' ' + colored(metadata["title"], "cyan")
            spinner_text = f"[{nth_dl}] %s{track_pretty}%s"
            # TODO: Use a table instead with download #, status (icon mode or skipped, cancelled, downloaded, metadata-only), artist, title, album (dark<(unknown)> if None), duration (±duration delta), filesize
            spinner_write = ' ' * len(f"[{nth_dl}] ") + '> %s'


            sp.text = spinner_text % ('Downloading ', '...')
예제 #5
0
def simple_keyboard_interrupt_handling():
    with kbi_safe_yaspin(text=DEFAULT_TEXT):
        time.sleep(5)