예제 #1
0
    def _on_drag_data_received(self, view, context, x, y, data, info, time):
        """
        Handle data dropped on the canvas.
        """
        if (data and data.get_format() == 8
                and info == DiagramPage.VIEW_TARGET_TOOLBOX_ACTION):
            tool = self.toolbox.get_tool(data.get_data().decode())
            tool.create_item((x, y))
            context.finish(True, False, time)
        elif (data and data.get_format() == 8
              and info == DiagramPage.VIEW_TARGET_ELEMENT_ID):
            element_id = data.get_data().decode()
            element = self.element_factory.lookup(element_id)
            assert element

            item_class = get_diagram_item(type(element))
            if item_class:
                tx = Transaction(self.event_manager)
                item = self.diagram.create(item_class)
                assert item

                x, y = view.get_matrix_v2i(item).transform_point(x, y)
                item.matrix.translate(x, y)
                item.subject = element
                tx.commit()
                view.unselect_all()
                view.focused_item = item

            else:
                log.warning("No graphical representation for UML element %s" %
                            type(element).__name__)
            context.finish(True, False, time)
        else:
            context.finish(False, False, time)
예제 #2
0
    def test_transactions(self):

        event_manager = EventManager()
        undo_manager = UndoManager(event_manager)

        assert not undo_manager._current_transaction

        # undo_manager.begin_transaction()
        tx = Transaction(event_manager)

        # assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction

        current = undo_manager._current_transaction
        # undo_manager.begin_transaction()
        tx2 = Transaction(event_manager)
        # assert undo_manager._transaction_depth == 2
        # assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction is current

        # undo_manager.commit_transaction()
        tx2.commit()

        # assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction is current

        # undo_manager.commit_transaction()
        tx.commit()
        # assert undo_manager._transaction_depth == 0
        assert undo_manager._current_transaction is None

        undo_manager.shutdown()
예제 #3
0
    def test_transaction_commit(self):
        """Test committing a transaction."""

        tx = Transaction()

        self.assertTrue(tx._stack, 'Transaction has no stack')
        self.assertEquals(1, len(begins),
                          'Incorrect number of TrasactionBegin events')
        self.assertEquals(0, len(commits),
                          'Incorrect number of TransactionCommit events')
        self.assertEquals(0, len(rollbacks),
                          'Incorrect number of TransactionRollback events')

        tx.commit()

        self.assertEquals(1, len(begins),
                          'Incorrect number of TrasactionBegin events')
        self.assertEquals(1, len(commits),
                          'Incorrect number of TransactionCommit events')
        self.assertEquals(0, len(rollbacks),
                          'Incorrect number of TransactionRollback events')
        self.assertFalse(tx._stack, 'Transaction stack is not empty')

        try:
            tx.commit()
        except TransactionError:
            pass
        else:
            self.fail('Commit should not have succeeded')
예제 #4
0
    def test_transaction_commit(self):
        """Test committing a transaction."""

        tx = Transaction()

        self.assertTrue(tx._stack, "Transaction has no stack")
        self.assertEqual(1, len(begins), "Incorrect number of TrasactionBegin events")
        self.assertEqual(
            0, len(commits), "Incorrect number of TransactionCommit events"
        )
        self.assertEqual(
            0, len(rollbacks), "Incorrect number of TransactionRollback events"
        )

        tx.commit()

        self.assertEqual(1, len(begins), "Incorrect number of TrasactionBegin events")
        self.assertEqual(
            1, len(commits), "Incorrect number of TransactionCommit events"
        )
        self.assertEqual(
            0, len(rollbacks), "Incorrect number of TransactionRollback events"
        )
        self.assertFalse(tx._stack, "Transaction stack is not empty")

        try:
            tx.commit()
        except TransactionError:
            pass
        else:
            self.fail("Commit should not have succeeded")
예제 #5
0
    def test_transaction_commit(self):
        """Test committing a transaction."""

        tx = Transaction(self.event_manager)

        assert tx._stack, "Transaction has no stack"
        assert 1 == len(begins), "Incorrect number of TrasactionBegin events"
        assert 0 == len(
            commits), "Incorrect number of TransactionCommit events"
        assert 0 == len(
            rollbacks), "Incorrect number of TransactionRollback events"

        tx.commit()

        assert 1 == len(begins), "Incorrect number of TrasactionBegin events"
        assert 1 == len(
            commits), "Incorrect number of TransactionCommit events"
        assert 0 == len(
            rollbacks), "Incorrect number of TransactionRollback events"
        assert not tx._stack, "Transaction stack is not empty"

        try:
            tx.commit()
        except TransactionError:
            pass
        else:
            self.fail("Commit should not have succeeded")
예제 #6
0
    def test_transactions(self):

        undo_manager = UndoManager()
        undo_manager.init(None)

        assert not undo_manager._current_transaction

        #undo_manager.begin_transaction()
        tx = Transaction()

        #assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction

        current = undo_manager._current_transaction
        #undo_manager.begin_transaction()
        tx2 = Transaction()
        #assert undo_manager._transaction_depth == 2
        #assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction is current

        #undo_manager.commit_transaction()
        tx2.commit()

        #assert undo_manager._transaction_depth == 1
        assert undo_manager._current_transaction is current

        #undo_manager.commit_transaction()
        tx.commit()
        #assert undo_manager._transaction_depth == 0
        assert undo_manager._current_transaction is None

        undo_manager.shutdown()
예제 #7
0
def test_actions(event_manager, undo_manager):
    undone = [0]

    def undo_action(undone=undone):
        undone[0] = 1
        undo_manager.add_undo_action(redo_action)

    def redo_action(undone=undone):
        undone[0] = -1
        undo_manager.add_undo_action(undo_action)

    tx = Transaction(event_manager)
    undo_manager.add_undo_action(undo_action)
    assert undo_manager._current_transaction
    assert undo_manager.can_undo()
    assert len(undo_manager._current_transaction._actions) == 1

    tx.commit()

    undo_manager.undo_transaction()
    assert not undo_manager.can_undo(), undo_manager._undo_stack
    assert undone[0] == 1, undone

    undone[0] = 0

    assert undo_manager.can_redo(), undo_manager._redo_stack

    undo_manager.redo_transaction()
    assert not undo_manager.can_redo()
    assert undo_manager.can_undo()
    assert undone[0] == -1, undone
예제 #8
0
    def test_transaction_stack(self):
        tx = Transaction()
        tx2 = Transaction()

        try:
            tx.commit()
        except TransactionError, e:
            self.assertEquals('Transaction on stack is not the transaction being closed.', str(e))
예제 #9
0
    def test_transaction(self):
        """Test basic transaction functionality."""

        tx = Transaction()
        tx.rollback()

        tx = Transaction()
        tx.commit()
예제 #10
0
    def test_transaction(self):
        """Test basic transaction functionality."""

        tx = Transaction()
        tx.rollback()

        tx = Transaction()
        tx.commit()
예제 #11
0
    def on_drag_data_received(self, context, x, y, selection, info, time):
        """
        Drop the data send by on_drag_data_get().
        """
        #print 'data-received', NamespaceView.TARGET_ELEMENT_ID, 'in', context.targets
        self.emit_stop_by_name('drag-data-received')
        if 'gaphor/element-id' in context.targets:
            #print 'drag_data_received'
            n, p = selection.data.split('#')
            drop_info = self.get_dest_row_at_pos(x, y)
        else:
            drop_info = None

        if drop_info:
            model = self.get_model()
            element = self.factory.lookup(n)
            path, position = drop_info
            iter = model.get_iter(path)
            dest_element = model.get_value(iter, 0)
            assert dest_element
            # Add the item to the parent if it is dropped on the same level,
            # else add it to the item.
            if position in (gtk.TREE_VIEW_DROP_BEFORE,
                            gtk.TREE_VIEW_DROP_AFTER):
                parent_iter = model.iter_parent(iter)
                if parent_iter is None:
                    dest_element = None
                else:
                    dest_element = model.get_value(parent_iter, 0)

            try:
                # Check if element is part of the namespace of dest_element:
                ns = dest_element
                while ns:
                    if ns is element:
                        raise AttributeError
                    ns = ns.namespace

                # Set package. This only works for classifiers, packages and
                # diagrams. Properties and operations should not be moved.
                tx = Transaction()
                if dest_element is None:
                    del element.package
                else:
                    element.package = dest_element
                tx.commit()

            except AttributeError as e:
                #log.info('Unable to drop data', e)
                context.drop_finish(False, time)
            else:
                context.drop_finish(True, time)
                # Finally let's try to select the element again.
                path = model.path_from_element(element)
                if len(path) > 1:
                    self.expand_row(path[:-1], False)
                selection = self.get_selection()
                selection.select_path(path)
예제 #12
0
파일: namespace.py 프로젝트: Nyox/gaphor
    def on_drag_data_received(self, context, x, y, selection, info, time):
        """
        Drop the data send by on_drag_data_get().
        """
        #print 'data-received', NamespaceView.TARGET_ELEMENT_ID, 'in', context.targets
        self.emit_stop_by_name('drag-data-received')
        if 'gaphor/element-id' in context.targets:
            #print 'drag_data_received'
            n, p = selection.data.split('#')
            drop_info = self.get_dest_row_at_pos(x, y)
        else:
            drop_info = None

        if drop_info:
            model = self.get_model()
            element = self.factory.lookup(n)
            path, position = drop_info
            iter = model.get_iter(path)
            dest_element = model.get_value(iter, 0)
            assert dest_element
            # Add the item to the parent if it is dropped on the same level,
            # else add it to the item.
            if position in (gtk.TREE_VIEW_DROP_BEFORE, gtk.TREE_VIEW_DROP_AFTER):
                parent_iter = model.iter_parent(iter)
                if parent_iter is None:
                    dest_element = None
                else:
                    dest_element = model.get_value(parent_iter, 0)

            try:
                # Check if element is part of the namespace of dest_element:
                ns = dest_element
                while ns:
                    if ns is element:
                        raise AttributeError
                    ns = ns.namespace

                # Set package. This only works for classifiers, packages and
                # diagrams. Properties and operations should not be moved.
                tx = Transaction()
                if dest_element is None:
                    del element.package
                else:
                    element.package = dest_element
                tx.commit()

            except AttributeError, e:
                #log.info('Unable to drop data', e)
                context.drop_finish(False, time)
            else:
                context.drop_finish(True, time)
                # Finally let's try to select the element again.
                path = model.path_from_element(element)
                if len(path) > 1:
                    self.expand_row(path[:-1], False)
                selection = self.get_selection()
                selection.select_path(path)
예제 #13
0
    def test_transaction_stack(self):
        """Test the transaction stack."""
        
        tx1 = Transaction()
        tx2 = Transaction()

        try:
            tx1.commit()
        except TransactionError, e:
            pass
예제 #14
0
    def test_transaction_stack(self):
        """Test the transaction stack."""

        tx1 = Transaction()
        tx2 = Transaction()

        try:
            tx1.commit()
        except TransactionError, e:
            pass
예제 #15
0
    def test_transaction_commit_after_rollback(self):
        tx = Transaction()
        tx2 = Transaction()

        tx2.rollback()

        tx.commit()
        self.assertEquals(1, len(begins))
        self.assertEquals(0, len(commits))
        self.assertEquals(1, len(rollbacks))
예제 #16
0
def test_transaction_stack(event_manager):
    """Test the transaction stack."""

    tx1 = Transaction(event_manager)
    tx2 = Transaction(event_manager)

    with pytest.raises(TransactionError):
        tx1.commit()

    tx2.rollback()
    tx1.rollback()
예제 #17
0
    def test_transaction_stack(self):
        """Test the transaction stack."""

        tx1 = Transaction()
        tx2 = Transaction()  # tx2 is used despite warnings

        try:
            tx1.commit()
        except TransactionError:
            pass
        else:
            self.fail('Commit should not have succeeded')
예제 #18
0
    def test_transaction_stack(self):
        """Test the transaction stack."""

        tx1 = Transaction()
        tx2 = Transaction()

        try:
            tx1.commit()
        except TransactionError as e:
            pass
        else:
            self.fail('Commit should not have succeeded')
예제 #19
0
    def on_drag_data_received(self, context, x, y, selection, info, time):
        """
        Drop the data send by on_drag_data_get().
        """
        self.stop_emission_by_name("drag-data-received")
        if info == NamespaceView.TARGET_ELEMENT_ID:
            n, _p = selection.get_data().decode().split("#")
            drop_info = self.get_dest_row_at_pos(x, y)
        else:
            drop_info = None

        if drop_info:
            model = self.get_model()
            element = self.factory.lookup(n)
            path, position = drop_info
            iter = model.get_iter(path)
            dest_element = model.get_value(iter, 0)
            assert dest_element
            # Add the item to the parent if it is dropped on the same level,
            # else add it to the item.
            if position in (
                Gtk.TreeViewDropPosition.BEFORE,
                Gtk.TreeViewDropPosition.AFTER,
            ):
                parent_iter = model.iter_parent(iter)
                if parent_iter is None:
                    dest_element = None
                else:
                    dest_element = model.get_value(parent_iter, 0)

            try:
                # Check if element is part of the namespace of dest_element:
                ns = dest_element
                while ns:
                    if ns is element:
                        raise AttributeError
                    ns = ns.namespace

                # Set package. This only works for classifiers, packages and
                # diagrams. Properties and operations should not be moved.
                tx = Transaction()
                if dest_element is None:
                    del element.package
                else:
                    element.package = dest_element
                tx.commit()

            except AttributeError as e:
                log.info("Unable to drop data %s" % e)
                context.finish(False, False, time)
            else:
                context.finish(True, True, time)
예제 #20
0
    def test_transaction_commit_after_rollback(self):
        """Test committing one transaction after rolling back another
        transaction."""
        
        tx1 = Transaction()
        tx2 = Transaction()

        tx2.rollback()
        tx1.commit()
        
        self.assertEquals(1, len(begins), 'Incorrect number of TrasactionBegin events')
        self.assertEquals(0, len(commits), 'Incorrect number of TransactionCommit events')
        self.assertEquals(1, len(rollbacks), 'Incorrect number of TransactionRollback events')
예제 #21
0
def test_transaction_commit_after_rollback(event_manager):
    """Test committing one transaction after rolling back another
    transaction."""

    tx1 = Transaction(event_manager)
    tx2 = Transaction(event_manager)

    tx2.rollback()
    tx1.commit()

    assert 1 == len(begins), "Incorrect number of TrasactionBegin events"
    assert 0 == len(commits), "Incorrect number of TransactionCommit events"
    assert 1 == len(rollbacks), "Incorrect number of TransactionRollback events"
예제 #22
0
    def _on_drag_data_received(self, view, context, x, y, data, info, time):
        """
        Handle data dropped on the canvas.
        """
        if (
            data
            and data.get_format() == 8
            and info == DiagramPage.VIEW_TARGET_TOOLBOX_ACTION
        ):
            tool = self.toolbox.get_tool(data.get_data().decode())
            tool.create_item((x, y))
            context.finish(True, False, time)
        elif (
            data
            and data.get_format() == 8
            and info == DiagramPage.VIEW_TARGET_ELEMENT_ID
        ):
            print("drag_data_received:", data.get_data(), info)
            n, p = data.get_data().decode().split("#")
            element = self.element_factory.lookup(n)
            assert element

            # TODO: use adapters to execute code below

            q = type(element)
            if p:
                q = q, p
            item_class = get_diagram_item(q)
            if isinstance(element, UML.Diagram):
                self.action_manager.execute("OpenModelElement")
            elif item_class:
                tx = Transaction()
                item = self.diagram.create(item_class)
                assert item

                x, y = view.get_matrix_v2i(item).transform_point(x, y)
                item.matrix.translate(x, y)
                item.subject = element
                tx.commit()
                view.unselect_all()
                view.focused_item = item

            else:
                log.warning(
                    "No graphical representation for UML element %s"
                    % type(element).__name__
                )
            context.finish(True, False, time)
        else:
            context.finish(False, False, time)
예제 #23
0
 def _text_edited(self, cell, path_str, new_text):
     """
     The text has been edited. This method updates the data object.
     Note that 'path_str' is a string where the fields are separated by
     colons ':', like this: '0:1:1'. We first turn them into a tuple.
     """
     try:
         model = self.get_property('model')
         iter = model.get_iter_from_string(path_str)
         element = model.get_value(iter, 0)
         tx = Transaction()
         element.name = new_text
         tx.commit()
     except Exception as e:
         log.error('Could not create path from string "%s"' % path_str)
예제 #24
0
파일: namespace.py 프로젝트: Nyox/gaphor
 def _text_edited(self, cell, path_str, new_text):
     """
     The text has been edited. This method updates the data object.
     Note that 'path_str' is a string where the fields are separated by
     colons ':', like this: '0:1:1'. We first turn them into a tuple.
     """
     try:
         model = self.get_property('model')
         iter = model.get_iter_from_string(path_str)
         element = model.get_value(iter, 0)
         tx = Transaction()
         element.name = new_text
         tx.commit()
     except Exception, e:
         log.error('Could not create path from string "%s"' % path_str)
예제 #25
0
    def test_transaction_commit_after_rollback(self):
        """Test committing one transaction after rolling back another
        transaction."""

        tx1 = Transaction()
        tx2 = Transaction()

        tx2.rollback()
        tx1.commit()

        self.assertEquals(1, len(begins),
                          'Incorrect number of TrasactionBegin events')
        self.assertEquals(0, len(commits),
                          'Incorrect number of TransactionCommit events')
        self.assertEquals(1, len(rollbacks),
                          'Incorrect number of TransactionRollback events')
예제 #26
0
def test_nested_transactions(event_manager, undo_manager):
    assert not undo_manager._current_transaction

    tx = Transaction(event_manager)

    assert undo_manager._current_transaction

    current = undo_manager._current_transaction
    tx2 = Transaction(event_manager)
    assert undo_manager._current_transaction is current

    tx2.commit()

    assert undo_manager._current_transaction is current

    tx.commit()
    assert undo_manager._current_transaction is None
예제 #27
0
def test_transaction_commit(event_manager):
    """Test committing a transaction."""

    tx = Transaction(event_manager)

    assert tx._stack, "Transaction has no stack"
    assert 1 == len(begins), "Incorrect number of TrasactionBegin events"
    assert 0 == len(commits), "Incorrect number of TransactionCommit events"
    assert 0 == len(rollbacks), "Incorrect number of TransactionRollback events"

    tx.commit()

    assert 1 == len(begins), "Incorrect number of TrasactionBegin events"
    assert 1 == len(commits), "Incorrect number of TransactionCommit events"
    assert 0 == len(rollbacks), "Incorrect number of TransactionRollback events"
    assert not tx._stack, "Transaction stack is not empty"

    with pytest.raises(TransactionError):
        tx.commit()
예제 #28
0
    def _on_drag_data_received(self, view, context, x, y, data, info, time):
        """
        Handle data dropped on the canvas.
        """
        if (data and data.get_format() == 8
                and info == DiagramPage.VIEW_TARGET_TOOLBOX_ACTION):
            tool = self.toolbox.get_tool(data.get_data().decode())
            tool.create_item((x, y))
            context.finish(True, False, time)
        elif (data and data.get_format() == 8
              and info == DiagramPage.VIEW_TARGET_ELEMENT_ID):
            print("drag_data_received:", data.get_data(), info)
            n, p = data.get_data().decode().split("#")
            element = self.element_factory.lookup(n)
            assert element

            # TODO: use adapters to execute code below

            q = type(element)
            if p:
                q = q, p
            item_class = get_diagram_item(q)
            if isinstance(element, UML.Diagram):
                self.action_manager.execute("OpenModelElement")
            elif item_class:
                tx = Transaction()
                item = self.diagram.create(item_class)
                assert item

                x, y = view.get_matrix_v2i(item).transform_point(x, y)
                item.matrix.translate(x, y)
                item.subject = element
                tx.commit()
                view.unselect_all()
                view.focused_item = item

            else:
                log.warning("No graphical representation for UML element %s" %
                            type(element).__name__)
            context.finish(True, False, time)
        else:
            context.finish(False, False, time)
