How to use gaphor - 10 common examples

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 / menu.py View on Github external
print 'ref:', item
        menu_item_refs.append(weakref.ref(item))
        if item.get_submenu():
            connect_weakref(item.get_submenu())


class FileNewAction(Action):
    id = 'FileNew'
    stock_id = 'gtk-new'

    def execute(self):
        print 'New'

register_action(FileNewAction)

class FileQuitAction(Action):
    id = 'FileQuit'
    stock_id = 'gtk-quit'
    tooltip = 'Quit the application'

    def execute(self):
        window.destroy()
        #gtk.main_quit()

register_action(FileQuitAction)

class FileCheckAction(CheckAction):
    id = 'FileCheck'
    label = '_Check'
    #stock_id = 'gtk-save'
    tooltip = 'Check the checkbox'
github gaphor / gaphor / tests / test_issue_132.py View on Github external
def create_with_attribute(self):
        self.class_ = self.element_factory.create(UML.Class)
        self.attribute = self.element_factory.create(UML.Property)
        self.class_.ownedAttribute = self.attribute
github gaphor / gaphor / tests / test_issue_53.py View on Github external
        profiles = element_factory.lselect(lambda e: e.isKindOf(UML.Profile))
github gaphor / gaphor / tests / menu.py View on Github external
if not self.active:
            import traceback
            traceback.print_stack()

register_action(YellowAction)

class BlueAction(RadioAction):
    id = 'Blue'
    label = 'B_lue'
    group = 'color'
    tooltip = 'Makes the world turn blue'
    
    def execute(self):
        print self.label, self.active

register_action(BlueAction)

class OneAction(RadioAction):
    id = 'One'
    label = 'One'
    group = 'count'
    tooltip = 'Makes the world turn one'
    
    def execute(self):
        print self.label, self.active

register_action(OneAction)

class TwoAction(RadioAction):
    id = 'Two'
    label = 'Two'
    group = 'count'
github gaphor / gaphor / tests / menu.py View on Github external
def execute(self):
        print self.label, self.active

register_action(OneAction)

class TwoAction(RadioAction):
    id = 'Two'
    label = 'Two'
    group = 'count'
    tooltip = 'Makes the world turn two'
    
    def execute(self):
        print self.label, self.active

register_action(TwoAction)

class NewRadioAction(RadioAction):
    pass

class StartAction(NewRadioAction):
    id = 'start'
    name = 'middle'
    names = ('start', 'middle', 'end')
    labels = ('Start', 'Middle', 'End')
    stock_ids = ('gtk-open', 'gtk-close', 'gtk-save')

    def execute(self):
        print 'StartAction', self.active


class ObjectAction(Action):
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 / ui / filemanager.py View on Github external
def load(self, filename):
        """Load the Gaphor model from the supplied file name.  A status window
        displays the loading progress.  The load generator updates the progress
        queue.  The loader is passed to a GIdleThread which executes the load
        generator.  If loading is successful, the filename is set."""

        queue = Queue()
        status_window: Optional[StatusWindow]
        main_window = self.main_window
        status_window = StatusWindow(
            gettext("Loading..."),
            gettext("Loading model from {filename}").format(filename=filename),
            parent=main_window.window,
            queue=queue,
        )

        try:
            loader = storage.load_generator(
                filename.encode("utf-8"), self.element_factory
            )
            worker = GIdleThread(loader, queue)

            worker.start()
            worker.wait()

            if worker.error:
                worker.reraise()
github gaphor / gaphor / gaphor / ui / filemanager.py View on Github external
"""Save the current UML model to the specified file name.  Before
        writing the model file, this will verify that there are no orphan
        references.  It will also verify that the filename has the correct
        extension.  A status window is displayed while the GIdleThread
        is executed.  This thread actually saves the model."""

        if not filename or not len(filename):
            return

        self.verify_orphans()
        filename = self.verify_filename(filename)

        main_window = self.main_window
        queue = Queue()
        status_window = StatusWindow(
            gettext("Saving..."),
            gettext("Saving model to {filename}").format(filename=filename),
            parent=main_window.window,
            queue=queue,
        )
        try:
            with open(filename.encode("utf-8"), "w") as out:
                saver = storage.save_generator(XMLWriter(out), self.element_factory)
                worker = GIdleThread(saver, queue)
                worker.start()
                worker.wait()

            if worker.error:
                worker.reraise()

            self.filename = filename
            self.event_manager.handle(FileSaved(self, filename))