From 9336df2afa945d61f8a8f8631020ea11138a56f2 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sun, 24 Dec 2023 13:23:24 -0600 Subject: [PATCH] Changing out threading for some sections; added 2 new tab option --- src/solarfm/core/controller.py | 2 ++ src/solarfm/core/fs_actions/file_system_actions.py | 9 ++++++++- .../core/mixins/signals/file_action_signals_mixin.py | 4 ++-- src/solarfm/core/mixins/ui/grid_mixin.py | 5 +++-- src/solarfm/core/ui_mixin.py | 7 +++---- src/solarfm/core/widgets/files_view/grid_mixin.py | 3 +-- src/solarfm/shellfm/windows/tabs/icons/icon.py | 6 +++--- 7 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/solarfm/core/controller.py b/src/solarfm/core/controller.py index e818db6..31f1bee 100644 --- a/src/solarfm/core/controller.py +++ b/src/solarfm/core/controller.py @@ -135,6 +135,8 @@ class Controller(UIMixin, SignalsMixins, Controller_Data): event_system.emit("open_files") if action == "open_with": event_system.emit("show_appchooser_menu") + if action == "open_2_new_tab": + event_system.emit("open_2_new_tab") if action == "execute": event_system.emit("execute_files") if action == "execute_in_terminal": diff --git a/src/solarfm/core/fs_actions/file_system_actions.py b/src/solarfm/core/fs_actions/file_system_actions.py index 561de7b..be6573c 100644 --- a/src/solarfm/core/fs_actions/file_system_actions.py +++ b/src/solarfm/core/fs_actions/file_system_actions.py @@ -40,6 +40,7 @@ class FileSystemActions(HandlerMixin, CRUDMixin): event_system.subscribe("open_files", self.open_files) event_system.subscribe("open_with_files", self.open_with_files) + event_system.subscribe("open_2_new_tab", self.open_2_new_tab) event_system.subscribe("execute_files", self.execute_files) event_system.subscribe("cut_files", self.cut_files) @@ -104,6 +105,12 @@ class FileSystemActions(HandlerMixin, CRUDMixin): state.tab.app_chooser_exec(app_info, uris) + def open_2_new_tab(self): + state = event_system.emit_and_await("get_current_state") + uri = state.uris[0] + message = f"FILE|{uri}" + logger.info(message) + event_system.emit("post_file_to_ipc", message) def execute_files(self, in_terminal=False): state = event_system.emit_and_await("get_current_state") @@ -111,4 +118,4 @@ class FileSystemActions(HandlerMixin, CRUDMixin): command = None for path in state.uris: command = f"{shlex.quote(path)}" if not in_terminal else f"{state.tab.terminal_app} -e {shlex.quote(path)}" - state.tab.execute(shlex.split(command), start_dir=state.tab.get_current_directory()) + state.tab.execute(shlex.split(command), start_dir=state.tab.get_current_directory()) \ No newline at end of file diff --git a/src/solarfm/core/mixins/signals/file_action_signals_mixin.py b/src/solarfm/core/mixins/signals/file_action_signals_mixin.py index aba1eac..6767b36 100644 --- a/src/solarfm/core/mixins/signals/file_action_signals_mixin.py +++ b/src/solarfm/core/mixins/signals/file_action_signals_mixin.py @@ -48,7 +48,7 @@ class FileActionSignalsMixin: else: self.soft_lock_countdown(data[0]) - @threaded + @daemon_threaded def soft_lock_countdown(self, tab_widget): self.soft_update_lock[tab_widget] = { "last_update_time": time.time()} @@ -102,4 +102,4 @@ class FileActionSignalsMixin: items = icon_grid.get_selected_items() if len(items) > 0: - icon_grid.scroll_to_path(items[0], False, 0.5, 0.5) + icon_grid.scroll_to_path(items[0], False, 0.5, 0.5) \ No newline at end of file diff --git a/src/solarfm/core/mixins/ui/grid_mixin.py b/src/solarfm/core/mixins/ui/grid_mixin.py index a769103..58c476d 100644 --- a/src/solarfm/core/mixins/ui/grid_mixin.py +++ b/src/solarfm/core/mixins/ui/grid_mixin.py @@ -26,13 +26,13 @@ class GridMixin: store.append([None, file[0]]) Gtk.main_iteration() - thread = self.generate_icons(tab, store, dir, files) + GLib.Thread("", 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() @@ -47,6 +47,7 @@ class GridMixin: 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) + GLib.idle_add(Gtk.main_iteration) async def update_store(self, i, store, dir, tab, file): icon = tab.create_icon(dir, file) diff --git a/src/solarfm/core/ui_mixin.py b/src/solarfm/core/ui_mixin.py index b596497..cbca606 100644 --- a/src/solarfm/core/ui_mixin.py +++ b/src/solarfm/core/ui_mixin.py @@ -6,6 +6,7 @@ gi.require_version('Gtk', '3.0') gi.require_version('Gdk', '3.0') from gi.repository import Gtk from gi.repository import Gdk +from gi.repository import GLib # Application imports from .mixins.ui.pane_mixin import PaneMixin @@ -37,14 +38,12 @@ class UIMixin(PaneMixin, WindowMixin): event_system.emit("load_files_view_state", (nickname, tabs, isHidden)) - - @daemon_threaded def _focus_last_visible_notebook(self, icon_grid): import time window = settings_manager.get_main_window() while not window.is_visible() and not window.get_realized(): - time.sleep(0.1) + time.sleep(0.2) icon_grid.event(Gdk.Event().new(type = Gdk.EventType.BUTTON_RELEASE)) @@ -79,7 +78,7 @@ class UIMixin(PaneMixin, WindowMixin): scroll_win = notebook.get_children()[-1] icon_grid = scroll_win.get_children()[0] - self._focus_last_visible_notebook(icon_grid) + GLib.Thread("", self._focus_last_visible_notebook, icon_grid) except UIMixinException as e: logger.info("\n: The saved session might be missing window data! :\nLocation: ~/.config/solarfm/session.json\nFix: Back it up and delete it to reset.\n") logger.debug(repr(e)) diff --git a/src/solarfm/core/widgets/files_view/grid_mixin.py b/src/solarfm/core/widgets/files_view/grid_mixin.py index 258b320..b6ab2f8 100644 --- a/src/solarfm/core/widgets/files_view/grid_mixin.py +++ b/src/solarfm/core/widgets/files_view/grid_mixin.py @@ -26,13 +26,12 @@ class GridMixin: store.append([None, file[0]]) Gtk.main_iteration() - thread = self.generate_icons(tab, store, dir, files) + GLib.Thread("", 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() diff --git a/src/solarfm/shellfm/windows/tabs/icons/icon.py b/src/solarfm/shellfm/windows/tabs/icons/icon.py index 72285b0..19e3faa 100644 --- a/src/solarfm/shellfm/windows/tabs/icons/icon.py +++ b/src/solarfm/shellfm/windows/tabs/icons/icon.py @@ -50,8 +50,8 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin): if not thumbnl: # 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_gtk_thread(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]) if not thumbnl: raise IconException("No known icons found.") @@ -201,4 +201,4 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin): pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB, False, 8, w, h, w * 3) - return pixbuf.scale_simple(wxh[0], wxh[1], 2) # BILINEAR = 2 + return pixbuf.scale_simple(wxh[0], wxh[1], 2) # BILINEAR = 2 \ No newline at end of file