diff options
| author | Chandler J <cjustice2000@gmail.com> | 2024-03-01 21:33:53 -0700 |
|---|---|---|
| committer | Chandler J <cjustice2000@gmail.com> | 2024-03-01 21:33:53 -0700 |
| commit | b956fdd8cd5a4dc0620d02d0f981e507a4ee85e5 (patch) | |
| tree | 8911f2dd2253f5f8223513ac454b508eb7dafbf8 /src | |
| parent | c6062afafacf10e5f4b8bbca03a954966fa58287 (diff) | |
instant rice now reads from a configuration file!
Diffstat (limited to 'src')
| -rw-r--r-- | src/instant_rice.py | 19 | ||||
| -rw-r--r-- | src/load_config.py | 73 | ||||
| -rw-r--r-- | src/update_i3.py | 13 |
3 files changed, 93 insertions, 12 deletions
diff --git a/src/instant_rice.py b/src/instant_rice.py index e0faa5e..a42ec0f 100644 --- a/src/instant_rice.py +++ b/src/instant_rice.py @@ -4,18 +4,19 @@ import update_rofi import update_i3 import update_polybar from get_args import get_args,usage -from paths import Paths - +from load_config import systemConfig + if __name__ == '__main__': + if len(sys.argv) > 1: img_path, update_dmenu, nolock, initialize, reconfigure = get_args(sys.argv) hex_colors, hex_compliments = user_interface.colorPickerUI(img_path) - - if 'polybar' in Paths: - update_polybar.updatePolybarTheme(Paths['polybar'], hex_colors, hex_compliments) - if 'rofi' in Paths: - update_rofi.updateRofiTheme(Paths['rofi'], hex_colors, hex_compliments) - if 'i3' in Paths: - update_i3.updatei3Theme(Paths['i3'], img_path, hex_colors, hex_compliments, nolock, update_dmenu) + config = systemConfig() + 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, nolock, config.use_dmenu, config.i3_lock_image) else: usage(sys.argv) diff --git a/src/load_config.py b/src/load_config.py new file mode 100644 index 0000000..2c894a3 --- /dev/null +++ b/src/load_config.py @@ -0,0 +1,73 @@ +from rich import print +import os + + +class systemConfig: + """ + Class which checks for presence of configuration files for programs + instant rice is compatible with. Additionally, loads the user's configuration + file for instant rice. + """ + + i3_config = "" + i3_lock_image = "" + polybar_config = "" + wallpaper_directory = "" + rofi_config = "" + username = "" + rice_config = "" + + #instant rice configuration settings + use_dmenu = False + generate_i3_lock = False + + def __init__(self): + print('[bold green]Loading configuration files') + + #Grab username to find configuration files + self.username = os.getlogin() + + # check if config files present and make accessible to instantrice + # if file not present do nothing. On user to initialize files + if os.path.exists(f'/home/{self.username}/.config/i3/'): + self.i3_config = f'/home/{self.username}/.config/i3/config' + self.i3_lock_image = f'/home/{self.username}/.config/i3/lock.png' + if os.path.exists(f'/home/{self.username}/.config/polybar/'): + 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() + else: + print(f'[bold red]InstantRice configuration not present.\nDrop default configuration file at /home/{self.username}/.config/InstantRice/config.rice?') + response = input('(a)ccept (d)ecline> ') + if response == "a": + self.rice_config = f'/home/{self.username}/.config/instantrice/config.rice' + self.copy_rice_config() + + def copy_rice_config(self): + + print(f'Creating instant rice configuration directory') + os.makedirs(f'/home/{self.username}/.config/instantrice') + + with open('../data/default_config.rice') as file: + data = file.readlines() + with open(f'{self.rice_config}', 'w') as file: + file.writelines(data) + + def get_user_preferences(self): + + with open(self.rice_config) as file: + data = file.readlines() + + for i, line in enumerate(data): + if "use_dmenu" in line: + match = line.split(' ') + self.use_dmenu = True if match[2] == 'True' else False + if "generate_i3_lock" in line: + match = line.split(' ') + self.generate_i3_lock = True if match[2] == 'True' else False + if "wallpaper_directory" in line: + match = line.split(' ') + self.wallpaper_directory = match[2] diff --git a/src/update_i3.py b/src/update_i3.py index 55509c9..eecc34f 100644 --- a/src/update_i3.py +++ b/src/update_i3.py @@ -3,9 +3,16 @@ import cv2 as cv import os from rich import print -from paths import Paths -def updatei3Theme(config_path: str, img_path: str, colors: list, compliments: list, lock: bool, dmenu: bool) -> None: +def updatei3Theme( + config_path: str, + img_path: str, + colors: list, + compliments: list, + lock: bool, + dmenu: bool, + lock_image_path: str, + ) -> None: print('[bold red]Updating i3 color scheme') data = '' with open(config_path, 'r') as file: @@ -41,7 +48,7 @@ def updatei3Theme(config_path: str, img_path: str, colors: list, compliments: li dim = (int(imgWidth * lock_scale), int(imgHeight * lock_scale)) img = cv.resize(img, dim, interpolation= cv.INTER_AREA) cv.imwrite('lock.png', img) - os.rename('lock.png', Paths['lockscreen'] + 'lock.png') + os.rename('lock.png', lock_image_path) with open(config_path, 'w') as file: file.writelines(data) |
