develop #12

Merged
itdominator merged 6 commits from develop into master 2023-09-30 19:36:35 +00:00
3 changed files with 74 additions and 30 deletions
Showing only changes of commit fd282a6595 - Show all commits

View File

@ -1,4 +1,5 @@
# Python imports # Python imports
import asyncio
# Lib imports # Lib imports
import gi import gi
@ -31,30 +32,51 @@ class GridMixin:
for i, icon in enumerate( self.create_icons_generator(tab, dir, files) ): for i, icon in enumerate( self.create_icons_generator(tab, dir, files) ):
self.load_icon(i, store, icon) self.load_icon(i, store, icon)
else: else:
for i, file in enumerate(files): # for i, file in enumerate(files):
self.create_icon(i, tab, store, dir, file[0]) # 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) )
# NOTE: Not likely called often from here but it could be useful # NOTE: Not likely called often from here but it could be useful
if save_state and not trace_debug: if save_state and not trace_debug:
self.fm_controller.save_state() 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)
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): def create_icons_generator(self, tab, dir, files):
for file in files: for file in files:
icon = tab.create_icon(dir, file[0]) icon = tab.create_icon(dir, file[0])
yield icon yield icon
@daemon_threaded # @daemon_threaded
def create_icon(self, i, tab, store, dir, file): # def create_icon(self, i, tab, store, dir, file):
icon = tab.create_icon(dir, file) # icon = tab.create_icon(dir, file)
GLib.idle_add(self.update_store, *(i, store, icon,)) # 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,))
@daemon_threaded # def update_store(self, i, store, icon):
def load_icon(self, i, store, icon): # itr = store.get_iter(i)
GLib.idle_add(self.update_store, *(i, store, icon,)) # store.set_value(itr, 0, 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): def create_tab_widget(self, tab):
return TabHeaderWidget(tab, self.close_tab) return TabHeaderWidget(tab, self.close_tab)

View File

@ -1,4 +1,5 @@
# Python imports # Python imports
import asyncio
# Lib imports # Lib imports
import gi import gi
@ -18,7 +19,6 @@ class GridMixin:
"""docstring for GridMixin""" """docstring for GridMixin"""
def load_store(self, tab, store, save_state = False, use_generator = False): def load_store(self, tab, store, save_state = False, use_generator = False):
store.clear()
dir = tab.get_current_directory() dir = tab.get_current_directory()
files = tab.get_files() files = tab.get_files()
@ -32,30 +32,52 @@ class GridMixin:
for i, icon in enumerate( self.create_icons_generator(tab, dir, files) ): for i, icon in enumerate( self.create_icons_generator(tab, dir, files) ):
self.load_icon(i, store, icon) self.load_icon(i, store, icon)
else: else:
for i, file in enumerate(files): # for i, file in enumerate(files):
self.create_icon(i, tab, store, dir, file[0]) # 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) )
# NOTE: Not likely called often from here but it could be useful # NOTE: Not likely called often from here but it could be useful
if save_state and not trace_debug: if save_state and not trace_debug:
self.fm_controller.save_state() 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)
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)
return 1
def create_icons_generator(self, tab, dir, files): def create_icons_generator(self, tab, dir, files):
for file in files: for file in files:
icon = tab.create_icon(dir, file[0]) icon = tab.create_icon(dir, file[0])
yield icon yield icon
@daemon_threaded # @daemon_threaded
def create_icon(self, i, tab, store, dir, file): # def create_icon(self, i, tab, store, dir, file):
icon = tab.create_icon(dir, file) # icon = tab.create_icon(dir, file)
GLib.idle_add(self.update_store, *(i, store, icon,)) # GLib.idle_add(self.update_store, *(i, store, icon,))
#
@daemon_threaded # @daemon_threaded
def load_icon(self, i, store, icon): # def load_icon(self, i, store, icon):
GLib.idle_add(self.update_store, *(i, store, icon,)) # GLib.idle_add(self.update_store, *(i, store, icon,))
#
def update_store(self, i, store, icon): # def update_store(self, i, store, icon):
itr = store.get_iter(i) # itr = store.get_iter(i)
store.set_value(itr, 0, icon) # store.set_value(itr, 0, icon)
def create_tab_widget(self, tab): def create_tab_widget(self, tab):
return TabHeaderWidget(tab, self.close_tab) return TabHeaderWidget(tab, self.close_tab)

View File

@ -50,8 +50,8 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
if not thumbnl: if not thumbnl:
# TODO: Detect if not in a thread and use directly for speed get_system_thumbnail # TODO: Detect if not in a thread and use directly for speed get_system_thumbnail
# thumbnl = self.get_system_thumbnail(full_path, self.sys_icon_wh[0]) thumbnl = self.get_system_thumbnail(full_path, self.sys_icon_wh[0])
thumbnl = self._get_system_thumbnail_gtk_thread(full_path, self.sys_icon_wh[0]) # thumbnl = self._get_system_thumbnail_gtk_thread(full_path, self.sys_icon_wh[0])
if not thumbnl: if not thumbnl:
raise IconException("No known icons found.") raise IconException("No known icons found.")