Changed icon generation

This commit is contained in:
itdominator 2021-04-24 17:05:58 -05:00
parent e864cce741
commit b45badf9fe
2 changed files with 41 additions and 22 deletions

View File

@ -25,34 +25,16 @@ def threaded(fn):
class Icon:
def create_icon(self, dir, file):
full_path = dir + "/" + file
return self.get_icon_image(file, full_path)
return self.get_icon_image(dir, file, full_path)
def create_thumbnail(self, dir, file):
full_path = dir + "/" + file
try:
file_hash = hashlib.sha256(str.encode(full_path)).hexdigest()
hash_img_pth = ABS_THUMBS_PTH + "/" + file_hash + ".jpg"
if isfile(hash_img_pth) == False:
self.generate_video_thumbnail(full_path, hash_img_pth)
thumbnl = self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH)
if thumbnl == None: # If no icon whatsoever, return internal default
thumbnl = Gtk.Image.new_from_file(self.DEFAULT_ICONS + "/video.png")
return thumbnl
except Exception as e:
print("Thumbnail generation issue:")
print( repr(e) )
return Gtk.Image.new_from_file(self.DEFAULT_ICONS + "/video.png")
def get_icon_image(self, file, full_path):
def get_icon_image(self, dir, file, full_path):
try:
thumbnl = None
# Video icon
if file.lower().endswith(self.fvideos):
thumbnl = Gtk.Image.new_from_file(self.DEFAULT_ICONS + "/video.png")
thumbnl = self.create_thumbnail(dir, file)
# thumbnl = Gtk.Image.new_from_file(self.DEFAULT_ICONS + "/video.png")
# Image Icon
elif file.lower().endswith(self.fimages):
thumbnl = self.create_scaled_image(full_path, self.VIDEO_ICON_WH)
@ -72,6 +54,24 @@ class Icon:
print( repr(e) )
return Gtk.Image.new_from_file(self.DEFAULT_ICON)
def create_thumbnail(self, dir, file):
full_path = dir + "/" + file
try:
file_hash = hashlib.sha256(str.encode(full_path)).hexdigest()
hash_img_pth = self.ABS_THUMBS_PTH + "/" + file_hash + ".jpg"
if isfile(hash_img_pth) == False:
self.generate_video_thumbnail(full_path, hash_img_pth)
thumbnl = self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH)
if thumbnl == None: # If no icon whatsoever, return internal default
thumbnl = Gtk.Image.new_from_file(self.DEFAULT_ICONS + "/video.png")
return thumbnl
except Exception as e:
print("Thumbnail generation issue:")
print( repr(e) )
return Gtk.Image.new_from_file(self.DEFAULT_ICONS + "/video.png")
def parse_desktop_files(self, full_path):
try:
xdgObj = DesktopEntry(full_path)

View File

@ -135,6 +135,25 @@ class View(Settings, Launcher, Icon, Path):
return False
def get_pixbuf_icon_str_combo(self):
data = []
dir = self.get_current_directory()
for file in self.files:
icon = self.create_icon(dir, file).get_pixbuf()
data.append([icon, file[0]])
return data
def get_gtk_icon_str_combo(self):
data = []
dir = self.get_current_directory()
for file in self.files:
icon = self.create_icon(dir, file)
data.append([icon, file[0]])
return data
def get_current_directory(self):
return self.get_path()