mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge branch 'css' of github.com:Textualize/textual into print
This commit is contained in:
@@ -58,7 +58,7 @@ App > Screen {
|
||||
#header {
|
||||
color: $text-primary-darken-1;
|
||||
background: $primary-darken-1;
|
||||
height: 3;
|
||||
height: 3
|
||||
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ Tweet {
|
||||
max-width: 80;
|
||||
margin: 1 3;
|
||||
background: $panel;
|
||||
color: $text-panel
|
||||
color: $text-panel;
|
||||
layout: vertical;
|
||||
/* border: outer $primary; */
|
||||
padding: 1;
|
||||
|
||||
@@ -275,8 +275,8 @@ class StylesBuilder:
|
||||
space: list[int] = []
|
||||
append = space.append
|
||||
for token in tokens:
|
||||
token_name, value, _, _, location, _ = token
|
||||
if token_name in ("number", "scalar"):
|
||||
token_name, value, _, _, _, _ = token
|
||||
if token_name == "number":
|
||||
try:
|
||||
append(int(value))
|
||||
except ValueError:
|
||||
@@ -289,11 +289,42 @@ class StylesBuilder:
|
||||
)
|
||||
self.styles._rules[name] = Spacing.unpack(cast(SpacingDimensions, tuple(space)))
|
||||
|
||||
def process_padding(self, name: str, tokens: list[Token]) -> None:
|
||||
self._process_space(name, tokens)
|
||||
def _process_space_partial(self, name: str, tokens: list[Token]) -> None:
|
||||
"""Process granular margin / padding declarations."""
|
||||
if len(tokens) != 1:
|
||||
self.error(name, tokens[0], "expected a single token here")
|
||||
|
||||
def process_margin(self, name: str, tokens: list[Token]) -> None:
|
||||
self._process_space(name, tokens)
|
||||
_EDGE_SPACING_MAP = {"top": 0, "right": 1, "bottom": 2, "left": 3}
|
||||
token = tokens[0]
|
||||
token_name, value, _, _, _, _ = token
|
||||
if token_name == "number":
|
||||
space = int(value)
|
||||
else:
|
||||
self.error(name, token, f"expected a number here; found {value!r}")
|
||||
style_name, _, edge = name.replace("-", "_").partition("_")
|
||||
|
||||
current_spacing = cast(
|
||||
"tuple[int, int, int, int]",
|
||||
self.styles._rules.get(style_name, (0, 0, 0, 0)),
|
||||
)
|
||||
|
||||
spacing_list = list(current_spacing)
|
||||
spacing_list[_EDGE_SPACING_MAP[edge]] = space
|
||||
|
||||
self.styles._rules[style_name] = Spacing(*spacing_list)
|
||||
|
||||
process_padding = _process_space
|
||||
process_margin = _process_space
|
||||
|
||||
process_margin_top = _process_space_partial
|
||||
process_margin_right = _process_space_partial
|
||||
process_margin_bottom = _process_space_partial
|
||||
process_margin_left = _process_space_partial
|
||||
|
||||
process_padding_top = _process_space_partial
|
||||
process_padding_right = _process_space_partial
|
||||
process_padding_bottom = _process_space_partial
|
||||
process_padding_left = _process_space_partial
|
||||
|
||||
def _parse_border(self, name: str, tokens: list[Token]) -> tuple[str, Color]:
|
||||
border_type = "solid"
|
||||
|
||||
@@ -28,7 +28,7 @@ from ..dom import DOMNode
|
||||
from .. import log
|
||||
|
||||
|
||||
class StylesheetParseError(Exception):
|
||||
class StylesheetParseError(StylesheetError):
|
||||
def __init__(self, errors: StylesheetErrors) -> None:
|
||||
self.errors = errors
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ class Key(InputEvent):
|
||||
|
||||
|
||||
@rich.repr.auto
|
||||
class MouseEvent(InputEvent, bubble=True):
|
||||
class MouseEvent(InputEvent, bubble=True, verbosity=2):
|
||||
"""Sent in response to a mouse event"""
|
||||
|
||||
__slots__ = [
|
||||
@@ -344,7 +344,7 @@ class MouseScrollDown(InputEvent, verbosity=3, bubble=True):
|
||||
self.y = y
|
||||
|
||||
|
||||
class MouseScrollUp(MouseScrollDown, bubble=True):
|
||||
class MouseScrollUp(MouseScrollDown, verbosity=3, bubble=True):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -91,7 +91,6 @@ class Screen(Widget):
|
||||
def on_idle(self, event: events.Idle) -> None:
|
||||
# Check for any widgets marked as 'dirty' (needs a repaint)
|
||||
if self._dirty_widgets:
|
||||
self.log(dirty=len(self._dirty_widgets))
|
||||
for widget in self._dirty_widgets:
|
||||
# Repaint widgets
|
||||
# TODO: Combine these in to a single update.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -9,6 +11,7 @@ from textual.css.stylesheet import Stylesheet, StylesheetParseError
|
||||
from textual.css.tokenize import tokenize
|
||||
from textual.css.tokenizer import Token, ReferencedBy
|
||||
from textual.css.transition import Transition
|
||||
from textual.geometry import Spacing
|
||||
from textual.layouts.dock import DockLayout
|
||||
|
||||
|
||||
@@ -1065,3 +1068,19 @@ class TestParseOpacity:
|
||||
with pytest.raises(StylesheetParseError):
|
||||
stylesheet.parse(css)
|
||||
assert stylesheet.rules[0].errors
|
||||
|
||||
|
||||
class TestParseMargin:
|
||||
def test_margin_partial(self):
|
||||
css = "#foo {margin: 1; margin-top: 2; margin-right: 3; margin-bottom: -1;}"
|
||||
stylesheet = Stylesheet()
|
||||
stylesheet.parse(css)
|
||||
assert stylesheet.rules[0].styles.margin == Spacing(2, 3, -1, 1)
|
||||
|
||||
|
||||
class TestParsePadding:
|
||||
def test_padding_partial(self):
|
||||
css = "#foo {padding: 1; padding-top: 2; padding-right: 3; padding-bottom: -1;}"
|
||||
stylesheet = Stylesheet()
|
||||
stylesheet.parse(css)
|
||||
assert stylesheet.rules[0].styles.padding == Spacing(2, 3, -1, 1)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from textual.css.tokenize import tokenize
|
||||
|
||||
Reference in New Issue
Block a user