Tidy up some Button documentation

Adds missing documentation for disabled to each of the button variant
constructors, and also pulls in a couple more public-visible Button-related
types into the docs.
This commit is contained in:
Dave Pearson
2023-03-01 16:46:47 +00:00
parent 086c7d6688
commit 0df17fc8f0
2 changed files with 11 additions and 1 deletions

View File

@@ -1 +1,3 @@
::: textual.widgets.Button ::: textual.widgets.Button
::: textual.widgets._button.ButtonVariant
::: textual.widgets._button.InvalidButtonVariant

View File

@@ -14,11 +14,16 @@ from ..reactive import reactive
from ..widgets import Static from ..widgets import Static
ButtonVariant = Literal["default", "primary", "success", "warning", "error"] ButtonVariant = Literal["default", "primary", "success", "warning", "error"]
"""The names of the valid button variants.
These are the variants that can be used with a [Button][textual.widgets.Button].
"""
_VALID_BUTTON_VARIANTS = {"default", "primary", "success", "warning", "error"} _VALID_BUTTON_VARIANTS = {"default", "primary", "success", "warning", "error"}
class InvalidButtonVariant(Exception): class InvalidButtonVariant(Exception):
pass """Exception raised if an invalid button variant is used."""
class Button(Static, can_focus=True): class Button(Static, can_focus=True):
@@ -262,6 +267,7 @@ class Button(Static, can_focus=True):
name: The name of the button. name: The name of the button.
id: The ID of the button in the DOM. id: The ID of the button in the DOM.
classes: The CSS classes of the button. classes: The CSS classes of the button.
disabled: Whether the button is disabled or not.
Returns: Returns:
A Button widget of the 'success' variant. A Button widget of the 'success' variant.
@@ -293,6 +299,7 @@ class Button(Static, can_focus=True):
name: The name of the button. name: The name of the button.
id: The ID of the button in the DOM. id: The ID of the button in the DOM.
classes: The CSS classes of the button. classes: The CSS classes of the button.
disabled: Whether the button is disabled or not.
Returns: Returns:
A Button widget of the 'warning' variant. A Button widget of the 'warning' variant.
@@ -324,6 +331,7 @@ class Button(Static, can_focus=True):
name: The name of the button. name: The name of the button.
id: The ID of the button in the DOM. id: The ID of the button in the DOM.
classes: The CSS classes of the button. classes: The CSS classes of the button.
disabled: Whether the button is disabled or not.
Returns: Returns:
A Button widget of the 'error' variant. A Button widget of the 'error' variant.