From bc9ca95fe820070ce81020181d87867f8462caf5 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Fri, 24 Jan 2025 20:21:06 +0000 Subject: [PATCH] Make ui_handler publicly available again --- traits/trait_notifiers.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/traits/trait_notifiers.py b/traits/trait_notifiers.py index ab7143d9e..3a8a94b2f 100644 --- a/traits/trait_notifiers.py +++ b/traits/trait_notifiers.py @@ -29,31 +29,33 @@ # The currently active handler for notifications that must be run on the UI # thread, or None if no handler has been set. -_ui_handler = None +# Note: the Pyface library current accesses the `ui_handler` attribute +# directly, so we can't make it private yet. +ui_handler = None def get_ui_handler(): """ Return the current user interface thread handler. """ - return _ui_handler + return ui_handler def set_ui_handler(handler): """ Sets up the user interface thread handler. """ - global _ui_handler + global ui_handler - _ui_handler = handler + ui_handler = handler def ui_dispatch(handler, *args, **kw): if threading.current_thread() == threading.main_thread(): handler(*args, **kw) - elif _ui_handler is None: + elif ui_handler is None: raise RuntimeError("no UI handler registered for dispatch='ui'") else: - _ui_handler(handler, *args, **kw) + ui_handler(handler, *args, **kw) class NotificationExceptionHandlerState(object): @@ -616,10 +618,10 @@ class FastUITraitChangeNotifyWrapper(TraitChangeNotifyWrapper): def dispatch(self, handler, *args): if threading.current_thread() == threading.main_thread(): handler(*args) - elif _ui_handler is None: + elif ui_handler is None: raise RuntimeError("no UI handler registered for dispatch='ui'") else: - _ui_handler(handler, *args) + ui_handler(handler, *args) class NewTraitChangeNotifyWrapper(TraitChangeNotifyWrapper):