slides.py 789 B

12345678910111213141516171819202122232425
  1. from glob import glob
  2. import os
  3. class Slides():
  4. def __init__(self,path):
  5. if os.path.isdir(path) != True:
  6. print("PATH is not a dir")
  7. self.files=sorted(glob("%s/*.png" % path), key=self.key_func)
  8. for f in range(0,len(self.files)):
  9. self.files[f] = os.path.abspath(self.files[f])
  10. self.cur_diapo=0
  11. def key_func(self,x):
  12. return int(os.path.split(x)[-1].rsplit('.', 1)[0])
  13. def cur(self):
  14. return dict(type='diapo', value=self.files[self.cur_diapo], progress="%d/%d" %(self.cur_diapo+1, len(self.files)))
  15. def prev(self):
  16. self.cur_diapo=max(self.cur_diapo-1, 0)
  17. return self.cur()
  18. def next(self):
  19. self.cur_diapo=min(self.cur_diapo+1, len(self.files)-1)
  20. return self.cur()