How to use the gaphor.UML.Class 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 / tests / test_association_undo.py View on Github external
def testAssociationUndo(self):
        factory = Application.get_service('element_factory')
        undo_manager = Application.get_service('undo_manager')

        diagram = factory.create(UML.Diagram)
        solver = diagram.canvas.solver
        
        class1 = factory.create(UML.Class)
        class1.name = 'class1'
        classItem1 = diagram.create(items.ClassItem, subject=class1)

        class2 = factory.create(UML.Class)
        class2.name = 'class2'
        classItem2 = diagram.create(items.ClassItem, subject=class2)
        
        assoc = diagram.create(items.AssociationItem)
        assert assoc.subject is None

        adapter = component.queryMultiAdapter((classItem1, assoc), IConnect)
        assert adapter
        adapter.connect(assoc.handles()[0])
        
        adapter = component.queryMultiAdapter((classItem2, assoc), IConnect)
        assert adapter
        adapter.connect(assoc.handles()[1])
        
        assert assoc.subject
        assert assoc.head_end.subject
github gaphor / gaphor / tests / test-ns.py View on Github external
m = factory.create(UML.Package)
m.name = 'm'
a = factory.create(UML.Package)
a.name = 'a'
a.package = m
assert a.package is m
assert a in m.ownedMember
assert a.namespace is m

b = factory.create(UML.Package)
b.name = 'b'
b.package = a
assert b in a.ownedMember
assert b.namespace is a

c = factory.create(UML.Class)
c.name = 'c'
c.package = b
d = factory.create(UML.Class)
d.name = 'd'
d.package = a
e = factory.create(UML.Class)
e.name = 'e'
e.package = b

assert c in b.ownedMember
assert c.namespace is b
assert d in a.ownedMember
assert d.namespace is a
assert e in b.ownedMember
assert e.namespace is b
github gaphor / gaphor / tests / test_issue_gaphas.py View on Github external
def test_remove_class_with_association(self):
        c1 = self.create(ClassItem, UML.Class)
        c1.name = "klassitem1"
        c2 = self.create(ClassItem, UML.Class)
        c2.name = "klassitem2"

        a = self.create(AssociationItem)

        assert 3 == len(self.diagram.canvas.get_all_items())

        self.connect(a, a.head, c1)
        self.connect(a, a.tail, c2)

        assert a.subject
        assert (
            self.element_factory.lselect(lambda e: e.isKindOf(UML.Association))[0]
            is a.subject
        )
github gaphor / gaphor / gaphor / plugins / python / __init__.py View on Github external
def visit_package(self, elmt):
        """get an astng objects tree from a gaphor objects tree (starting
        from a package node)
        """
        try:
            return self._uids[elmt.id]
        except:
            pass
        # get astng module representation
        module = builder.build_module(elmt.name)
        self._uids[elmt.id] = module
        subpackages = [sub for sub in elmt.member if isinstance(sub, UML.Package)]
        subclasses = [sub for sub in elmt.member if isinstance(sub, UML.Class)]
        for member in subclasses:
	    if isinstance(member, UML.Class):
                self.visit(member)
            elif not isinstance(member, UML.Package):
                print 'ignored', elmt
        # write it to the correct location
        if subpackages:
            package_dir = self.mk_package_dir(elmt)
            stream = open(join(package_dir, '__init__.py'), 'w')
        else:
            package_dir = self.mk_package_dir(elmt.namespace)
            stream = open(join(package_dir, '%s.py' % elmt.name), 'w')
        stream.write('"""%s"""\n\n' % elmt.name)
        stream.write('__revision__ = "$Id$"\n\n')
        stream.write(module.as_string())
        stream.write('\n')
github gaphor / gaphor / gaphor / actions / itemactions.py View on Github external
    @transactional
    def execute(self):
        view = self._window.get_current_diagram_view()
        focus_item = get_parent_focus_item(self._window)
        subject = focus_item.subject
        assert isinstance(subject, (UML.Class, UML.Interface))
        
        attribute = self.element_factory.create(UML.Property)
        attribute.parse('new')
        subject.ownedAttribute = attribute

        # Select this item for editing
        presentation = attribute.presentation
        focus_item.request_update()

        wx, wy = view.transform_point_c2w(*get_pointer(view))
        #for f in focus_item._attributes:
github gaphor / gaphor / gaphor / plugins / pynsource / engineer.py View on Github external
def _create_class(self, clazz, name):
        c = self.element_factory.create(UML.Class)
        c.name = name
        c.package = self.diagram.namespace
        ci = self.diagram.create(ClassItem)
        ci.subject = c
        clazz.gaphor_class = c
        clazz.gaphor_class_item = ci
github gaphor / gaphor / gaphor / ui / command / diagrampopup.py View on Github external
def execute(self):
	print 'creating attribute'
        subject = get_parent_focus_item(self._window).subject
        assert isinstance(subject, UML.Class)
        elemfact = gaphor.resource(UML.ElementFactory)
        attribute = elemfact.create(UML.Property)
        attribute.name = 'new'
        subject.ownedAttribute = attribute
	print 'done'
github gaphor / gaphor / gaphor / plugins / pynsource / engineer.py View on Github external
                        lambda e: isinstance(e, UML.Class) and e.name == superclassname
                    )
github gaphor / gaphor / gaphor / ui / iconoption.py View on Github external
@get_icon_option.register(UML.Class)
def get_option_class(element):
    if element.extension:
        return "metaclass"
github gaphor / gaphor / gaphor / diagram / classes / klass.py View on Github external
EditableText,
    Text,
    draw_border,
    draw_top_separator,
)
from gaphor.diagram.text import (
    TextAlign,
    VerticalAlign,
    FontStyle,
    FontWeight,
    TextDecoration,
)
from gaphor.diagram.support import represents


@represents(UML.Class)
@represents(UML.Stereotype)
class ClassItem(ElementPresentation, Classified):
    """This item visualizes a Class instance.

    A ClassItem contains two compartments: one for attributes and one for
    operations.
    """

    def __init__(self, id=None, model=None):
        super().__init__(id, model)

        self.watch("show_stereotypes", self.update_shapes).watch(
            "show_attributes", self.update_shapes
        ).watch("show_operations", self.update_shapes).watch(
            "subject[NamedElement].name"
        ).watch(