Test support, providing the ability to run the event loop from tests.
- class traits_futures.wx.event_loop_helper.AppForTesting(*args: Any, **kwargs: Any)¶
Subclass of wx.App used for testing.
Override base class to ensure we have at least one window.
Clean up when the object is no longer needed.
Exit the application main event loop with a given exit code.
The event loop can be started and stopped several times for a single AppForTesting object.
- class traits_futures.wx.event_loop_helper.AttributeSetter(*args: Any, **kwargs: Any)¶
Event handler that allows us to set object attributes from with a running event loop.
- class traits_futures.wx.event_loop_helper.EventLoopHelper¶
Support for running the wx event loop in unit tests.
Dispose of any resources used by this object.
Prepare the event loop for use.
- run_until(object, trait, condition, timeout)¶
Run event loop until the given condition holds true, or until timeout.
The condition is re-evaluated, with the object as argument, every time the trait changes.
traits.has_traits.HasTraits) – Object whose trait we monitor.
str) – Name of the trait to monitor for changes.
condition – Single-argument callable, returning a boolean. This will be called with object as the only input.
float) – Number of seconds to allow before timing out with an exception.
RuntimeError – If timeout is reached, regardless of whether the condition is true or not at that point.
- setattr_soon(obj, name, value)¶
Arrange for an attribute to be set once the event loop is running.
In typical usage, obj will be a
HasTraitsinstance and name will be the name of a trait on obj.
This method is not thread-safe. It’s designed to be called from the main thread.
- class traits_futures.wx.event_loop_helper.TimeoutTimer(*args: Any, **kwargs: Any)¶
Single-shot timer that executes a given callback on completion.
float) – Timeout in seconds.
callback – Callable taking no arguments, to be executed when the timer times out.
tuple, optional) – Tuple of positional arguments to pass to the callable. If not provided, no positional arguments are passed.
dict, optional) – Dictionary of keyword arguments to pass to the callable. If not provided, no keyword arguments are passed.
Execute the callback when the timer completes.
Start the timer.
Stop the timer if it hasn’t already expired. The callback will not be executed.