source: orange/Orange/OrangeCanvas/gui/tests/test_stackedwidget.py @ 11100:cf6f6744dd9b

Revision 11100:cf6f6744dd9b, 2.2 KB checked in by Ales Erjavec <ales.erjavec@…>, 19 months ago (diff)

Added gui widget toolkit.

Line 
1"""
2Test for StackedWidget
3
4"""
5from PyQt4.QtGui import QWidget, QLabel, QGroupBox, QListView, QVBoxLayout
6
7from .. import test
8from .. import stackedwidget
9
10
11class TestStackedWidget(test.QAppTestCase):
12    def test(self):
13        window = QWidget()
14        layout = QVBoxLayout()
15        window.setLayout(layout)
16
17        stack = stackedwidget.AnimatedStackedWidget()
18        stack.transitionFinished.connect(self.app.exit)
19
20        layout.addStretch(2)
21        layout.addWidget(stack)
22        layout.addStretch(2)
23        window.show()
24
25        widget1 = QLabel("A label " * 10)
26        widget1.setWordWrap(True)
27
28        widget2 = QGroupBox("Group")
29
30        widget3 = QListView()
31        self.assertEqual(stack.count(), 0)
32        self.assertEqual(stack.currentIndex(), -1)
33
34        stack.addWidget(widget1)
35        self.assertEqual(stack.count(), 1)
36        self.assertEqual(stack.currentIndex(), 0)
37
38        stack.addWidget(widget2)
39        stack.addWidget(widget3)
40        self.assertEqual(stack.count(), 3)
41        self.assertEqual(stack.currentIndex(), 0)
42
43        def widgets():
44            return [stack.widget(i) for i in range(stack.count())]
45
46        self.assertSequenceEqual([widget1, widget2, widget3],
47                                 widgets())
48        stack.show()
49
50        stack.removeWidget(widget2)
51        self.assertEqual(stack.count(), 2)
52        self.assertEqual(stack.currentIndex(), 0)
53        self.assertSequenceEqual([widget1, widget3],
54                                 widgets())
55
56        stack.setCurrentIndex(1)
57        # wait until animation finished
58        self.app.exec_()
59
60        self.assertEqual(stack.currentIndex(), 1)
61
62        widget2 = QGroupBox("Group")
63        stack.insertWidget(1, widget2)
64        self.assertEqual(stack.count(), 3)
65        self.assertEqual(stack.currentIndex(), 2)
66        self.assertSequenceEqual([widget1, widget2, widget3],
67                                 widgets())
68
69        stack.transitionFinished.disconnect(self.app.exit)
70
71        self.singleShot(2000, lambda: stack.setCurrentIndex(0))
72        self.singleShot(4000, lambda: stack.setCurrentIndex(1))
73        self.singleShot(6000, lambda: stack.setCurrentIndex(2))
74
75        self.app.exec_()
Note: See TracBrowser for help on using the repository browser.