Skip to content

Commit d795c43

Browse files
committed
Refine
1 parent 07bd5db commit d795c43

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

src/textual/demo/demo_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class DemoApp(App):
5757
tooltip="Save an SVG 'screenshot' of the current screen",
5858
),
5959
Binding(
60-
"ctrl+m",
60+
"ctrl+a",
6161
"app.maximize",
6262
"Maximize",
6363
tooltip="Maximized the focused widget (if possible)",

src/textual/demo/widgets.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ class Sparklines(containers.VerticalGroup):
537537
VerticalScroll {
538538
height: auto;
539539
border: heavy transparent;
540-
&:focus { border: heavy $accent; }
540+
&:focus { border: heavy $border; }
541541
}
542542
}
543543
@@ -686,13 +686,11 @@ class Trees(containers.VerticalGroup):
686686
def compose(self) -> ComposeResult:
687687
yield Markdown(self.TREES_MD)
688688
with containers.VerticalGroup():
689-
yield Tree("80s movies")
690-
691-
def on_mount(self) -> None:
692-
tree = self.query_one(Tree)
693-
tree.show_root = False
694-
tree.add_json(MOVIES_TREE)
695-
tree.root.expand()
689+
tree = Tree("80s movies")
690+
tree.show_root = False
691+
tree.add_json(MOVIES_TREE)
692+
tree.root.expand()
693+
yield tree
696694

697695

698696
class TextAreas(containers.VerticalGroup):
@@ -754,14 +752,17 @@ def on_select_changed(self, event: Select.Changed) -> None:
754752
class YourWidgets(containers.VerticalGroup):
755753
DEFAULT_CLASSES = "column"
756754
YOUR_MD = """\
757-
## Your widget here
755+
## Your Widget Here!
758756
759757
The Textual API allows you to [build custom re-usable widgets](https://textual.textualize.io/guide/widgets/#custom-widgets) and share them across projects.
760758
Custom widgets can be themed, just like the builtin widget library.
761759
762760
Combine existing widgets to add new functionality, or use the powerful [Line API](https://textual.textualize.io/guide/widgets/#line-api) for unique creations.
763761
764762
"""
763+
DEFAULT_CSS = """
764+
YourWidgets { margin-bottom: 2; }
765+
"""
765766

766767
def compose(self) -> ComposeResult:
767768
yield Markdown(self.YOUR_MD)
@@ -773,13 +774,11 @@ class WidgetsScreen(PageScreen):
773774
CSS = """
774775
WidgetsScreen {
775776
align-horizontal: center;
776-
Markdown {
777-
background: transparent;
778-
}
777+
Markdown { background: transparent; }
779778
& > VerticalScroll {
780779
scrollbar-gutter: stable;
781780
&> * {
782-
&:last-of-type { margin-bottom: 2; }
781+
783782
&:even { background: $boost; }
784783
padding-bottom: 1;
785784
}

src/textual/renderables/sparkline.py

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

77
from rich.color import Color
88
from rich.console import Console, ConsoleOptions, RenderResult
9+
from rich.measure import Measurement
910
from rich.segment import Segment
1011
from rich.style import Style
1112

@@ -95,6 +96,11 @@ def __rich_console__(
9596
bucket_index += step
9697
yield Segment(self.BARS[bar_index], Style.from_color(bar_color))
9798

99+
def __rich_measure__(
100+
self, console: "Console", options: "ConsoleOptions"
101+
) -> Measurement:
102+
return Measurement(self.width or options.max_width, 1)
103+
98104

99105
if __name__ == "__main__":
100106
console = Console()

src/textual/widgets/_sparkline.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ def __init__(
8888
def render(self) -> RenderResult:
8989
"""Renders the sparkline when there is data available."""
9090
data = self.data or []
91-
if not data:
92-
return ""
9391
_, base = self.background_colors
9492
min_color = base + (
9593
self.get_component_styles("sparkline--min-color").color

0 commit comments

Comments
 (0)