Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
✨ Add a tester for Textualize/textual#3045
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Feb 20, 2024
1 parent 34863b0 commit 5d72735
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions tooltip_hell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""Test harness for tooltip issues."""

from textual import on
from textual.app import App, ComposeResult
from textual.containers import Grid, VerticalScroll
from textual.widget import Widget
from textual.widgets import Button, Label

class GoodTipper:

@staticmethod
def tip(widget: Widget) -> Widget:
widget.tooltip = (
f"[bold]This is a tooltip![/]\n\n"
f"[italic]The widget's ID is {widget.id}\n\n"
"It has a bunch of text. Cool huh?"
)
return widget

class Buttonatron(Grid, GoodTipper, can_focus=True):

DEFAULT_CSS = """
Buttonatron {
height: 1fr;
grid-size: 5;
grid-rows: 5;
Button {
width: 1fr;
height: 1fr;
margin: 0 1 0 1;
}
}
"""

BINDINGS = [("space", "add")]

def action_add(self) -> None:
button_id = str(len(self.children))
self.mount(
self.tip(
Button(f"Button #{button_id}\n\nPress me to remove me", id=f"button-{button_id}")
)
)

@on(Button.Pressed)
def remove_button(self, event: Button.Pressed) -> None:
event.control.remove()

class LabelsAllTheWayDown(VerticalScroll, GoodTipper, can_focus=True):

DEFAULT_CSS = """
LabelsAllTheWayDown {
Grid {
grid-size: 5;
height: auto;
grid-rows: 10;
Label {
background: $panel;
border: panel cornflowerblue;
width: 1fr;
height: 1fr;
margin-bottom: 1;
}
}
}
"""

def compose(self) -> ComposeResult:
with Grid():
for n in range(200):
yield self.tip(Label(f"Here is label #{n}", id=f"label-{n}"))

class TooltipHellApp(App[None]):

CSS = """
Screen > * {
border: blank;
&:focus {
border: thick green;
}
}
"""

def compose(self) -> ComposeResult:
yield Buttonatron()
yield LabelsAllTheWayDown()

if __name__ == "__main__":
TooltipHellApp().run()

### tooltip_hell.py ends here

0 comments on commit 5d72735

Please sign in to comment.