diff options
| -rw-r--r-- | src/get_args.py | 12 | ||||
| -rw-r--r-- | src/instant_rice.py | 3 | ||||
| -rw-r--r-- | src/manage_saves.py | 36 | ||||
| -rw-r--r-- | src/user_interface.py | 40 |
4 files changed, 75 insertions, 16 deletions
diff --git a/src/get_args.py b/src/get_args.py index f878e77..9197995 100644 --- a/src/get_args.py +++ b/src/get_args.py @@ -4,25 +4,25 @@ import os from rich import print -def get_args(args, walls_dir) -> tuple: +def get_args(args, walls_dir, theme_dir) -> tuple: # arguments that can be passed into program VALID_ARGS = ['-r', '-p', '--initialize', '--reconfigure'] initialize = False reconfigure = False - theme = None - VALID_ARGS = ['-r', '-p', '--initialize', '--reconfigure'] - + img_path = '' if '-p' in args: index = args.index('-p') isFile = os.path.isfile(args[index + 1]) if isFile == True: print("reached") theme = manage_saves.load_theme(args[index + 1]) - - if '-r' in args: + elif '-t' in args: + theme = user_interface.themeSelector(theme_dir) + img_path = theme['wallpaper'] + elif '-r' in args: img_path = user_interface.pickRandomWallpaper(walls_dir) else: img_path = f"{os.getcwd()}/{args[1]}" diff --git a/src/instant_rice.py b/src/instant_rice.py index 4102fa1..2c8bd0a 100644 --- a/src/instant_rice.py +++ b/src/instant_rice.py @@ -8,13 +8,14 @@ import initialize_rofi from get_args import get_args,usage from load_config import systemConfig from rich import print + if __name__ == '__main__': if len(sys.argv) > 1: config = systemConfig() - img_path, initialize, reconfigure, theme = get_args(sys.argv, config.wallpaper_directory) + img_path, initialize, reconfigure, theme = get_args(sys.argv, config.wallpaper_directory, config.theme_directory) if initialize: initialize_rofi.reconfigureRofi() diff --git a/src/manage_saves.py b/src/manage_saves.py index 44ce2a3..2730a5d 100644 --- a/src/manage_saves.py +++ b/src/manage_saves.py @@ -1,19 +1,44 @@ from rich import print -from theme import Theme import json -def save_theme(hex_colors, hex_compliments, wallpaper_location, save_location): +import os + +class Theme: + def __init__(self, colors, comp_colors, wallpaper, name): + self.colors = colors + self.comp_colors = comp_colors + self.wallpaper = wallpaper + self.name = name + def toDict(self): + return { + "name" : self.name, + "colors" : self.colors, + "comp_colors": self.comp_colors, + "wallpaper" : self.wallpaper, + } + + +def getAllThemes(theme_dir): + themes = [] + themes_in_dir = [file for file in os.listdir(theme_dir) if os.path.isfile(os.path.join(theme_dir, file)) and file.endswith('.theme')] + + for file in themes_in_dir: + theme_location = theme_dir + file + themes.append(load_theme(theme_location)) + return themes + + +def save_theme(hex_colors, hex_compliments, wallpaper_location, save_location, theme_name): """ Save a theme to the disk at a specified location as a json object. """ - - theme = Theme(hex_colors, hex_compliments, wallpaper_location) - + theme = Theme(hex_colors, hex_compliments, wallpaper_location, theme_name) with open(save_location, 'w') as file: json.dump(theme.toDict(), file) print('[bold green]color palette saved successfully') + def load_theme(save_location): """ Load a theme from disk at a specified location @@ -21,3 +46,4 @@ def load_theme(save_location): with open(save_location, 'r') as file: data = json.loads(file.read()) return data + diff --git a/src/user_interface.py b/src/user_interface.py index bcc5ceb..1ac0636 100644 --- a/src/user_interface.py +++ b/src/user_interface.py @@ -15,6 +15,7 @@ def colorPickerUI(img_path: str, num_palettes: int) -> tuple: final_colors, final_compliments = selectColorsFromPalette(hex_colors, hex_compliments) return final_colors, final_compliments + def displayColors(hex_colors: list, hex_compliments: list): constrast_levels = color_engine.checkContrast(hex_colors, hex_compliments) main_colors = '' @@ -50,6 +51,7 @@ def selectPalette(img_path: str, num_palettes: int) -> tuple: return hex_colors, hex_compliments + def selectColorsFromPalette(hex_colors: list, hex_compliments: list) -> tuple: selectedColors = [] selected = False @@ -74,6 +76,7 @@ def selectColorsFromPalette(hex_colors: list, hex_compliments: list) -> tuple: return final_colors, final_compliments + def pickRandomWallpaper(walls_dir: str) -> str: confirmed = False history = [] @@ -87,8 +90,6 @@ def pickRandomWallpaper(walls_dir: str) -> str: if wallpaper in history: continue history.append(wallpaper) - # TODO: Replace image preview with something native to python - # (Currently borrowing viu module from Rust) os.system(f'viu {wallpaper}') print(f'picked wallpaper: {wallpaper}') print('[bold](a)ccept (r)etry') @@ -99,6 +100,7 @@ def pickRandomWallpaper(walls_dir: str) -> str: return wallpaper + def saveThemePrompt(hex_colors, hex_compliments, wallpaper_location, theme_location): print('[bold green]Save configuration as preset? (y/n)') do_save = input('>') @@ -107,6 +109,36 @@ def saveThemePrompt(hex_colors, hex_compliments, wallpaper_location, theme_locat theme_name = input('>') theme_path = theme_location + theme_name + ".theme" - manage_saves.save_theme(hex_colors, hex_compliments, wallpaper_location, theme_path) + manage_saves.save_theme(hex_colors, hex_compliments, wallpaper_location, theme_path, theme_name) print(f'[bold green]Theme {theme_name} saved!') - + + +def themeSelector(theme_dir): + all_themes = manage_saves.getAllThemes(theme_dir) + num_themes = len(all_themes) - 1 + + + for i, theme in enumerate(all_themes): + colors = '' + comp_colors = '' + for j in range(len(theme['colors'])): + colors += f'[on {theme['colors'][j]}] [/on {theme['colors'][j]}]' + comp_colors += f'[on {theme['comp_colors'][j]}] [/on {theme['comp_colors'][j]}]' + print(f'{colors} Theme ({i}): {theme['name']}\n{comp_colors} Wallpaper: {theme['wallpaper']}') + os.system(f'viu {theme['wallpaper']} -w 50') + print('[bold green]Select theme (IE, 4)') + + + while True: + response = input('>') + if response.isdigit(): + if int(response) <= num_themes: + # valid selection + return all_themes[int(response)] + else: + print(f'[bold red]invalid selection, please enter a valid integer [0 - {num_themes}]') + continue + else: + print(f'[bold red]invalid selection, please enter a valid integer [0 - {num_themes}]') + continue + |
