Merge branch 'css' of github.com:Textualize/textual into print

This commit is contained in:
Darren Burns
2022-04-13 15:32:37 +01:00
7 changed files with 63 additions and 12 deletions

View File

@@ -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;

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -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)

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import pytest
from textual.css.tokenize import tokenize