Skip to content

Instantly share code, notes, and snippets.

@hahastudio
Created December 20, 2012 14:10
Show Gist options
  • Save hahastudio/4345505 to your computer and use it in GitHub Desktop.
Save hahastudio/4345505 to your computer and use it in GitHub Desktop.
from PyQt4 import QtCore
import glob
import os
import time
def all_files(pattern, search_path, pathsep=os.pathsep):
for path in search_path.split(pathsep):
for match in glob.glob(os.path.join(path, pattern)):
yield match
class FileThread(QtCore.QThread):
"""docstring for FileThread"""
def __init__(self, path, patterns, fileDsp):
super(FileThread, self).__init__()
self.path = path
self.patterns = patterns
self.fileDsp = fileDsp
self.fileDict = {}
for pattern in self.patterns:
for f in all_files(pattern, self.path):
self.fileDict[f] = os.path.getmtime(f)
def run(self):
while 1:
fl = []
for pattern in self.patterns:
for f in all_files(pattern, self.path):
mtime = os.path.getmtime(f)
try:
if mtime > self.fileDict[f]:
fl.append(os.path.split(f)[1])
self.fileDict[f] = mtime
except KeyError:
fl.append(os.path.split(f)[1])
self.fileDict[f] = mtime
self.fileDsp.clear()
for f in fl:
self.fileDsp.addItem(f)
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment