def skiptest_derivedunion(self): class A(Element): is_unlinked = False def unlink(self): self.is_unlinked = True Element.unlink(self) A.a = association('a', A, upper=1) A.b = association('b', A) A.derived_a = derivedunion('derived_a', A, 0, 1, A.a) A.derived_b = derivedunion('derived_b', A, 0, '*', A.b) events = [] @component.adapter(IAssociationChangeEvent) def handler(event, events=events): events.append(event) Application.register_handler(handler) try: a = A() a.a = A() assert len(events) == 2, events assert events[0].property is A.derived_a assert events[1].property is A.a finally: Application.unregister_handler(handler)
def skiptest_redefine(self): from zope import component from gaphor.application import Application class A(Element): is_unlinked = False def unlink(self): self.is_unlinked = True Element.unlink(self) A.a = association('a', A, upper=1) A.a = redefine(A, 'a', A, A.a) events = [] @component.adapter(IAssociationChangeEvent) def handler(event, events=events): events.append(event) Application.register_handler(handler) try: a = A() a.a = A() assert len(events) == 2 assert events[0].property is A.a, events[0].property assert events[1].property is A.a.original, events[1].property finally: Application.unregister_handler(handler)
def test_show_diagram(self): main_w = Application.get_service("main_window") element_factory = Application.get_service("element_factory") diagram = element_factory.create(UML.Diagram) main_w.open() self.component_registry.handle(DiagramShow(diagram)) self.assertEqual(self.get_current_diagram(), diagram)
def tearDown(self): self.page.close() del self.page self.diagram.unlink() del self.diagram Application.shutdown() assert len(self.element_factory.lselect()) == 0
def test_show_diagram(self): main_w = Application.get_service('main_window') element_factory = Application.get_service('element_factory') diagram = element_factory.create(UML.Diagram) main_w.open() self.assertEqual(main_w.get_current_diagram(), None) main_w.show_diagram(diagram)
def setUp(self): Application.init() element_factory = Application.get_service("element_factory") from gaphor.storage.storage import load dist = pkg_resources.get_distribution("gaphor") path = os.path.join(dist.location, "test-diagrams/issue_53.gaphor") load(path, element_factory)
def setUp(self): Application.init(services=['adapter_loader', 'element_factory', 'main_window', 'properties_manager', 'action_manager', 'properties', 'element_dispatcher']) self.main_window = Application.get_service('main_window') self.element_factory = Application.get_service('element_factory') self.diagram = self.element_factory.create(UML.Diagram) self.comment = self.diagram.create(CommentItem, subject=self.element_factory.create(UML.Comment)) self.commentline = self.diagram.create(CommentLineItem) self.view = self.main_window.show_diagram(self.diagram).view
def setUp(self): Application.init( services=[ "main_window", "properties", "element_factory", "diagram_export_manager", "action_manager", ] )
def setUp(self): Application.init(services=self.services) self.element_factory = Application.get_service("element_factory") assert len(list(self.element_factory.select())) == 0, list( self.element_factory.select() ) self.diagram = self.element_factory.create(UML.Diagram) assert len(list(self.element_factory.select())) == 1, list( self.element_factory.select() )
def setUp(self): Application.init(services=['element_factory', 'main_window', 'ui_manager', 'action_manager', 'properties', 'element_dispatcher']) main_window = Application.get_service('main_window') main_window.open() element_factory = Application.get_service('element_factory') self.element_factory = element_factory self.diagram = element_factory.create(UML.Diagram) self.tab = main_window.show_diagram(self.diagram) self.assertEquals(self.tab.diagram, self.diagram) self.assertEquals(self.tab.view.canvas, self.diagram.canvas) self.assertEquals(len(element_factory.lselect()), 1)
def testDiagramLayout(self): elemfact = Application.get_service("element_factory") diagram_layout = Application.get_service("diagram_layout") diagram = elemfact.create(UML.Diagram) c1 = diagram.create(items.ClassItem, subject=elemfact.create(UML.Class)) c2 = diagram.create(items.ClassItem, subject=elemfact.create(UML.Class)) c2.matrix.translate(100, 100) c2.request_update() diagram_layout.layout_diagram(diagram)
def testLoadAll(self): from gaphor.application import Application Application.init() am = Application.get_service("action_manager") ui = am.ui_manager.get_ui() assert '<menuitem name="file-quit" action="file-quit"/>' in ui, ui # From filemanager: assert '<menuitem name="file-new" action="file-new"/>' in ui, ui # From Undomanager assert '<toolitem name="edit-undo" action="edit-undo"/>' in ui, ui
def setUp(self): Application.init(services=['element_factory', 'main_window', 'action_manager', 'properties', 'element_dispatcher']) main_window = Application.get_service('main_window') element_factory = Application.get_service('element_factory') self.element_factory = element_factory self.diagram = element_factory.create(UML.Diagram) self.tab = DiagramTab(main_window) self.tab.set_diagram(self.diagram) self.assertEquals(self.tab.diagram, self.diagram) widget = self.tab.construct() main_window.add_tab(self.tab, widget, 'title') self.assertEquals(self.tab.view.canvas, self.diagram.canvas) self.assertEquals(len(element_factory.lselect()), 1)
def setUp(self): Application.init( services=[ "element_factory", "main_window", "properties_manager", "action_manager", "properties", "element_dispatcher", ] ) self.main_window = Application.get_service("main_window") self.main_window.open()
def setUp(self): Application.init( services=[ "file_manager", "element_factory", "properties", "main_window", "action_manager", ] ) self.recent_files_backup = Application.get_service("properties").get( "recent-files" )
def test_uml_associations(self): from zope import component from gaphor.UML.interfaces import IAssociationChangeEvent from gaphor.UML.properties import association, derivedunion from gaphor.UML import Element class A(Element): is_unlinked = False def unlink(self): self.is_unlinked = True Element.unlink(self) A.a1 = association('a1', A, upper=1) A.a2 = association('a2', A, upper=1) A.b1 = association('b1', A, upper='*') A.b2 = association('b2', A, upper='*') A.b3 = association('b3', A, upper=1) A.derived_a = derivedunion('derived_a', 0, 1, A.a1, A.a2) A.derived_b = derivedunion('derived_b', 0, '*', A.b1, A.b2, A.b3) events = [] @component.adapter(IAssociationChangeEvent) def handler(event, events=events): events.append(event) Application.register_handler(handler) try: a = A() undo_manager = UndoManager() undo_manager.init(Application) undo_manager.begin_transaction() a.a1 = A() undo_manager.commit_transaction() assert len(events) == 1, events assert events[0].property is A.a1 assert undo_manager.can_undo() undo_manager.undo_transaction() assert not undo_manager.can_undo() assert undo_manager.can_redo() assert len(events) == 2, events assert events[1].property is A.a1 finally: Application.unregister_handler(handler) undo_manager.shutdown()
def setUp(self): """Initialize Gaphor services and register transaction event handlers.""" Application.init(services=['component_registry']) component_registry = Application.get_service('component_registry') component_registry.register_handler(handle_begins, [TransactionBegin]) component_registry.register_handler(handle_commits, [TransactionCommit]) component_registry.register_handler(handle_rollback, [TransactionRollback]) del begins[:] del commits[:] del rollbacks[:]
def testPackageRemoval(self): # Load the application element_factory = Application.get_service("element_factory") # Find all profile instances profiles = element_factory.lselect(lambda e: e.isKindOf(UML.Profile)) # Check there is 1 profile self.assertEqual(1, len(profiles)) # Check the profile has 1 presentation self.assertEqual(1, len(profiles[0].presentation)) # Unlink the presentation profiles[0].presentation[0].unlink() self.assertFalse(element_factory.lselect(lambda e: e.isKindOf(UML.Profile))) classes = element_factory.lselect(lambda e: e.isKindOf(UML.Class)) self.assertEqual(1, len(classes)) # Check if the link is really removed: self.assertFalse(classes[0].appliedStereotype) self.assertFalse( element_factory.lselect(lambda e: e.isKindOf(UML.InstanceSpecification)) ) self.assertEqual( 3, len(element_factory.lselect(lambda e: e.isKindOf(UML.Diagram))) )
def __get__(self, obj, class_=None): """ Resolve a dependency, but only if we're called from an object instance. """ if not obj: return self return Application.get_service(self._name)
def test_iconnect_2(self): """Test connect/disconnect on comment and actor using comment-line. """ element_factory = Application.get_service("element_factory") diagram = element_factory.create(UML.Diagram) self.component_registry.handle(DiagramShow(diagram)) comment = diagram.create( CommentItem, subject=element_factory.create(UML.Comment) ) actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, "View should be available here" tool = ConnectHandleTool(view) # Connect one end to the Comment: handle = line.handles()[0] tool.grab_handle(line, handle) comment_bb = view.get_item_bounding_box(comment) handle.pos = (comment_bb.x1, comment_bb.y1) sink = tool.glue(line, handle, handle.pos) assert sink is not None assert sink.item is comment tool.connect(line, handle, handle.pos) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo is not None, None) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is comment) # Connect the other end to the Actor: handle = line.handles()[-1] tool.grab_handle(line, handle) actor_bb = view.get_item_bounding_box(actor) handle.pos = actor_bb.x1, actor_bb.y1 sink = tool.glue(line, handle, handle.pos) self.assertTrue(sink.item is actor) tool.connect(line, handle, handle.pos) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is actor) # Try to connect far away from any item will only do a full disconnect self.assertEqual( len(comment.subject.annotatedElement), 1, comment.subject.annotatedElement ) self.assertTrue(actor.subject in comment.subject.annotatedElement) sink = tool.glue(line, handle, (500, 500)) self.assertTrue(sink is None, sink) tool.connect(line, handle, (500, 500)) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo is None)
def tearDown(self): """Finished with the test case. Unregister event handlers that store transaction events.""" component_registry = Application.get_service('component_registry') component_registry.unregister_handler(handle_begins, [TransactionBegin]) component_registry.unregister_handler(handle_commits, [TransactionCommit]) component_registry.unregister_handler(handle_rollback, [TransactionRollback])
def setUp(self): Application.init( services=[ "element_factory", "main_window", "properties_manager", "action_manager", "properties", "element_dispatcher", ] ) self.main_window = Application.get_service("main_window") self.main_window.open() self.element_factory = Application.get_service("element_factory") self.diagram = self.element_factory.create(UML.Diagram) self.comment = self.diagram.create( CommentItem, subject=self.element_factory.create(UML.Comment) ) self.commentline = self.diagram.create(CommentLineItem)
def test_show_diagram(self): main_w = MainWindow() element_factory = Application.get_service('element_factory') diagram = element_factory.create(UML.Diagram) ui_manager = gtk.UIManager() main_w.ui_manager = ui_manager main_w.construct() self.assertEqual(main_w.get_current_diagram(), None) main_w.show_diagram(diagram)
def setUp(self): Application.init( services=[ "element_factory", "main_window", "action_manager", "properties", "element_dispatcher", ] ) main_window = Application.get_service("main_window") main_window.open() self.element_factory = Application.get_service("element_factory") self.diagram = self.element_factory.create(UML.Diagram) self.page = DiagramPage(self.diagram) self.page.construct() self.assertEqual(self.page.diagram, self.diagram) self.assertEqual(self.page.view.canvas, self.diagram.canvas) self.assertEqual(len(self.element_factory.lselect()), 1)
def test_uml_associations(self): from gaphor.UML.event import AssociationChangeEvent from gaphor.UML.properties import association, derivedunion from gaphor.UML import Element class A(Element): is_unlinked = False def unlink(self): self.is_unlinked = True Element.unlink(self) A.a1 = association("a1", A, upper=1) A.a2 = association("a2", A, upper=1) A.b1 = association("b1", A, upper="*") A.b2 = association("b2", A, upper="*") A.b3 = association("b3", A, upper=1) A.derived_a = derivedunion("derived_a", 0, 1, A.a1, A.a2) A.derived_b = derivedunion("derived_b", 0, "*", A.b1, A.b2, A.b3) events = [] @event_handler(AssociationChangeEvent) def handler(event, events=events): events.append(event) compreg = Application.get_service("component_registry") compreg.register_handler(handler) try: a = A(factory=self.element_factory) undo_manager = UndoManager() undo_manager.init(Application) undo_manager.begin_transaction() a.a1 = A(factory=self.element_factory) undo_manager.commit_transaction() assert len(events) == 1, events assert events[0].property is A.a1 assert undo_manager.can_undo() undo_manager.undo_transaction() assert not undo_manager.can_undo() assert undo_manager.can_redo() assert len(events) == 2, events assert events[1].property is A.a1 finally: compreg.unregister_handler(handler) undo_manager.shutdown()
def test_recent_files(self): fileman = Application.get_service('file_manager') properties = Application.get_service('properties') # ensure the recent_files list is empty: properties.set('recent-files', []) fileman.update_recent_files() for i in range(0, 9): a = fileman.action_group.get_action('file-recent-%d' % i) assert a assert a.get_property('visible') == False, '%s, %d' % (a.get_property('visible'), i) fileman.filename = 'firstfile' a = fileman.action_group.get_action('file-recent-%d' % 0) assert a assert a.get_property('visible') == True assert a.props.label == '_1. firstfile', a.props.label for i in range(1, 9): a = fileman.action_group.get_action('file-recent-%d' % i) assert a assert a.get_property('visible') == False
def launch(model=None): """Start the main application by initiating and running Application. The file_manager service is used here to load a Gaphor model if one was specified on the command line. Otherwise, a new model is created and the Gaphor GUI is started.""" # Make sure gui is loaded ASAP. # This prevents menu items from appearing at unwanted places. Application.essential_services.append('main_window') Application.init() main_window = Application.get_service('main_window') main_window.open() file_manager = Application.get_service('file_manager') if model: file_manager.load(model) else: file_manager.action_new() Application.run()
def test(self): factory = Application.get_service('element_factory') ns = NamespaceModel(factory) m = factory.create(UML.Package) m.name = 'm' assert ns._nodes.has_key(m) assert ns.path_from_element(m) == (1,) assert ns.element_from_path((1,)) is m a = factory.create(UML.Package) a.name = 'a' assert a in ns._nodes assert a in ns._nodes[None] assert m in ns._nodes assert ns.path_from_element(a) == (1,), ns.path_from_element(a) assert ns.path_from_element(m) == (2,), ns.path_from_element(m) a.package = m assert a in ns._nodes assert a not in ns._nodes[None] assert a in ns._nodes[m] assert m in ns._nodes assert a.package is m assert a in m.ownedMember assert a.namespace is m assert ns.path_from_element(a) == (1, 0), ns.path_from_element(a) c = factory.create(UML.Class) c.name = 'c' assert c in ns._nodes assert ns.path_from_element(c) == (1,), ns.path_from_element(c) assert ns.path_from_element(m) == (2,), ns.path_from_element(m) assert ns.path_from_element(a) == (2, 0), ns.path_from_element(a) c.package = m assert c in ns._nodes assert c not in ns._nodes[None] assert c in ns._nodes[m] c.package = a assert c in ns._nodes assert c not in ns._nodes[None] assert c not in ns._nodes[m] assert c in ns._nodes[a] c.unlink() assert c not in ns._nodes assert c not in ns._nodes[None] assert c not in ns._nodes[m] assert c not in ns._nodes[a]
def setUp(self): super(ElementDispatcherAsServiceTestCase, self).setUp() self.events = [] self.dispatcher = Application.get_service("element_dispatcher") element_factory = self.element_factory class A(Element): def __init__(self): super().__init__(factory=element_factory) A.one = association("one", A, lower=0, upper=1, composite=True) A.two = association("two", A, lower=0, upper=2, composite=True) self.A = A
def skiptest_redefine_subclass(self): from zope import component class A(Element): is_unlinked = False def unlink(self): self.is_unlinked = True Element.unlink(self) A.a = association('a', A, upper=1) class B(A): pass B.b = redefine(B, 'b', A, A.a) events = [] @component.adapter(IAssociationChangeEvent) def handler(event, events=events): events.append(event) Application.register_handler(handler) try: a = A() a.a = A() # Only a.a changes, no B class involved assert len(events) == 1 assert events[0].property is A.a, events[0].property #assert events[1].property is A.a.original, events[1].property del events[:] a = B() a.a = A() # Now events are sent for both association and redefine assert len(events) == 2 assert events[0].property is B.b, events[0].property assert events[1].property is B.b.original, events[1].property finally: Application.unregister_handler(handler)
def test_iconnect(self): """ Test basic glue functionality using CommentItem and CommentLine items. """ element_factory = Application.get_service("element_factory") diagram = element_factory.create(UML.Diagram) self.component_registry.handle(DiagramShow(diagram)) comment = diagram.create(CommentItem, subject=element_factory.create(UML.Comment)) actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) actor.matrix.translate(200, 200) diagram.canvas.update_matrix(actor) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, "View should be available here" comment_bb = view.get_item_bounding_box(comment) # select handle: handle = line.handles()[-1] tool = ConnectHandleTool(view=view) tool.grab_handle(line, handle) handle.pos = (comment_bb.x, comment_bb.y) item = tool.glue(line, handle, handle.pos) self.assertTrue(item is not None) tool.connect(line, handle, handle.pos) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo.constraint is not None) self.assertTrue(cinfo.connected is actor, cinfo.connected) Connector(line, handle).disconnect() cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo is None)
def setUp(self): self.session = Application.new_session(services=[ "event_manager", "component_registry", "element_factory", "main_window", "properties_manager", "properties", "namespace", "diagrams", "toolbox", "elementeditor", "export_menu", "tools_menu", ]) self.component_registry = self.session.get_service( "component_registry") self.event_manager = self.session.get_service("event_manager") self.main_window = self.session.get_service("main_window") self.main_window.open()
def test_service_load(self): """Test loading services and querying utilities.""" Application.init(['undo_manager', 'file_manager', 'properties']) self.assertTrue(Application.get_service('undo_manager') is not None, 'Failed to load the undo manager service') self.assertTrue(Application.get_service('file_manager') is not None, 'Failed to load the file manager service') self.assertTrue(component.queryUtility(IService, 'undo_manager') is not None, ( 'Failed to query the undo manager utility')) self.assertTrue(component.queryUtility(IService, 'file_manager') is not None, ( 'Failed to query the file manager utility')) Application.shutdown()
def test_service_load(self): """Test loading services and querying utilities.""" Application.init(["undo_manager", "file_manager", "properties"]) self.assertTrue( Application.get_service("undo_manager") is not None, "Failed to load the undo manager service", ) self.assertTrue( Application.get_service("file_manager") is not None, "Failed to load the file manager service", ) Application.shutdown()
def testPackageRemovalByRemovingTheDiagram(self): element_factory = Application.get_service('element_factory') diagram = element_factory.lselect(lambda e: e.isKindOf(UML.Diagram) and e.name == 'Stereotypes diagram')[0] self.assertTrue(diagram) diagram.unlink() self.assertFalse( element_factory.lselect(lambda e: e.isKindOf(UML.Profile))) classes = element_factory.lselect(lambda e: e.isKindOf(UML.Class)) self.assertEquals(1, len(classes)) # Check if the link is really removed: self.assertFalse(classes[0].appliedStereotype) self.assertFalse( element_factory.lselect( lambda e: e.isKindOf(UML.InstanceSpecification))) self.assertEquals( 2, len(element_factory.lselect(lambda e: e.isKindOf(UML.Diagram))))
def setUp(self): Application.init(['element_factory']) self.factory = Application.get_service('element_factory')
def tearDown(self): del self.factory self.clearEvents() Application.shutdown()
def test_derivedunion_events(): from gaphor.UML.event import DerivedAdded, DerivedDeleted class A(Element): is_unlinked = False def unlink(self): self.is_unlinked = True Element.unlink(self) A.a1 = association("a1", A, upper=1) A.a2 = association("a2", A, upper=1) A.b1 = association("b1", A, upper="*") A.b2 = association("b2", A, upper="*") A.b3 = association("b3", A, upper=1) A.derived_a = derivedunion(A, "derived_a", object, 0, 1, A.a1, A.a2) A.derived_b = derivedunion(A, "derived_b", object, 0, "*", A.b1, A.b2, A.b3) events = [] @event_handler(AssociationUpdated) def handler(event, events=events): events.append(event) Application.register_handler(handler) try: a = A() a.a1 = A() assert len(events) == 2 assert events[0].property is A.derived_a assert events[1].property is A.a1 assert a.derived_a is a.a1 a.a1 = A() assert len(events) == 4, len(events) assert a.derived_a is a.a1 a.a2 = A() # Should not emit DerivedSet assert len(events) == 5, len(events) assert events[4].property is A.a2 del events[:] old_a1 = a.a1 del a.a1 assert len(events) == 2, len(events) assert events[0].property is A.derived_a assert events[0].new_value is a.a2, "{} {} {}".format( a.a1, a.a2, events[3].new_value) assert events[0].old_value is old_a1, "{} {} {}".format( a.a1, a.a2, events[3].old_value) assert events[1].property is A.a1 del events[:] old_a2 = a.a2 del a.a2 assert len(events) == 2, len(events) assert events[0].property is A.derived_a assert events[0].new_value is None, "{} {} {}".format( a.a1, a.a2, events[5].new_value) assert events[0].old_value is old_a2, "{} {} {}".format( a.a1, a.a2, events[5].old_value) assert events[1].property is A.a2 del events[:] assert len(events) == 0, len(events) a.b1 = A() assert len(events) == 2 assert events[0].property is A.derived_b assert events[1].property is A.b1 a.b2 = A() assert len(events) == 4 assert events[2].property is A.derived_b assert events[3].property is A.b2 a.b2 = A() assert len(events) == 6 assert events[4].property is A.derived_b assert events[5].property is A.b2 a.b3 = A() assert len(events) == 8, len(events) assert events[6].property is A.derived_b assert events[7].property is A.b3 # Add b3's value to b2, should not emit derived union event a.b2 = a.b3 assert len(events) == 9, len(events) assert events[8].property is A.b2 # Remove b3's value to b2 del a.b2[a.b3] assert len(events) == 10, len(events) assert events[9].property is A.b2 a.b3 = A() assert len(events) == 13, len(events) assert events[10].property is A.derived_b assert isinstance(events[10], DerivedDeleted), type(events[10]) assert events[11].property is A.derived_b assert isinstance(events[11], DerivedAdded), type(events[11]) assert events[12].property is A.b3 del a.b3 assert len(events) == 15, len(events) assert events[13].property is A.derived_b assert isinstance(events[13], DerivedDeleted), type(events[10]) assert events[14].property is A.b3 finally: Application.unregister_handler(handler)
def test_creation(self): # MainWindow should be created as resource main_w = Application.get_service("main_window") main_w.open() self.assertEqual(self.get_current_diagram(), None)
def tearDown(self): Application.get_service('element_factory').shutdown() Application.shutdown()
def application(): app = Application() yield app app.shutdown()
def setUp(self): Application.init(services=self.services) self.element_factory = Application.get_service('element_factory') self.backup_service = Application.get_service('backup_service')
def get_service(self, name): return Application.get_service(name)
def app_activate(app): if not Application.has_sessions(): app.open([], "__new__")
def action_manager(): Application.init() return Application.get_service("action_manager")
def on_session_shutdown(event): Application.shutdown_session(session) if not Application.sessions: gtk_app.quit()
def skiptest_derivedunion_events(self): from zope import component from gaphor.UML.event import DerivedSetEvent, DerivedAddEvent, DerivedDeleteEvent class A(Element): is_unlinked = False def unlink(self): self.is_unlinked = True Element.unlink(self) A.a1 = association('a1', A, upper=1) A.a2 = association('a2', A, upper=1) A.b1 = association('b1', A, upper='*') A.b2 = association('b2', A, upper='*') A.b3 = association('b3', A, upper=1) A.derived_a = derivedunion('derived_a', object, 0, 1, A.a1, A.a2) A.derived_b = derivedunion('derived_b', object, 0, '*', A.b1, A.b2, A.b3) events = [] @component.adapter(IAssociationChangeEvent) def handler(event, events=events): events.append(event) Application.register_handler(handler) try: a = A() a.a1 = A() assert len(events) == 2 assert events[0].property is A.derived_a assert events[1].property is A.a1 assert a.derived_a is a.a1 a.a1 = A() assert len(events) == 4, len(events) assert a.derived_a is a.a1 a.a2 = A() # Should not emit DerivedSetEvent assert len(events) == 5, len(events) assert events[4].property is A.a2 del events[:] old_a1 = a.a1 del a.a1 assert len(events) == 2, len(events) assert events[0].property is A.derived_a assert events[0].new_value is a.a2, '%s %s %s' % ( a.a1, a.a2, events[3].new_value) assert events[0].old_value is old_a1, '%s %s %s' % ( a.a1, a.a2, events[3].old_value) assert events[1].property is A.a1 del events[:] old_a2 = a.a2 del a.a2 assert len(events) == 2, len(events) assert events[0].property is A.derived_a assert events[0].new_value is None, '%s %s %s' % ( a.a1, a.a2, events[5].new_value) assert events[0].old_value is old_a2, '%s %s %s' % ( a.a1, a.a2, events[5].old_value) assert events[1].property is A.a2 del events[:] assert len(events) == 0, len(events) a.b1 = A() assert len(events) == 2 assert events[0].property is A.derived_b assert events[1].property is A.b1 a.b2 = A() assert len(events) == 4 assert events[2].property is A.derived_b assert events[3].property is A.b2 a.b2 = A() assert len(events) == 6 assert events[4].property is A.derived_b assert events[5].property is A.b2 a.b3 = A() assert len(events) == 8, len(events) assert events[6].property is A.derived_b assert events[7].property is A.b3 # Add b3's value to b2, should not emit derived union event a.b2 = a.b3 assert len(events) == 9, len(events) assert events[8].property is A.b2 # Remove b3's value to b2 del a.b2[a.b3] assert len(events) == 10, len(events) assert events[9].property is A.b2 a.b3 = A() assert len(events) == 13, len(events) assert events[10].property is A.derived_b assert type(events[10]) is DerivedDeleteEvent, type(events[10]) assert events[11].property is A.derived_b assert type(events[11]) is DerivedAddEvent, type(events[11]) assert events[12].property is A.b3 del a.b3 assert len(events) == 15, len(events) assert events[13].property is A.derived_b assert type(events[13]) is DerivedDeleteEvent, type(events[10]) assert events[14].property is A.b3 finally: Application.unregister_handler(handler)
def application(services=["element_factory", "action_manager"]): Application.init(services=services) yield Application Application.shutdown()
def tearDown(self): Application.shutdown()
def session(): session = Application.new_session() yield session
def test_init_from_application(self): Application.get_service('diagram_export_manager') Application.get_service('main_window')
def shutDown(self): Application.shutdown()
def setUp(self): Application.init(services=[ 'main_window', 'properties', 'element_factory', 'diagram_export_manager', 'action_manager', 'ui_manager' ])
def setUp(self): Application.init(["element_factory"]) self.factory = Application.get_service("element_factory") clearEvents()
def test_iconnect_2(self): """Test connect/disconnect on comment and actor using comment-line. """ element_factory = Application.get_service('element_factory') diagram = element_factory.create(UML.Diagram) #self.main_window.show_diagram(diagram) comment = diagram.create(CommentItem, subject=element_factory.create(UML.Comment)) actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) actor.matrix.translate(200, 200) diagram.canvas.update_matrix(actor) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, 'View should be available here' tool = ConnectHandleTool(view) # select handle: handle = line.handles()[0] tool.grab_handle(line, handle) # Connect one end to the Comment #handle.pos = view.get_matrix_v2i(line).transform_point(45, 48) sink = tool.glue(line, handle, (0, 0)) assert sink is not None assert sink.item is comment tool.connect(line, handle, (0, 0)) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo is not None, None) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is comment) pos = view.get_matrix_i2v(line).transform_point(handle.x, handle.y) self.assertAlmostEquals(0, pos[0], 0.00001) self.assertAlmostEquals(0, pos[1], 0.00001) # Connect the other end to the actor: handle = line.handles()[-1] tool.grab_handle(line, handle) handle.pos = 140, 150 sink = tool.glue(line, handle, (200, 200)) self.assertTrue(sink.item is actor) tool.connect(line, handle, (200, 200)) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is actor) self.assertEquals( (200, 200), view.get_matrix_i2v(line).transform_point(handle.x, handle.y)) # Try to connect far away from any item will only do a full disconnect self.assertEquals(len(comment.subject.annotatedElement), 1, comment.subject.annotatedElement) self.assertTrue(actor.subject in comment.subject.annotatedElement) sink = tool.glue(line, handle, (500, 500)) self.assertTrue(sink is None, sink) tool.connect(line, handle, (500, 500)) self.assertEquals((200, 200), view.canvas.get_matrix_i2c(line).transform_point( handle.x, handle.y)) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo is None)
def setUp(self): Application.init( services=["element_factory", "properties", "main_window", "action_manager"] )
def setUp(self): Application.init(services=self.services) self.element_factory = Application.get_service('element_factory') assert len(list(self.element_factory.select())) == 0, list(self.element_factory.select()) self.diagram = self.element_factory.create(uml2.Diagram) assert len(list(self.element_factory.select())) == 1, list(self.element_factory.select())
def setUp(self): Application.init() element_factory = Application.get_service('element_factory') from gaphor.storage.storage import load load('tests/issue_53.gaphor', element_factory)
def skiptest_connect_3(self): """Test connecting through events (button press/release, motion). """ element_factory = Application.get_service("element_factory") diagram = element_factory.create(UML.Diagram) comment = diagram.create(CommentItem, subject=element_factory.create(UML.Comment)) # self.assertEqual(30, comment.height) # self.assertEqual(100, comment.width) actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) actor.matrix.translate(200, 200) diagram.canvas.update_matrix(actor) # assert actor.height == 60, actor.height # assert actor.width == 38, actor.width line = diagram.create(CommentLineItem) assert line.handles()[0].pos, (0.0, 0.0) assert line.handles()[-1].pos, (10.0, 10.0) view = self.get_diagram_view(diagram) assert view, "View should be available here" tool = ConnectHandleTool(view) tool.on_button_press(Gdk.Event(x=0, y=0, state=0)) tool.on_button_release(Gdk.Event(x=0, y=0, state=0)) handle = line.handles()[0] assert (0.0, 0.0) == view.canvas.get_matrix_i2c(line).transform_point( *handle.pos) cinfo = diagram.canvas.get_connection(handle) assert cinfo.connected is comment # self.assertTrue(handle.connected_to is comment, 'c = ' + str(handle.connected_to)) # self.assertTrue(handle.connection_data is not None) # Grab the second handle and drag it to the actor tool.on_button_press(Gdk.Event(x=10, y=10, state=0)) tool.on_motion_notify(Gdk.Event(x=200, y=200, state=0xFFFF)) tool.on_button_release(Gdk.Event(x=200, y=200, state=0)) handle = line.handles()[-1] assert (200, 200) == view.canvas.get_matrix_i2c(line).transform_point( handle.x, handle.y) cinfo = diagram.canvas.get_connection(handle) assert cinfo.connected is actor # self.assertTrue(handle.connection_data is not None) self.assertTrue(actor.subject in comment.subject.annotatedElement) # Press, release, nothing should change tool.on_button_press(Gdk.Event(x=200, y=200, state=0)) tool.on_motion_notify(Gdk.Event(x=200, y=200, state=0xFFFF)) tool.on_button_release(Gdk.Event(x=200, y=200, state=0)) handle = line.handles()[-1] assert (200, 200) == view.canvas.get_matrix_i2c(line).transform_point( handle.x, handle.y) cinfo = diagram.canvas.get_connection(handle) assert cinfo.connected is actor # self.assertTrue(handle.connection_data is not None) self.assertTrue(actor.subject in comment.subject.annotatedElement) # Move second handle away from the actor. Should remove connection tool.on_button_press(Gdk.Event(x=200, y=200, state=0)) tool.on_motion_notify(Gdk.Event(x=500, y=500, state=0xFFFF)) tool.on_button_release(Gdk.Event(x=500, y=500, state=0)) handle = line.handles()[-1] assert (500, 500) == view.canvas.get_matrix_i2c(line).transform_point( handle.x, handle.y) cinfo = diagram.canvas.get_connection(handle) assert cinfo is None # self.assertTrue(handle.connection_data is None) self.assertEqual(len(comment.subject.annotatedElement), 0)
def tearDown(self): self.element_factory.shutdown() Application.shutdown()