Global threading decorators; Endpoint registry creation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Python imports
|
||||
import builtins
|
||||
import builtins, threading
|
||||
|
||||
# Lib imports
|
||||
|
||||
@@ -7,6 +7,21 @@ import builtins
|
||||
from utils.ipc_server import IPCServer
|
||||
|
||||
|
||||
# NOTE: Threads will not die with parent's destruction
|
||||
def threaded_wrapper(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
|
||||
return wrapper
|
||||
|
||||
# NOTE: Insure threads die with parent's destruction
|
||||
def daemon_threaded_wrapper(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
return wrapper
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class EventSystem(IPCServer):
|
||||
@@ -65,10 +80,32 @@ class EventSystem(IPCServer):
|
||||
|
||||
|
||||
|
||||
class EndpointRegistry():
|
||||
def __init__(self):
|
||||
self._endpoints = {}
|
||||
|
||||
def register(self, rule, **options):
|
||||
def decorator(f):
|
||||
_endpoint = options.pop("endpoint", None)
|
||||
self._endpoints[rule] = f
|
||||
return f
|
||||
|
||||
return decorator
|
||||
|
||||
def get_endpoints(self):
|
||||
return self._endpoints
|
||||
|
||||
|
||||
|
||||
|
||||
# NOTE: Just reminding myself we can add to builtins two different ways...
|
||||
# __builtins__.update({"event_system": Builtins()})
|
||||
builtins.app_name = "SolarFM"
|
||||
builtins.event_system = EventSystem()
|
||||
builtins.endpoint_registry = EndpointRegistry()
|
||||
builtins.threaded = threaded_wrapper
|
||||
builtins.daemon_threaded = daemon_threaded_wrapper
|
||||
builtins.event_sleep_time = 0.05
|
||||
builtins.trace_debug = False
|
||||
builtins.debug = False
|
||||
builtins.app_settings = None
|
||||
|
@@ -4,9 +4,9 @@ import os, inspect, time
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from __builtins__ import EventSystem
|
||||
from utils.settings import Settings
|
||||
from core.controller import Controller
|
||||
from __builtins__ import EventSystem
|
||||
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# Python imports
|
||||
import os, gc, threading, time
|
||||
import os, gc, time
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
@@ -14,19 +14,6 @@ from .signals.keyboard_signals_mixin import KeyboardSignalsMixin
|
||||
from .controller_data import Controller_Data
|
||||
|
||||
|
||||
# NOTE: Threads will not die with parent's destruction
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
|
||||
return wrapper
|
||||
|
||||
# NOTE: Insure threads die with parent's destruction
|
||||
def daemon_threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
return wrapper
|
||||
|
||||
|
||||
|
||||
|
||||
class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMixin, Controller_Data):
|
||||
@@ -177,23 +164,28 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
|
||||
|
||||
|
||||
|
||||
|
||||
@endpoint_registry.register(rule="go_home")
|
||||
def go_home(self, widget=None, eve=None):
|
||||
self.builder.get_object("go_home").released()
|
||||
|
||||
@endpoint_registry.register(rule="refresh_tab")
|
||||
def refresh_tab(self, widget=None, eve=None):
|
||||
self.builder.get_object("refresh_tab").released()
|
||||
|
||||
@endpoint_registry.register(rule="go_up")
|
||||
def go_up(self, widget=None, eve=None):
|
||||
self.builder.get_object("go_up").released()
|
||||
|
||||
@endpoint_registry.register(rule="grab_focus_path_entry")
|
||||
def grab_focus_path_entry(self, widget=None, eve=None):
|
||||
self.builder.get_object("path_entry").grab_focus()
|
||||
|
||||
@endpoint_registry.register(rule="tggl_top_main_menubar")
|
||||
def tggl_top_main_menubar(self, widget=None, eve=None):
|
||||
top_main_menubar = self.builder.get_object("top_main_menubar")
|
||||
top_main_menubar.hide() if top_main_menubar.is_visible() else top_main_menubar.show()
|
||||
|
||||
@endpoint_registry.register(rule="open_terminal")
|
||||
def open_terminal(self, widget=None, eve=None):
|
||||
wid, tid = self.fm_controller.get_active_wid_and_tid()
|
||||
tab = self.get_fm_window(wid).get_tab_by_id(tid)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# Python imports
|
||||
import traceback, threading, time
|
||||
import traceback, time
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
@@ -9,10 +9,6 @@ from gi.repository import Gtk, GLib
|
||||
# Application imports
|
||||
|
||||
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
return wrapper
|
||||
|
||||
|
||||
class ExceptionHookMixin:
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# Python imports
|
||||
import os, threading, subprocess, time
|
||||
import os
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
@@ -11,12 +11,6 @@ from gi.repository import Gtk, Gdk, GLib, Gio, GdkPixbuf
|
||||
# Application imports
|
||||
|
||||
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
return wrapper
|
||||
|
||||
|
||||
|
||||
|
||||
# NOTE: Consider trying to use Gtk.TreeView with css that turns it into a grid...
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# Python imports
|
||||
import os, time, threading, shlex
|
||||
import os, time, shlex
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
@@ -9,10 +9,6 @@ from gi.repository import Gtk, GObject, GLib, Gio
|
||||
# Application imports
|
||||
|
||||
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
return wrapper
|
||||
|
||||
|
||||
class WidgetFileActionMixin:
|
||||
|
Reference in New Issue
Block a user