From 25b3cebcc2b4c596b2670821681a84207132166d Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sun, 22 Jun 2025 20:09:20 +0545 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=85=20style(config,=20gui):=20replace?= =?UTF-8?q?=20hardcoded=20paths=20with=20user-specific=20paths=20in=20conf?= =?UTF-8?q?ig=20and=20gui=20modules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.py | 16 ++++++++-------- config/data.py | 4 +--- config/settings/constants.py | 2 +- config/settings/gui.py | 12 ++++-------- config/settings/utils.py | 28 ++++++++++++---------------- main.py | 2 +- 6 files changed, 27 insertions(+), 37 deletions(-) diff --git a/config/config.py b/config/config.py index fa97473..f86acbd 100644 --- a/config/config.py +++ b/config/config.py @@ -1,5 +1,3 @@ -from fabric import Application -import shutil import os import sys from pathlib import Path @@ -18,11 +16,13 @@ def _configure_sys_path_for_direct_execution(): if str(project_root) not in sys.path: sys.path.insert(0, str(project_root)) - _configure_sys_path_for_direct_execution() +import shutil -if __name__ == "__main__" and (__package__ is None or __package__ == ""): +from fabric import Application + +if __name__ == "__main__" and (__package__ is None or __package__ == ''): from config.data import APP_NAME, APP_NAME_CAP from config.settings.gui import HyprConfGUI from config.settings.utils import load_bind_vars @@ -40,12 +40,12 @@ def open_config(): show_lock_checkbox = True dest_lock = os.path.expanduser("~/.config/hypr/hyprlock.conf") - src_lock = os.path.expanduser(f"~/.config/{APP_NAME_CAP}/config/hypr/hyprlock.conf") + src_lock = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/hyprlock.conf") if not os.path.exists(dest_lock) and os.path.exists(src_lock): try: os.makedirs(os.path.dirname(dest_lock), exist_ok=True) shutil.copy(src_lock, dest_lock) - show_lock_checkbox = False + show_lock_checkbox = False print(f"Copied default hyprlock config to {dest_lock}") except Exception as e: print(f"Error copying default hyprlock config: {e}") @@ -53,7 +53,7 @@ def open_config(): show_idle_checkbox = True dest_idle = os.path.expanduser("~/.config/hypr/hypridle.conf") - src_idle = os.path.expanduser(f"~/.config/{APP_NAME_CAP}/config/hypr/hypridle.conf") + src_idle = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/hypridle.conf") if not os.path.exists(dest_idle) and os.path.exists(src_idle): try: os.makedirs(os.path.dirname(dest_idle), exist_ok=True) @@ -69,7 +69,7 @@ def open_config(): show_lock_checkbox=show_lock_checkbox, show_idle_checkbox=show_idle_checkbox, application=app, - on_destroy=lambda *_: app.quit(), + on_destroy=lambda *_: app.quit() ) app.add_window(window) diff --git a/config/data.py b/config/data.py index 68d4d89..dbe70f0 100644 --- a/config/data.py +++ b/config/data.py @@ -40,9 +40,7 @@ DOCK_THEME = "Pills" def load_config(): """Load the configuration from config.json""" - config_path = os.path.expanduser( - f"~/.config/{APP_NAME_CAP}/config/json/config.json" - ) + config_path = os.path.expanduser(f"~/{APP_NAME_CAP}/config/json/config.json") config = {} if os.path.exists(config_path): diff --git a/config/settings/constants.py b/config/settings/constants.py index 1abe5bb..ce210cb 100644 --- a/config/settings/constants.py +++ b/config/settings/constants.py @@ -8,7 +8,7 @@ from config.data import ( SOURCE_STRING = f""" # {APP_NAME_CAP} -source = ~/.config/{APP_NAME_CAP}/config/hypr/{APP_NAME}.conf +source = ~/{APP_NAME_CAP}/config/hypr/{APP_NAME}.conf """ DEFAULTS = { diff --git a/config/settings/gui.py b/config/settings/gui.py index 53429c4..9b7800a 100644 --- a/config/settings/gui.py +++ b/config/settings/gui.py @@ -907,7 +907,7 @@ class HyprConfGUI(Window): print(f"{start_time:.4f}: Background task started.") config_json = os.path.expanduser( - f"~/.config/{APP_NAME_CAP}/config/json/config.json" + f"~/{APP_NAME_CAP}/config/json/config.json" ) os.makedirs(os.path.dirname(config_json), exist_ok=True) try: @@ -935,9 +935,7 @@ class HyprConfGUI(Window): if replace_lock: print(f"{time.time():.4f}: Replacing hyprlock config...") - src = os.path.expanduser( - f"~/.config/{APP_NAME_CAP}/config/hypr/hyprlock.conf" - ) + src = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/hyprlock.conf") dest = os.path.expanduser("~/.config/hypr/hyprlock.conf") if os.path.exists(src): backup_and_replace(src, dest, "Hyprlock") @@ -947,9 +945,7 @@ class HyprConfGUI(Window): if replace_idle: print(f"{time.time():.4f}: Replacing hypridle config...") - src = os.path.expanduser( - f"~/.config/{APP_NAME_CAP}/config/hypr/hypridle.conf" - ) + src = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/hypridle.conf") dest = os.path.expanduser("~/.config/hypr/hypridle.conf") if os.path.exists(src): backup_and_replace(src, dest, "Hypridle") @@ -987,7 +983,7 @@ class HyprConfGUI(Window): print(f"{time.time():.4f}: Finished start_config().") print(f"{time.time():.4f}: Initiating Modus restart using Popen...") - main_py = os.path.expanduser(f"~/.config/{APP_NAME_CAP}/main.py") + main_py = os.path.expanduser(f"~/{APP_NAME_CAP}/main.py") kill_cmd = f"killall {APP_NAME}" start_cmd = ["uwsm", "app", "--", "python", main_py] try: diff --git a/config/settings/utils.py b/config/settings/utils.py index b23b9d6..4096f64 100644 --- a/config/settings/utils.py +++ b/config/settings/utils.py @@ -76,12 +76,12 @@ def ensure_matugen_config(): }, "templates": { "hyprland": { - "input_path": f"~/.config/{APP_NAME_CAP}/config/matugen/templates/hyprland-colors.conf", - "output_path": f"~/.config/{APP_NAME_CAP}/config/hypr/colors.conf", + "input_path": f"~/{APP_NAME_CAP}/config/matugen/templates/hyprland-colors.conf", + "output_path": f"~/{APP_NAME_CAP}/config/hypr/colors.conf", }, f"{APP_NAME}": { - "input_path": f"~/.config/{APP_NAME_CAP}/config/matugen/templates/{APP_NAME}.css", - "output_path": f"~/.config/{APP_NAME_CAP}/styles/colors.css", + "input_path": f"~/{APP_NAME_CAP}/config/matugen/templates/{APP_NAME}.css", + "output_path": f"~/{APP_NAME_CAP}/styles/colors.css", "post_hook": f"fabric-cli exec {APP_NAME} 'app.set_css()' &", }, }, @@ -124,10 +124,8 @@ def ensure_matugen_config(): print(f"Error writing matugen config to {config_path}: {e}") current_wall = os.path.expanduser("~/.current.wall") - hypr_colors = os.path.expanduser( - f"~/.config/{APP_NAME_CAP}/config/hypr/colors.conf" - ) - css_colors = os.path.expanduser(f"~/.config/{APP_NAME_CAP}/styles/colors.css") + hypr_colors = os.path.expanduser(f"~/{APP_NAME_CAP}/config/hypr/colors.conf") + css_colors = os.path.expanduser(f"~/{APP_NAME_CAP}/styles/colors.css") if ( not os.path.exists(current_wall) @@ -140,7 +138,7 @@ def ensure_matugen_config(): image_path = "" if not os.path.exists(current_wall): example_wallpaper_path = os.path.expanduser( - f"~/.config/{APP_NAME_CAP}/assets/wallpapers_example/example-1.jpg" + f"~/{APP_NAME_CAP}/assets/wallpapers_example/example-1.jpg" ) if os.path.exists(example_wallpaper_path): try: @@ -194,9 +192,7 @@ def load_bind_vars(): # Usar .copy() para no modificar DEFAULTS accidentalmente bind_vars.update(settings_constants.DEFAULTS.copy()) - config_json = os.path.expanduser( - f"~/.config/{APP_NAME_CAP}/config/json/config.json" - ) + config_json = os.path.expanduser(f"~/{APP_NAME_CAP}/config/json/config.json") if os.path.exists(config_json): try: with open(config_json, "r") as f: @@ -250,17 +246,17 @@ def generate_hyprconf() -> str: is_vertical = bar_position in ["Left", "Right"] animation_type = "slidefadevert" if is_vertical else "slidefade" - return f"""exec-once = uwsm-app $(python {home}/.config/{APP_NAME_CAP}/main.py) + return f"""exec-once = uwsm-app $(python {home}/{APP_NAME_CAP}/main.py) exec = pgrep -x "hypridle" > /dev/null || uwsm app -- hypridle exec = uwsm app -- swww-daemon exec-once = wl-paste --type text --watch cliphist store exec-once = wl-paste --type image --watch cliphist store $fabricSend = fabric-cli exec {APP_NAME} -$axMessage = notify-send "Modus" "FIRE IN THE HOLE‼️🗣️🔥🕳️" -i "{home}/{AP.config / P_NAME_CAP}/assets/modus.png" -A "🗣️" -A "🔥" -A "🕳️" -a "Source Code" +$axMessage = notify-send "Modus" "FIRE IN THE HOLE‼️🗣️🔥🕳️" -i "{home}/{APP_NAME_CAP}/assets/modus.png" -A "🗣️" -A "🔥" -A "🕳️" -a "Source Code" # Reload {APP_NAME_CAP} -bind = {bind_vars.get("prefix_restart", "ALT SHIFT")}, {bind_vars.get("suffix_restart", "R")}, exec, killall {APP_NAME}; uwsm-app $(python {home}/.config/{APP_NAME_CAP}/main.py) +bind = {bind_vars.get("prefix_restart", "ALT SHIFT")}, {bind_vars.get("suffix_restart", "R")}, exec, killall {APP_NAME}; uwsm-app $(python {home}/{APP_NAME_CAP}/main.py) # Message bind = {bind_vars.get("prefix_msg", "SUPER")}, {bind_vars.get("suffix_msg", "A")}, exec, $Message # Application Switcher @@ -283,7 +279,7 @@ bind = {bind_vars.get("prefix_power", "SUPER")}, {bind_vars.get("suffix_power", # Toggle Caffeine bind = {bind_vars.get("prefix_caffeine", "SUPER SHIFT")}, {bind_vars.get("suffix_caffeine", "M")}, exec, $fabricSend "launcher.show_launcher('caffeine on', external=True)" # Settings -bind = {bind_vars.get("prefix_settings", "SUPER")}, {bind_vars.get("suffix_settings", "I")}, exec, uwsm-app $(python {home}/.config/{APP_NAME_CAP}/config/config.py) # Settings +bind = {bind_vars.get("prefix_settings", "SUPER")}, {bind_vars.get("suffix_settings", "I")}, exec, uwsm-app $(python {home}/{APP_NAME_CAP}/config/config.py) # Settings # Restart Modus bind = {bind_vars.get("prefix_restart_inspector", "SUPER CTRL ALT")}, {bind_vars.get("suffix_restart_inspector", "B")}, exec, killall {APP_NAME}; uwsm-app $(GTK_DEBUG=interactive python {home}/.config/{APP_NAME_CAP}/main.py) # Restart with inspector diff --git a/main.py b/main.py index 621878b..52dfa6a 100644 --- a/main.py +++ b/main.py @@ -35,7 +35,7 @@ if __name__ == "__main__": current_wallpaper = os.path.expanduser("~/.current.wall") if not os.path.exists(current_wallpaper): example_wallpaper = os.path.expanduser( - f"~/.config/{APP_NAME_CAP}/assets/wallpapers_example/example-1.png" + f"~/{APP_NAME_CAP}/assets/wallpapers_example/example-1.png" ) os.symlink(example_wallpaper, current_wallpaper)