source: orange/Orange/OrangeCanvas/document/tests/test_quickmenu.py @ 11163:c2e366a1e9df

Revision 11163:c2e366a1e9df, 2.5 KB checked in by Ales Erjavec <ales.erjavec@…>, 18 months ago (diff)

Moved QuickMenu from 'canvas' to 'document' package.

Line 
1from PyQt4.QtCore import QPoint
2from ..quickmenu import QuickMenu, SuggestMenuPage, FlattenedTreeItemModel, \
3                        ToolTree, QAction
4
5from ...gui.test import QAppTestCase
6
7
8class TestMenu(QAppTestCase):
9    def test_menu(self):
10        from PyQt4.QtGui import QStringListModel
11        menu = QuickMenu()
12
13        def triggered(action):
14            print "Triggered", action.text()
15
16        def hovered(action):
17            print "Hover", action.text()
18
19        menu.triggered.connect(triggered)
20        menu.hovered.connect(hovered)
21
22        items_page = ToolTree()
23        model = QStringListModel(["one", "two", "file not found"])
24        items_page.setModel(model)
25        menu.addPage("w", items_page)
26
27        page_c = ToolTree()
28        menu.addPage("c", page_c)
29
30        menu.popup(QPoint(200, 200))
31        menu.activateWindow()
32
33        self.app.exec_()
34
35    def test_menu_with_registry(self):
36        from ...registry.qt import run_discovery
37
38        registry = run_discovery()
39        menu = QuickMenu()
40        menu.setModel(registry.model())
41
42        triggered_action = []
43
44        def triggered(action):
45            print "Triggered", action.text()
46            self.assertIsInstance(action, QAction)
47            triggered_action.append(action)
48
49        def hovered(action):
50            self.assertIsInstance(action, QAction)
51            print "Hover", action.text()
52
53        menu.triggered.connect(triggered)
54        menu.hovered.connect(hovered)
55        self.app.setActiveWindow(menu)
56
57        rval = menu.exec_(QPoint(200, 200))
58
59        if triggered_action:
60            self.assertIs(triggered_action[0], rval)
61
62    def test_search(self):
63        from ...registry.qt import run_discovery
64
65        registry = run_discovery()
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.app.exec_()
74
75    def test_flattened_model(self):
76        from PyQt4.QtGui import QStringListModel
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.