Skip to content

Commit d1464b5

Browse files
committed
Enhance Focus event with from_app_focus argument
Added a new argument `from_app_focus` to the Focus event class to indicate whether the focus event was triggered by the application regaining focus or by user interaction within the Textual app. Updated the constructor to initialize this new attribute.
1 parent b444c0f commit d1464b5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/textual/events.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
from dataclasses import dataclass
1717
from pathlib import Path
1818
from typing import TYPE_CHECKING, Type, TypeVar
19-
from typing_extensions import Self
2019

2120
import rich.repr
2221
from rich.style import Style
22+
from typing_extensions import Self
2323

2424
from textual._types import CallbackType
2525
from textual.geometry import Offset, Size
@@ -722,8 +722,18 @@ class Focus(Event, bubble=False):
722722
723723
- [ ] Bubbles
724724
- [ ] Verbose
725+
726+
Args:
727+
from_app_focus: True if this focus event has been sent because the app itself has
728+
regained focus (via an AppFocus event). False if the focus came from within
729+
the Textual app (e.g. via the user pressing tab or a programmatic setting
730+
of the focused widget).
725731
"""
726732

733+
def __init__(self, from_app_focus: bool = False) -> None:
734+
self.from_app_focus = from_app_focus
735+
super().__init__()
736+
727737

728738
class Blur(Event, bubble=False):
729739
"""Sent when a widget is blurred (un-focussed).

0 commit comments

Comments
 (0)