Skip to content

Commit

Permalink
Enhance Focus event with from_app_focus argument
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
darrenburns committed Dec 12, 2024
1 parent b444c0f commit d1464b5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/textual/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING, Type, TypeVar
from typing_extensions import Self

import rich.repr
from rich.style import Style
from typing_extensions import Self

from textual._types import CallbackType
from textual.geometry import Offset, Size
Expand Down Expand Up @@ -722,8 +722,18 @@ class Focus(Event, bubble=False):
- [ ] Bubbles
- [ ] Verbose
Args:
from_app_focus: True if this focus event has been sent because the app itself has
regained focus (via an AppFocus event). False if the focus came from within
the Textual app (e.g. via the user pressing tab or a programmatic setting
of the focused widget).
"""

def __init__(self, from_app_focus: bool = False) -> None:
self.from_app_focus = from_app_focus
super().__init__()


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

0 comments on commit d1464b5

Please sign in to comment.