示例#1
0
    def test_objectnode_editor(self):
        node = self.create(ObjectNodeItem, UML.ObjectNode)
        self.diagram.canvas.update_now()

        adapter = Editor(node)
        print(node, adapter)
        assert adapter.is_editable(10, 10)
示例#2
0
    def test_classifier_editor(self):
        """
        Test classifier editor
        """
        klass = self.create(ClassItem, UML.Class)
        klass.subject.name = "Class1"

        self.diagram.canvas.update()

        attr = self.element_factory.create(UML.Property)
        attr.name = "blah"
        klass.subject.ownedAttribute = attr

        oper = self.element_factory.create(UML.Operation)
        oper.name = "method"
        klass.subject.ownedOperation = oper

        self.diagram.canvas.update()

        edit = Editor(klass)

        assert "ClassifiedItemEditor" == edit.__class__.__name__

        assert edit.is_editable(10, 10)

        # Test the inner working of the editor
        self.assertEqual(klass, edit._edit)
        assert "Class1" == edit.get_text()
示例#3
0
    def on_double_click(self, event):
        view = self.view
        item = view.hovered_item
        if item:
            editor = Editor(item)
            if not editor:
                return False

            log.debug(f"Found editor {editor!r}")
            x, y = view.get_matrix_v2i(item).transform_point(event.x, event.y)
            if editor.is_editable(x, y):
                text = editor.get_text()
                root_coords = event.get_root_coords()
                self.create_edit_window(root_coords.x_root, root_coords.y_root,
                                        text, editor)
                return True
示例#4
0
 def on_double_click(self, event):
     view = self.view
     item = view.hovered_item
     if item:
         try:
             editor = Editor(item)
         except TypeError:
             # Could not adapt to Editor
             return False
         log.debug("Found editor %r" % editor)
         x, y = view.get_matrix_v2i(item).transform_point(event.x, event.y)
         if editor.is_editable(x, y):
             text = editor.get_text()
             root_coords = event.get_root_coords()
             self.create_edit_window(root_coords.x_root, root_coords.y_root,
                                     text, editor)
             return True
示例#5
0
    def test_association_editor(self):
        assoc = self.create(AssociationItem)
        adapter = Editor(assoc)
        assert not adapter.is_editable(10, 10)
        assert adapter._edit is None

        # Intermezzo: connect the association between two classes
        class1 = self.create(ClassItem, UML.Class)
        class2 = self.create(ClassItem, UML.Class)

        assoc.handles()[0].pos = 10, 10
        assoc.handles()[-1].pos = 100, 100
        self.connect(assoc, assoc.head, class1)
        self.connect(assoc, assoc.tail, class2)
        assert assoc.subject

        # Now the association has a subject member, so editing should really
        # work.
        pos = 55, 55
        self.assertTrue(adapter.is_editable(*pos))
        self.assertTrue(adapter._edit is assoc)

        pos = assoc.head_end._name_bounds[:2]
        self.assertTrue(adapter.is_editable(*pos))
        self.assertTrue(adapter._edit is assoc.head_end)

        pos = assoc.tail_end._name_bounds[:2]
        self.assertTrue(adapter.is_editable(*pos))
        self.assertTrue(adapter._edit is assoc.tail_end)
示例#6
0
    def test_classifier_editor(self):
        """
        Test classifier editor
        """
        klass = self.create(ClassItem, UML.Class)
        klass.subject.name = "Class1"

        self.diagram.canvas.update()

        attr = self.element_factory.create(UML.Property)
        attr.name = "blah"
        klass.subject.ownedAttribute = attr

        oper = self.element_factory.create(UML.Operation)
        oper.name = "method"
        klass.subject.ownedOperation = oper

        self.diagram.canvas.update()

        edit = Editor(klass)

        self.assertEqual("CompartmentItemEditor", edit.__class__.__name__)

        self.assertEqual(True, edit.is_editable(10, 10))

        # Test the inner working of the editor
        self.assertEqual(klass, edit._edit)
        self.assertEqual("Class1", edit.get_text())

        # The attribute:
        y = klass._header_size[1] + klass.style.compartment_padding[0] + 3
        self.assertEqual(True, edit.is_editable(4, y))
        self.assertEqual(attr, edit._edit.subject)
        self.assertEqual("+ blah", edit.get_text())

        y += klass.compartments[0].height
        # The operation
        self.assertEqual(True, edit.is_editable(3, y))
        self.assertEqual(oper, edit._edit.subject)
        self.assertEqual("+ method()", edit.get_text())
示例#7
0
from gaphor.diagram.editors import Editor, AbstractEditor, NamedItemEditor
from gaphor.diagram.actions.action import ActionItem
from gaphor.diagram.actions.activitynodes import ForkNodeItem

Editor.register(ActionItem, NamedItemEditor)


@Editor.register(ForkNodeItem)
class ForkNodeItemEditor(AbstractEditor):
    """Text edit support for fork node join specification."""
    def __init__(self, item):
        self._item = item

    def is_editable(self, x, y):
        return True

    def get_text(self):
        """
        Get join specification text.
        """
        if self._item.subject.joinSpec:
            return self._item.subject.joinSpec
        else:
            return ""

    def update_text(self, text):
        """
        Set join specification text.
        """
        spec = self._item.subject.joinSpec
        if not spec: