add night mode for themes
This commit is contained in:
parent
2c73e0e6a5
commit
2f6f6ff725
@ -3,11 +3,11 @@
|
||||
from wallpyperFuncs import *
|
||||
|
||||
def main():
|
||||
theme = ""
|
||||
|
||||
if len(sys.argv) == 2 and sys.argv[1] in ("help","--help","-h"):
|
||||
printHelpInfo()
|
||||
else:
|
||||
|
||||
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":
|
||||
@ -23,15 +23,62 @@ def main():
|
||||
|
||||
r = Rofi()
|
||||
theme = themes[r.select('Themes:', themes)[0]]
|
||||
except ModuleNotFoundError:
|
||||
printHelpInfo()
|
||||
exit(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
|
||||
|
@ -4,6 +4,7 @@ import random
|
||||
import sys
|
||||
from time import sleep
|
||||
from threading import Thread
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def printHelpInfo():
|
||||
@ -12,6 +13,7 @@ Commands:
|
||||
quit, stop shutdown wallpyper
|
||||
set <theme> set <theme> theme
|
||||
help, --help, -h print this information""")
|
||||
sys.exit(0)
|
||||
|
||||
def runCommand(commandName, output=False):
|
||||
if output:
|
||||
@ -66,21 +68,12 @@ def setRandomWallpaper(path):
|
||||
setWallpaper(wallpaperName)
|
||||
|
||||
|
||||
def setDynamicWallpaper(path, delay):
|
||||
while True:
|
||||
setRandomWallpaper(path)
|
||||
sleep(delay)
|
||||
|
||||
|
||||
def setTheme(themeName = None):
|
||||
killLastSession()
|
||||
|
||||
def setTheme(themeName = None, nightMode = False):
|
||||
config = getConfig()
|
||||
|
||||
if themeName == None:
|
||||
themeName = config["default_theme"]
|
||||
|
||||
|
||||
if nightMode:
|
||||
theme = config[themeName]["night"]
|
||||
else:
|
||||
theme = config[themeName]
|
||||
|
||||
if theme["type"] == "static":
|
||||
@ -98,12 +91,13 @@ def setTheme(themeName = None):
|
||||
|
||||
delay = delay[0] + delay[1]*60 + delay[2]*3600
|
||||
|
||||
wallpyperThread = Thread(target=setDynamicWallpaper, args=(theme["path"],delay,))
|
||||
wallpyperThread.start()
|
||||
global threadIsAlive
|
||||
while threadIsAlive:
|
||||
setRandomWallpaper(theme["path"])
|
||||
sleep(delay)
|
||||
|
||||
else:
|
||||
printHelpInfo()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def getThemes():
|
||||
@ -116,3 +110,34 @@ def getThemes():
|
||||
themes.append(e)
|
||||
|
||||
return themes
|
||||
|
||||
def timeDiff(time1, time2):
|
||||
time1 = list(map(int,time1.split(":")))
|
||||
time2 = list(map(int,time2.split(":")))
|
||||
|
||||
seconds = 0
|
||||
|
||||
diff = 0
|
||||
while (time1[2]+diff)%60 != time2[2]:
|
||||
diff+=1
|
||||
|
||||
seconds+=diff
|
||||
|
||||
if (diff + time1[2] > 60): time1[1]+=1
|
||||
|
||||
diff = 0
|
||||
while (time1[1]+diff)%60 != time2[1]:
|
||||
diff+=1
|
||||
|
||||
seconds+=diff*60
|
||||
|
||||
if (diff + time1[1] > 60): time1[0]+=1
|
||||
|
||||
diff = 0
|
||||
|
||||
while (time1[0]+diff)%24 != time2[0]:
|
||||
diff+=1
|
||||
|
||||
seconds+=diff*60*60
|
||||
|
||||
return seconds
|
Loading…
Reference in New Issue
Block a user