Replies: 2 comments 3 replies
-
Do you think you could provide an MRE of the problems you're talking about here? I ask because I don't really recognise any of them as issues I run into when using from textual import on
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.screen import ModalScreen
from textual.widgets import ListView, ListItem, Label, Button
class ModalDialog(ModalScreen[None]):
CSS = """
ModalDialog {
align: center middle;
Vertical {
border: panel cornflowerblue;
width: 70%;
height: 70%;
Button {
width: 1fr;
}
}
}
"""
def compose(self) -> ComposeResult:
with Vertical():
yield ListView(*[ListItem(Label(f"This is list item in a modal screen {n}")) for n in range(100)])
yield Button("Close")
@on(Button.Pressed)
def close(self) -> None:
self.dismiss()
class ModalScreenFocusApp(App[None]):
def compose(self) -> ComposeResult:
yield ListView(*[ListItem(Label(f"This is list item {n}")) for n in range(100)])
@on(ListView.Selected)
def show_modal(self) -> None:
self.push_screen(ModalDialog())
if __name__ == "__main__":
ModalScreenFocusApp().run() If you could show a similar-sized example of the problems you're seeing, it might make it easier for people to help. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your response @davep The main thing I'd like to do is visually attach my new "modal" (i'm not actually using a from textual import on
from textual.app import App, ComposeResult
from textual.widgets import ListView, ListItem, Label, Static, Button
class ListItemPrompt(Static):
BINDINGS = [
('x', 'cancel', 'Cancel'),
('c', 'confirm', 'Confirm'),
]
def on_mount(self):
self.query('Button').first().focus()
def compose(self):
yield Button('Cancel')
yield Button('Confirm')
def action_cancel(self):
self.remove()
def action_confirm(self):
self.remove()
class PromptApp(App[None]):
def compose(self) -> ComposeResult:
yield ListView(*[ListItem(Label(f"This is list item {n}")) for n in range(100)])
def on_list_view_selected(self, message) -> None:
message.item.mount(ListItemPrompt())
if __name__ == "__main__":
PromptApp().run() The issue with this example is that while the This example is still incomplete because there is no way currently to act on the cancel or confirm button press. I would handle this by generating a custom |
Beta Was this translation helpful? Give feedback.
-
I'd like to have a Dialog that prompts the user for Cancel/Confirm. It's important that other hotkeys be disabled while this Dialog is presented.
I'm aware of ModalScreen and it generally satisfies that requirement, but it has two downsides:
I have a ListView and want to allow hotkeys to perform actions on individual ListItems. I am mounting a custom Dialog widget after the ListItem that contains a Cancel and Confirm button. While this is displayed, though, I don't want the up/down arrows to move the highlight up/down in the ListView, for example.
My Diaglog is focused, so I can capture up/down keybindings, but it doesn't feel reusable enough for me to explicitly mask a list of keybindings I know exist. I really want to capture/eat/disable all other non-priority bindings that are not used for my Dialog. I feel like I'm missing something, but don't see a good way to do this.
Can anyone point me in the right direction?
Beta Was this translation helpful? Give feedback.
All reactions