summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/color_engine.py8
-rw-r--r--src/get_args.py23
-rw-r--r--src/instant_rice.py17
-rw-r--r--src/load_config.py9
-rw-r--r--src/manage_saves.py32
-rw-r--r--src/theme.py12
-rw-r--r--src/update_i3.py3
-rw-r--r--src/user_interface.py28
8 files changed, 88 insertions, 44 deletions
diff --git a/src/color_engine.py b/src/color_engine.py
index 7a177fb..504e84b 100644
--- a/src/color_engine.py
+++ b/src/color_engine.py
@@ -24,9 +24,9 @@ def compColors(color_list: list) -> list:
"""
compliments = []
for color in color_list:
- curr_hex = color[1:] # slice off the # from the hex code
+ curr_hex = color[1:]
rgb = (curr_hex[0:2], curr_hex[2:4], curr_hex[4:6])
- comp = ['%02X' % (255 - int(a, 16)) for a in rgb] # magic :D
+ comp = ['%02X' % (255 - int(a, 16)) for a in rgb]
compliments.append('#' + ''.join(comp))
return compliments
@@ -50,6 +50,7 @@ def checkContrast(hex_color_list: list, hex_compliment_list: list) -> list:
return contrast_values
+
def relativeLuminance(color: list) -> float:
"""
Determines the luminance of color. The luminance allows us to
@@ -76,7 +77,6 @@ def relativeLuminance(color: list) -> float:
return luminance
-
def rgbToHex(input_values: list) -> list:
"""
Takes in a list of RBG color values and returns a list of those same colors as hex values
@@ -89,6 +89,7 @@ def rgbToHex(input_values: list) -> list:
hex_list.append('#{:02x}{:02x}{:02x}'.format(red, green, blue))
return hex_list
+
def hexToRGB(hex_value: str) -> tuple:
"""
Takes in a list of Hex values and returns a tuple of those colors as rgb values
@@ -96,6 +97,7 @@ def hexToRGB(hex_value: str) -> tuple:
hex_value = hex_value.lstrip('#')
return tuple(int(hex_value[i:i+2], 16) for i in (0, 2, 4))
+
def hexToRGB_list(hex_list: list) -> list:
colors = []
for color in hex_list:
diff --git a/src/get_args.py b/src/get_args.py
index 45f41cf..f878e77 100644
--- a/src/get_args.py
+++ b/src/get_args.py
@@ -11,21 +11,16 @@ def get_args(args, walls_dir) -> tuple:
initialize = False
reconfigure = False
- color_save = None
+
+ theme = None
+ VALID_ARGS = ['-r', '-p', '--initialize', '--reconfigure']
- # load saved palette
if '-p' in args:
index = args.index('-p')
- try:
- if os.path.isfile(args[index + 1]):
- color_save = manage_saves.load_color_palette(args[index + 1])
- else:
- print(f'[bold red] Error!! invalid argument {args[index + 1]}. -p should be followed by a color palette save')
- exit(2)
- except IndexError:
- print('[bold red]Error!! -p should be followed by location of a color palette save')
- usage(args)
- exit(2)
+ isFile = os.path.isfile(args[index + 1])
+ if isFile == True:
+ print("reached")
+ theme = manage_saves.load_theme(args[index + 1])
if '-r' in args:
img_path = user_interface.pickRandomWallpaper(walls_dir)
@@ -34,13 +29,13 @@ def get_args(args, walls_dir) -> tuple:
if not os.path.exists(img_path) and\
args[1] not in VALID_ARGS:
print(f'[bold red]ERROR: invalid image path {os.getcwd()}/{args[1]}')
- exit(3)
+ exit(2)
if '--initialize' in args:
initialize = True
if '--reconfigure' in args:
reconfigure = True
- return img_path, initialize, reconfigure, color_save
+ return img_path, initialize, reconfigure, theme
def usage(args) -> None:
diff --git a/src/instant_rice.py b/src/instant_rice.py
index e94dc64..4102fa1 100644
--- a/src/instant_rice.py
+++ b/src/instant_rice.py
@@ -4,7 +4,6 @@ import user_interface
import update_rofi
import update_i3
import update_polybar
-import initialize_i3
import initialize_rofi
from get_args import get_args,usage
from load_config import systemConfig
@@ -14,17 +13,29 @@ if __name__ == '__main__':
if len(sys.argv) > 1:
config = systemConfig()
- img_path, initialize, reconfigure, color_save = get_args(sys.argv, config.wallpaper_directory)
+
+ img_path, initialize, reconfigure, theme = get_args(sys.argv, config.wallpaper_directory)
+
if initialize:
initialize_rofi.reconfigureRofi()
print('[bold green]Initialization Completed. Exiting...')
exit(0)
- hex_colors, hex_compliments = user_interface.colorPickerUI(img_path, config.num_palettes)
+
+ if theme == None:
+ hex_colors, hex_compliments = user_interface.colorPickerUI(img_path, config.num_palettes)
+ user_interface.saveThemePrompt(hex_colors, hex_compliments, img_path, config.theme_directory)
+ else:
+ hex_colors = theme['colors']
+ hex_compliments = theme['comp_colors']
+
if config.polybar_config:
update_polybar.updatePolybarTheme(config.polybar_config, hex_colors, hex_compliments)
+
if config.rofi_config:
update_rofi.updateRofiTheme(config.rofi_config, hex_colors, hex_compliments)
+
if config.i3_config:
update_i3.updatei3Theme(config.i3_config, img_path, hex_colors, hex_compliments, config.generate_i3_lock, config.use_dmenu, config.i3_lock_image, config.menu_keybind)
+
else:
usage(sys.argv)
diff --git a/src/load_config.py b/src/load_config.py
index e28e9c3..5fe99b9 100644
--- a/src/load_config.py
+++ b/src/load_config.py
@@ -23,6 +23,7 @@ class systemConfig:
self.use_dmenu = False
self.generate_i3_lock = False
self.menu_keybind = ""
+ self.theme_directory = ""
print('[bold green]Loading configuration files')
@@ -38,6 +39,7 @@ class systemConfig:
self.polybar_config = f'/home/{self.username}/.config/polybar/config.ini'
if os.path.exists(f'/home/{self.username}/.config/rofi/config.rasi'):
self.rofi_config = f'/home/{self.username}/.config/rofi/config.rasi'
+
if os.path.exists(f'/home/{self.username}/.config/instantrice/'):
self.rice_config = f'/home/{self.username}/.config/instantrice/config.rice'
self.get_user_preferences()
@@ -86,6 +88,13 @@ class systemConfig:
if match[2].isdigit():
self.num_palettes = int(match[2])
else:
+ print(f'Invalid configuration parameter at line {i}:\n{line}.\nUsing default \
+ configuration of 15 palettes.')
+ if "theme_directory" in line:
+ match = line.strip().split(' ')
+ if not match[2].endswith('/'):
+ match[2] += '/'
+ self.theme_directory = match[2]
print(f'Invalid configuration parameter at line {i}:\n{line}Using default configuration of 15 palettes.')
if "menu_keybind" in line:
diff --git a/src/manage_saves.py b/src/manage_saves.py
index 1ada559..44ce2a3 100644
--- a/src/manage_saves.py
+++ b/src/manage_saves.py
@@ -1,21 +1,23 @@
-import pickle
from rich import print
-
-def save_color_palette(hex_colors, hex_compliments, save_directory):
+from theme import Theme
+import json
+def save_theme(hex_colors, hex_compliments, wallpaper_location, save_location):
+ """
+ Save a theme to the disk at a specified location as a json object.
+ """
- colors = (hex_colors, hex_compliments)
- with open(save_directory, 'wb') as file:
- pickle.dump(colors, file, pickle.HIGHEST_PROTOCOL)
-
- print('[bold green]color palette saved successfully')
+ theme = Theme(hex_colors, hex_compliments, wallpaper_location)
-def load_color_palette(save_location):
- with open(save_location, 'rb') as file:
- try:
- data = pickle.load(file)
- except:
- print('invalid arguments. -p should be followed by a color palette save')
- exit(2)
+ 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
+ """
+ with open(save_location, 'r') as file:
+ data = json.loads(file.read())
return data
diff --git a/src/theme.py b/src/theme.py
new file mode 100644
index 0000000..4bda7e1
--- /dev/null
+++ b/src/theme.py
@@ -0,0 +1,12 @@
+
+class Theme:
+ def __init__(self, colors, comp_colors, wallpaper):
+ self.colors = colors
+ self.comp_colors = comp_colors
+ self.wallpaper = wallpaper
+ def toDict(self):
+ return {
+ "colors" : self.colors,
+ "comp_colors": self.comp_colors,
+ "wallpaper" : self.wallpaper
+ }
diff --git a/src/update_i3.py b/src/update_i3.py
index 3fc8858..b06b47e 100644
--- a/src/update_i3.py
+++ b/src/update_i3.py
@@ -53,11 +53,12 @@ def update_i3_colors(
img_path: str,
menu_keybind: str,
) -> None:
+
data = ''
+
with open(config_path, 'r') as file:
data = file.readlines()
-
for i, line in enumerate(data):
# update colors
if "set $bgcolor" in line:
diff --git a/src/user_interface.py b/src/user_interface.py
index 0adc765..bcc5ceb 100644
--- a/src/user_interface.py
+++ b/src/user_interface.py
@@ -1,16 +1,17 @@
import os
import random
import color_engine
+import manage_saves
from rich import print
-def colorPickerUI(img_path: str, num_palettes: int, saved_colors = None) -> tuple:
-#display the selected color scheme and ask user if they like it or want to generate a new color scheme
- if saved_colors == None:
- hex_colors, hex_compliments = selectPalette(img_path, num_palettes)
- else:
- hex_colors, hex_compliments = saved_colors
- print(f'[bold green] colors successfully loaded from file')
+
+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
@@ -30,7 +31,6 @@ def displayColors(hex_colors: list, hex_compliments: list):
def selectPalette(img_path: str, num_palettes: int) -> tuple:
-
confirmed = False
hex_colors = None
hex_compliments = None
@@ -98,3 +98,15 @@ def pickRandomWallpaper(walls_dir: str) -> str:
confirmed = True
return wallpaper
+
+def saveThemePrompt(hex_colors, hex_compliments, wallpaper_location, theme_location):
+ print('[bold green]Save configuration as preset? (y/n)')
+ do_save = input('>')
+ if do_save == 'y':
+ print('[bold green]enter theme name')
+ theme_name = input('>')
+ theme_path = theme_location + theme_name + ".theme"
+
+ manage_saves.save_theme(hex_colors, hex_compliments, wallpaper_location, theme_path)
+ print(f'[bold green]Theme {theme_name} saved!')
+