Textualize / textual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.
https://textual.textualize.io/
MIT License
25.2k stars 773 forks source link

`on_leave` event being fired by widget in inactive screen #4630

Closed kwevin closed 3 months ago

kwevin commented 3 months ago

Occurs in version v0.63 and v0.66

Textual Diagnostics

Versions

Name Value
Textual 0.63.0
Rich 13.7.1

Python

Name Value
Version 3.11.1
Implementation CPython
Compiler MSC v.1934 64 bit (AMD64)
Executable C:\Users\Kevin\AppData\Local\pypoetry\Cache\virtualenvs\listentui-qruDwX8r-py3.11\Scripts\python.exe

Operating System

Name Value
System Windows
Release 10
Version 10.0.22621

Terminal

Name Value
Terminal Application Windows Terminal
TERM Not set
COLORTERM Not set
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=171, height=30
legacy_windows False
min_width 1
max_width 171
is_terminal True
encoding utf-8
max_height 30
justify None
overflow None
no_wrap False
highlight None
markup None
height None

on_leave event is being fired despite staying within the widget. This only started happening after updating to v0.63.0 from v0.62.0. I've attempted to narrow down the issue and found out that widgets or tasks from an inactive screen was causing the issue.

https://github.com/Textualize/textual/assets/86712199/7a91a23c-0f1f-4ab8-ba06-7574c5516f09

Here is how the screen is pushed. And by commenting out the widgets in tabbed content at main.py (the main screen) and pushing a test screen, the issue doesn't appear. if the test screen was pushed with all the tabbed content widget it would repeatedly fire _on_leave like in the example video.

Here is a demonstration of what I am talking about.

https://github.com/Textualize/textual/assets/86712199/13000885-d3aa-4378-87fb-0e2da23fb9e1

All the code can be found at https://github.com/kwevin/LISTEN.tui/tree/mre in the mre branch To run my repository, you would need libmpv to be in your PATH or env variable. Guide here.

Thank you.

charles-001 commented 3 months ago

+1 this issue affects me as well

willmcgugan commented 3 months ago

I'm going to need an MRE for this. If I can't reproduce it, I'm working blind.

If you can reproduce it in your app, I would suggest removing things until it goes away.

Check that whatever is under cursor isn't actually changing. Are you recomposing? That will cause a leave. Ditto if you setting the loading flag on a widget, that will cause a leave event because the loading indicator is now under the mouse.

Are you using workers? Any threads?

Basically, I need something to work with.

kwevin commented 3 months ago

I tried to recreate the issue with an MRE but i have no luck in doing so. Though I've narrowed down the issue to be a widget in an inactive screen I don't still know what cause the issues.

Are you recomposing?

It is using reactive to change the content when hovered over. But by commenting out the widgets in another screen the issue was resolved.

Are you using workers? Any threads?

No workers or threads are used to push the screen. There are normal worker and threaded worker running in the background.

The screen stack I currently have looks like this:

App
   |
Main(Screen) <-- caused by some widget here
   |
Popup(Screen) <-- issue happens here

By commenting out the widgets in my Main screen the issue in the popup screen disappear. This also only started happening after upgrading to v0.63.0. I'll try to narrow down what is causing it, but so far recreating the situation under and MRE seems to not have work.

charles-001 commented 3 months ago

@willmcgugan - I seemed to have successfully created an MRE. The issue with the code attached is:

tab.dashboard_container.display = False
tab.loading_indicator.display = False
tab.progressbar.display = False
tab.additional_info.display = False
tab.line.display = False

It seems from v0.63.0 and onwards, this type of code is problematic.

mre.py.zip

github-actions[bot] commented 3 months ago

Don't forget to star the repository!

Follow @textualizeio for Textual updates.