source: orange/Orange/OrangeCanvas/document/tests/test_quickmenu.py @ 11370:03af193a01d3

Revision 11370:03af193a01d3, 2.5 KB checked in by Ales Erjavec <ales.erjavec@…>, 14 months ago (diff)

Moved 'icon' and 'title' property from ToolTree widget, to quickmenu.MenuPage.

Line 
1from PyQt4.QtGui import QStringListModel
2from PyQt4.QtCore import QPoint
3
4from ..quickmenu import QuickMenu, SuggestMenuPage, FlattenedTreeItemModel, \
5                        MenuPage, QAction
6
7from ...gui.test import QAppTestCase
8from ...registry import global_registry
9from ...registry.qt import QtWidgetRegistry
10
11
12class TestMenu(QAppTestCase):
13    def test_menu(self):
14        menu = QuickMenu()
15
16        def triggered(action):
17            print "Triggered", action.text()
18
19        def hovered(action):
20            print "Hover", action.text()
21
22        menu.triggered.connect(triggered)
23        menu.hovered.connect(hovered)
24
25        items_page = MenuPage()
26        model = QStringListModel(["one", "two", "file not found"])
27        items_page.setModel(model)
28        menu.addPage("w", items_page)
29
30        page_c = MenuPage()
31        menu.addPage("c", page_c)
32
33        menu.popup(QPoint(200, 200))
34        menu.activateWindow()
35
36        self.app.exec_()
37
38    def test_menu_with_registry(self):
39        registry = QtWidgetRegistry(global_registry())
40
41        menu = QuickMenu()
42        menu.setModel(registry.model())
43
44        triggered_action = []
45
46        def triggered(action):
47            print "Triggered", action.text()
48            self.assertIsInstance(action, QAction)
49            triggered_action.append(action)
50
51        def hovered(action):
52            self.assertIsInstance(action, QAction)
53            print "Hover", action.text()
54
55        menu.triggered.connect(triggered)
56        menu.hovered.connect(hovered)
57        self.app.setActiveWindow(menu)
58
59        rval = menu.exec_(QPoint(200, 200))
60
61        if triggered_action:
62            self.assertIs(triggered_action[0], rval)
63
64    def test_search(self):
65        registry = QtWidgetRegistry(global_registry())
66
67        menu = SuggestMenuPage()
68
69        menu.setModel(registry.model())
70        menu.show()
71        menu.setFilterFixedString("la")
72        self.singleShot(2500, lambda: menu.setFilterFixedString("ba"))
73        self.singleShot(5000, lambda: menu.setFilterFixedString("ab"))
74        self.app.exec_()
75
76    def test_flattened_model(self):
77        model = QStringListModel(["0", "1", "2", "3"])
78        flat = FlattenedTreeItemModel()
79        flat.setSourceModel(model)
80
81        def get(row):
82            return flat.index(row, 0).data().toPyObject()
83
84        self.assertEqual(get(0), "0")
85        self.assertEqual(get(1), "1")
86        self.assertEqual(get(3), "3")
87        self.assertEqual(flat.rowCount(), model.rowCount())
88        self.assertEqual(flat.columnCount(), 1)
Note: See TracBrowser for help on using the repository browser.