Python-With-Gtk-Template/src/__builtins__.py

54 lines
1.3 KiB
Python
Raw Normal View History

2022-09-05 23:01:39 +00:00
import builtins, threading
2021-10-11 04:33:58 +00:00
2022-01-23 22:56:27 +00:00
# Python imports
import builtins
# Lib imports
# Application imports
2022-09-05 23:01:39 +00:00
from utils.event_system import EventSystem
2022-01-23 22:56:27 +00:00
2022-02-25 23:53:58 +00:00
2022-01-23 22:56:27 +00:00
2022-09-05 23:01:39 +00:00
# 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
2022-01-23 22:56:27 +00:00
2022-09-05 23:01:39 +00:00
# NOTE: Threads WILL 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
2022-01-23 22:56:27 +00:00
2022-09-05 23:01:39 +00:00
class EndpointRegistry():
def __init__(self):
self._endpoints = {}
2022-01-23 22:56:27 +00:00
2022-09-05 23:01:39 +00:00
def register(self, rule, **options):
def decorator(f):
self._endpoints[rule] = f
return f
2022-01-23 22:56:27 +00:00
2022-09-05 23:01:39 +00:00
return decorator
2022-01-23 22:56:27 +00:00
2022-09-05 23:01:39 +00:00
def get_endpoints(self):
return self._endpoints
2022-01-23 22:56:27 +00:00
2021-10-11 04:28:19 +00:00
2021-10-11 04:33:58 +00:00
2021-10-11 04:28:19 +00:00
2022-01-23 22:56:27 +00:00
# NOTE: Just reminding myself we can add to builtins two different ways...
# __builtins__.update({"event_system": Builtins()})
builtins.app_name = "<change_me>"
2022-02-25 23:53:58 +00:00
builtins.event_system = EventSystem()
2022-09-05 23:01:39 +00:00
builtins.endpoint_registry = EndpointRegistry()
builtins.threaded = threaded_wrapper
builtins.daemon_threaded = daemon_threaded_wrapper
builtins.event_sleep_time = 0.05
2022-01-23 22:56:27 +00:00
builtins.trace_debug = False
2022-03-25 03:11:02 +00:00
builtins.debug = False