Thumbnail speed improvements

This commit is contained in:
itdominator 2022-01-19 16:10:43 -06:00
parent 5a9fa8253b
commit 216cc9d34c
9 changed files with 33 additions and 35 deletions

View File

@ -62,5 +62,5 @@ class Builtins(DBusControllerMixin):
# NOTE: Just reminding myself we can add to builtins two different ways... # NOTE: Just reminding myself we can add to builtins two different ways...
# __builtins__.update({"event_system": Builtins()}) # __builtins__.update({"event_system": Builtins()})
builtins.event_system = Builtins() builtins.event_system = Builtins()
builtins.event_sleep_time = 0.5 builtins.event_sleep_time = 0.2
builtins.debug = False builtins.debug = False

View File

@ -14,7 +14,7 @@ from __builtins__ import Builtins
class Main(Builtins): class Main(Builtins):
def __init__(self, args, unknownargs): def __init__(self, args, unknownargs):
event_system.create_ipc_server() event_system.create_ipc_server()
time.sleep(0.5) time.sleep(0.2)
if not event_system.is_ipc_alive: if not event_system.is_ipc_alive:
if unknownargs: if unknownargs:
for arg in unknownargs: for arg in unknownargs:

View File

@ -17,7 +17,7 @@ def threaded(fn):
class Icon(DesktopIconMixin, VideoIconMixin): class Icon(DesktopIconMixin, VideoIconMixin):
def create_icon(self, dir, file): def create_icon(self, dir, file):
full_path = dir + "/" + file full_path = f"{dir}/{file}"
return self.get_icon_image(dir, file, full_path) return self.get_icon_image(dir, file, full_path)
def get_icon_image(self, dir, file, full_path): def get_icon_image(self, dir, file, full_path):
@ -36,29 +36,27 @@ class Icon(DesktopIconMixin, VideoIconMixin):
return None return None
def create_thumbnail(self, dir, file): def create_thumbnail(self, dir, file):
full_path = dir + "/" + file full_path = f"{dir}/{file}"
try: try:
file_hash = hashlib.sha256(str.encode(full_path)).hexdigest() file_hash = hashlib.sha256(str.encode(full_path)).hexdigest()
hash_img_pth = self.ABS_THUMBS_PTH + "/" + file_hash + ".jpg" hash_img_pth = f"{self.ABS_THUMBS_PTH}/{file_hash}.jpg"
if isfile(hash_img_pth) == False: if isfile(hash_img_pth) == False:
self.generate_video_thumbnail(full_path, hash_img_pth) self.generate_video_thumbnail(full_path, hash_img_pth)
thumbnl = self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH) thumbnl = self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH)
if thumbnl == None: # If no icon whatsoever, return internal default if thumbnl == None: # If no icon whatsoever, return internal default
thumbnl = GdkPixbuf.Pixbuf.new_from_file(self.DEFAULT_ICONS + "/video.png") thumbnl = GdkPixbuf.Pixbuf.new_from_file(f"{self.DEFAULT_ICONS}/video.png")
return thumbnl return thumbnl
except Exception as e: except Exception as e:
print("Thumbnail generation issue:") print("Thumbnail generation issue:")
print( repr(e) ) print( repr(e) )
return GdkPixbuf.Pixbuf.new_from_file(self.DEFAULT_ICONS + "/video.png") return GdkPixbuf.Pixbuf.new_from_file(f"{self.DEFAULT_ICONS}/video.png")
def create_scaled_image(self, path, wxh): def create_scaled_image(self, path, wxh):
try: try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file(path) return GdkPixbuf.Pixbuf.new_from_file_at_scale(path, wxh[0], wxh[1], True)
scaled_pixbuf = pixbuf.scale_simple(wxh[0], wxh[1], 2) # 2 = BILINEAR and is best by default
return scaled_pixbuf
except Exception as e: except Exception as e:
print("Image Scaling Issue:") print("Image Scaling Issue:")
print( repr(e) ) print( repr(e) )

View File

@ -107,7 +107,7 @@ class WidgetFileActionMixin:
def open_with_files(self, appchooser_widget): def open_with_files(self, appchooser_widget):
wid, tid, view, iconview, store = self.get_current_state() wid, tid, view, iconview, store = self.get_current_state()
app_info = appchooser_widget.get_app_info() app_info = appchooser_widget.get_app_info()
uris = self.format_to_uris(store, wid, tid, self.selected_files, True) uris = self.format_to_uris(store, wid, tid, self.selected_files)
view.app_chooser_exec(app_info, uris) view.app_chooser_exec(app_info, uris)

View File

@ -1,5 +1,5 @@
# Python imports # Python imports
import os, threading, subprocess import os, threading, subprocess, time
# Lib imports # Lib imports
import gi import gi
@ -20,15 +20,13 @@ def threaded(fn):
class WidgetMixin: class WidgetMixin:
def load_store(self, view, store, save_state=False): def load_store(self, view, store, save_state=False):
store.clear() store.clear()
dir = view.get_current_directory() dir = view.get_current_directory()
files = view.get_files() files = view.get_files()
icon = GdkPixbuf.Pixbuf.new_from_file(view.DEFAULT_ICON)
for i, file in enumerate(files): for i, file in enumerate(files):
store.append([icon, file[0]]) store.append([None, file[0]])
self.create_icon(i, view, store, dir, file[0]) self.create_icon(i, view, store, dir, file[0])
# NOTE: Not likely called often from here but it could be useful # NOTE: Not likely called often from here but it could be useful
@ -49,6 +47,10 @@ class WidgetMixin:
try: try:
itr = store.get_iter(i) itr = store.get_iter(i)
except Exception as e:
try:
time.sleep(0.2)
itr = store.get_iter(i)
except Exception as e: except Exception as e:
print(":Invalid Itr detected: (Potential race condition...)") print(":Invalid Itr detected: (Potential race condition...)")
print(f"Index Requested: {i}") print(f"Index Requested: {i}")
@ -113,7 +115,7 @@ class WidgetMixin:
def create_grid_iconview_widget(self, view, wid): def create_grid_iconview_widget(self, view, wid):
scroll = Gtk.ScrolledWindow() scroll = Gtk.ScrolledWindow()
grid = Gtk.IconView() grid = Gtk.IconView()
store = Gtk.ListStore(GdkPixbuf.Pixbuf, str) store = Gtk.ListStore(GdkPixbuf.Pixbuf or None, str)
grid.set_model(store) grid.set_model(store)
grid.set_pixbuf_column(0) grid.set_pixbuf_column(0)
@ -154,8 +156,8 @@ class WidgetMixin:
def create_grid_treeview_widget(self, view, wid): def create_grid_treeview_widget(self, view, wid):
scroll = Gtk.ScrolledWindow() scroll = Gtk.ScrolledWindow()
grid = Gtk.TreeView() grid = Gtk.TreeView()
store = Gtk.ListStore(GdkPixbuf.Pixbuf, str) store = Gtk.ListStore(GdkPixbuf.Pixbuf or None, str)
# store = Gtk.TreeStore(GdkPixbuf.Pixbuf, str) # store = Gtk.TreeStore(GdkPixbuf.Pixbuf or None, str)
column = Gtk.TreeViewColumn("Icons") column = Gtk.TreeViewColumn("Icons")
icon = Gtk.CellRendererPixbuf() icon = Gtk.CellRendererPixbuf()
name = Gtk.CellRendererText() name = Gtk.CellRendererText()

View File

@ -62,5 +62,5 @@ class Builtins(DBusControllerMixin):
# NOTE: Just reminding myself we can add to builtins two different ways... # NOTE: Just reminding myself we can add to builtins two different ways...
# __builtins__.update({"event_system": Builtins()}) # __builtins__.update({"event_system": Builtins()})
builtins.event_system = Builtins() builtins.event_system = Builtins()
builtins.event_sleep_time = 0.5 builtins.event_sleep_time = 0.2
builtins.debug = False builtins.debug = False

View File

@ -14,7 +14,7 @@ from __builtins__ import Builtins
class Main(Builtins): class Main(Builtins):
def __init__(self, args, unknownargs): def __init__(self, args, unknownargs):
event_system.create_ipc_server() event_system.create_ipc_server()
time.sleep(0.5) time.sleep(0.2)
if not event_system.is_ipc_alive: if not event_system.is_ipc_alive:
if unknownargs: if unknownargs:
for arg in unknownargs: for arg in unknownargs:

View File

