Skip to content

Commit 01ae0ad

Browse files
committed
tooltip params
1 parent 14f5a9d commit 01ae0ad

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

src/textual/widgets/_button.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def __init__(
184184
id: str | None = None,
185185
classes: str | None = None,
186186
disabled: bool = False,
187+
tooltip: RenderableType | None = None,
187188
):
188189
"""Create a Button widget.
189190
@@ -194,6 +195,7 @@ def __init__(
194195
id: The ID of the button in the DOM.
195196
classes: The CSS classes of the button.
196197
disabled: Whether the button is disabled or not.
198+
tooltip: Optional tooltip.
197199
"""
198200
super().__init__(name=name, id=id, classes=classes, disabled=disabled)
199201

@@ -204,6 +206,8 @@ def __init__(
204206
self.variant = variant
205207
self.active_effect_duration = 0.3
206208
"""Amount of time in seconds the button 'press' animation lasts."""
209+
if tooltip is not None:
210+
self.tooltip = tooltip
207211

208212
def get_content_width(self, container: Size, viewport: Size) -> int:
209213
try:

src/textual/widgets/_input.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def __init__(
257257
id: str | None = None,
258258
classes: str | None = None,
259259
disabled: bool = False,
260+
tooltip: RenderableType | None = None,
260261
) -> None:
261262
"""Initialise the `Input` widget.
262263
@@ -279,6 +280,7 @@ def __init__(
279280
id: Optional ID for the widget.
280281
classes: Optional initial classes for the widget.
281282
disabled: Whether the input is disabled or not.
283+
tooltip: Optional tooltip.
282284
"""
283285
super().__init__(name=name, id=id, classes=classes, disabled=disabled)
284286

@@ -335,6 +337,8 @@ def __init__(
335337

336338
if value is not None:
337339
self.value = value
340+
if tooltip is not None:
341+
self.tooltip = tooltip
338342

339343
def _position_to_cell(self, position: int) -> int:
340344
"""Convert an index within the value to cell position."""

src/textual/widgets/_option_list.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ def __init__(
285285
classes: str | None = None,
286286
disabled: bool = False,
287287
wrap: bool = True,
288+
tooltip: RenderableType | None = None,
288289
):
289290
"""Initialise the option list.
290291
@@ -295,6 +296,7 @@ def __init__(
295296
classes: The CSS classes of the option list.
296297
disabled: Whether the option list is disabled or not.
297298
wrap: Should prompts be auto-wrapped?
299+
tooltip: Optional tooltip.
298300
"""
299301
super().__init__(name=name, id=id, classes=classes, disabled=disabled)
300302

@@ -361,6 +363,9 @@ def __init__(
361363
# the state of the option list in regard to its available options.
362364
self.action_first()
363365

366+
if tooltip is not None:
367+
self.tooltip = tooltip
368+
364369
def get_content_width(self, container: Size, viewport: Size) -> int:
365370
"""Get maximum width of options."""
366371
console = self.app.console

src/textual/widgets/_radio_set.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import ClassVar, Optional
66

77
import rich.repr
8+
from rich.console import RenderableType
89

910
from .. import _widget_navigation
1011
from ..binding import Binding, BindingType
@@ -121,6 +122,7 @@ def __init__(
121122
id: str | None = None,
122123
classes: str | None = None,
123124
disabled: bool = False,
125+
tooltip: RenderableType | None = None,
124126
) -> None:
125127
"""Initialise the radio set.
126128
@@ -130,6 +132,7 @@ def __init__(
130132
id: The ID of the radio set in the DOM.
131133
classes: The CSS classes of the radio set.
132134
disabled: Whether the radio set is disabled or not.
135+
tooltip: Optional tooltip.
133136
134137
Note:
135138
When a `str` label is provided, a
@@ -148,6 +151,8 @@ def __init__(
148151
classes=classes,
149152
disabled=disabled,
150153
)
154+
if tooltip is not None:
155+
self.tooltip = tooltip
151156

152157
def _on_mount(self, _: Mount) -> None:
153158
"""Perform some processing once mounted in the DOM."""

src/textual/widgets/_select.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ def __init__(
298298
id: str | None = None,
299299
classes: str | None = None,
300300
disabled: bool = False,
301+
tooltip: RenderableType | None = None,
301302
):
302303
"""Initialize the Select control.
303304
@@ -315,6 +316,7 @@ def __init__(
315316
id: The ID of the control in the DOM.
316317
classes: The CSS classes of the control.
317318
disabled: Whether the control is disabled or not.
319+
tooltip: Optional tooltip.
318320
319321
Raises:
320322
EmptySelectError: If no options are provided and `allow_blank` is `False`.
@@ -324,6 +326,8 @@ def __init__(
324326
self.prompt = prompt
325327
self._value = value
326328
self._setup_variables_for_options(options)
329+
if tooltip is not None:
330+
self.tooltip = tooltip
327331

328332
@classmethod
329333
def from_values(

src/textual/widgets/_toggle_button.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from typing import TYPE_CHECKING, ClassVar
99

10+
from rich.console import RenderableType
1011
from rich.style import Style
1112
from rich.text import Text, TextType
1213

@@ -130,6 +131,7 @@ def __init__(
130131
id: str | None = None,
131132
classes: str | None = None,
132133
disabled: bool = False,
134+
tooltip: RenderableType | None = None,
133135
) -> None:
134136
"""Initialise the toggle.
135137
@@ -141,13 +143,16 @@ def __init__(
141143
id: The ID of the toggle in the DOM.
142144
classes: The CSS classes of the toggle.
143145
disabled: Whether the button is disabled or not.
146+
tooltip: RenderableType | None = None,
144147
"""
145148
super().__init__(name=name, id=id, classes=classes, disabled=disabled)
146149
self._button_first = button_first
147150
# NOTE: Don't send a Changed message in response to the initial set.
148151
with self.prevent(self.Changed):
149152
self.value = value
150153
self._label = self._make_label(label)
154+
if tooltip is not None:
155+
self.tooltip = tooltip
151156

152157
def _make_label(self, label: TextType) -> Text:
153158
"""Make a `Text` label from a `TextType` value.

0 commit comments

Comments
 (0)