idle_add refactor for event source clearing; Gtk main call moved

This commit is contained in:
itdominator 2024-01-03 20:36:17 -06:00
parent 37e3265be5
commit 8e5ae4824c
7 changed files with 37 additions and 20 deletions

View File

@ -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()

View File

@ -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):

View File

@ -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):

View File

@ -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)

View File

@ -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)

View File

@ -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()
Gtk.main_quit()
def main(self):
Gtk.main()

View File

@ -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: