Fixed Icon generation logic

This commit is contained in:
Maxim Stewart 2019-10-15 02:10:46 -05:00
parent edeaad3c85
commit beadd27490
3 changed files with 32 additions and 24 deletions

Binary file not shown.

View File

@ -20,8 +20,7 @@ from utils.FileHandler import FileHandler
def threaded(fn): def threaded(fn):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
thread = threading.Thread(target=fn, args=args, kwargs=kwargs).start() threading.Thread(target=fn, args=args, kwargs=kwargs).start()
return wrapper return wrapper
@ -85,10 +84,9 @@ class Grid:
desktop.sort() desktop.sort()
files.sort() files.sort()
startVideoIcons = len(dirPaths)
files = dirPaths + vids + images + desktop + files files = dirPaths + vids + images + desktop + files
self.generateGridIcons(path, files) self.generateGridIcons(path, files)
self.fillVideoIcons(path, vids, startVideoIcons) self.fillVideoIcons(path, vids, len(dirPaths))
@threaded @threaded
@ -103,7 +101,7 @@ class Grid:
# Wait till we have a proper index... # Wait till we have a proper index...
while len(self.store) < (start + 1): while len(self.store) < (start + 1):
time.sleep(.500) time.sleep(.200)
i = start i = start
for file in files: for file in files:

View File

@ -30,6 +30,8 @@ class Icon:
self.iconContainerWH = settings.returnContainerWH() self.iconContainerWH = settings.returnContainerWH()
self.systemIconImageWH = settings.returnSystemIconImageWH() self.systemIconImageWH = settings.returnSystemIconImageWH()
self.viIconWH = settings.returnVIIconWH() self.viIconWH = settings.returnVIIconWH()
self.SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__)) + "/"
self.INTERNAL_ICON_PTH = self.SCRIPT_PTH + "../resources/icons/text.png"
def createIcon(self, dir, file): def createIcon(self, dir, file):
@ -38,30 +40,36 @@ class Icon:
def createThumbnail(self, dir, file): def createThumbnail(self, dir, file):
fullPath = dir + "/" + file fullPath = dir + "/" + file
# Video thumbnail try:
if file.lower().endswith(self.vidsList): # Video thumbnail
fileHash = hashlib.sha256(str.encode(fullPath)).hexdigest() if file.lower().endswith(self.vidsList):
hashImgPth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png" fileHash = hashlib.sha256(str.encode(fullPath)).hexdigest()
hashImgPth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png"
if isfile(hashImgPth) == False: if isfile(hashImgPth) == False:
self.generateVideoThumbnail(fullPath, hashImgPth) self.generateVideoThumbnail(fullPath, hashImgPth)
thumbnl = self.createScaledImage(hashImgPth, self.viIconWH) thumbnl = self.createScaledImage(hashImgPth, self.viIconWH)
if thumbnl == None: # If no icon, try stock file icon... if thumbnl == None: # If no icon whatsoever, return internal default
thumbnl = gtk.Image.new_from_icon_name("gtk-file", gtk.IconSize.LARGE_TOOLBAR) thumbnl = gtk.Image.new_from_file(self.SCRIPT_PTH + "../resources/icons/video.png")
if thumbnl == None: # If no icon whatsoever, return internal default return thumbnl
thumbnl = gtk.Image.new_from_file("resources/icons/bin.png") except Exception as e:
print("Thumbnail generation issue:")
print(e)
return gtk.Image.new_from_file(self.SCRIPT_PTH + "../resources/icons/video.png")
return thumbnl
def getIconImage(self, file, fullPath): def getIconImage(self, file, fullPath):
try: try:
thumbnl = None thumbnl = None
# Video icon
if file.lower().endswith(self.vidsList):
thumbnl = gtk.Image.new_from_file(self.SCRIPT_PTH + "../resources/icons/video.png")
# Image Icon # Image Icon
if file.lower().endswith(self.imagesList): elif file.lower().endswith(self.imagesList):
thumbnl = self.createScaledImage(fullPath, self.viIconWH) thumbnl = self.createScaledImage(fullPath, self.viIconWH)
# .desktop file parsing # .desktop file parsing
elif fullPath.lower().endswith( ('.desktop',) ): elif fullPath.lower().endswith( ('.desktop',) ):
@ -70,16 +78,14 @@ class Icon:
else: else:
thumbnl = self.getSystemThumbnail(fullPath, self.systemIconImageWH[0]) thumbnl = self.getSystemThumbnail(fullPath, self.systemIconImageWH[0])
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 if thumbnl == None: # If no icon whatsoever, return internal default
thumbnl = gtk.Image.new_from_file("resources/icons/bin.png") thumbnl = gtk.Image.new_from_file(self.INTERNAL_ICON_PTH)
return thumbnl return thumbnl
except Exception as e: except Exception as e:
print("Icon generation issue:")
print(e) print(e)
return gtk.Image.new_from_file("resources/icons/bin.png") return gtk.Image.new_from_file(self.INTERNAL_ICON_PTH)
def parseDesktopFiles(self, fullPath): def parseDesktopFiles(self, fullPath):
@ -132,6 +138,7 @@ class Icon:
return self.createScaledImage(altIconPath, self.systemIconImageWH) return self.createScaledImage(altIconPath, self.systemIconImageWH)
except Exception as e: except Exception as e:
print(".desktop icon generation issue:")
print(e) print(e)
return None return None
@ -140,7 +147,7 @@ class Icon:
try: try:
if os.path.exists(filename): if os.path.exists(filename):
gioFile = gio.File.new_for_path(filename) gioFile = gio.File.new_for_path(filename)
info = gioFile.query_info('standard::icon' , 0 , gio.Cancellable()) info = gioFile.query_info('standard::icon' , 0, gio.Cancellable())
icon = info.get_icon().get_names()[0] icon = info.get_icon().get_names()[0]
iconTheme = gtk.IconTheme.get_default() iconTheme = gtk.IconTheme.get_default()
iconData = iconTheme.lookup_icon(icon , size , 0) iconData = iconTheme.lookup_icon(icon , size , 0)
@ -152,6 +159,7 @@ class Icon:
else: else:
return None return None
except Exception as e: except Exception as e:
print("system icon generation issue:")
print(e) print(e)
return None return None
@ -162,6 +170,7 @@ class Icon:
scaledPixBuf = pixbuf.scale_simple(wxh[0], wxh[1], 2) # 2 = BILINEAR and is best by default scaledPixBuf = pixbuf.scale_simple(wxh[0], wxh[1], 2) # 2 = BILINEAR and is best by default
return gtk.Image.new_from_pixbuf(scaledPixBuf) return gtk.Image.new_from_pixbuf(scaledPixBuf)
except Exception as e: except Exception as e:
print("Image Scaling Issue:")
print(e) print(e)
return None return None
@ -170,4 +179,5 @@ class Icon:
proc = subprocess.Popen([self.thubnailGen, "-t", "65%", "-s", "300", "-c", "jpg", "-i", fullPath, "-o", hashImgPth]) proc = subprocess.Popen([self.thubnailGen, "-t", "65%", "-s", "300", "-c", "jpg", "-i", fullPath, "-o", hashImgPth])
proc.wait() proc.wait()
except Exception as e: except Exception as e:
print("Video thumbnail generation issue in thread:")
print(e) print(e)