mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add a Label widget
For the moment this does nothing more than inherit from a Static; but what it does do is make it easier for someone to add text to their application and to style it by styling all the Labels. Before now it would be common to use a Static but if you try and style (or query) all Statics, you'd also get things like Buttons, which inherit from Static. See #1190
This commit is contained in:
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
https://github.com/Textualize/textual/issues/1094
|
||||
- Added Pilot.wait_for_animation
|
||||
- Added `Widget.move_child` https://github.com/Textualize/textual/issues/1121
|
||||
- Added a `Label` widget https://github.com/Textualize/textual/issues/1190
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ from textual.containers import Horizontal
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.screen import Screen
|
||||
from textual.widget import Widget
|
||||
from textual.widgets import Footer, Button, Static
|
||||
from textual.widgets import Footer, Button, Label
|
||||
from textual.css.query import DOMQuery
|
||||
from textual.reactive import reactive
|
||||
from textual.binding import Binding
|
||||
@@ -33,10 +33,10 @@ class Help(Screen):
|
||||
Returns:
|
||||
ComposeResult: The result of composing the help screen.
|
||||
"""
|
||||
yield Static(Markdown(Path(__file__).with_suffix(".md").read_text()))
|
||||
yield Label(Markdown(Path(__file__).with_suffix(".md").read_text()))
|
||||
|
||||
|
||||
class WinnerMessage(Static):
|
||||
class WinnerMessage(Label):
|
||||
"""Widget to tell the user they have won."""
|
||||
|
||||
MIN_MOVES: Final = 14
|
||||
@@ -91,9 +91,9 @@ class GameHeader(Widget):
|
||||
ComposeResult: The result of composing the game header.
|
||||
"""
|
||||
yield Horizontal(
|
||||
Static(self.app.title, id="app-title"),
|
||||
Static(id="moves"),
|
||||
Static(id="progress"),
|
||||
Label(self.app.title, id="app-title"),
|
||||
Label(id="moves"),
|
||||
Label(id="progress"),
|
||||
)
|
||||
|
||||
def watch_moves(self, moves: int):
|
||||
@@ -102,7 +102,7 @@ class GameHeader(Widget):
|
||||
Args:
|
||||
moves (int): The number of moves made.
|
||||
"""
|
||||
self.query_one("#moves", Static).update(f"Moves: {moves}")
|
||||
self.query_one("#moves", Label).update(f"Moves: {moves}")
|
||||
|
||||
def watch_filled(self, filled: int):
|
||||
"""Watch the on-count reactive and update when it changes.
|
||||
@@ -110,7 +110,7 @@ class GameHeader(Widget):
|
||||
Args:
|
||||
filled (int): The number of cells that are currently on.
|
||||
"""
|
||||
self.query_one("#progress", Static).update(f"Filled: {filled}")
|
||||
self.query_one("#progress", Label).update(f"Filled: {filled}")
|
||||
|
||||
|
||||
class GameCell(Button):
|
||||
|
||||
@@ -15,6 +15,7 @@ if typing.TYPE_CHECKING:
|
||||
from ._directory_tree import DirectoryTree
|
||||
from ._footer import Footer
|
||||
from ._header import Header
|
||||
from ._label import Label
|
||||
from ._placeholder import Placeholder
|
||||
from ._pretty import Pretty
|
||||
from ._static import Static
|
||||
@@ -30,6 +31,7 @@ __all__ = [
|
||||
"DirectoryTree",
|
||||
"Footer",
|
||||
"Header",
|
||||
"Label",
|
||||
"Placeholder",
|
||||
"Pretty",
|
||||
"Static",
|
||||
|
||||
@@ -5,6 +5,7 @@ from ._checkbox import Checkbox as Checkbox
|
||||
from ._directory_tree import DirectoryTree as DirectoryTree
|
||||
from ._footer import Footer as Footer
|
||||
from ._header import Header as Header
|
||||
from ._label import Label as Label
|
||||
from ._placeholder import Placeholder as Placeholder
|
||||
from ._pretty import Pretty as Pretty
|
||||
from ._static import Static as Static
|
||||
|
||||
7
src/textual/widgets/_label.py
Normal file
7
src/textual/widgets/_label.py
Normal file
@@ -0,0 +1,7 @@
|
||||
"""Provides a simple Label widget."""
|
||||
|
||||
from ._static import Static
|
||||
|
||||
|
||||
class Label(Static):
|
||||
"""A simple label widget for displaying text-oriented rendenrables."""
|
||||
Reference in New Issue
Block a user