Skip to content

Commit

Permalink
Merge pull request #2601 from marek-piirikivi/value_specification_action
Browse files Browse the repository at this point in the history
Add ValueSpecificationAction
  • Loading branch information
danyeaw committed Aug 8, 2023
2 parents 32b0ff3 + 0ec9a25 commit cb572c6
Show file tree
Hide file tree
Showing 64 changed files with 1,067 additions and 349 deletions.
2 changes: 2 additions & 0 deletions gaphor/UML/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from gaphor.UML.actions.action import (
AcceptEventActionItem,
ActionItem,
ValueSpecificationActionItem,
CallBehaviorActionItem,
SendSignalActionItem,
)
Expand All @@ -29,6 +30,7 @@
__all__ = [
"AcceptEventActionItem",
"ActionItem",
"ValueSpecificationActionItem",
"CallBehaviorActionItem",
"ActivityItem",
"ActivityParameterNodeItem",
Expand Down
26 changes: 25 additions & 1 deletion gaphor/UML/actions/action.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Action diagram item."""

from gaphor import UML
from gaphor.diagram.presentation import ElementPresentation, Named
from gaphor.diagram.presentation import ElementPresentation, Named, Valued
from gaphor.diagram.shapes import Box, Text, draw_border, stroke
from gaphor.diagram.support import represents
from gaphor.UML.recipes import stereotypes_str
Expand Down Expand Up @@ -33,6 +33,30 @@ def __init__(self, diagram, id=None):
self.watch("subject.appliedStereotype.classifier.name")


@represents(UML.ValueSpecificationAction)
class ValueSpecificationActionItem(Valued, ElementPresentation):
def __init__(self, diagram, id=None):
super().__init__(diagram, id, width=50, height=30)

self.width = 100
self.shape = Box(
Text(
text=lambda: "«valueSpecification»",
),
Text(
text=lambda: self.subject.value or "",
width=lambda: self.width - 4,
),
style={
"padding": (4, 12, 4, 12),
"border-radius": 15,
},
draw=draw_border,
)

self.watch("subject[ValueSpecificationAction].value")


@represents(UML.CallBehaviorAction)
class CallBehaviorActionItem(ActionItem):
def __init__(self, diagram, id=None):
Expand Down
22 changes: 22 additions & 0 deletions gaphor/UML/actions/actionspropertypages.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ def _on_ordering_show_change(self, button, gparam):
self.item.show_ordering = button.get_active()


@PropertyPages.register(UML.ValueSpecificationAction)
class ValueSpecificationActionPropertyPage(PropertyPageBase):
order = 15

def __init__(self, item):
self.subject = item

def construct(self):
builder = new_builder("value-specifiation-action-editor")

value = builder.get_object("value")
value.set_text(self.subject.value or "")
value.connect("changed", self._on_value_change)

return builder.get_object("value-specifiation-action-editor")

@transactional
def _on_value_change(self, entry):
value = entry.get_text()
self.subject.value = value


@PropertyPages.register(UML.CallBehaviorAction)
class CallBehaviorActionPropertyPage(PropertyPageBase):
order = 15
Expand Down
17 changes: 17 additions & 0 deletions gaphor/UML/actions/actionstoolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def partition_config(new_item):
new_item.partition = partition


def value_specification_action_config(new_item):
activity_config(new_item, i18nize("ValueSpecificationAction"))
new_item.subject.value = "1"


actions = ToolSection(
gettext("Actions"),
(
Expand Down Expand Up @@ -95,6 +100,18 @@ def partition_config(new_item):
),
handle_index=SE,
),
ToolDef(
"toolbox-value-specification-action",
gettext("Value specification action"),
"gaphor-value-specification-action-symbolic",
"<Alt>v",
new_item_factory(
diagramitems.ValueSpecificationActionItem,
UML.ValueSpecificationAction,
config_func=value_specification_action_config,
),
handle_index=SE,
),
ToolDef(
"toolbox-initial-node",
gettext("Initial node"),
Expand Down
15 changes: 13 additions & 2 deletions gaphor/UML/actions/pinconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from gaphor import UML
from gaphor.diagram.connectors import Connector
from gaphor.UML.actions.action import ActionItem
from gaphor.UML.actions.pin import InputPinItem, PinItem
from gaphor.UML.actions.action import ActionItem, ValueSpecificationActionItem
from gaphor.UML.actions.pin import InputPinItem, PinItem, OutputPinItem


@Connector.register(ActionItem, PinItem)
Expand Down Expand Up @@ -46,3 +46,14 @@ def disconnect(self, handle: Handle) -> None:
del pin.subject
pin.change_parent(None)
subject.unlink()


@Connector.register(ValueSpecificationActionItem, PinItem)
class ValueSpecificationActionPinConnector(ActionPinConnector):
def allow(self, handle: Handle, port: Port) -> bool:
return (
super().allow(handle, port)
and not len(self.action.subject.outputValue)
and isinstance(self.pin, OutputPinItem)
and not self.pin.subject
)
21 changes: 21 additions & 0 deletions gaphor/UML/actions/propertypages.ui
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,27 @@
</style>
</object>

<object class="GtkBox" id="value-specifiation-action-editor">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Value</property>
<property name="xalign">0</property>
<style>
<class name="title" />
</style>
</object>
</child>
<child>
<object class="GtkEntry" id="value">
<property name="focusable">1</property>
</object>
</child>
<style>
<class name="propertypage" />
</style>
</object>

<object class="GtkBox" id="transition-editor">
<property name="orientation">vertical</property>
<child>
Expand Down
1 change: 1 addition & 0 deletions gaphor/UML/tests/test_diagramitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_all_diagram_items_have_a_model_element_mapping(item_class):
diagramitems.DiagramItem,
diagramitems.ExecutionSpecificationItem,
diagramitems.PartitionItem,
diagramitems.ValueSpecificationActionItem,
]


Expand Down
6 changes: 6 additions & 0 deletions gaphor/UML/uml.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,11 @@ class CallBehaviorAction(CallAction):
behavior: relation_one[Behavior]


class ValueSpecificationAction(Action):
result: relation_one[OutputPin]
value: _attribute[str] = _attribute("value", str)


# 86: override Lifeline.parse: Callable[[Lifeline, str], None]
# defined in umloverrides.py

Expand Down Expand Up @@ -1326,3 +1331,4 @@ class CallBehaviorAction(CallAction):
DirectedRelationship.target.add(InformationFlow.informationTarget) # type: ignore[attr-defined]
CallAction.result = association("result", OutputPin, composite=True)
CallBehaviorAction.behavior = association("behavior", Behavior, upper=1, composite=True)
ValueSpecificationAction.result = association("result", OutputPin, upper=1, composite=True)
30 changes: 29 additions & 1 deletion gaphor/diagram/instanteditors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from gaphas.geometry import Rectangle
from gi.repository import Gdk, Gtk

from gaphor.diagram.presentation import LinePresentation, Named
from gaphor.diagram.presentation import LinePresentation, Named, Valued
from gaphor.transaction import Transaction


Expand Down Expand Up @@ -51,6 +51,34 @@ def update_text():
return True


@instant_editor.register(Valued)
def valued_item_editor(item, view, event_manager, pos=None) -> bool:
"""Text edit support for Valued items."""

subject = item.subject
if not subject:
return False

if isinstance(item, LinePresentation):
box = item.middle_shape_size
i2v = view.get_matrix_i2v(item)
x, y = i2v.transform_point(box.x, box.y)
w, h = i2v.transform_distance(box.width, box.height)
box = Rectangle(x, y, w, h)
else:
box = view.get_item_bounding_box(item)
value = subject.value or ""
entry = popup_entry(value)

def update_text():
with Transaction(event_manager):
item.subject.value = entry.get_buffer().get_text()

show_popover(entry, view, box, update_text)

return True


def popup_entry(text, update_text=None, done=None):
buffer = Gtk.EntryBuffer()
buffer.set_text(text, -1)
Expand Down
4 changes: 4 additions & 0 deletions gaphor/diagram/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Named:
"""Marker for any NamedElement presentations."""


class Valued:
"""Marker for any element that has a value."""


class Classified(Named):
"""Marker for Classifier presentations."""

Expand Down
2 changes: 2 additions & 0 deletions gaphor/ui/icons/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ ICONS=diagram \
primitive-type \
block \
interface-block \
value-specification-action \
call-behavior-action \
value-type \
proxyport \
package \
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cb572c6

Please sign in to comment.