From 8e5ae4824c762e6e8f34a0369d1ba6e44d3d0973 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Wed, 3 Jan 2024 20:36:17 -0600 Subject: [PATCH] idle_add refactor for event source clearing; Gtk main call moved --- src/solarfm/__main__.py | 6 +----- src/solarfm/app.py | 2 +- .../mixins/signals/file_action_signals_mixin.py | 10 +++++++--- src/solarfm/core/mixins/ui/grid_mixin.py | 13 ++++++++++--- src/solarfm/core/widgets/files_view/grid_mixin.py | 13 ++++++++++--- src/solarfm/core/window.py | 8 +++++--- src/solarfm/utils/ipc_server.py | 5 +++-- 7 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/solarfm/__main__.py b/src/solarfm/__main__.py index 1da80a8..b798304 100644 --- a/src/solarfm/__main__.py +++ b/src/solarfm/__main__.py @@ -8,9 +8,6 @@ import traceback from setproctitle import setproctitle # Lib imports -import gi -gi.require_version('Gtk', '3.0') -from gi.repository import Gtk # Application imports from __builtins__ import * @@ -45,7 +42,6 @@ def run(): settings_manager.do_dirty_start_check() Application(args, unknownargs) - Gtk.main() except Exception as e: traceback.print_exc() quit() @@ -53,4 +49,4 @@ def run(): if __name__ == "__main__": """ Set process title, get arguments, and create GTK main thread. """ - run() + run() \ No newline at end of file diff --git a/src/solarfm/app.py b/src/solarfm/app.py index 471b8d9..b910ad6 100644 --- a/src/solarfm/app.py +++ b/src/solarfm/app.py @@ -34,7 +34,7 @@ class Application(IPCServer): raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...") self.setup_debug_hook() - Window(args, unknownargs) + Window(args, unknownargs).main() def socket_realization_check(self): 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 6501975..0f61246 100644 --- a/src/solarfm/core/mixins/signals/file_action_signals_mixin.py +++ b/src/solarfm/core/mixins/signals/file_action_signals_mixin.py @@ -41,13 +41,15 @@ class FileActionSignalsMixin: Gio.FileMonitorEvent.MOVED_OUT]: if eve_type in [Gio.FileMonitorEvent.MOVED_IN, Gio.FileMonitorEvent.MOVED_OUT]: - self.update_on_soft_lock_end(data[0]) + # self.update_on_soft_lock_end(data[0]) + GLib.Thread("", self.soft_lock_countdown, data[0]) elif data[0] in self.soft_update_lock.keys(): self.soft_update_lock[data[0]]["last_update_time"] = time.time() else: - self.soft_lock_countdown(data[0]) + # self.soft_lock_countdown(data[0]) + GLib.Thread("", self.soft_lock_countdown, data[0]) - @daemon_threaded + # @daemon_threaded def soft_lock_countdown(self, tab_widget): self.soft_update_lock[tab_widget] = { "last_update_time": time.time()} @@ -61,6 +63,8 @@ class FileActionSignalsMixin: self.soft_update_lock.pop(tab_widget, None) GLib.idle_add(self.update_on_soft_lock_end, *(tab_widget,)) + thread = GLib.Thread.self() + thread.unref() def update_on_soft_lock_end(self, tab_widget): diff --git a/src/solarfm/core/mixins/ui/grid_mixin.py b/src/solarfm/core/mixins/ui/grid_mixin.py index be7d7a3..2c77129 100644 --- a/src/solarfm/core/mixins/ui/grid_mixin.py +++ b/src/solarfm/core/mixins/ui/grid_mixin.py @@ -57,25 +57,32 @@ class GridMixin: else: asyncio.run( self.create_icons(tab, store, dir, files) ) + thread = GLib.Thread.self() + thread.unref() + async def create_icons(self, tab, store, dir, files): icons = [self.get_icon(tab, dir, file[0]) for file in files] data = await asyncio.gather(*icons) tasks = [self.update_store(i, store, icon) for i, icon in enumerate(data)] await asyncio.gather(*tasks) - GLib.idle_add(Gtk.main_iteration) + GLib.idle_add(self.do_ui_update) async def update_store(self, i, store, icon): itr = store.get_iter(i) GLib.idle_add(self.insert_store, store, itr, icon) + async def get_icon(self, tab, dir, file): + return tab.create_icon(dir, file) + def insert_store(self, store, itr, icon): store.set_value(itr, 0, icon) # Note: If the function returns GLib.SOURCE_REMOVE or False it is automatically removed from the list of event sources and will not be called again. return False - async def get_icon(self, tab, dir, file): - return tab.create_icon(dir, file) + def do_ui_update(self): + Gtk.main_iteration() + return False def create_tab_widget(self, tab): return TabHeaderWidget(tab, self.close_tab) diff --git a/src/solarfm/core/widgets/files_view/grid_mixin.py b/src/solarfm/core/widgets/files_view/grid_mixin.py index dd11204..88b663b 100644 --- a/src/solarfm/core/widgets/files_view/grid_mixin.py +++ b/src/solarfm/core/widgets/files_view/grid_mixin.py @@ -57,25 +57,32 @@ class GridMixin: else: asyncio.run( self.create_icons(tab, store, dir, files) ) + thread = GLib.Thread.self() + thread.unref() + async def create_icons(self, tab, store, dir, files): icons = [self.get_icon(tab, dir, file[0]) for file in files] data = await asyncio.gather(*icons) tasks = [self.update_store(i, store, icon) for i, icon in enumerate(data)] await asyncio.gather(*tasks) - GLib.idle_add(Gtk.main_iteration) + GLib.idle_add(self.do_ui_update) async def update_store(self, i, store, icon): itr = store.get_iter(i) GLib.idle_add(self.insert_store, store, itr, icon) + async def get_icon(self, tab, dir, file): + return tab.create_icon(dir, file) + def insert_store(self, store, itr, icon): store.set_value(itr, 0, icon) # Note: If the function returns GLib.SOURCE_REMOVE or False it is automatically removed from the list of event sources and will not be called again. return False - async def get_icon(self, tab, dir, file): - return tab.create_icon(dir, file) + def do_ui_update(self): + Gtk.main_iteration() + return False def create_tab_widget(self, tab): return TabHeaderWidget(tab, self.close_tab) diff --git a/src/solarfm/core/window.py b/src/solarfm/core/window.py index 4bce515..ced3919 100644 --- a/src/solarfm/core/window.py +++ b/src/solarfm/core/window.py @@ -87,12 +87,14 @@ class Window(Gtk.ApplicationWindow): cr.set_operator(cairo.OPERATOR_SOURCE) cr.paint() cr.set_operator(cairo.OPERATOR_OVER) - + def _load_interactive_debug(self): self.set_interactive_debugging(True) - def _tear_down(self, widget = None, eve = None): event_system.emit("shutting_down") settings_manager.clear_pid() - Gtk.main_quit() \ No newline at end of file + Gtk.main_quit() + + def main(self): + Gtk.main() \ No newline at end of file diff --git a/src/solarfm/utils/ipc_server.py b/src/solarfm/utils/ipc_server.py index bc5178b..eda6dab 100644 --- a/src/solarfm/utils/ipc_server.py +++ b/src/solarfm/utils/ipc_server.py @@ -51,9 +51,10 @@ class IPCServer(Singleton): listener = Listener((self._ipc_address, self._ipc_port)) self.is_ipc_alive = True - self._run_ipc_loop(listener) + # self._run_ipc_loop(listener) + GLib.Thread("", self._run_ipc_loop, listener) - @daemon_threaded + # @daemon_threaded def _run_ipc_loop(self, listener) -> None: while True: try: