-
Use case: active menus, modal dialogs, etc. - I want to ensure that only specified widgets can receive focus until I determine otherwise. The current approach I am pursuing is to identify all widgets that are focusable and selectively remove that focus (remembering the ones I've changed) and then rest when done. It there a smarter way? For reference, what I'm doing now is: def push_focus(self):
"""remove focus for everything"""
self._focus_save = self.focused
self.set_focus(None)
for widget in self.screen.focus_chain:
self._focuslist.append(widget)
widget.can_focus = False
def pop_focus(self):
"""restore focus"""
while len(self._focuslist) > 0:
self._focuslist.pop().can_focus = True
if self._focus_save is not None:
self.set_focus(self._focus_save) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
As you'll have noticed, there's no builtin method of doing this and what you've got there looks like a good approach (I might personally be tempted to wrap it up in a class of its own, depending on how often it'd be used and in how many apps, but the core idea looks sound to me). As Textual stands right now the more "Textuallly" method of doing it would be to use As a simple illustration of this, see the help screen in the Five by Five example -- the main game grid there is done as buttons, and the help screen is modal; so doing that as a screen and popping it up over the main game screen means the user can't interact with the main game while the help is visible. |
Beta Was this translation helpful? Give feedback.
As you'll have noticed, there's no builtin method of doing this and what you've got there looks like a good approach (I might personally be tempted to wrap it up in a class of its own, depending on how often it'd be used and in how many apps, but the core idea looks sound to me).
As Textual stands right now the more "Textuallly" method of doing it would be to use
Screen
s; so if you have some sort of modal action that you want on top of your main screen, etc, you'd implement that in aScreen
, push that onto the screen stack, and then pop it back off when done.As a simple illustration of this, see the help screen in the Five by Five example -- the main game grid there is done as buttons, a…