Access stylesheet from Presentation
This commit is contained in:
parent
56d5f02780
commit
8f73b6c56b
@ -7,4 +7,4 @@ from gaphor.core.modeling.coremodel import (
|
||||
from gaphor.core.modeling.diagram import Diagram
|
||||
from gaphor.core.modeling.elementfactory import ElementFactory
|
||||
from gaphor.core.modeling.event import *
|
||||
from gaphor.core.modeling.presentation import Presentation
|
||||
from gaphor.core.modeling.presentation import Presentation, Stylesheet
|
||||
|
@ -37,11 +37,11 @@ class PackageableElement(NamedElement):
|
||||
pass
|
||||
|
||||
|
||||
# 49: override Diagram
|
||||
# 55: override Diagram
|
||||
# defined in gaphor.core.modeling.diagram
|
||||
|
||||
|
||||
# 40: override Presentation
|
||||
# 46: override Presentation
|
||||
# defined in gaphor.core.modeling.presentation
|
||||
|
||||
|
||||
@ -50,17 +50,19 @@ class Comment(Element):
|
||||
annotatedElement: relation_many[Element]
|
||||
|
||||
|
||||
class Stylesheet(Element):
|
||||
stylesheet: attribute[str]
|
||||
# 40: override Stylesheet
|
||||
# defined in gaphor.core.modeling.presentation
|
||||
|
||||
|
||||
NamedElement.name = attribute("name", str)
|
||||
Comment.body = attribute("body", str)
|
||||
Stylesheet.stylesheet = attribute("stylesheet", str)
|
||||
# 46: override Presentation.subject
|
||||
# 43: override Stylesheet.stylesheet
|
||||
# defined in gaphor.core.modeling.presentation
|
||||
|
||||
# 43: override Element.presentation
|
||||
# 52: override Presentation.subject
|
||||
# defined in gaphor.core.modeling.presentation
|
||||
|
||||
# 49: override Element.presentation
|
||||
# defined in gaphor.core.modeling.presentation
|
||||
|
||||
Comment.annotatedElement = association(
|
||||
|
@ -7,7 +7,7 @@ from __future__ import annotations
|
||||
from typing import TYPE_CHECKING, Callable, Generic, List, Optional, TypeVar
|
||||
|
||||
from gaphor.core.modeling import Element
|
||||
from gaphor.core.modeling.properties import association, relation_one
|
||||
from gaphor.core.modeling.properties import association, attribute, relation_one
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from gaphas.canvas import Canvas # noqa
|
||||
@ -17,6 +17,10 @@ if TYPE_CHECKING:
|
||||
S = TypeVar("S", bound=Element)
|
||||
|
||||
|
||||
class Stylesheet(Element):
|
||||
stylesheet: attribute[str] = attribute("stylesheet", str)
|
||||
|
||||
|
||||
class Presentation(Element, Generic[S]):
|
||||
"""
|
||||
This presentation is used to link the behaviors of `gaphor.core.modeling` and `gaphas.Item`.
|
||||
@ -77,6 +81,10 @@ class Presentation(Element, Generic[S]):
|
||||
self.canvas.remove(self)
|
||||
super().unlink()
|
||||
|
||||
@property
|
||||
def stylesheet(self):
|
||||
return next(self.model.select(lambda e: isinstance(e, Stylesheet)), None)
|
||||
|
||||
|
||||
Element.presentation = association(
|
||||
"presentation", Presentation, composite=True, opposite="subject"
|
||||
|
35
gaphor/core/modeling/tests/test_presentation.py
Normal file
35
gaphor/core/modeling/tests/test_presentation.py
Normal file
@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
from gaphas.item import Item
|
||||
|
||||
from gaphor.core.eventmanager import EventManager
|
||||
from gaphor.core.modeling.diagram import Diagram
|
||||
from gaphor.core.modeling.elementfactory import ElementFactory
|
||||
from gaphor.core.modeling.presentation import Presentation, Stylesheet
|
||||
|
||||
|
||||
class StubItem(Presentation, Item):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def element_factory():
|
||||
event_manager = EventManager()
|
||||
return ElementFactory(event_manager)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def diagram(element_factory):
|
||||
return element_factory.create(Diagram)
|
||||
|
||||
|
||||
def test_presentation_stylesheet(diagram, element_factory):
|
||||
stylesheet = element_factory.create(Stylesheet)
|
||||
presentation = diagram.create(StubItem)
|
||||
|
||||
assert presentation.stylesheet is stylesheet
|
||||
|
||||
|
||||
def test_presentation_stylesheet_is_absent(diagram):
|
||||
presentation = diagram.create(StubItem)
|
||||
|
||||
assert presentation.stylesheet is None
|
@ -37,6 +37,12 @@ NamedElement.qualifiedName = derived(
|
||||
lambda obj: [_namedelement_qualifiedname(obj)],
|
||||
)
|
||||
%%
|
||||
override Stylesheet
|
||||
# defined in gaphor.core.modeling.presentation
|
||||
%%
|
||||
override Stylesheet.stylesheet
|
||||
# defined in gaphor.core.modeling.presentation
|
||||
%%
|
||||
override Presentation
|
||||
# defined in gaphor.core.modeling.presentation
|
||||
%%
|
||||
|
Loading…
Reference in New Issue
Block a user