How to use the gaphas.Item function in gaphas

To help you get started, we’ve selected a few gaphas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gaphor / gaphor / gaphor / storage / storage.py View on Github external
def save_element(name, value):
        """
        Save attributes and references from items in the gaphor.UML module.
        A value may be a primitive (string, int), a gaphor.UML.collection
        (which contains a list of references to other UML elements) or a
        gaphas.Canvas (which contains canvas items).
        """
        # log.debug('saving element: %s|%s %s' % (name, value, type(value)))
        if isinstance(value, (uml2.Element, gaphas.Item)):
            save_reference(name, value)
        elif isinstance(value, collection):
            save_collection(name, value)
        elif isinstance(value, gaphas.Canvas):
            writer.startElement('canvas', {})
            value.save(save_canvasitem)
            writer.endElement('canvas')
        else:
            save_value(name, value)
github gaphor / gaphor / gaphor / UML / diagram.py View on Github external
def create(self, type, parent=None, subject=None):
        """Create a new canvas item on the canvas. It is created with
        a unique ID and it is attached to the diagram's root item.  The type
        parameter is the element class to create.  The new element also has an
        optional parent and subject."""

        assert issubclass(type, gaphas.Item)
        obj = type(str(uuid.uuid1()))
        if subject:
            obj.subject = subject
        self.canvas.add(obj, parent)
        return obj
github gaphor / gaphor / gaphor / services / copyservice.py View on Github external
def load_element():
                    item = new_items.get(value.id)
                    if item:
                        copy.load(name, item)
                    else:
                        item = self.element_factory.lookup(value.id)
                        if item:
                            copy.load(name, item)

                if reference or isinstance(value, Element):
                    setattr(copy, name, value)
                elif isinstance(value, collection):
                    values = value
                    for value in values:
                        setattr(copy, name, value)
                elif isinstance(value, gaphas.Item):
                    load_element()
                else:
                    # Plain attribute
                    copy.load(name, str(value))
github gaphor / gaphor / gaphor / storage / verify.py View on Github external
def verify_canvasitem(name, value, reference=False):
        """
        Verify attributes and references in a gaphor.diagram.* object.
        The extra attribute reference can be used to force UML 
        """
        if isinstance(value, collection) or (
            isinstance(value, (list, tuple)) and reference == True
        ):
            verify_collection(name, value)
        elif reference:
            verify_reference(name, value)
        elif isinstance(value, gaphas.Item):
            elements.add(value.id)
            value.save(verify_canvasitem)

            # save subitems
            for child in value.canvas.get_children(value):
                verify_canvasitem(None, child)

        elif isinstance(value, UML.Element):
            verify_reference(name, value)
github gaphor / gaphor / gaphor / UML / diagram.py View on Github external
def create_as(self, type, id, parent=None, subject=None):
        assert issubclass(type, gaphas.Item)
        item = type(id, self.model)
        if subject:
            item.subject = subject
        self.canvas.add(item, parent)
        self.model.handle(DiagramItemCreated(self.model, item))
        return item
github gaphor / gaphor / gaphor / storage / storage.py View on Github external
def save_element(name, value):
        """
        Save attributes and references from items in the gaphor.UML module.
        A value may be a primitive (string, int), a gaphor.UML.collection
        (which contains a list of references to other UML elements) or a
        gaphas.Canvas (which contains canvas items).
        """
        if isinstance(value, (UML.Element, gaphas.Item)):
            save_reference(name, value)
        elif isinstance(value, collection):
            save_collection(name, value)
        elif isinstance(value, gaphas.Canvas):
            writer.startElement("canvas", {})
            value.save(save_canvasitem)
            writer.endElement("canvas")
        else:
            save_value(name, value)
github gaphor / gaphor / gaphor / storage / storage.py View on Github external
def save_canvasitem(name, value, reference=False):
        """
        Save attributes and references in a gaphor.diagram.* object.
        The extra attribute reference can be used to force UML 
        """
        # log.debug('saving canvasitem: %s|%s %s' % (name, value, type(value)))
        if isinstance(value, collection) or \
                (isinstance(value, (list, tuple)) and reference):
            save_collection(name, value)
        elif reference:
            save_reference(name, value)
        elif isinstance(value, gaphas.Item):
            writer.startElement('item', {'id': value.id,
                                         'type': value.__class__.__name__})
            value.save(save_canvasitem)

            # save subitems
            for child in value.canvas.get_children(value):
                save_canvasitem(None, child)

            writer.endElement('item')

        elif isinstance(value, uml2.Element):
            save_reference(name, value)
        else:
            save_value(name, value)
github gaphor / gaphor / gaphor / actions / diagramactions.py View on Github external
def copy_func(self, name, value, reference=False):
        if reference or isinstance(value, UML.Element):
            self._load_element(name, value)
        elif isinstance(value, UML.collection):
            for item in value:
                self._load_element(name, item)
        elif isinstance(value, gaphas.Item):
            self._load_element(name, value)
        else:
            # Plain attribute
            self._item.load(name, str(value))
github gaphor / gaphor / gaphor / storage / verify.py View on Github external
def verify_element(name, value):
        """
        Store the element id.
        """
        if isinstance(value, (UML.Element, gaphas.Item)):
            verify_reference(name, value)
        elif isinstance(value, collection):
            verify_collection(name, value)
        elif isinstance(value, gaphas.Canvas):
            value.save(verify_canvasitem)
github gaphor / gaphor / gaphor / services / copyservice.py View on Github external
def __init__(self, event_manager, element_factory, diagrams):
        self.event_manager = event_manager
        self.element_factory = element_factory
        self.diagrams = diagrams
        self.copy_buffer: Set[gaphas.Item] = set()

        event_manager.subscribe(self._update)