Beispiel #1
0
    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)))
Beispiel #2
0
    def test_table_drag_col(self):
        table = Table(self.window, drag_cols=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()

        table.event_generate('<ButtonPress-1>', x=10, y=5)
        self.window.update()
        self.assertTrue(table._visual_drag.winfo_ismapped())
        table.event_generate('<Motion>',
                             x=10 + table.column('#1', 'width'),
                             y=5)
        table.event_generate('<ButtonRelease-1>')
        self.assertFalse(table._visual_drag.winfo_ismapped())
        self.assertEqual(table['displaycolumns'], ('B', 'A', 'C'))
        table.event_generate('<ButtonPress-1>',
                             x=table.winfo_width() - 20,
                             y=5)
        self.window.update()
        self.assertFalse(table._visual_drag.winfo_ismapped())
        table.event_generate('<ButtonPress-1>',
                             x=table.column('#1', 'width') + 10,
                             y=5)
        self.window.update()
        self.assertTrue(table._visual_drag.winfo_ismapped())
        table.event_generate('<Motion>', x=10, y=5)
        table.event_generate('<ButtonRelease-1>')
        self.assertFalse(table._visual_drag.winfo_ismapped())
        self.assertEqual(table['displaycolumns'], ('A', 'B', 'C'))
        table.event_generate('<ButtonPress-1>', x=10, y=5)
        self.window.update()
        self.assertTrue(table._visual_drag.winfo_ismapped())
        table.event_generate('<Motion>',
                             x=10 + table.column('#1', 'width'),
                             y=5)
        table.event_generate('<Motion>',
                             x=10 + 2 * table.column('#1', 'width'),
                             y=5)
        table.event_generate('<ButtonRelease-1>')
        self.assertFalse(table._visual_drag.winfo_ismapped())
        self.assertEqual(table['displaycolumns'], ('B', 'C', 'A'))
        table.event_generate('<ButtonPress-1>',
                             x=10 + 2 * table.column('#1', 'width'),
                             y=5)
        self.window.update()
        self.assertTrue(table._visual_drag.winfo_ismapped())
        table.event_generate('<Motion>',
                             x=10 + table.column('#1', 'width'),
                             y=5)
        table.event_generate('<ButtonRelease-1>')
        self.assertFalse(table._visual_drag.winfo_ismapped())
        self.assertEqual(table['displaycolumns'], ('B', 'A', 'C'))