Split thumbnail generation after icons are loaded

This commit is contained in:
Maxim Stewart 2019-10-15 00:56:13 -05:00
parent c95ef55124
commit edeaad3c85
3 changed files with 44 additions and 11 deletions

Binary file not shown.

View File

@ -20,7 +20,7 @@ from utils.FileHandler import FileHandler
def threaded(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
thread = threading.Thread(target=fn, args=args, kwargs=kwargs).start()
return wrapper
@ -85,8 +85,10 @@ class Grid:
desktop.sort()
files.sort()
startVideoIcons = len(dirPaths)
files = dirPaths + vids + images + desktop + files
self.generateGridIcons(path, files)
self.fillVideoIcons(path, vids, startVideoIcons)
@threaded
@ -95,9 +97,29 @@ class Grid:
image = self.iconFactory.createIcon(dirPath, file).get_pixbuf()
glib.idle_add(self.addToGrid, (image, file,))
@threaded
def fillVideoIcons(self, dirPath, files, start):
model = self.grid.get_model()
# Wait till we have a proper index...
while len(self.store) < (start + 1):
time.sleep(.500)
i = start
for file in files:
image = self.iconFactory.createThumbnail(dirPath, file).get_pixbuf()
iter = model.get_iter_from_string(str(i))
glib.idle_add(self.replaceInGrid, (iter, image,))
i += 1
def addToGrid(self, dataSet):
self.store.append([dataSet[0], dataSet[1]])
def replaceInGrid(self, dataSet):
# Iter, row column, new pixbuf...
self.store.set_value(dataSet[0], 0 , dataSet[1])
def iconDblLeftClick(self, widget, item):
try:
model = widget.get_model()

View File

@ -36,21 +36,32 @@ class Icon:
fullPath = dir + "/" + file
return self.getIconImage(file, fullPath)
def createThumbnail(self, dir, file):
fullPath = dir + "/" + file
# Video thumbnail
if file.lower().endswith(self.vidsList):
fileHash = hashlib.sha256(str.encode(fullPath)).hexdigest()
hashImgPth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png"
if isfile(hashImgPth) == False:
self.generateVideoThumbnail(fullPath, hashImgPth)
thumbnl = self.createScaledImage(hashImgPth, self.viIconWH)
if thumbnl == None: # If no icon, try stock file icon...
thumbnl = gtk.Image.new_from_icon_name("gtk-file", gtk.IconSize.LARGE_TOOLBAR)
if thumbnl == None: # If no icon whatsoever, return internal default
thumbnl = gtk.Image.new_from_file("resources/icons/bin.png")
return thumbnl
def getIconImage(self, file, fullPath):
try:
thumbnl = None
# Video thumbnail
if file.lower().endswith(self.vidsList):
fileHash = hashlib.sha256(str.encode(fullPath)).hexdigest()
hashImgPth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png"
if isfile(hashImgPth) == False:
self.generateVideoThumbnail(fullPath, hashImgPth)
thumbnl = self.createScaledImage(hashImgPth, self.viIconWH)
# Image Icon
elif file.lower().endswith(self.imagesList):
if file.lower().endswith(self.imagesList):
thumbnl = self.createScaledImage(fullPath, self.viIconWH)
# .desktop file parsing
elif fullPath.lower().endswith( ('.desktop',) ):