mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Help text for fractional properties
This commit is contained in:
@@ -81,6 +81,7 @@ class BasicApp(App):
|
||||
|
||||
def action_toggle_border(self):
|
||||
self.focused.styles.border = [("solid", "red"), ("dashed", "white")]
|
||||
self.focused.styles.opacity = "x"
|
||||
|
||||
|
||||
BasicApp.run(css_file="uber.css", log="textual.log", log_verbosity=1)
|
||||
|
||||
@@ -526,8 +526,8 @@ def fractional_property_help_text(
|
||||
Bullet(
|
||||
f"In Python, you can set [i]{property_name}[/] to a string or float value",
|
||||
examples=[
|
||||
Example(f"widget.styles.{property_name} = 0.25"),
|
||||
Example(f'widget.styles.{property_name} = "50%"'),
|
||||
Example(f"widget.styles.{property_name} = 0.25"),
|
||||
],
|
||||
)
|
||||
],
|
||||
@@ -535,11 +535,11 @@ def fractional_property_help_text(
|
||||
Bullet(
|
||||
f"In Textual CSS, you can set [i]{property_name}[/] to a string or float",
|
||||
examples=[
|
||||
Example(f"{property_name}: 0.25;"),
|
||||
Example(f"{property_name}: 50%;"),
|
||||
Example(f"{property_name}: 0.25;"),
|
||||
],
|
||||
)
|
||||
],
|
||||
)
|
||||
).get_by_context(context)
|
||||
],
|
||||
)
|
||||
|
||||
@@ -14,7 +14,11 @@ from typing import Iterable, NamedTuple, TYPE_CHECKING, cast
|
||||
import rich.repr
|
||||
from rich.style import Style
|
||||
|
||||
from ._help_text import border_property_help_text, layout_property_help_text
|
||||
from ._help_text import (
|
||||
border_property_help_text,
|
||||
layout_property_help_text,
|
||||
fractional_property_help_text,
|
||||
)
|
||||
from ._help_text import (
|
||||
spacing_wrong_number_of_values,
|
||||
scalar_help_text,
|
||||
@@ -908,8 +912,9 @@ class FractionalProperty:
|
||||
elif isinstance(value, str) and value.endswith("%"):
|
||||
float_value = float(Scalar.parse(value).value) / 100
|
||||
else:
|
||||
raise StyleTypeError(
|
||||
f"{self.name} must be a str (e.g. '10%') or a float (e.g. 0.1)"
|
||||
raise StyleValueError(
|
||||
f"{self.name} must be a str (e.g. '10%') or a float (e.g. 0.1)",
|
||||
help_text=fractional_property_help_text(name, context="inline"),
|
||||
)
|
||||
if obj.set_rule(name, clamp(float_value, 0, 1)):
|
||||
obj.refresh()
|
||||
|
||||
@@ -16,6 +16,7 @@ from ._help_text import (
|
||||
layout_property_help_text,
|
||||
docks_property_help_text,
|
||||
dock_property_help_text,
|
||||
fractional_property_help_text,
|
||||
)
|
||||
from .constants import (
|
||||
VALID_ALIGN_HORIZONTAL,
|
||||
@@ -315,13 +316,7 @@ class StylesBuilder:
|
||||
error = True
|
||||
|
||||
if error:
|
||||
self.error(
|
||||
name,
|
||||
token,
|
||||
f"property 'opacity' has invalid value {_join_tokens(tokens)!r}; "
|
||||
f"expected a percentage or float between 0 and 1; "
|
||||
f"example valid values: '0.4', '40%'",
|
||||
)
|
||||
self.error(name, token, fractional_property_help_text(name, context="css"))
|
||||
|
||||
def _process_space(self, name: str, tokens: list[Token]) -> None:
|
||||
space: list[int] = []
|
||||
|
||||
Reference in New Issue
Block a user