aboutsummaryrefslogtreecommitdiffstats
path: root/tests/QtUiTools/bug_392.py
blob: 9cc8b210b879999cb57a55a41719bcd357a6cb52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import unittest
import os
from helper import UsesQApplication

from PySide import QtGui, QtDeclarative
from PySide.QtUiTools import QUiLoader

class MyWidget(QtGui.QComboBox):
    def __init__(self, parent=None):
        QtGui.QComboBox.__init__(self, parent)

    def isPython(self):
        return True

class BugTest(UsesQApplication):
    def testCase(self):
        w = QtGui.QWidget()
        loader = QUiLoader()

        filePath = os.path.join(os.path.dirname(__file__), 'action.ui')
        result = loader.load(filePath, w)
        self.assert_(isinstance(result.statusbar.actionFoo, QtGui.QAction))

    def testCustomWidgets(self):
        w = QtGui.QWidget()
        loader = QUiLoader()

        filePath = os.path.join(os.path.dirname(__file__), 'customwidget.ui')
        result = loader.load(filePath, w)
        self.assert_(isinstance(result.declarativeView, QtDeclarative.QDeclarativeView))
        self.assert_(isinstance(result.worldTimeClock, QtGui.QWidget))

    def testPythonCustomWidgets(self):
        w = QtGui.QWidget()
        loader = QUiLoader()
        loader.registerCustomWidget(MyWidget)

        filePath = os.path.join(os.path.dirname(__file__), 'pycustomwidget.ui')
        result = loader.load(filePath, w)
        self.assert_(isinstance(result.custom, MyWidget))
        self.assert_(result.custom.isPython())

    def testPythonCustomWidgetsTwice(self):
        w = QtGui.QWidget()
        loader = QUiLoader()
        loader.registerCustomWidget(MyWidget)

        filePath = os.path.join(os.path.dirname(__file__), 'pycustomwidget2.ui')
        result = loader.load(filePath, w)
        self.assert_(isinstance(result.custom, MyWidget))
        self.assert_(isinstance(result.custom2, MyWidget))
        self.assert_(result.custom.isPython())

if __name__ == '__main__':
    unittest.main()