Wrapped async in daemon thread for icon loading
This commit is contained in:
parent
2de4de6b22
commit
e6739c3087
@ -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)
|
||||
@ -56,4 +57,4 @@ class Application(IPCServer):
|
||||
)
|
||||
except ValueError:
|
||||
# Typically: ValueError: signal only works in main thread
|
||||
...
|
||||
...
|
@ -26,59 +26,36 @@ 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])
|
||||
|
||||
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:
|
||||
try:
|
||||
loop = asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
loop = None
|
||||
|
||||
if loop and loop.is_running():
|
||||
loop.create_task( self.create_icons(tab, store, dir, files) )
|
||||
else:
|
||||
asyncio.run( self.create_icons(tab, store, dir, files) )
|
||||
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:
|
||||
loop = None
|
||||
|
||||
if loop and loop.is_running():
|
||||
loop.create_task( self.create_icons(tab, store, dir, files) )
|
||||
else:
|
||||
asyncio.run( self.create_icons(tab, store, dir, files) )
|
||||
|
||||
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)
|
||||
|
||||
@ -144,4 +121,4 @@ class GridMixin:
|
||||
icon_grid = obj.get_children()[0]
|
||||
name = icon_grid.get_name()
|
||||
if name == _name:
|
||||
return icon_grid
|
||||
return icon_grid
|
@ -26,58 +26,36 @@ 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])
|
||||
try:
|
||||
loop = asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
loop = None
|
||||
|
||||
if loop and loop.is_running():
|
||||
loop.create_task( self.create_icons(tab, store, dir, files) )
|
||||
else:
|
||||
asyncio.run( self.create_icons(tab, store, dir, files) )
|
||||
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:
|
||||
loop = None
|
||||
|
||||
if loop and loop.is_running():
|
||||
loop.create_task( self.create_icons(tab, store, dir, files) )
|
||||
else:
|
||||
asyncio.run( self.create_icons(tab, store, dir, files) )
|
||||
|
||||
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)
|
||||
|
||||
@ -136,4 +114,4 @@ class GridMixin:
|
||||
store = icon_grid.get_model()
|
||||
tab_label = notebook.get_tab_label(obj).get_children()[0]
|
||||
|
||||
return store, tab_label
|
||||
return store, tab_label
|
Loading…
Reference in New Issue
Block a user