-
Notifications
You must be signed in to change notification settings - Fork 837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Widget documentation sweep #1909
Changes from all commits
fb02fde
597b46f
3602dab
ac18b00
cfb21d0
f96eb93
27e1311
318e129
d0dedc0
4a505e8
b071121
766cae2
4258698
61aa558
287ef15
ed2d547
87f2169
74526c1
c619984
c0cc080
8b22875
4271886
11e16b4
43cc67d
3478615
a326169
d4ef173
a4f22d0
5a61459
bba5017
d50fcc7
46bf558
8f9cf74
4971e0e
9c45c7d
75625ef
52adf3f
7ca3357
865a8e5
662c1d8
e21e552
a837cd1
ac35c1d
dbb5263
3192ee7
3658610
6e836de
3f90812
e8d0f7a
65ba559
2e060c0
acb1cc6
6d03829
106c5aa
fa1f699
80fd76f
40b41a1
8917bb6
3850070
fb5a10a
b73cd78
abdcf2f
21e7cfb
22b0b5b
48dd54c
af6d56c
cf34e5e
2fce894
52b69d5
88f771b
ee126a9
30d8943
ef29a77
acaec34
e8537c6
2deb90e
0992b36
f8167ac
ca1abcf
b617d67
3122748
ab963d2
ce016d5
5afbf48
53b0e54
24fa963
aa96b54
847e2cc
768d4ae
348fbe2
b1c6da2
b3fe97e
88fcf4f
5cfa998
d9ab2ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
::: textual.widgets.Placeholder | ||
::: textual.widgets._placeholder.PlaceholderVariant |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
::: textual.widgets.Tree | ||
::: textual.widgets._tree.TreeNode | ||
::: textual.widgets._tree.NodeID | ||
::: textual.widgets._tree.TreeDataType |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: textual.widgets.Welcome |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,3 +1,5 @@ | ||||||
"""Provides a Textual placeholder widget; useful when designing an app's layout.""" | ||||||
|
||||||
from __future__ import annotations | ||||||
|
||||||
from itertools import cycle | ||||||
|
@@ -8,9 +10,11 @@ | |||||
from .. import events | ||||||
from ..css._error_tools import friendly_list | ||||||
from ..reactive import Reactive, reactive | ||||||
from ..widget import RenderResult, Widget | ||||||
from ..widget import Widget | ||||||
|
||||||
PlaceholderVariant = Literal["default", "size", "text"] | ||||||
"""The different variants of placeholder.""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of moving the variant table from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed this. Yeah, I was debating that too. |
||||||
|
||||||
_VALID_PLACEHOLDER_VARIANTS_ORDERED: list[PlaceholderVariant] = [ | ||||||
"default", | ||||||
"size", | ||||||
|
@@ -94,14 +98,12 @@ def __init__( | |||||
|
||||||
Args: | ||||||
label: The label to identify the placeholder. | ||||||
If no label is present, uses the placeholder ID instead. Defaults to None. | ||||||
If no label is present, uses the placeholder ID instead. | ||||||
variant: The variant of the placeholder. | ||||||
Defaults to "default". | ||||||
name: The name of the placeholder. Defaults to None. | ||||||
id: The ID of the placeholder in the DOM. | ||||||
Defaults to None. | ||||||
classes: A space separated string with the CSS classes | ||||||
of the placeholder, if any. Defaults to None. | ||||||
of the placeholder, if any. | ||||||
""" | ||||||
# Create and cache renderables for all the variants. | ||||||
self._renderables = { | ||||||
|
@@ -115,12 +117,19 @@ def __init__( | |||||
self.styles.background = f"{next(Placeholder._COLORS)} 50%" | ||||||
|
||||||
self.variant = self.validate_variant(variant) | ||||||
"""The current variant of the placeholder.""" | ||||||
|
||||||
# Set a cycle through the variants with the correct starting point. | ||||||
self._variants_cycle = cycle(_VALID_PLACEHOLDER_VARIANTS_ORDERED) | ||||||
while next(self._variants_cycle) != self.variant: | ||||||
pass | ||||||
|
||||||
def render(self) -> RenderableType: | ||||||
"""Render the placeholder. | ||||||
|
||||||
Returns: | ||||||
The value to render. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
""" | ||||||
return self._renderables[self.variant] | ||||||
|
||||||
def cycle_variant(self) -> None: | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
"""Provides a scrollable text-logging widget.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import cast | ||
from typing import Optional, cast | ||
|
||
from rich.console import RenderableType | ||
from rich.highlighter import ReprHighlighter | ||
from rich.measure import measure_renderables | ||
from rich.pretty import Pretty | ||
from rich.protocol import is_renderable | ||
from rich.segment import Segment | ||
from rich.style import Style | ||
from rich.text import Text | ||
|
||
from .._cache import LRUCache | ||
|
@@ -19,6 +20,8 @@ | |
|
||
|
||
class TextLog(ScrollView, can_focus=True): | ||
"""A widget for logging text.""" | ||
|
||
DEFAULT_CSS = """ | ||
TextLog{ | ||
background: $surface; | ||
|
@@ -27,7 +30,7 @@ class TextLog(ScrollView, can_focus=True): | |
} | ||
""" | ||
|
||
max_lines: var[int | None] = var(None) | ||
max_lines: var[int | None] = var[Optional[int]](None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as my understanding goes, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What benefit do we get from that? A downside I can see is that it might be confusing to a reader of the code, seeing two "different" types like that. |
||
min_width: var[int] = var(78) | ||
wrap: var[bool] = var(False) | ||
highlight: var[bool] = var(False) | ||
|
@@ -54,10 +57,10 @@ def __init__( | |
wrap: Enable word wrapping (default is off). | ||
highlight: Automatically highlight content. | ||
markup: Apply Rich console markup. | ||
name: The name of the button. | ||
id: The ID of the button in the DOM. | ||
classes: The CSS classes of the button. | ||
disabled: Whether the button is disabled or not. | ||
name: The name of the text log. | ||
id: The ID of the text log in the DOM. | ||
classes: The CSS classes of the text log. | ||
disabled: Whether the text log is disabled or not. | ||
davep marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
super().__init__(name=name, id=id, classes=classes, disabled=disabled) | ||
self.max_lines = max_lines | ||
|
@@ -91,9 +94,9 @@ def write( | |
|
||
Args: | ||
content: Rich renderable (or text). | ||
width: Width to render or None to use optimal width. Defaults to `None`. | ||
expand: Enable expand to widget width, or False to use `width`. Defaults to `False`. | ||
shrink: Enable shrinking of content to fit width. Defaults to `True`. | ||
width: Width to render or ``None`` to use optimal width. | ||
expand: Enable expand to widget width, or ``False`` to use `width`. | ||
shrink: Enable shrinking of content to fit width. | ||
""" | ||
|
||
renderable: RenderableType | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a difference between surrounding
True
with a pair of backticks versus two pairs of backticks? I have seen both and haven't understood the difference yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question; I was asking myself the same thing as I was going through the docstrings and seeing a difference. I tested it and from what I can tell there's zero difference; both have the same effect (my uninformed guess here would be it's mkdocstrings or something supporting a couple of other doc systems' styles).