diff --git a/src/wallpyperFuncs.py b/src/wallpyperFuncs.py index e5a46f4..b837210 100644 --- a/src/wallpyperFuncs.py +++ b/src/wallpyperFuncs.py @@ -67,6 +67,17 @@ def setRandomWallpaper(path): wallpaperName = path+random.choices(os.listdir(path))[0] setWallpaper(wallpaperName) +def setNextWallpaper(path): + if 'wallpaperIndex' not in globals(): + globals()['wallpaperIndex'] = -1 + + global wallpaperIndex + + wallpaperIndex+=1 + + wallpaperName = path + sorted(os.listdir(path))[wallpaperIndex%len(os.listdir(path))] + setWallpaper(wallpaperName) + def setTheme(themeName = None, nightMode = False): config = getConfig() @@ -77,10 +88,9 @@ def setTheme(themeName = None, nightMode = False): theme = config[themeName] if theme["type"] == "static": - try: - if theme["random"]: setRandomWallpaper(theme["path"]) - else: setWallpaper(theme["url"]) - except KeyError: + if "random" in theme and theme["random"]: + setRandomWallpaper(theme["path"]) + else: setWallpaper(theme["url"]) elif theme["type"] == "dynamic": @@ -91,9 +101,21 @@ def setTheme(themeName = None, nightMode = False): delay = delay[0] + delay[1]*60 + delay[2]*3600 + random = False + + if "random" in theme and theme["random"]: + random = True + + if 'threadIsAlive' not in globals(): + globals()['threadIsAlive'] = True + + global threadIsAlive while threadIsAlive: - setRandomWallpaper(theme["path"]) + if random: + setRandomWallpaper(theme["path"]) + else: + setNextWallpaper(theme["path"]) sleep(delay) else: