~ubuntu-branches/ubuntu/oneiric/pyside/oneiric

« back to all changes in this revision

Viewing changes to tests/qtcore/qthread_signal_test.py

  • Committer: Bazaar Package Importer
  • Author(s): Didier Raboud
  • Date: 2010-09-27 21:01:06 UTC
  • mfrom: (1.2.1 upstream) (6.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20100927210106-m1nrq8vmd3exqb9o
Tags: 0.4.1-0ubuntu1
* New 0.4.1 upstream release. (LP: #648612)
  - Add some 0.4.1 symbols.

* Patches:
  - u_c130273_fix_py25_QtScript_property.patch
    Remove, was from upstream.
  - u_20e226b_fix_missing_qcoreapplication_arguments_method.patch
    Remove, was from upstream.
  - u_268bf77_fixed_signal_signature_parser.patch
    Remove, was from upstream.
  + libPythonVersionPostfix.patch: Refresh
  + usePySpecificShiboken.patch: Refresh
  + lessBuildVerbosity.patch: Refresh

* Bump the B-D chain versions.
* Make sure the private.py is installed in QtCore module.
* Build against Qt 4.7.
  - Add libqtwebkit-dev
  - Drop QtMultimedia module.
  - Add the QtDeclarative package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
'''Test cases for connecting signals between threads'''
3
 
 
4
 
import unittest
5
 
 
6
 
from PySide.QtCore import QThread, QObject, SIGNAL, QCoreApplication
7
 
 
8
 
thread_run = False
9
 
 
10
 
class Source(QObject):
11
 
    def __init__(self, *args):
12
 
        QObject.__init__(self, *args)
13
 
 
14
 
    def emit_sig(self):
15
 
        self.emit(SIGNAL('source()'))
16
 
 
17
 
class Target(QObject):
18
 
    def __init__(self, *args):
19
 
        QObject.__init__(self, *args)
20
 
        self.called = False
21
 
 
22
 
    def myslot(self):
23
 
        self.called = True
24
 
 
25
 
class ThreadJustConnects(QThread):
26
 
    def __init__(self, source, *args):
27
 
        QThread.__init__(self, *args)
28
 
        self.source = source
29
 
        self.target = Target()
30
 
 
31
 
    def run(self):
32
 
        global thread_run
33
 
        thread_run = True
34
 
        QObject.connect(self.source, SIGNAL('source()'), self.target.myslot)
35
 
 
36
 
        while not self.target.called:
37
 
            pass
38
 
 
39
 
 
40
 
 
41
 
class BasicConnection(unittest.TestCase):
42
 
 
43
 
    def testEmitOutsideThread(self):
44
 
        global thread_run
45
 
 
46
 
        app = QCoreApplication([])
47
 
        source = Source()
48
 
        thread = ThreadJustConnects(source)
49
 
 
50
 
        QObject.connect(thread, SIGNAL('finished()'), lambda: app.exit(0))
51
 
        thread.start()
52
 
 
53
 
        while not thread_run:
54
 
            pass
55
 
 
56
 
        source.emit_sig()
57
 
 
58
 
        app.exec_()
59
 
        thread.wait()
60
 
 
61
 
        self.assert_(thread.target.called)
62
 
 
63
 
if __name__ == '__main__':
64
 
    unittest.main()