idle_add refactor for event source clearing; Gtk main call moved
This commit is contained in:
parent
37e3265be5
commit
8e5ae4824c
|
@ -8,9 +8,6 @@ import traceback
|
||||||
from setproctitle import setproctitle
|
from setproctitle import setproctitle
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
import gi
|
|
||||||
gi.require_version('Gtk', '3.0')
|
|
||||||
from gi.repository import Gtk
|
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from __builtins__ import *
|
from __builtins__ import *
|
||||||
|
@ -45,7 +42,6 @@ def run():
|
||||||
|
|
||||||
settings_manager.do_dirty_start_check()
|
settings_manager.do_dirty_start_check()
|
||||||
Application(args, unknownargs)
|
Application(args, unknownargs)
|
||||||
Gtk.main()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
quit()
|
quit()
|
||||||
|
@ -53,4 +49,4 @@ def run():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
""" Set process title, get arguments, and create GTK main thread. """
|
""" Set process title, get arguments, and create GTK main thread. """
|
||||||
run()
|
run()
|
|
@ -34,7 +34,7 @@ class Application(IPCServer):
|
||||||
raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...")
|
raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...")
|
||||||
|
|
||||||
self.setup_debug_hook()
|
self.setup_debug_hook()
|
||||||
Window(args, unknownargs)
|
Window(args, unknownargs).main()
|
||||||
|
|
||||||
|
|
||||||
def socket_realization_check(self):
|
def socket_realization_check(self):
|
||||||
|
|
|
@ -41,13 +41,15 @@ class FileActionSignalsMixin:
|
||||||
Gio.FileMonitorEvent.MOVED_OUT]:
|
Gio.FileMonitorEvent.MOVED_OUT]:
|
||||||
|
|
||||||
if eve_type in [Gio.FileMonitorEvent.MOVED_IN, 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():
|
elif data[0] in self.soft_update_lock.keys():
|
||||||
self.soft_update_lock[data[0]]["last_update_time"] = time.time()
|
self.soft_update_lock[data[0]]["last_update_time"] = time.time()
|
||||||
else:
|
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):
|
def soft_lock_countdown(self, tab_widget):
|
||||||
self.soft_update_lock[tab_widget] = { "last_update_time": time.time()}
|
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)
|
self.soft_update_lock.pop(tab_widget, None)
|
||||||
GLib.idle_add(self.update_on_soft_lock_end, *(tab_widget,))
|
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):
|
def update_on_soft_lock_end(self, tab_widget):
|
||||||
|
|
|
@ -57,25 +57,32 @@ class GridMixin:
|
||||||
else:
|
else:
|
||||||
asyncio.run( self.create_icons(tab, store, dir, files) )
|
asyncio.run( self.create_icons(tab, store, dir, files) )
|
||||||
|
|
||||||
|
thread = GLib.Thread.self()
|
||||||
|
thread.unref()
|
||||||
|
|
||||||
async def create_icons(self, tab, store, dir, files):
|
async def create_icons(self, tab, store, dir, files):
|
||||||
icons = [self.get_icon(tab, dir, file[0]) for file in files]
|
icons = [self.get_icon(tab, dir, file[0]) for file in files]
|
||||||
data = await asyncio.gather(*icons)
|
data = await asyncio.gather(*icons)
|
||||||
tasks = [self.update_store(i, store, icon) for i, icon in enumerate(data)]
|
tasks = [self.update_store(i, store, icon) for i, icon in enumerate(data)]
|
||||||
await asyncio.gather(*tasks)
|
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):
|
async def update_store(self, i, store, icon):
|
||||||
itr = store.get_iter(i)
|
itr = store.get_iter(i)
|
||||||
GLib.idle_add(self.insert_store, store, itr, icon)
|
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):
|
def insert_store(self, store, itr, icon):
|
||||||
store.set_value(itr, 0, 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.
|
# 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
|
return False
|
||||||
|
|
||||||
async def get_icon(self, tab, dir, file):
|
def do_ui_update(self):
|
||||||
return tab.create_icon(dir, file)
|
Gtk.main_iteration()
|
||||||
|
return False
|
||||||
|
|
||||||
def create_tab_widget(self, tab):
|
def create_tab_widget(self, tab):
|
||||||
return TabHeaderWidget(tab, self.close_tab)
|
return TabHeaderWidget(tab, self.close_tab)
|
||||||
|
|
|
@ -57,25 +57,32 @@ class GridMixin:
|
||||||
else:
|
else:
|
||||||
asyncio.run( self.create_icons(tab, store, dir, files) )
|
asyncio.run( self.create_icons(tab, store, dir, files) )
|
||||||
|
|
||||||
|
thread = GLib.Thread.self()
|
||||||
|
thread.unref()
|
||||||
|
|
||||||
async def create_icons(self, tab, store, dir, files):
|
async def create_icons(self, tab, store, dir, files):
|
||||||
icons = [self.get_icon(tab, dir, file[0]) for file in files]
|
icons = [self.get_icon(tab, dir, file[0]) for file in files]
|
||||||
data = await asyncio.gather(*icons)
|
data = await asyncio.gather(*icons)
|
||||||
tasks = [self.update_store(i, store, icon) for i, icon in enumerate(data)]
|
tasks = [self.update_store(i, store, icon) for i, icon in enumerate(data)]
|
||||||
await asyncio.gather(*tasks)
|
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):
|
async def update_store(self, i, store, icon):
|
||||||
itr = store.get_iter(i)
|
itr = store.get_iter(i)
|
||||||
GLib.idle_add(self.insert_store, store, itr, icon)
|
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):
|
def insert_store(self, store, itr, icon):
|
||||||
store.set_value(itr, 0, 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.
|
# 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
|
return False
|
||||||
|
|
||||||
async def get_icon(self, tab, dir, file):
|
def do_ui_update(self):
|
||||||
return tab.create_icon(dir, file)
|
Gtk.main_iteration()
|
||||||
|
return False
|
||||||
|
|
||||||
def create_tab_widget(self, tab):
|
def create_tab_widget(self, tab):
|
||||||
return TabHeaderWidget(tab, self.close_tab)
|
return TabHeaderWidget(tab, self.close_tab)
|
||||||
|
|
|
@ -87,12 +87,14 @@ class Window(Gtk.ApplicationWindow):
|
||||||
cr.set_operator(cairo.OPERATOR_SOURCE)
|
cr.set_operator(cairo.OPERATOR_SOURCE)
|
||||||
cr.paint()
|
cr.paint()
|
||||||
cr.set_operator(cairo.OPERATOR_OVER)
|
cr.set_operator(cairo.OPERATOR_OVER)
|
||||||
|
|
||||||
def _load_interactive_debug(self):
|
def _load_interactive_debug(self):
|
||||||
self.set_interactive_debugging(True)
|
self.set_interactive_debugging(True)
|
||||||
|
|
||||||
|
|
||||||
def _tear_down(self, widget = None, eve = None):
|
def _tear_down(self, widget = None, eve = None):
|
||||||
event_system.emit("shutting_down")
|
event_system.emit("shutting_down")
|
||||||
settings_manager.clear_pid()
|
settings_manager.clear_pid()
|
||||||
Gtk.main_quit()
|
Gtk.main_quit()
|
||||||
|
|
||||||
|
def main(self):
|
||||||
|
Gtk.main()
|
|
@ -51,9 +51,10 @@ class IPCServer(Singleton):
|
||||||
listener = Listener((self._ipc_address, self._ipc_port))
|
listener = Listener((self._ipc_address, self._ipc_port))
|
||||||
|
|
||||||
self.is_ipc_alive = True
|
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:
|
def _run_ipc_loop(self, listener) -> None:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue