Switch between multiple sets of bindings #1306
-
It would be great to support binding modes in my textual apps. Similar to command mode and edit mode in vim I'd like to be able to switch out different sets of bindings. I see I can have different bindings associated with different screens but I'd like to be able to change between binding sets within one screen. I tried updating the |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 2 replies
-
I what sort of situations are you finding you want to swap bindings within a screen? What sort of context causes the wish to swap around? I ask only because, last week, I sort of found myself wanting to do the same but I realise that what I really wanted to be doing was to have relevant bindings at the widget level. |
Beta Was this translation helpful? Give feedback.
-
Oh interesting I didn't realise you could add bindings to widgets! So would you have different bindings when different widgets are in focus? I have about 8 widgets on my screen, but I only want two of them to be focusable, and one or other should always be in focus. Right now to achieve this I'm not using focus and doing things manually, but I can definitely change that. |
Beta Was this translation helpful? Give feedback.
-
Yup, that's what I did with this app. Mostly I don't want any bindings other than a couple of very general ones, but when focus is within one of the activity displays, I have a whole bunch of bindings on that widget. Note too that the bindings are in effect if any of that widget's children are focused. More generally, this is how bindings work in Textual. There's a slight aside I won't get into here, but in effect everything is a widget and a binding declared for a widget is good for that widget and all child widgets. Define for your app? That's good for all screens and widgets within. Defined for one screen? That's good for all widgets within. Defined for a particular widget? That's good for that widget and its children. |
Beta Was this translation helpful? Give feedback.
-
Ok that makes sense. In that case I have two widgets that I want different (overlapping) bindings on. If neither of them is in focus I want one of them to be kept in focus. I.e none of the other widgets should be focusable. Do you have thoughts on a "correct" way to do that? |
Beta Was this translation helpful? Give feedback.
-
What are the other widgets such that they can be focused but you don't want them to have focus? Normally I'd only use a focusable widget if I want it to have focus, otherwise I'd use something different that can't have focus. |
Beta Was this translation helpful? Give feedback.
-
Heh I guess this is getting to the core of my misunderstanding. I assumed all widgets were always focusable (but I couldn't seem to get focus working either). From your question I'm guessing widget focus is opt in somehow which makes sense why I couldn't get my widget to focus. I can't figure out from the docs how to make a "focusable widget". Maybe to rephrase my question. How do I make two of my widgets focusable? And how do I ensure that I can't be in a fully blurred state (one widget must always be in focus)? (Feel free to redirect me to the forum if that's a better place for this question) |
Beta Was this translation helpful? Give feedback.
-
Aye, I think this is turning more into a Q&A, I'll move this to there. |
Beta Was this translation helpful? Give feedback.
Heh I guess this is getting to the core of my misunderstanding. I assumed all widgets were always focusable (but I couldn't seem to get focus working either). From your question I'm guessing widget focus is opt in somehow which makes sense why I couldn't get my widget to focus. I can't figure out from the docs how to make a "focusable widget".
Maybe to rephrase my question. How do I make two of my widgets focusable? And how do I ensure that I can't be in a fully blurred state (one widget must always be in focus)?
(Feel free to redirect me to the forum if that's a better place for this question)