예제 #29
0
    def test_transaction_commit(self):
        tx = Transaction()
        self.assertTrue(tx._stack)
        self.assertEquals(1, len(begins))
        self.assertEquals(0, len(commits))
        self.assertEquals(0, len(rollbacks))

        tx.commit()
        self.assertEquals(1, len(begins))
        self.assertEquals(1, len(commits))
        self.assertEquals(0, len(rollbacks))

        self.assertFalse(tx._stack)

        try:
            tx.commit()
        except TransactionError:
            pass # ok
        else:
            assert False, 'should not be reached'
예제 #30
0
    def test_actions(self):
        undone = [0]

        def undo_action(undone=undone):
            # print 'undo_action called'
            undone[0] = 1
            undo_manager.add_undo_action(redo_action)

        def redo_action(undone=undone):
            # print 'redo_action called'
            undone[0] = -1
            undo_manager.add_undo_action(undo_action)

        undo_manager = UndoManager()
        undo_manager.init(Application)

        # undo_manager.begin_transaction()
        tx = Transaction()
        undo_manager.add_undo_action(undo_action)
        assert undo_manager._current_transaction
        assert undo_manager.can_undo()
        assert len(undo_manager._current_transaction._actions) == 1

        # undo_manager.commit_transaction()
        tx.commit()

        undo_manager.undo_transaction()
        assert not undo_manager.can_undo(), undo_manager._undo_stack
        assert undone[0] == 1, undone

        undone[0] = 0

        assert undo_manager.can_redo(), undo_manager._redo_stack

        undo_manager.redo_transaction()
        assert not undo_manager.can_redo()
        assert undo_manager.can_undo()
        assert undone[0] == -1, undone

        undo_manager.shutdown()
예제 #31
0
    def test_actions(self):
        undone = [0]

        def undo_action(undone=undone):
            #print 'undo_action called'
            undone[0] = 1
            undo_manager.add_undo_action(redo_action)

        def redo_action(undone=undone):
            #print 'redo_action called'
            undone[0] = -1
            undo_manager.add_undo_action(undo_action)

        undo_manager = UndoManager()
        undo_manager.init(Application)

        #undo_manager.begin_transaction()
        tx = Transaction()
        undo_manager.add_undo_action(undo_action)
        assert undo_manager._current_transaction
        assert undo_manager.can_undo()
        assert len(undo_manager._current_transaction._actions) == 1

        #undo_manager.commit_transaction()
        tx.commit()

        undo_manager.undo_transaction()
        assert not undo_manager.can_undo(), undo_manager._undo_stack
        assert undone[0] == 1, undone

        undone[0] = 0

        assert undo_manager.can_redo(), undo_manager._redo_stack

        undo_manager.redo_transaction()
        assert not undo_manager.can_redo()
        assert undo_manager.can_undo()
        assert undone[0] == -1, undone

        undo_manager.shutdown()
예제 #32
0
    def test_transactions(self):

        event_manager = EventManager()
        undo_manager = UndoManager(event_manager)

        assert not undo_manager._current_transaction

        tx = Transaction(event_manager)

        assert undo_manager._current_transaction

        current = undo_manager._current_transaction
        tx2 = Transaction(event_manager)
        assert undo_manager._current_transaction is current

        tx2.commit()

        assert undo_manager._current_transaction is current

        tx.commit()
        assert undo_manager._current_transaction is None

        undo_manager.shutdown()