def test_broken_line_style(): # diagram css is missing the closing bracket css = "diagram { line-style: sloppy * { }" compiled_style_sheet = CompiledStyleSheet(css) props = compiled_style_sheet.match(Node("mytype")) assert props.get("line-style") is None
def test_line_style(css_value, result): css = f"mytype {{ line-style: {css_value} }}" compiled_style_sheet = CompiledStyleSheet(css) props = compiled_style_sheet.match(Node("mytype")) assert props.get("line-style") == result
def test_color_typing_in_progress(): css = "mytype { color: # }" compiled_style_sheet = CompiledStyleSheet(css) props = compiled_style_sheet.match(Node("mytype")) assert props.get("color") is None
def test_color(): css = "mytype { color: #00ff00 }" compiled_style_sheet = CompiledStyleSheet(css) props = compiled_style_sheet.match(Node("mytype")) assert props.get("color") == (0, 1, 0, 1)
def test_empty_compiled_style_sheet(): css = "" compiled_style_sheet = CompiledStyleSheet(css) props = compiled_style_sheet.match(Node("mytype")) assert props == {}
class StyleSheet(Element): _compiled_style_sheet: CompiledStyleSheet def __init__(self, id=None, model=None): super().__init__(id, model) self.compile_style_sheet() styleSheet: attribute[str] = attribute("styleSheet", str, "") def compile_style_sheet(self) -> None: self._compiled_style_sheet = CompiledStyleSheet(self.styleSheet) def match(self, node: StyleNode) -> Style: return self._compiled_style_sheet.match(node) def postload(self): super().postload() self.compile_style_sheet() def handle(self, event): # Ensure compiled style sheet is always up to date: if (isinstance(event, AttributeUpdated) and event.property is StyleSheet.styleSheet): self.compile_style_sheet() super().handle(event)
def test_compiled_style_sheet(): css = """ * { font-size: 42; font-family: overridden } mytype { font-family: sans } """ compiled_style_sheet = CompiledStyleSheet(css) props = compiled_style_sheet.match(Node("mytype")) assert props.get("font-family") == "sans" assert props.get("font-size") == 42
def compile_style_sheet(self) -> None: self._compiled_style_sheet = CompiledStyleSheet(self.styleSheet)
def compile_style_sheet(self) -> None: self._compiled_style_sheet = CompiledStyleSheet( SYSTEM_STYLE_SHEET, self.styleSheet)