File size: 4,590 Bytes
433dc73 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | #!/usr/bin/env python3
"""
==============================================================================
VYRON OS — Phase 5.1 Dynamic Dual-Theme Switching Engine (Vyron UI V2)
Location: /usr/local/bin/vyron-theme
Commands:
vyron-theme dark - Switch to Vyron UI V2 Dark Mode
vyron-theme light - Switch to Vyron UI V2 Light Mode
vyron-theme switch - Toggle between Dark and Light mode
vyron-theme status - Display current active theme
vyron-theme --json - Output JSON theme status
==============================================================================
"""
import os
import sys
import json
import subprocess
CONFIG_DIR = os.path.expanduser("~/.config/vyron")
STATE_FILE = os.path.join(CONFIG_DIR, "theme.state")
DARK_WALLPAPER = "/usr/share/backgrounds/vyron-dark.png"
LIGHT_WALLPAPER = "/usr/share/backgrounds/vyron-light.png"
def run_cmd(args):
try:
res = subprocess.run(args, capture_output=True, text=True, timeout=5)
return res.returncode == 0
except Exception:
return False
def run_cmd_out(args):
try:
res = subprocess.run(args, capture_output=True, text=True, timeout=5)
return res.stdout.strip()
except Exception:
return ""
def get_current_theme():
if os.path.exists(STATE_FILE):
try:
with open(STATE_FILE, "r") as f:
theme = f.read().strip().lower()
if theme in ["dark", "light"]:
return theme
except Exception:
pass
gtk_theme = run_cmd_out(["xfconf-query", "-c", "xsettings", "-p", "/Net/ThemeName"])
if "light" in gtk_theme.lower():
return "light"
return "dark"
def set_xfconf_property(channel, prop, value, prop_type="string"):
run_cmd(["xfconf-query", "-c", channel, "-p", prop, "-s", str(value)])
if not run_cmd(["xfconf-query", "-c", channel, "-p", prop]):
run_cmd(["xfconf-query", "-c", channel, "-p", prop, "-n", "-t", prop_type, "-s", str(value)])
def set_wallpapers(wallpaper_path):
if not os.path.exists(wallpaper_path):
return
out = run_cmd_out(["xfconf-query", "-c", "xfce4-desktop", "-l"])
if out:
for line in out.splitlines():
line = line.strip()
if "last-image" in line or "image-path" in line:
run_cmd(["xfconf-query", "-c", "xfce4-desktop", "-p", line, "-s", wallpaper_path])
set_xfconf_property("xfce4-desktop", "/backdrop/screen0/monitor0/workspace0/last-image", wallpaper_path, "string")
set_xfconf_property("xfce4-desktop", "/backdrop/screen0/monitor0/workspace0/image-style", 5, "int")
def apply_theme(theme):
os.makedirs(CONFIG_DIR, exist_ok=True)
theme = theme.lower()
if theme == "dark":
gtk_theme = "Vyron-V2-Dark"
wm_theme = "Vyron-V2-Dark"
icon_theme = "Vyron-V2-Icons"
wallpaper = DARK_WALLPAPER
else:
gtk_theme = "Vyron-V2-Light"
wm_theme = "Vyron-V2-Light"
icon_theme = "Vyron-V2-Icons"
wallpaper = LIGHT_WALLPAPER
set_xfconf_property("xsettings", "/Net/ThemeName", gtk_theme)
set_xfconf_property("xfwm4", "/general/theme", wm_theme)
set_xfconf_property("xsettings", "/Net/IconThemeName", icon_theme)
set_wallpapers(wallpaper)
try:
with open(STATE_FILE, "w") as f:
f.write(theme)
except Exception:
pass
if os.environ.get("DISPLAY"):
run_cmd(["notify-send", "-a", "Vyron UI V2", f"Vyron Theme: {theme.capitalize()} Active", f"Applied {gtk_theme} theme."])
print(f"Applied Vyron UI V2 {theme.capitalize()} Mode: GTK={gtk_theme}, WM={wm_theme}, Wallpaper={wallpaper}")
def main():
if len(sys.argv) < 2 or sys.argv[1] in ["status", "--status"]:
current = get_current_theme()
if "--json" in sys.argv:
print(json.dumps({"theme": current, "status": "active", "version": "2.0.0"}))
else:
print(f"Vyron UI V2 Theme Status: {current.upper()} MODE")
return
cmd = sys.argv[1].lower()
if cmd == "dark":
apply_theme("dark")
elif cmd == "light":
apply_theme("light")
elif cmd in ["switch", "toggle"]:
current = get_current_theme()
next_theme = "light" if current == "dark" else "dark"
apply_theme(next_theme)
elif cmd == "--json":
print(json.dumps({"theme": get_current_theme(), "status": "active", "version": "2.0.0"}))
else:
print(f"Usage: vyron-theme [dark|light|switch|status|--json]")
sys.exit(1)
if __name__ == "__main__":
main()
|