def cli(): """ Menu.""" state = STATES.MAIN while 1: if state == STATES.MAIN: click.echo('Main menu:') click.echo(' s: select image') click.echo(' v: preview image') click.echo(' q: quit') char = click.getchar() if char == 's': state = STATES.SELECT elif char == 'v': state = STATES.VIEW elif char == 'q': state = STATES.QUIT else: click.echo('Invalid input') elif state == STATES.SELECT: click.echo('Select menu:') selected_image = select_image_prompt('b') if selected_image: desktop.set_desktop_background(selected_image) state = STATES.MAIN elif state == STATES.VIEW: click.echo('View menu:') launch_selected_image() state = STATES.MAIN elif state == 'quit': return
def cli(folder): if not os.path.exists(folder): click.echo('Creating image folder: %s.' % folder) os.makedirs(folder) data = { 'downloaded_images': [] } click.echo('Downloading to folder %s.' % folder) un_splash_downloader = UnSplashImageDownloader(folder) downloaded_images = un_splash_downloader.start() for image_path in downloaded_images: click.echo(click.style('Saved image in path %s.' % image_path, fg='green')) data['downloaded_images'].append(image_path) # randomly select image random_image = downloaded_images[random.randrange(0, len(downloaded_images) - 1)] desktop.set_desktop_background(random_image) click.echo(click.style('Set background image to %s.' % random_image, fg='green')) with open(DATA_STORE_FILE, 'w') as outfile: json.dump(data, outfile)