From b45badf9fe1d0130895a46edba3f32058e63027d Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 24 Apr 2021 17:05:58 -0500 Subject: [PATCH] Changed icon generation --- src/shellfm/windows/view/Icon.py | 44 ++++++++++++++++---------------- src/shellfm/windows/view/View.py | 19 ++++++++++++++ 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/shellfm/windows/view/Icon.py b/src/shellfm/windows/view/Icon.py index b6cf648..d129d04 100644 --- a/src/shellfm/windows/view/Icon.py +++ b/src/shellfm/windows/view/Icon.py @@ -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) diff --git a/src/shellfm/windows/view/View.py b/src/shellfm/windows/view/View.py index 37552b4..6d31f0c 100644 --- a/src/shellfm/windows/view/View.py +++ b/src/shellfm/windows/view/View.py @@ -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()