Coder Social home page Coder Social logo

Comments (8)

willmcgugan avatar willmcgugan commented on June 1, 2024

We should implement these ANSI codes. Should be straightforward in theory. Enable the escape sequences, and convert them to AppFocus and AppBlur.

Talk to @willmcgugan if more clarification is needed.

from textual.

davep avatar davep commented on June 1, 2024

With an eye on the motivation for this: it would seem that there's benefit to the widgets in the focus chain knowing when AppFocus and AppBlur happens; I wonder if perhaps those events should be posted to the focused widget and allowed to bubble?

from textual.

willmcgugan avatar willmcgugan commented on June 1, 2024

What is the benefit?

from textual.

davep avatar davep commented on June 1, 2024

Just thinking about if there's utility for it when it comes to a random developer wanting to implement functionality on a widget that's related to having focus or not, and wanting to take into account if there emulator window has focus (while I recognise that it's not done with Focus and Blur with Input and TextArea, I'm thinking about any situations we've not considered yet that might be akin to the original motivation for the question that resulted in this issue).

from textual.

willmcgugan avatar willmcgugan commented on June 1, 2024

The behaviour (in Textual-web) is that when the window loses focus, the focused widget is blurred. When the window regains focus, the previously blurred widget is focused again.

This feels like an extension of the regular focus mechanism. I can't think why a developer would want to do something different. You can always check if the windows as focus with self.app.app_focus.

from textual.

davep avatar davep commented on June 1, 2024

The behaviour (in Textual-web) is that when the window loses focus, the focused widget is blurred. When the window regains focus, the previously blurred widget is focused again.

Ahh, cool, so it seems this is already taken care of anyway? Nice.

from textual.

davep avatar davep commented on June 1, 2024

Something to consider, perhaps as part of this, or as a fresh issue: it seems that the current implementation of AppBlur and AppFocus, as seen in textual-web, causes focus to be fully lost. For example, while testing with this code:

from pathlib import Path
from textual.app import App, ComposeResult
from textual.widgets import Digits, Input, TextArea

class AppFocusBlurApp(App[None]):

    def compose(self) -> ComposeResult:
        yield Digits("")
        yield Input(placeholder="Here's an input to help test")
        yield TextArea(Path(__file__).read_text(), language="python")

    def update_digits(self) -> None:
        self.query_one(Digits).update(
            ("1" if self.app_focus else "0") * (self.size.width // 3)
        )

    def on_mount(self) -> None:
        self.update_digits()

    def watch_app_focus(self) -> None:
        self.update_digits()

if __name__ == "__main__":
    AppFocusBlurApp().run()

if I focus the Input, Cmd-tab away to another window, then Cmd-tab back, I've lost my place in the form. It would be normal to expect focus to settle back where it was before once the app is focused again.

from textual.

github-actions avatar github-actions commented on June 1, 2024

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

from textual.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.