How to use the gaphas.state.reversible_property 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 / diagram / compartment.py View on Github external
if self._drawing_style == self.DRAW_COMPARTMENT:
            self.draw = self.draw_compartment
            self.pre_update = self.pre_update_compartment
            self.post_update = self.post_update_compartment

        elif self._drawing_style == self.DRAW_COMPARTMENT_ICON:
            self.draw = self.draw_compartment_icon
            self.pre_update = self.pre_update_compartment_icon
            self.post_update = self.post_update_compartment_icon

        elif self._drawing_style == self.DRAW_ICON:
            self.draw = self.draw_icon
            self.pre_update = self.pre_update_icon
            self.post_update = self.post_update_icon

    drawing_style = reversible_property(
        lambda self: self._drawing_style, set_drawing_style
    )

    def create_compartment(self, name):
        """
        Create a new compartment. Compartments contain data such as
        attributes and operations.

        It is common to create compartments during the construction of the
        diagram item. Their visibility can be toggled by Compartment.visible.
        """
        c = Compartment(name, self)
        c.font = self.style.feature_font
        self._compartments.append(c)
        return c
github gaphor / gaphor / gaphor / diagram / classes / association.py View on Github external
f"{base}.type[Class].ownedAttribute", self.on_association_end_value
        ).watch(
            f"{base}.type[Interface].ownedAttribute", self.on_association_end_value
        ).watch(
            f"{base}.appliedStereotype.classifier", self.on_association_end_value
        ).watch(
            "subject[Association].ownedEnd"
        ).watch(
            "subject[Association].navigableOwnedEnd"
        )

    def set_show_direction(self, dir):
        self._show_direction = dir
        self.request_update()

    show_direction = reversible_property(
        lambda s: s._show_direction, set_show_direction
    )

    def save(self, save_func):
        super().save(save_func)
        save_func("show-direction", self._show_direction)
        if self._head_end.subject:
            save_func("head-subject", self._head_end.subject)
        if self._tail_end.subject:
            save_func("tail-subject", self._tail_end.subject)

    def load(self, name, value):
        # end_head and end_tail were used in an older Gaphor version
        if name in ("head_end", "head_subject", "head-subject"):
            self._head_end.subject = value
        elif name in ("tail_end", "tail_subject", "tail-subject"):
github gaphor / gaphor / gaphor / diagram / classes / klass.py View on Github external
self._operations.visible = value
        self._operations.use_extra_space = value
        self._attributes.use_extra_space = not self._operations.visible

    show_operations = reversible_property(fget=lambda s: s._operations.visible,
            fset=_set_show_operations)
    
    @observed
    def _set_show_attributes(self, value):
        """Sets the show attributes property.  This will either show or hide
        the attributes compartment of the ClassItem.  This is part of the
        show_attributes property."""
        
        self._attributes.visible = value

    show_attributes = reversible_property(fget=lambda s: s._attributes.visible,
                               fset=_set_show_attributes)

    def _create_attribute(self, attribute):
        """Create a new attribute item.  This will create a new FeatureItem
        and assigns the specified attribute as the subject."""
        
        new = FeatureItem()
        new.subject = attribute
        new.font = self.style.feature_font
        
        self._attributes.append(new)


    def _create_operation(self, operation):
        """Create a new operation item.  This will create a new OperationItem
        and assigns the specified operation as the subject."""
github gaphor / gaphor / gaphor / diagram / actions / objectnode.py View on Github external
and f"{{ ordering = {self.subject.ordering} }}",
                style={"min-width": 0, "min-height": 0},
            ),
        )

        self.watch("subject[NamedElement].name")
        self.watch("subject.appliedStereotype.classifier.name")
        self.watch("subject[ObjectNode].upperBound")
        self.watch("subject[ObjectNode].ordering")

    @observed
    def _set_show_ordering(self, value):
        self._show_ordering = value
        self.request_update()

    show_ordering = reversible_property(lambda s: s._show_ordering, _set_show_ordering)

    def save(self, save_func):
        save_func("show-ordering", self._show_ordering)
        super().save(save_func)

    def load(self, name, value):
        if name == "show-ordering":
            self._show_ordering = ast.literal_eval(value)
        else:
            super().load(name, value)
