add night mode for themes
This commit is contained in:
parent
2c73e0e6a5
commit
2f6f6ff725
@ -3,35 +3,82 @@
|
|||||||
from wallpyperFuncs import *
|
from wallpyperFuncs import *
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
theme = ""
|
|
||||||
|
|
||||||
if len(sys.argv) == 2 and sys.argv[1] in ("help","--help","-h"):
|
if len(sys.argv) == 2 and sys.argv[1] in ("help","--help","-h"):
|
||||||
printHelpInfo()
|
printHelpInfo()
|
||||||
else:
|
|
||||||
if len(sys.argv) == 1: theme = None
|
theme = ""
|
||||||
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) == 1: theme = None
|
||||||
if len(sys.argv) == 2:
|
elif len(sys.argv) == 2 and sys.argv[1] in ("quit", "stop"): killLastSession(); sys.exit(0)
|
||||||
themes = getThemes()
|
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:
|
try:
|
||||||
import dmenu
|
from rofi import Rofi
|
||||||
|
|
||||||
theme = dmenu.show(themes, prompt='Themes:')
|
r = Rofi()
|
||||||
except ModuleNotFoundError:
|
theme = themes[r.select('Themes:', themes)[0]]
|
||||||
try:
|
except ModuleNotFoundError: printHelpInfo()
|
||||||
from rofi import Rofi
|
elif len(sys.argv) == 3:
|
||||||
|
theme = sys.argv[2]
|
||||||
r = Rofi()
|
|
||||||
theme = themes[r.select('Themes:', themes)[0]]
|
|
||||||
except ModuleNotFoundError:
|
|
||||||
printHelpInfo()
|
|
||||||
exit(0)
|
|
||||||
elif len(sys.argv) == 3:
|
|
||||||
theme = sys.argv[2]
|
|
||||||
else: printHelpInfo()
|
|
||||||
else: printHelpInfo()
|
else: printHelpInfo()
|
||||||
|
else: printHelpInfo()
|
||||||
|
|
||||||
setTheme(theme)
|
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__':
|
if __name__ == '__main__':
|
||||||
main()
|
try:
|
||||||
|
main()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
@ -4,6 +4,7 @@ import random
|
|||||||
import sys
|
import sys
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def printHelpInfo():
|
def printHelpInfo():
|
||||||
@ -12,6 +13,7 @@ Commands:
|
|||||||
quit, stop shutdown wallpyper
|
quit, stop shutdown wallpyper
|
||||||
set <theme> set <theme> theme
|
set <theme> set <theme> theme
|
||||||
help, --help, -h print this information""")
|
help, --help, -h print this information""")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
def runCommand(commandName, output=False):
|
def runCommand(commandName, output=False):
|
||||||
if output:
|
if output:
|
||||||
@ -66,22 +68,13 @@ def setRandomWallpaper(path):
|
|||||||
setWallpaper(wallpaperName)
|
setWallpaper(wallpaperName)
|
||||||
|
|
||||||
|
|
||||||
def setDynamicWallpaper(path, delay):
|
def setTheme(themeName = None, nightMode = False):
|
||||||
while True:
|
|
||||||
setRandomWallpaper(path)
|
|
||||||
sleep(delay)
|
|
||||||
|
|
||||||
|
|
||||||
def setTheme(themeName = None):
|
|
||||||
killLastSession()
|
|
||||||
|
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
|
||||||
if themeName == None:
|
if nightMode:
|
||||||
themeName = config["default_theme"]
|
theme = config[themeName]["night"]
|
||||||
|
else:
|
||||||
|
theme = config[themeName]
|
||||||
theme = config[themeName]
|
|
||||||
|
|
||||||
if theme["type"] == "static":
|
if theme["type"] == "static":
|
||||||
try:
|
try:
|
||||||
@ -98,12 +91,13 @@ def setTheme(themeName = None):
|
|||||||
|
|
||||||
delay = delay[0] + delay[1]*60 + delay[2]*3600
|
delay = delay[0] + delay[1]*60 + delay[2]*3600
|
||||||
|
|
||||||
wallpyperThread = Thread(target=setDynamicWallpaper, args=(theme["path"],delay,))
|
global threadIsAlive
|
||||||
wallpyperThread.start()
|
while threadIsAlive:
|
||||||
|
setRandomWallpaper(theme["path"])
|
||||||
|
sleep(delay)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
printHelpInfo()
|
printHelpInfo()
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
def getThemes():
|
def getThemes():
|
||||||
@ -115,4 +109,35 @@ def getThemes():
|
|||||||
if type(config[e]) == dict:
|
if type(config[e]) == dict:
|
||||||
themes.append(e)
|
themes.append(e)
|
||||||
|
|
||||||
return themes
|
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