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

80 lines
2.4 KiB
Python
Raw Normal View History

2022-01-23 16:56:27 -06:00
# Python imports
import builtins
import traceback
2023-01-29 00:06:52 -06:00
import threading
import sys
2022-01-23 16:56:27 -06:00
# Lib imports
# Application imports
# from libs.db import DB
2024-01-11 19:35:04 -06:00
from libs.event_system import EventSystem
from libs.endpoint_registry import EndpointRegistry
from libs.keybindings import Keybindings
from libs.logger import Logger
from libs.settings.manager import SettingsManager
2022-02-25 17:53:58 -06:00
2022-09-05 18:01:39 -05:00
# NOTE: Threads WILL NOT die with parent's destruction.
def threaded_wrapper(fn):
def wrapper(*args, **kwargs):
thread = threading.Thread(target = fn, args = args, kwargs = kwargs, daemon = False)
thread.start()
return thread
2022-09-05 18:01:39 -05:00
return wrapper
2022-01-23 16:56:27 -06:00
2022-09-05 18:01:39 -05:00
# NOTE: Threads WILL die with parent's destruction.
def daemon_threaded_wrapper(fn):
def wrapper(*args, **kwargs):
thread = threading.Thread(target = fn, args = args, kwargs = kwargs, daemon = True)
thread.start()
return thread
2022-09-05 18:01:39 -05:00
return wrapper
2022-01-23 16:56:27 -06:00
def call_chain_wrapper(fn):
def wrapper(*args, **kwargs):
print()
print()
for line in traceback.format_stack():
print( line.strip() )
print()
print()
return fn(*args, **kwargs)
return wrapper
2022-01-23 16:56:27 -06:00
2021-10-10 23:33:58 -05:00
2022-01-23 16:56:27 -06:00
# NOTE: Just reminding myself we can add to builtins two different ways...
# __builtins__.update({"event_system": Builtins()})
2024-02-29 18:50:34 -06:00
builtins.APP_NAME = "<change_me>"
builtins.keybindings = Keybindings()
2022-02-25 17:53:58 -06:00
builtins.event_system = EventSystem()
2022-09-05 18:01:39 -05:00
builtins.endpoint_registry = EndpointRegistry()
builtins.settings_manager = SettingsManager()
# builtins.db = DB()
2023-09-17 20:08:09 -05:00
settings_manager.load_settings()
builtins.settings = settings_manager.settings
builtins.logger = Logger(
settings_manager.get_home_config_path(), \
_ch_log_lvl = settings.debugging.ch_log_lvl, \
_fh_log_lvl = settings.debugging.fh_log_lvl
).get_logger()
2022-09-05 18:01:39 -05:00
builtins.threaded = threaded_wrapper
builtins.daemon_threaded = daemon_threaded_wrapper
builtins.call_chain = call_chain_wrapper
def custom_except_hook(exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logger.error("Uncaught exception", exc_info = (exc_type, exc_value, exc_traceback))
sys.excepthook = custom_except_hook