github gaphor / gaphor / gaphor / diagram / classes / association.py View on Github external
.watch(base + 'aggregation', self.on_association_end_value)\
            .watch(base + 'classifier', self.on_association_end_value)\
            .watch(base + 'visibility', self.on_association_end_value)\
            .watch(base + 'lowerValue', self.on_association_end_value)\
            .watch(base + 'upperValue', self.on_association_end_value)\
            .watch(base + 'owningAssociation', self.on_association_end_value) \
            .watch(base + 'type.ownedAttribute', self.on_association_end_value) \
            .watch(base + 'type.ownedAttribute', self.on_association_end_value) \
            .watch('subject.ownedEnd') \
            .watch('subject.navigableOwnedEnd')

    def set_show_direction(self, dir):
        self._show_direction = dir
        self.request_update()

    show_direction = reversible_property(lambda s: s._show_direction, set_show_direction)

    def setup_canvas(self):
        super(AssociationItem, self).setup_canvas()

    def teardown_canvas(self):
        super(AssociationItem, self).teardown_canvas()

    def save(self, save_func):
        NamedLine.save(self, save_func)
        save_func('show-direction', self._show_direction)
        if self._head_end.subject:
            save_func('head-subject', self._head_end.subject)
        if self._tail_end.subject:
            save_func('tail-subject', self._tail_end.subject)

    def load(self, name, value):
github gaphor / gaphor / gaphor / diagram / actions / activitynodes.py View on Github external
if name == "matrix":
            self.matrix = ast.literal_eval(value)
        elif name == "height":
            self._handles[1].pos.y = ast.literal_eval(value)
        elif name == "combined":
            self._combined = value
        else:
            # DiagramItem.load(self, name, value)
            super().load(name, value)

    @observed
    def _set_combined(self, value):
        # self.preserve_property('combined')
        self._combined = value

    combined = reversible_property(lambda s: s._combined, _set_combined)

    def setup_canvas(self):
        super().setup_canvas()

        h1, h2 = self._handles
        cadd = self.canvas.solver.add_constraint
        c1 = EqualsConstraint(a=h1.pos.x, b=h2.pos.x)
        c2 = LessThanConstraint(smaller=h1.pos.y, bigger=h2.pos.y, delta=30)
        self.__constraints = (cadd(c1), cadd(c2))
        list(map(self.canvas.solver.add_constraint, self.__constraints))

    def teardown_canvas(self):
        super().teardown_canvas()
        list(map(self.canvas.solver.remove_constraint, self.__constraints))

    def pre_update(self, context):
github gaphor / gaphor / gaphor / diagram / diagramitem.py View on Github external
def __init__(self):
        super().__init__()
        self._stereotype = self.add_text(
            "stereotype",
            style=self.STEREOTYPE_ALIGN,
            visible=lambda: self._stereotype.text,
        )
        self._show_stereotypes_attrs = False

    @observed
    def _set_show_stereotypes_attrs(self, value):
        self._show_stereotypes_attrs = value
        self.update_stereotypes_attrs()

    show_stereotypes_attrs = reversible_property(
        fget=lambda s: s._show_stereotypes_attrs,
        fset=_set_show_stereotypes_attrs,
        doc="""
            Diagram item should show stereotypes attributes when property
            is set to True.

            When changed, method `update_stereotypes_attrs` is called.
            """,
    )

    def update_stereotypes_attrs(self):
        """
        Update display of stereotypes attributes.

        The method does nothing at the moment. In the future it should
        probably display stereotypes attributes under stereotypes header.
github gaphor / gaphor / gaphor / diagram / classes / interface.py View on Github external
.watch('subject.supplierDependency')


    @observed
    def set_drawing_style(self, style):
        """
        In addition to setting the drawing style, the handles are
        make non-movable if the icon (folded) style is used.
        """
        super(InterfaceItem, self).set_drawing_style(style)
        if self._drawing_style == self.DRAW_ICON:
            self.folded = self.FOLDED_PROVIDED # set default folded mode
        else:
            self.folded = self.FOLDED_NONE # unset default folded mode

    drawing_style = reversible_property(lambda self: self._drawing_style, set_drawing_style)

    def _is_folded(self):
        """
        Check if interface item is folded interface item.
        """
        return self._folded

    def _set_folded(self, folded):
        """
        Set folded notation.

        :param folded: Folded state, see FOLDED_* constants.
        """

        self._folded = folded
github gaphor / gaphor / gaphor / diagram / classes / klass.py View on Github external
synchronized."""
        super(ClassItem, self).postload()
        self.sync_attributes()
        self.sync_operations()

    @observed
    def _set_show_operations(self, value):
        """Sets the show operations property.  This will either show or hide
        the operations compartment of the ClassItem.  This is part of the
        show_operations property."""
        
        self._operations.visible = value
        self._operations.use_extra_space = value
        self._attributes.use_extra_space = not self._operations.visible

    show_operations = reversible_property(fget=lambda s: s._operations.visible,
            fset=_set_show_operations)
    
    @observed
    def _set_show_attributes(self, value):
        """Sets the show attributes property.  This will either show or hide
        the attributes compartment of the ClassItem.  This is part of the
        show_attributes property."""
        
        self._attributes.visible = value

    show_attributes = reversible_property(fget=lambda s: s._attributes.visible,
                               fset=_set_show_attributes)

    def _create_attribute(self, attribute):
        """Create a new attribute item.  This will create a new FeatureItem
        and assigns the specified attribute as the subject."""