diff options
Diffstat (limited to 'src/user_interface.py')
| -rw-r--r-- | src/user_interface.py | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/src/user_interface.py b/src/user_interface.py index f3d068a..12014a6 100644 --- a/src/user_interface.py +++ b/src/user_interface.py @@ -1,19 +1,25 @@ import os import random -from paths import Paths + import color_engine from rich import print -def colorPickerUI(img_path: str) -> tuple: +def colorPickerUI(img_path: str, num_palettes: int) -> tuple: #display the selected color scheme and ask user if they like it or want to generate a new color scheme + hex_colors, hex_compliments = selectPalette(img_path, num_palettes) + final_colors, final_compliments = selectColorsFromPalette(hex_colors, hex_compliments) + return final_colors, final_compliments + +def selectPalette(img_path: str, num_palettes: int) -> tuple: + # confirmed = False while not confirmed: print() - popularColors = color_engine.grabColors(img_path, 3) + popularColors = color_engine.grabColors(img_path, num_palettes) hex_colors = color_engine.rgbToHex(popularColors) hex_compliments = color_engine.compColors(hex_colors) - + constrast_levels = color_engine.checkContrast(hex_colors, hex_compliments) main_colors = '' complimentary_colors = '' @@ -22,29 +28,53 @@ def colorPickerUI(img_path: str) -> tuple: print(main_colors) for color in hex_compliments: complimentary_colors += f'[on {color}] [/on {color}]' - print(complimentary_colors) - print() + print(complimentary_colors, '\n') count = 0 for i in range(len(hex_colors)): - print(f'[{hex_compliments[i]} on {hex_colors[i]}]\tGenerated Color Scheme\t\t ({count})') + print(f'[{hex_compliments[i]} on {hex_colors[i]}]\tGenerated Color Scheme\t\t ({count})', f'contrast: {constrast_levels[i]}') count += 1 - print('[bold](a)ccept (r)etry') + print('[bold](a)ccept palette (g)enerate new palette') response = input('> ') - if response == 'r': - continue - else: + if response == 'a': confirmed = True + print('[bold green]Palette Confirmed!') + else: + continue + return hex_colors, hex_compliments -def pickRandomWallpaper() -> str: +def selectColorsFromPalette(hex_colors, hex_compliments): + selected = False + while not selected: + print('[bold blue]Select top 3 colors from list in order Primary, Secondary, Accent (IE, "4 10 6")') + selectedColors = input("> ") + selectedColors = selectedColors.split() + all_digits = all(i.isdigit() for i in selectedColors) + if all_digits: + selected = True + else: + print('[bold red]Invalid selection. Use positive integers corresponding to color pair to select.') + continue + + selectedColors = [int(i) for i in selectedColors] + final_colors = [] + final_compliments = [] + + for selection in selectedColors: + final_colors.append(hex_colors[selection]) + final_compliments.append(hex_compliments[selection]) + + return final_colors, final_compliments + +def pickRandomWallpaper(walls_dir) -> str: confirmed = False history = [] - num_wallpapers = len(os.listdir(Paths['wallpapers'])) + num_wallpapers = len(os.listdir(walls_dir)) while not confirmed: if len(history) == num_wallpapers: print('[bold blue] Wallpapers exhausted. Resetting history...') history.clear() - wallpaper = Paths['wallpapers'] + random.choice(os.listdir(Paths['wallpapers'])) + wallpaper = walls_dir + random.choice(os.listdir(walls_dir)) if wallpaper in history: continue history.append(wallpaper) |
