Wrapped async in daemon thread for icon loading

This commit is contained in:
itdominator 2023-11-12 23:25:46 -06:00
parent 2de4de6b22
commit e6739c3087
3 changed files with 33 additions and 77 deletions

View File

@ -15,6 +15,7 @@ class AppLaunchException(Exception):
...
class Application(IPCServer):
""" docstring for Application. """
@ -30,7 +31,7 @@ class Application(IPCServer):
message = f"FILE|{arg}"
self.send_ipc_message(message)
raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...")
raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...")
self.setup_debug_hook()
Window(args, unknownargs)

View File

@ -26,15 +26,14 @@ class GridMixin:
store.append([None, file[0]])
Gtk.main_iteration()
# for i, file in enumerate(files):
# self.create_icon(i, tab, store, dir, file[0])
self.generate_icons(tab, store, dir, files)
if use_generator:
# NOTE: tab > icon > _get_system_thumbnail_gtk_thread must not be used
# as the attempted promotion back to gtk threading stalls the generator. (We're already in main gtk thread)
for i, icon in enumerate( self.create_icons_generator(tab, dir, files) ):
self.load_icon(i, store, icon)
else:
# NOTE: Not likely called often from here but it could be useful
if save_state and not trace_debug:
self.fm_controller.save_state()
@daemon_threaded
def generate_icons(self, tab, store, dir, files):
try:
loop = asyncio.get_running_loop()
except RuntimeError:
@ -45,40 +44,18 @@ class GridMixin:
else:
asyncio.run( self.create_icons(tab, store, dir, files) )
# NOTE: Not likely called often from here but it could be useful
if save_state and not trace_debug:
self.fm_controller.save_state()
async def create_icons(self, tab, store, dir, files):
tasks = [self.update_store(i, store, dir, tab, file[0]) for i, file in enumerate(files)]
await asyncio.gather(*tasks)
async def load_icon(self, i, store, icon):
self.update_store(i, store, icon)
GLib.idle_add(self.update_store, i, store, icon )
async def update_store(self, i, store, dir, tab, file):
icon = tab.create_icon(dir, file)
itr = store.get_iter(i)
store.set_value(itr, 0, icon)
def create_icons_generator(self, tab, dir, files):
for file in files:
icon = tab.create_icon(dir, file[0])
yield icon
# @daemon_threaded
# def create_icon(self, i, tab, store, dir, file):
# icon = tab.create_icon(dir, file)
# GLib.idle_add(self.update_store, *(i, store, icon,))
#
# @daemon_threaded
# def load_icon(self, i, store, icon):
# GLib.idle_add(self.update_store, *(i, store, icon,))
# def update_store(self, i, store, icon):
# itr = store.get_iter(i)
# store.set_value(itr, 0, icon)
def create_tab_widget(self, tab):
return TabHeaderWidget(tab, self.close_tab)

View File

@ -26,14 +26,14 @@ class GridMixin:
store.append([None, file[0]])
Gtk.main_iteration()
if use_generator:
# NOTE: tab > icon > _get_system_thumbnail_gtk_thread must not be used
# as the attempted promotion back to gtk threading stalls the generator. (We're already in main gtk thread)
for i, icon in enumerate( self.create_icons_generator(tab, dir, files) ):
self.load_icon(i, store, icon)
else:
# for i, file in enumerate(files):
# self.create_icon(i, tab, store, dir, file[0])
self.generate_icons(tab, store, dir, files)
# NOTE: Not likely called often from here but it could be useful
if save_state and not trace_debug:
self.fm_controller.save_state()
@daemon_threaded
def generate_icons(self, tab, store, dir, files):
try:
loop = asyncio.get_running_loop()
except RuntimeError:
@ -44,40 +44,18 @@ class GridMixin:
else:
asyncio.run( self.create_icons(tab, store, dir, files) )
# NOTE: Not likely called often from here but it could be useful
if save_state and not trace_debug:
self.fm_controller.save_state()
async def create_icons(self, tab, store, dir, files):
tasks = [self.update_store(i, store, dir, tab, file[0]) for i, file in enumerate(files)]
await asyncio.gather(*tasks)
async def load_icon(self, i, store, icon):
self.update_store(i, store, icon)
GLib.idle_add(self.update_store, i, store, icon )
async def update_store(self, i, store, dir, tab, file):
icon = tab.create_icon(dir, file)
itr = store.get_iter(i)
store.set_value(itr, 0, icon)
def create_icons_generator(self, tab, dir, files):
for file in files:
icon = tab.create_icon(dir, file[0])
yield icon
# @daemon_threaded
# def create_icon(self, i, tab, store, dir, file):
# icon = tab.create_icon(dir, file)
# GLib.idle_add(self.update_store, *(i, store, icon,))
#
# @daemon_threaded
# def load_icon(self, i, store, icon):
# GLib.idle_add(self.update_store, *(i, store, icon,))
#
# def update_store(self, i, store, icon):
# itr = store.get_iter(i)
# store.set_value(itr, 0, icon)
def create_tab_widget(self, tab):
return TabHeaderWidget(tab, self.close_tab)