Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding global event handlers directly from the widget #4485

Closed
piankma opened this issue May 6, 2024 · 2 comments · Fixed by #4487
Closed

Adding global event handlers directly from the widget #4485

piankma opened this issue May 6, 2024 · 2 comments · Fixed by #4487

Comments

@piankma
Copy link

piankma commented May 6, 2024

Hello,

I'm working right now on a project, that utilizes the menubar:
CleanShot 2024-05-06 at 23 00 07@2x
Functionality of this widget is pretty clear:

  • on hover, change background and show tooltip
  • on click, execute predefined action
  • on click outside of the widget, close it...
    and the third point gave me this headache. It's pretty simple to program this behaviour - just implement the MouseDown event on App class, and if not event.get_content_offset(widget) it will close the menu or do whatever else you want.

I thought that I could share this widget later on, as from my point of view Textual lacks this kind of widget. But - it will be hard to reuse for other people, as it requires additional code on the app subclass.
So, my feature request is the ability to add global event handlers directly from widget.
I've discussed with Will on Discord about Widget.capture_mouse(true), but... this captures the mouse and prohibits other events from hapenning, like hover or click on submenu items (subwidgets in this context) which is not acceptable.

Copy link

github-actions bot commented May 6, 2024

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

Copy link

github-actions bot commented May 7, 2024

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant