WallPyPer/src/wallpyper.py

85 lines
2.4 KiB
Python
Executable File

#!/usr/bin/python3
from wallpyperFuncs import *
def main():
if len(sys.argv) == 2 and sys.argv[1] in ("help","--help","-h"):
printHelpInfo()
theme = ""
if len(sys.argv) == 1: theme = None
elif len(sys.argv) == 2 and sys.argv[1] in ("quit", "stop"): killLastSession(); sys.exit(0)
elif len(sys.argv) >= 2 and sys.argv[1] == "set":
if len(sys.argv) == 2:
themes = getThemes()
try:
import dmenu
theme = dmenu.show(themes, prompt='Themes:')
except ModuleNotFoundError:
try:
from rofi import Rofi
r = Rofi()
theme = themes[r.select('Themes:', themes)[0]]
except ModuleNotFoundError: printHelpInfo()
elif len(sys.argv) == 3:
theme = sys.argv[2]
else: printHelpInfo()
else: printHelpInfo()
config = getConfig()
if theme == None:
theme = config["default_theme"]
if theme not in config:
print(f'There is no "{theme}" in config')
exit(0)
killLastSession()
if "night" in config[theme]:
nightTime = None
if "night_time" in config[theme]:
nightTime = config[theme]["night_time"].split("-")
elif "default_night_time" in config:
nightTime = config["default_night_time"].split("-")
if nightTime != None:
nightMode = False
currentTime = datetime.now().strftime("%H:%M:%S")
if timeDiff(currentTime, nightTime[0]+":0") > timeDiff(currentTime, nightTime[1]+":0"):
nightMode = True
while True:
threadIsAlive = True
mode = Thread(target=setTheme, args=(theme, nightMode), daemon = True)
mode.start()
currentTime = datetime.now().strftime("%H:%M:%S")
if nightMode:
sleep(timeDiff(currentTime, nightTime[1]+":0"))
else:
sleep(timeDiff(currentTime, nightTime[0]+":0"))
nightMode = not nightMode
threadIsAlive = False
mode.join()
else:
setTheme(theme)
else:
setTheme(theme)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass