本文整理汇总了Python中matrix.Matrix.move_col方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.move_col方法的具体用法?Python Matrix.move_col怎么用?Python Matrix.move_col使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.move_col方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MatrixMoveTest
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import move_col [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)
示例2: Scene
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import move_col [as 别名]
#.........这里部分代码省略.........
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):
if not ((x1,y1) in self.grid and (x2,y2) in self.grid):
self.error('Invalid coordinates')
return
self.add_undo('mi', ((x1, y1, self.grid[x1,y1]), (x2, y2, self.grid[x2,y2])))
self.grid[x2,y2] = self.grid[x1,y1]
self.grid[x1,y1] = None