当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.move_row方法代码示例

本文整理汇总了Python中matrix.Matrix.move_row方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.move_row方法的具体用法?Python Matrix.move_row怎么用?Python Matrix.move_row使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matrix.Matrix的用法示例。


在下文中一共展示了Matrix.move_row方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MatrixMoveTest

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import move_row [as 别名]
class MatrixMoveTest(unittest.TestCase):

    def setUp(self):
        data = [
            ['One', 'Two', 'Three', 'Four'],
            ['Aye', 'Bee', 'See', 'Door'],
            ['Bip', 'Blop', 'Foo', 'Bar'],
            ['Cats', 'Dogs', 'Yay', 'Oops']
        ]
        self.matrix = Matrix(default_item, data)

    def test_move_row_down(self):
        data = [
            ['Aye', 'Bee', 'See', 'Door'],
            ['Bip', 'Blop', 'Foo', 'Bar'],
            ['One', 'Two', 'Three', 'Four'],
            ['Cats', 'Dogs', 'Yay', 'Oops']
        ]
        self.matrix.move_row(0,2)
        self.assertEqual(self.matrix.data, data)

    def test_move_row_up(self):
        data = [
            ['One', 'Two', 'Three', 'Four'],
            ['Aye', 'Bee', 'See', 'Door'],
            ['Cats', 'Dogs', 'Yay', 'Oops'],
            ['Bip', 'Blop', 'Foo', 'Bar']
        ]
        self.matrix.move_row(3,2)
        self.assertEqual(self.matrix.data, data)

    def test_move_row_last_to_first(self):
        data = [
            ['Cats', 'Dogs', 'Yay', 'Oops'],
            ['One', 'Two', 'Three', 'Four'],
            ['Aye', 'Bee', 'See', 'Door'],
            ['Bip', 'Blop', 'Foo', 'Bar']
        ]
        self.matrix.move_row(3,0)
        self.assertEqual(self.matrix.data, data)

    def test_move_row_first_to_last(self):
        data = [
            ['Aye', 'Bee', 'See', 'Door'],
            ['Bip', 'Blop', 'Foo', 'Bar'],
            ['Cats', 'Dogs', 'Yay', 'Oops'],
            ['One', 'Two', 'Three', 'Four']
        ]
        self.matrix.move_row(0,3)
        self.assertEqual(self.matrix.data, data)

    def test_move_col_right(self):
        data = [
            ['One', 'Three', 'Four', 'Two'],
            ['Aye', 'See', 'Door', 'Bee'],
            ['Bip', 'Foo', 'Bar', 'Blop'],
            ['Cats', 'Yay', 'Oops', 'Dogs']
        ]
        self.matrix.move_col(1,3)
        self.assertEqual(self.matrix.data, data)

    def test_move_col_left(self):
        data = [
            ['One', 'Three', 'Two', 'Four'],
            ['Aye', 'See', 'Bee', 'Door'],
            ['Bip', 'Foo', 'Blop', 'Bar'],
            ['Cats', 'Yay', 'Dogs', 'Oops']
        ]
        self.matrix.move_col(2,1)
        self.assertEqual(self.matrix.data, data)

    def test_move_col_last_to_first(self):
        data = [
            ['Four', 'One', 'Two', 'Three'],
            ['Door', 'Aye', 'Bee', 'See'],
            ['Bar', 'Bip', 'Blop', 'Foo'],
            ['Oops', 'Cats', 'Dogs', 'Yay']
        ]
        self.matrix.move_col(3,0)
        self.assertEqual(self.matrix.data, data)

    def test_move_col_first_to_last(self):
        data = [
            ['Two', 'Three', 'Four', 'One'],
            ['Bee', 'See', 'Door', 'Aye'],
            ['Blop', 'Foo', 'Bar', 'Bip'],
            ['Dogs', 'Yay', 'Oops', 'Cats']
        ]
        self.matrix.move_col(0,3)
        self.assertEqual(self.matrix.data, data)
开发者ID:nycz,项目名称:libsyntyche,代码行数:92,代码来源:test_matrix.py

示例2: Scene

# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import move_row [as 别名]

#.........这里部分代码省略.........
    def _insert(self, pos, name, arg):
        if self.do_row(arg):
            if pos != -1 and (0,pos-1) not in self.grid:
                self.error('Invalid row')
                return
            self.grid.add_row(pos)
            x, y = 0, pos
            self.add_undo('ir', pos)
        else:
            if pos != -1 and (pos-1,0) not in self.grid:
                self.error('Invalid column')
                return
            self.grid.add_col(pos)
            x, y = pos, 0
            self.add_undo('ic', pos)
        self.set_cell(x, y, name)
        self.draw_scene()


    # ======== MOVE ==========================================================
    def move_plotline(self, oldpos, newpos):
        self._move(oldpos, newpos, 'p')

    def move_timeslot(self, oldpos, newpos):
        self._move(oldpos, newpos, 't')

    def _move(self, oldpos, newpos, arg):
        foldpos, fnewpos = _fix_movepos(oldpos, newpos)
        if self.do_row(arg):
            if (0,oldpos) not in self.grid:
                self.error('Invalid row')
                return
            self.add_undo('mr', (oldpos, newpos))
            self.grid.move_row(foldpos, fnewpos)
        else:
            if (oldpos,0) not in self.grid:
                self.error('Invalid column')
                return
            self.add_undo('mc', (oldpos, newpos))
            self.grid.move_col(foldpos, fnewpos)
        self.draw_scene()

    # ======== REMOVE ========================================================
    def remove_plotline(self, pos):
        self._remove(pos, 'p')

    def remove_timeslot(self, pos):
        self._remove(pos, 't')

    def _remove(self, pos, arg):
        if self.do_row(arg):
            if (0,pos) not in self.grid:
                self.error('Invalid row')
                return
            self.add_undo('rr', (pos, self.grid.row(pos)))
            self.grid.remove_row(pos)
        else:
            if (pos,0) not in self.grid:
                self.error('Invalid column')
                return
            self.add_undo('rc', (pos, self.grid.col(pos)))
            self.grid.remove_col(pos)
        self.draw_scene()

    # ======== CELLS =========================================================
    def move_cell(self, x1, y1, x2, y2):
开发者ID:nycz,项目名称:urd,代码行数:70,代码来源:scene.py


注:本文中的matrix.Matrix.move_row方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。