How to use the gaphor.core.event_handler function in gaphor

To help you get started, we’ve selected a few gaphor 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 / ui / diagrampage.py View on Github external
    @event_handler(DiagramItemCreated)
    def _on_diagram_item_created(self, event):
        assert self.widget
        if self.properties("reset-tool-after-create", True):
            self.widget.action_group.actions.lookup_action("select-tool").activate(
                GLib.Variant.new_string("toolbox-pointer")
            )
github gaphor / gaphor / gaphor / ui / diagrampage.py View on Github external
    @event_handler(PropertyChanged)
    def _on_sloppy_lines(self, event: PropertyChanged = None):
        if not event or event.key == "diagram.sloppiness":
            self.set_drawing_style(event and event.new_value or 0.0)
github gaphor / gaphor / gaphor / services / undomanager.py View on Github external
    @event_handler(ElementCreated)
    def undo_create_event(self, event):
        factory = event.service
        # A factory is not always present, e.g. for DiagramItems
        if not factory:
            return
        element = event.element

        def _undo_create_event():
            try:
                del factory._elements[element.id]
            except KeyError:
                pass  # Key was probably already removed in an unlink call
            self.event_manager.handle(ElementDeleted(factory, element))

        self.add_undo_action(_undo_create_event)
github gaphor / gaphor / gaphor / services / sanitizerservice.py View on Github external
    @event_handler(AssociationDeleted)
    def _unlink_on_presentation_delete(self, event):
        """
        Unlink the model element if no more presentations link to the `item`'s
        subject or the deleted item was the only item currently linked.
        """
        if event.property is UML.Element.presentation:
            old_presentation = event.old_value
            if old_presentation and not event.element.presentation:
                event.element.unlink()
github gaphor / gaphor / gaphor / services / sanitizerservice.py View on Github external
    @event_handler(AssociationSet)
    def _disconnect_extension_end(self, event):
        if event.property is UML.ExtensionEnd.type and event.old_value:
            ext = event.element
            p = ext.opposite
            if not p:
                return
            st = event.old_value
            meta = getattr(UML, p.type.name, None)
            if st:
                self.perform_unlink_for_instances(st, meta)
github gaphor / gaphor / gaphor / ui / mainwindow.py View on Github external
    @event_handler(FileLoaded, FileSaved)
    def _on_file_manager_state_changed(self, event):
        self.model_changed = False
        self.filename = event.filename
        self.set_title()
github gaphor / gaphor / gaphor / services / undomanager.py View on Github external
    @event_handler(ElementDeleted)
    def undo_delete_event(self, event):
        factory = event.service
        # A factory is not always present, e.g. for DiagramItems
        if not factory:
            return
        element = event.element
        assert factory, f"No factory defined for {element} ({factory})"

        def _undo_delete_event():
            factory._elements[element.id] = element
            self.event_manager.handle(ElementCreated(factory, element))

        self.add_undo_action(_undo_delete_event)
github gaphor / gaphor / gaphor / ui / mainwindow.py View on Github external
    @event_handler(UndoManagerStateChanged)
    def _on_undo_manager_state_changed(self, event):
        """
        """
        undo_manager = event.service
        if self.model_changed != undo_manager.can_undo():
            self.model_changed = undo_manager.can_undo()
            self.set_title()
github gaphor / gaphor / gaphor / UML / elementdispatcher.py View on Github external
    @event_handler(ModelReady)
    def on_model_loaded(self, event):
        for key, value in list(self._handlers.items()):
            for h, remainders in list(value.items()):
                for remainder in remainders:
                    self._add_handlers(key[0], (key[1],) + remainder, h)
github gaphor / gaphor / gaphor / services / undomanager.py View on Github external
    @event_handler(AttributeUpdated)
    def undo_attribute_change_event(self, event):
        attribute = event.property
        element = event.element
        value = event.old_value

        def _undo_attribute_change_event():
            attribute._set(element, value)

        self.add_undo_action(_undo_attribute_change_event)