Browse Source

improved animation selection logic, added support for subdirs and symlinks in animation directory

master
Fr3deric 7 years ago
parent
commit
b899ec0fdc
  1. 16
      utils/miniplayer.py

16
utils/miniplayer.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/env python3
import threading
import os
@ -55,6 +55,8 @@ class MiniPlayer(object): @@ -55,6 +55,8 @@ class MiniPlayer(object):
self.maxPlayNext = 3
self.__playNext = []
self.__running = False
self.__anims = {}
self.__anims_remaining = {}
def terminate(self):
self.__running = False
@ -79,10 +81,16 @@ class MiniPlayer(object): @@ -79,10 +81,16 @@ class MiniPlayer(object):
"""
if len(self.__playNext) > 0 and os.path.isfile(self.__playNext[0]):
return self.__playNext.pop(0)
anim = self.__playNext.pop(0)
else:
files = os.listdir(self.__animDir)
return random.choice(files)
anims = { os.path.join(dp, fn) for dp, dns, fns in \
os.walk(self.__animDir, followlinks=True) for fn in fns }
if anims != self.__anims or len(self.__anims_remaining) == 0:
self.__anims = anims
self.__anims_remaining = set(anims)
anim = random.sample(self.__anims_remaining, 1)[0]
self.__anims_remaining.remove(anim)
return anim
def run(self):
"""

Loading…
Cancel
Save