2
2
3
3
from __future__ import annotations
4
4
5
- from typing import Any
6
-
7
5
from textual .app import ComposeResult
8
6
from textual .binding import Binding
9
7
from textual .containers import Horizontal , Vertical
10
- from textual .message import Message
11
8
from textual .screen import ModalScreen
12
- from textual .widget import Widget
13
9
from textual .widgets import Button , Input , Label
14
10
15
11
16
- class InputDialog (ModalScreen [None ]):
12
+ class InputDialog (ModalScreen [str ]):
17
13
"""A modal dialog for getting a single input from the user."""
18
14
19
15
DEFAULT_CSS = """
@@ -59,32 +55,18 @@ class InputDialog(ModalScreen[None]):
59
55
]
60
56
"""Bindings for the dialog."""
61
57
62
- def __init__ ( # pylint:disable=redefined-builtin,too-many-arguments
63
- self ,
64
- requester : Widget ,
65
- prompt : str ,
66
- initial : str | None = None ,
67
- cargo : Any = None ,
68
- id : str | None = None ,
69
- ) -> None :
58
+ def __init__ (self , prompt : str , initial : str | None = None ) -> None :
70
59
"""Initialise the input dialog.
71
60
72
61
Args:
73
- requester: The widget requesting the input.
74
62
prompt: The prompt for the input.
75
63
initial: The initial value for the input.
76
- cargo: Any cargo value for the input.
77
- id: The ID for the dialog.
78
64
"""
79
- super ().__init__ (id = id )
80
- self ._requester = requester
81
- """A reference to the widget requesting the input."""
65
+ super ().__init__ ()
82
66
self ._prompt = prompt
83
67
"""The prompt to display for the input."""
84
68
self ._initial = initial
85
69
"""The initial value to use for the input."""
86
- self ._cargo = cargo
87
- """Any cargo data for the input dialog."""
88
70
89
71
def compose (self ) -> ComposeResult :
90
72
"""Compose the child widgets."""
@@ -100,33 +82,6 @@ def on_mount(self) -> None:
100
82
"""Set up the dialog once the DOM is ready."""
101
83
self .query_one (Input ).focus ()
102
84
103
- class Result (Message ):
104
- """The input dialog result message."""
105
-
106
- def __init__ (
107
- self , sender_id : str | None , value : str , cargo : Any = None
108
- ) -> None :
109
- """Initialise the result message.
110
-
111
- Args:
112
- sender_id: The ID of the dialog sending the message.
113
- value: The value to attach as the result.
114
- cargo: Any cargo data for the result.
115
- """
116
- super ().__init__ ()
117
- self .sender_id : str | None = sender_id
118
- """The ID of the sending dialog."""
119
- self .value : str = value
120
- """The value of the result."""
121
- self .cargo : Any = cargo
122
- """Cargo data for the result."""
123
-
124
- def _return_input (self ) -> None :
125
- """Return the input value from the dialog."""
126
- self ._requester .post_message (
127
- self .Result (self .id , self .query_one (Input ).value , self ._cargo )
128
- )
129
-
130
85
def on_button_pressed (self , event : Button .Pressed ) -> None :
131
86
"""Handle one of the dialog's buttons been pressed.
132
87
@@ -136,8 +91,7 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
136
91
if event .button .id == "cancel" :
137
92
self .app .pop_screen ()
138
93
elif event .button .id == "ok" and self .query_one (Input ).value .strip ():
139
- self ._return_input ()
140
- self .app .pop_screen ()
94
+ self .dismiss (self .query_one (Input ).value )
141
95
142
96
def on_input_submitted (self ) -> None :
143
97
"""Do default processing when the user hits enter in the input."""
0 commit comments