def test_table_methods(self): table = Table(self.window, columns=('A', 'B', 'C')) table.pack() self.window.update() self.assertEqual(table._visual_drag.cget('columns'), ('A', 'B', 'C')) table.configure(columns=('E', 'F', 'G')) self.assertEqual(table.cget('columns'), ('E', 'F', 'G')) self.assertEqual(table._visual_drag.cget('columns'), ('E', 'F', 'G')) for i in range(20): table.insert('', 'end', str(i), values=tuple(str(i) for a in 'EFG')) self.assertEqual(table.get_children(""), table._visual_drag.get_children("")) self.assertIs(table.column('E', 'type'), str) table.column('E', type=int) self.assertIs(table.column('E', 'type'), int) table.column('E', width=80) self.assertEqual(table._visual_drag.column('E', 'width'), 80) self.assertIn('type', table.column('G')) table.delete('0', '2') self.assertFalse('2' in table._visual_drag.get_children("")) self.assertEqual(table.get_children(""), table._visual_drag.get_children("")) table.detach('1', '7') self.assertFalse('1' in table._visual_drag.get_children("")) self.assertEqual(table.get_children(""), table._visual_drag.get_children("")) table.reattach('1', '', 0) self.assertTrue('1' in table._visual_drag.get_children("")) self.assertEqual(table.get_children(""), table._visual_drag.get_children("")) table.heading('E', text='col E') self.assertEqual(table._visual_drag.heading('E', 'text'), 'col E') table.item('4', values=('a', 'b', 'c'), text='4') self.assertEqual(table._visual_drag.item('4', 'values'), ('a', 'b', 'c')) self.assertEqual(table._visual_drag.item('4', 'text'), '4') keys = [ 'columns', 'displaycolumns', 'show', 'selectmode', 'height', 'padding', 'xscrollcommand', 'yscrollcommand', 'takefocus', 'cursor', 'style', 'class', 'sortable', 'drag_cols' ] self.assertEqual(sorted(table.keys()), sorted(keys)) table.move('4', '', 0) self.assertEqual(table.get_children('')[0], '4') self.assertEqual(table._visual_drag.get_children('')[0], '4') table.configure(height=10) self.assertEqual(table.bbox('19'), '') self.assertEqual(table._visual_drag.bbox('19'), '') self.assertEqual(table.set('3', 'F'), '3') table.set('3', 'F', 'f') self.assertEqual(table._visual_drag.set('3', 'F'), 'f') table.set_children("", '4', '7') self.assertEqual(table.get_children(""), ('4', '7')) self.assertEqual(table._visual_drag.get_children(""), ('4', '7'))
def test_table_drag_row(self): table = Table(self.window, drag_rows=True, columns=list('ABC')) table.pack() for i in range(10): table.insert('', 'end', str(i), values=tuple(a + str(i) for a in 'ABC')) self.window.update() bbox = table.bbox('2') table.event_generate('<ButtonPress-1>', x=bbox[0] + 5, y=bbox[1] + 5) self.window.update() self.assertTrue(table._visual_drag.winfo_ismapped()) table.event_generate('<Motion>', x=bbox[0] + 5, y=bbox[1] + 5 + bbox[3]) table.event_generate('<Motion>', x=bbox[0] + 5, y=bbox[1] + 5 + 2 * bbox[3]) table.event_generate('<ButtonRelease-1>') self.assertFalse(table._visual_drag.winfo_ismapped()) self.assertEqual(table.get_children(''), ('0', '1', '3', '4', '2') + tuple(str(i) for i in range(5, 10))) self.window.update() bbox = table.bbox('2') table.event_generate('<ButtonPress-1>', x=bbox[0] + 5, y=bbox[1] + 5) self.window.update() self.assertTrue(table._visual_drag.winfo_ismapped()) table.event_generate('<Motion>', x=bbox[0] + 5, y=bbox[1] + 5 - bbox[3]) table.event_generate('<Motion>', x=bbox[0] + 5, y=bbox[1] + 5 - 2 * bbox[3]) table.event_generate('<ButtonRelease-1>') self.assertFalse(table._visual_drag.winfo_ismapped()) self.assertEqual(table.get_children(''), tuple(str(i) for i in range(10))) bbox = table.bbox('0') table.event_generate('<ButtonPress-1>', x=bbox[0] + 5, y=bbox[1] + 5) self.window.update() self.assertTrue(table._visual_drag.winfo_ismapped()) table.event_generate('<Motion>', x=bbox[0] + 5, y=bbox[1] + 5 - bbox[3]) table.event_generate('<Motion>', x=bbox[0] + 5, y=bbox[1] + 5 - 2 * bbox[3]) table.event_generate('<ButtonRelease-1>') self.assertFalse(table._visual_drag.winfo_ismapped()) self.assertEqual(table.get_children(''), tuple(str(i) for i in range(10))) bbox = table.bbox('0') table.event_generate('<ButtonPress-1>', x=bbox[0] + 5, y=bbox[1] + 5) self.window.update() self.assertTrue(table._visual_drag.winfo_ismapped()) for i in range(1, 20): table.event_generate('<Motion>', x=bbox[0] + 5, y=bbox[1] + 5 + i * bbox[3]) table.event_generate('<ButtonRelease-1>') self.assertFalse(table._visual_drag.winfo_ismapped()) self.assertEqual(table.get_children(''), tuple(str(i) for i in range(1, 10)) + ('0', )) bbox = table.bbox('0') table.event_generate('<ButtonPress-1>', x=bbox[0] + 5, y=bbox[1] + 5) self.window.update() self.assertTrue(table._visual_drag.winfo_ismapped()) for i in range(1, 20): table.event_generate('<Motion>', x=bbox[0] + 5, y=bbox[1] + 5 - i * bbox[3]) table.event_generate('<ButtonRelease-1>') self.assertFalse(table._visual_drag.winfo_ismapped()) self.assertEqual(table.get_children(''), tuple(str(i) for i in range(10)))