Add lifecycle event handlers to `toga.Window`
harbor run -t mimo-v2.6-rl/format-code-task-000541harbor download mimo-v2.6-rl/format-code-task-000541Fix the following issue:
toga.WindowRight now a Window only lets you respond to one lifecycle event, on_close.
Applications frequently need to react to a window changing its focus or
visibility — for example, pausing background work when a window is hidden, or
refreshing data when it comes back to the foreground.
Add four new optional event handlers to toga.Window:
on_gain_focus — the window became the application's current (focused) window.on_lose_focus — the window stopped being the application's current window.on_show — the window became visible.on_hide — the window stopped being visible.Window
constructor and as a readable/writable property, in exactly the same way
the existing on_close handler works. Assigning a new callable to the
property replaces the handler.on_close behaves.The handlers fire in response to the following observable state changes:
on_show handler fires; when it transitions from visible to not-visible, its
on_hide handler fires. This applies whether visibility is changed through
show()/hide() or through the visible property. A request that does not
actually change the visibility (e.g. showing an already-visible window) must
not fire either handler.on_hide handler; restoring it from the minimized state back to a visible
state fires its on_show handler. Switching between other window states does
not fire these handlers, and a state request that leaves the state unchanged
fires nothing.on_lose_focus handler
fired, and the window that becomes current has its on_gain_focus handler
fired. Setting the current window to the window that is already current fires
neither handler.Adding these handlers should not disturb the existing on_close behavior.