Commit dc55d526 authored by Duggan, John's avatar Duggan, John
Browse files

Fix Trame crash when passing string-typed styles to layout components

parent 46754430
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
### nova-trame, 0.18.2

* Passing a string to the style parameter to GridLayout, HBoxLayout, and VBoxLayout will no longer cause Trame to crash (thanks to John Duggan).

### nova-trame, 0.18.1

* The `CompactTheme` has been overhauled and should produce denser UIs (thanks to Kristin Maroun).
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ Changelog = "https://code.ornl.gov/ndip/public-packages/nova-trame/blob/main/CHA

[tool.poetry]
name = "nova-trame"
version = "0.18.1"
version = "0.18.2"
description = "A Python Package for injecting curated themes and custom components into Trame applications"
authors = ["Duggan, John <dugganjw@ornl.gov>"]
readme = "README.md"
+5 −2
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ from typing import Any, Optional, Union
from trame.widgets import html
from trame_client.widgets.core import AbstractElement

from .utils import merge_styles


class GridLayout(html.Div):
    """Creates a grid with a specified number of columns."""
@@ -68,9 +70,10 @@ class GridLayout(html.Div):
            classes = " ".join(classes)
        classes += " d-grid"

        style = self.get_root_styles(columns, height, width, halign, valign, gap) | kwargs.pop("style", {})
        widget_style = self.get_root_styles(columns, height, width, halign, valign, gap)
        user_style = kwargs.pop("style", {})

        super().__init__(classes=classes, style=style, **kwargs)
        super().__init__(classes=classes, style=merge_styles(widget_style, user_style), **kwargs)

    def get_root_styles(
        self,
+5 −2
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ from typing import Any, Optional, Union

from trame.widgets import html

from .utils import merge_styles


class HBoxLayout(html.Div):
    """Creates an element that horizontally stacks its children."""
@@ -59,9 +61,10 @@ class HBoxLayout(html.Div):
            classes = " ".join(classes)
        classes += " d-flex flex-row"

        style = self.get_root_styles(height, width, halign, valign, gap, vspace) | kwargs.pop("style", {})
        widget_style = self.get_root_styles(height, width, halign, valign, gap, vspace)
        user_style = kwargs.pop("style", {})

        super().__init__(classes=classes, style=style, **kwargs)
        super().__init__(classes=classes, style=merge_styles(widget_style, user_style), **kwargs)

    def get_root_styles(
        self,
+16 −0
Original line number Diff line number Diff line
"""Utilities for our layout components."""

from typing import Dict, Union


def merge_styles(*styles: Union[Dict[str, str], str]) -> str:
    result = ""

    for style in styles:
        if isinstance(style, dict):
            for key, value in style.items():
                result += f" {key}: {value};"
        else:
            result += f" {style};"

    return result
Loading