slides.py 842 B

1234567891011121314151617181920212223242526
  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.data = "{'type'='diapo', 'value'='%s', 'number'='%d', 'total'='%d'}"
  8. self.files=sorted(glob("%s/*.png" % path), key=self.key_func)
  9. for f in range(0,len(self.files)):
  10. self.files[f] = os.path.abspath(self.files[f])
  11. self.cur_diapo=0
  12. def key_func(self,x):
  13. return int(os.path.split(x)[-1].rsplit('.', 1)[0])
  14. def cur(self):
  15. return ( self.data % (self.files[self.cur_diapo], self.cur_diapo+1, len(self.files)))
  16. def prev(self):
  17. self.cur_diapo=max(self.cur_diapo-1, 0)
  18. return self.cur()
  19. def next(self):
  20. self.cur_diapo=min(self.cur_diapo+1, len(self.files)-1)
  21. return self.cur()