@ -17,7 +17,7 @@ def threaded(fn):
class Icon(DesktopIconMixin, VideoIconMixin): class Icon(DesktopIconMixin, VideoIconMixin):
def create_icon(self, dir, file): def create_icon(self, dir, file):
full_path = dir + "/" + file full_path = f"{dir}/{file}"
return self.get_icon_image(dir, file, full_path) return self.get_icon_image(dir, file, full_path)
def get_icon_image(self, dir, file, full_path): def get_icon_image(self, dir, file, full_path):
@ -36,22 +36,22 @@ class Icon(DesktopIconMixin, VideoIconMixin):
return None return None
def create_thumbnail(self, dir, file): def create_thumbnail(self, dir, file):
full_path = dir + "/" + file full_path = f"{dir}/{file}"
try: try:
file_hash = hashlib.sha256(str.encode(full_path)).hexdigest() file_hash = hashlib.sha256(str.encode(full_path)).hexdigest()
hash_img_pth = self.ABS_THUMBS_PTH + "/" + file_hash + ".jpg" hash_img_pth = f"{self.ABS_THUMBS_PTH}/{file_hash}.jpg"
if isfile(hash_img_pth) == False: if isfile(hash_img_pth) == False:
self.generate_video_thumbnail(full_path, hash_img_pth) self.generate_video_thumbnail(full_path, hash_img_pth)
thumbnl = self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH) thumbnl = self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH)
if thumbnl == None: # If no icon whatsoever, return internal default if thumbnl == None: # If no icon whatsoever, return internal default
thumbnl = GdkPixbuf.Pixbuf.new_from_file(self.DEFAULT_ICONS + "/video.png") thumbnl = GdkPixbuf.Pixbuf.new_from_file(f"{self.DEFAULT_ICONS}/video.png")
return thumbnl return thumbnl
except Exception as e: except Exception as e:
print("Thumbnail generation issue:") print("Thumbnail generation issue:")
print( repr(e) ) print( repr(e) )
return GdkPixbuf.Pixbuf.new_from_file(self.DEFAULT_ICONS + "/video.png") return GdkPixbuf.Pixbuf.new_from_file(f"{self.DEFAULT_ICONS}/video.png")
def create_scaled_image(self, path, wxh): def create_scaled_image(self, path, wxh):

View File

@ -20,15 +20,13 @@ def threaded(fn):
class WidgetMixin: class WidgetMixin:
def load_store(self, view, store, save_state=False): def load_store(self, view, store, save_state=False):
store.clear() store.clear()
dir = view.get_current_directory() dir = view.get_current_directory()
files = view.get_files() files = view.get_files()
icon = GdkPixbuf.Pixbuf()
for i, file in enumerate(files): for i, file in enumerate(files):
store.append([icon, file[0]]) store.append([None, file[0]])
self.create_icon(i, view, store, dir, file[0]) self.create_icon(i, view, store, dir, file[0])
# NOTE: Not likely called often from here but it could be useful # NOTE: Not likely called often from here but it could be useful
@ -117,7 +115,7 @@ class WidgetMixin:
def create_grid_iconview_widget(self, view, wid): def create_grid_iconview_widget(self, view, wid):
scroll = Gtk.ScrolledWindow() scroll = Gtk.ScrolledWindow()
grid = Gtk.IconView() grid = Gtk.IconView()
store = Gtk.ListStore(GdkPixbuf.Pixbuf, str) store = Gtk.ListStore(GdkPixbuf.Pixbuf or None, str)
grid.set_model(store) grid.set_model(store)
grid.set_pixbuf_column(0) grid.set_pixbuf_column(0)
@ -158,8 +156,8 @@ class WidgetMixin:
def create_grid_treeview_widget(self, view, wid): def create_grid_treeview_widget(self, view, wid):
scroll = Gtk.ScrolledWindow() scroll = Gtk.ScrolledWindow()
grid = Gtk.TreeView() grid = Gtk.TreeView()
store = Gtk.ListStore(GdkPixbuf.Pixbuf, str) store = Gtk.ListStore(GdkPixbuf.Pixbuf or None, str)
# store = Gtk.TreeStore(GdkPixbuf.Pixbuf, str) # store = Gtk.TreeStore(GdkPixbuf.Pixbuf or None, str)
column = Gtk.TreeViewColumn("Icons") column = Gtk.TreeViewColumn("Icons")
icon = Gtk.CellRendererPixbuf() icon = Gtk.CellRendererPixbuf()
name = Gtk.CellRendererText() name = Gtk.CellRendererText()