summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/color_engine.py18
-rw-r--r--src/instant_rice.py2
-rw-r--r--src/load_config.py46
-rw-r--r--src/update_i3.py10
-rw-r--r--src/user_interface.py8
5 files changed, 54 insertions, 30 deletions
diff --git a/src/color_engine.py b/src/color_engine.py
index c24450b..7a177fb 100644
--- a/src/color_engine.py
+++ b/src/color_engine.py
@@ -50,9 +50,17 @@ def checkContrast(hex_color_list: list, hex_compliment_list: list) -> list:
return contrast_values
-def relativeLuminance(color: list):
-
- threshold = 0.03928 # this whole function is magic constants lol
+def relativeLuminance(color: list) -> float:
+ """
+ Determines the luminance of color. The luminance allows us to
+ compute the contrast between two colors by comparing their
+ relative luminance.
+
+ The magic constants in this function are all taken from the following
+ description of relative luminance:
+ https://www.w3.org/TR/WCAG20/#relativeluminancedef
+ """
+ threshold = 0.03928
channels = []
for channel in color:
@@ -86,12 +94,12 @@ def hexToRGB(hex_value: str) -> tuple:
Takes in a list of Hex values and returns a tuple of those colors as rgb values
"""
hex_value = hex_value.lstrip('#')
- return tuple(int(hex_value[i:i+2], 16) for i in (0, 2, 4)) # Magic :DDDDDD
+ 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:
hex_value = color.lstrip('#')
- colors.append(tuple(int(hex_value[i:i+2], 16) for i in (0, 2, 4))) # Magic :DDDDDD
+ colors.append(tuple(int(hex_value[i:i+2], 16) for i in (0, 2, 4)))
return colors
diff --git a/src/instant_rice.py b/src/instant_rice.py
index e13f67b..e94dc64 100644
--- a/src/instant_rice.py
+++ b/src/instant_rice.py
@@ -25,6 +25,6 @@ if __name__ == '__main__':
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)
+ 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 dbc0d81..e28e9c3 100644
--- a/src/load_config.py
+++ b/src/load_config.py
@@ -9,19 +9,21 @@ class systemConfig:
file for instant rice.
"""
- i3_config = ""
- i3_lock_image = ""
- polybar_config = ""
- wallpaper_directory = ""
- rofi_config = ""
- username = ""
- rice_config = ""
- #instant rice configuration settings
- num_palettes = 15
- use_dmenu = False
- generate_i3_lock = False
-
+
def __init__(self):
+ self.i3_config = ""
+ self.i3_lock_image = ""
+ self.polybar_config = ""
+ self.wallpaper_directory = ""
+ self.rofi_config = ""
+ self.username = ""
+ self.rice_config = ""
+ #instant rice configuration settings
+ self.num_palettes = 15
+ self.use_dmenu = False
+ self.generate_i3_lock = False
+ self.menu_keybind = ""
+
print('[bold green]Loading configuration files')
#Grab username to find configuration files
@@ -64,19 +66,29 @@ class systemConfig:
for i, line in enumerate(data):
if "use_dmenu" in line:
match = line.split(' ')
- self.use_dmenu = True if match[2] == 'True' else False
+ self.use_dmenu = True if match[2].lower() == 'true' else False
+
if "generate_i3_lock" in line:
match = line.split(' ')
- self.generate_i3_lock = True if match[2] == 'True' else False
+ self.generate_i3_lock = True if match[2].lower() == 'true' else False
+
if "wallpaper_directory" in line:
match = line.strip().split(' ')
if not match[2].endswith('/'):
match[2] += '/'
- self.wallpaper_directory = match[2]
+ if os.path.exists(match[2]):
+ self.wallpaper_directory = match[2]
+ else:
+ print(f'Invalid configuration parameter at line {i}:\n{line}Directory does not exist; Please fix error before rerunning.')
+
if "num_palettes" in line:
match = line.strip().split(' ')
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.')
+ print(f'Invalid configuration parameter at line {i}:\n{line}Using default configuration of 15 palettes.')
+
+ if "menu_keybind" in line:
+ match = line.strip().split(' ')
+ self.menu_keybind = match[2]
+ print(self.menu_keybind)
diff --git a/src/update_i3.py b/src/update_i3.py
index 1d4b792..3fc8858 100644
--- a/src/update_i3.py
+++ b/src/update_i3.py
@@ -12,12 +12,13 @@ def updatei3Theme(
update_i3_lock: bool,
dmenu: bool,
lock_img_path: str,
+ menu_keybind: str,
) -> None:
print('[bold red]Updating i3 color scheme')
- update_i3_colors(config_path, colors, compliments, dmenu, img_path)
+ update_i3_colors(config_path, colors, compliments, dmenu, img_path, menu_keybind)
if update_i3_lock:
change_i3_lock_img(img_path, lock_img_path)
@@ -49,7 +50,8 @@ def update_i3_colors(
colors: list,
compliments: list,
dmenu: bool,
- img_path: str
+ img_path: str,
+ menu_keybind: str,
) -> None:
data = ''
with open(config_path, 'r') as file:
@@ -72,10 +74,10 @@ def update_i3_colors(
if "set $bgimage" in line:
data[i] = 'set $bgimage ' + img_path + '\n'
# update i3 lock image
- if "bindsym $mod+d exec --no-startup-id dmenu_run" in line:
+ if f"bindsym {menu_keybind} exec --no-startup-id dmenu_run" in line:
if dmenu:
print('[bold red]Updating Dmenu color scheme')
- data[i] = f"bindsym $mod+d exec --no-startup-id dmenu_run -nb '{colors[0]}' -sf '{compliments[0]}' -sb '{colors[1]}' -nf '{compliments[1]}'\n"
+ data[i] = f"bindsym {menu_keybind} exec --no-startup-id dmenu_run -nb '{colors[0]}' -sf '{compliments[0]}' -sb '{colors[1]}' -nf '{compliments[1]}'\n"
with open(config_path, 'w') as file:
diff --git a/src/user_interface.py b/src/user_interface.py
index 4162d1e..0adc765 100644
--- a/src/user_interface.py
+++ b/src/user_interface.py
@@ -50,7 +50,8 @@ def selectPalette(img_path: str, num_palettes: int) -> tuple:
return hex_colors, hex_compliments
-def selectColorsFromPalette(hex_colors, hex_compliments):
+def selectColorsFromPalette(hex_colors: list, hex_compliments: list) -> tuple:
+ selectedColors = []
selected = False
while not selected:
print('[bold blue]Select top 3 colors from list in order Primary, Secondary, Accent (IE, "4 10 6")')
@@ -62,7 +63,7 @@ def selectColorsFromPalette(hex_colors, hex_compliments):
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 = []
@@ -73,10 +74,11 @@ def selectColorsFromPalette(hex_colors, hex_compliments):
return final_colors, final_compliments
-def pickRandomWallpaper(walls_dir) -> str:
+def pickRandomWallpaper(walls_dir: str) -> str:
confirmed = False
history = []
num_wallpapers = len(os.listdir(walls_dir))
+ wallpaper = ''
while not confirmed:
if len(history) == num_wallpapers:
print('[bold blue] Wallpapers exhausted. Resetting history...')