~ubuntu-branches/ubuntu/natty/pyside/natty

« back to all changes in this revision

Viewing changes to tests/QtCore/bug_462.py

  • Committer: Bazaar Package Importer
  • Author(s): Didier Raboud
  • Date: 2011-02-18 18:01:00 UTC
  • mfrom: (1.1.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110218180100-y8aqmcdbcbd6gpeh
Tags: upstream-1.0.0~rc1
ImportĀ upstreamĀ versionĀ 1.0.0~rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import unittest
 
2
import sys
 
3
 
 
4
from PySide.QtCore import QObject, QCoreApplication, QEvent, QThread
 
5
 
 
6
class MyEvent(QEvent):
 
7
    def __init__(self,i):
 
8
        super(MyEvent,self).__init__(QEvent.Type(QEvent.User + 100 ))
 
9
        self.i = i
 
10
 
 
11
class MyThread (QThread):
 
12
    def __init__(self,owner):
 
13
        super(MyThread,self).__init__()
 
14
        self.owner=owner;
 
15
 
 
16
    def run(self):
 
17
        for i in xrange(3):
 
18
            e=MyEvent(i);
 
19
            QCoreApplication.postEvent(self.owner,e)
 
20
 
 
21
class MyBaseObject(QObject):
 
22
    def __init__(self):
 
23
        QObject.__init__(self)
 
24
        self.events = []
 
25
        self.t = MyThread(self)
 
26
        self.t.start()
 
27
 
 
28
    def customEvent(self, event):
 
29
        self.events.append(event)
 
30
        if len(self.events) == 3:
 
31
            self.t.wait()
 
32
            self.app.quit()
 
33
 
 
34
 
 
35
class CheckForEventsTypes(unittest.TestCase):
 
36
    def testTypes(self):
 
37
        o = MyBaseObject()
 
38
        o.app = QCoreApplication(sys.argv)
 
39
        o.app.exec_()
 
40
        for e in o.events:
 
41
            self.assert_(isinstance(e, MyEvent))
 
42
        o.app = None
 
43
 
 
44
if __name__ == '__main__':
 
45
    unittest.main()