source: orange/Orange/OrangeCanvas/application/tests/test_widgettoolbox.py @ 11117:ded694b002e0

Revision 11117:ded694b002e0, 2.0 KB checked in by Ales Erjavec <ales.erjavec@…>, 18 months ago (diff)

Added a WidgetToolBox class (toolbox with widget buttons grouped by category).

Line 
1"""
2Tests for WidgetsToolBox.
3
4"""
5from PyQt4.QtGui import QWidget, QHBoxLayout
6from PyQt4.QtCore import QSize
7
8from ...registry import global_registry
9from ...registry.qt import QtWidgetRegistry
10
11
12from ..widgettoolbox import WidgetToolBox, WidgetToolGrid, ToolGrid
13
14from ...gui import test
15
16
17class TestWidgetToolBox(test.QAppTestCase):
18    def test_widgettoolgrid(self):
19        w = QWidget()
20        layout = QHBoxLayout()
21
22        reg = global_registry()
23        qt_reg = QtWidgetRegistry(reg)
24
25        triggered_actions1 = []
26        triggered_actions2 = []
27
28        model = qt_reg.model()
29        data_descriptions = qt_reg.widgets("Data")
30
31        file_action = qt_reg.action_for_widget(
32            "Orange.OrangeWidgets.Data.OWFile.OWFile"
33        )
34
35        actions = map(qt_reg.action_for_widget, data_descriptions)
36
37        grid = ToolGrid(w)
38        grid.setActions(actions)
39        grid.actionTriggered.connect(triggered_actions1.append)
40        layout.addWidget(grid)
41
42        grid = WidgetToolGrid(w)
43
44        grid.setModel(model, rootIndex=model.index(0, 0))
45        self.assertIs(model, grid.model())
46        grid.actionTriggered.connect(triggered_actions2.append)
47
48        layout.addWidget(grid)
49
50        w.setLayout(layout)
51        w.show()
52        file_action.trigger()
53
54        self.app.exec_()
55
56    def test_toolbox(self):
57
58        w = QWidget()
59        layout = QHBoxLayout()
60
61        reg = global_registry()
62        qt_reg = QtWidgetRegistry(reg)
63
64        triggered_actions = []
65
66        model = qt_reg.model()
67
68        file_action = qt_reg.action_for_widget(
69            "Orange.OrangeWidgets.Data.OWFile.OWFile"
70        )
71
72        box = WidgetToolBox()
73        box.setModel(model)
74        box.triggered.connect(triggered_actions.append)
75        layout.addWidget(box)
76
77        box.setButtonSize(QSize(50, 80))
78
79        w.setLayout(layout)
80        w.show()
81
82        file_action.trigger()
83
84        box.setButtonSize(QSize(60, 80))
85        box.setIconSize(QSize(35, 35))
86        box.setTabButtonHeight(40)
87        box.setTabIconSize(QSize(30, 30))
88        self.app.exec_()
Note: See TracBrowser for help on using the repository browser.