source: orange/Orange/OrangeCanvas/gui/tests/test_lineedit.py @ 11105:34a1ed8255dc

Revision 11105:34a1ed8255dc, 1.5 KB checked in by Ales Erjavec <ales.erjavec@…>, 18 months ago (diff)

Added a QLineEdit subclass with support for action/button in left/right side.

Line 
1"""
2Test for searchwidget
3
4"""
5
6from PyQt4.QtGui import QAction, QStyle, QIcon, QMenu
7
8from ..lineedit import LineEdit
9
10from ..test import QAppTestCase
11
12
13class TestSearchWidget(QAppTestCase):
14    def test_lineedit(self):
15        """test LineEdit
16        """
17        line = LineEdit()
18        line.show()
19
20        action1 = QAction(QIcon(line.style().standardPixmap(
21                                    QStyle.SP_ArrowBack)
22                                ),
23                          "Search", line)
24        menu = QMenu()
25        menu.addAction("Regex")
26        menu.addAction("Wildcard")
27        action1.setMenu(menu)
28
29        line.setAction(action1, LineEdit.LeftPosition)
30        self.assertIs(line.actionAt(LineEdit.LeftPosition), action1)
31        self.assertTrue(line.button(LineEdit.LeftPosition) is not None)
32        self.assertTrue(line.button(LineEdit.RightPosition) is None)
33
34        with self.assertRaises(ValueError):
35            line.removeActionAt(100)
36
37        line.removeActionAt(LineEdit.LeftPosition)
38        self.assertIs(line.actionAt(LineEdit.LeftPosition), None)
39
40        line.setAction(action1, LineEdit.LeftPosition)
41
42        action2 = QAction(QIcon(line.style().standardPixmap(
43                                        QStyle.SP_TitleBarCloseButton)),
44                          "Delete", line)
45        line.setAction(action2, LineEdit.RightPosition)
46
47        line.setPlaceholderText("Search")
48        self.assertEqual(line.placeholderText(), "Search")
49
50        b = line.button(LineEdit.RightPosition)
51        b.setFlat(False)
52        self.app.exec_()
Note: See TracBrowser for help on using the repository browser.