-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyFImageFiles.py
38 lines (31 loc) · 978 Bytes
/
PyFImageFiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
try:
#For Python3
from configparser import ConfigParser
except ImportError:
#For Python2
from ConfigParser import ConfigParser
import glob, os
from random import randint
import threading
class PyFImageFiles:
def refreshFiles(self):
formats = ["jpg", "jpeg", "png", "gif", "bmp", "eps", "tiff"]
refreshRate = 60.0 * 10.0
#print("Refreshing files")
for format in formats:
self.images.extend(glob.glob("*." + format))
self.refreshTimer = threading.Timer(refreshRate, self.refreshFiles)
self.refreshTimer.start()
def destroy(self):
self.refreshTimer.cancel()
def __init__(self):
#Read from the settings ini
config = ConfigParser()
config.read("PyctureSettings.ini")
#Set our image path from settings
images_path = config.get("DEFAULT", "images_path")
os.chdir(images_path)
self.images = []
self.refreshFiles()
def getRandomImage(self):
return self.images[randint(0, len(self.images) - 1)]