ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change
on this file since f237c05 was
5032ea68,
checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago
|
threaded file load, data object related fixes, more unit tests.
|
-
Property mode set to
100755
|
File size:
1.3 KB
|
Line | |
---|
1 | from PyQt4.QtCore import * |
---|
2 | from PyQt4.QtGui import * |
---|
3 | from PyQt4.QtTest import * |
---|
4 | |
---|
5 | class QtSignalSpy(QObject): |
---|
6 | """ |
---|
7 | Helper class for testing Qt signals. |
---|
8 | """ |
---|
9 | def __init__(self, widget, signal, parent=None): |
---|
10 | """ |
---|
11 | """ |
---|
12 | super(QtSignalSpy, self).__init__(parent) |
---|
13 | |
---|
14 | self._recorder = {} |
---|
15 | self._count = 0 |
---|
16 | self._signal = [] |
---|
17 | |
---|
18 | # Assign our own slot to the emitted signal |
---|
19 | try: |
---|
20 | if isinstance(signal, pyqtBoundSignal): |
---|
21 | signal.connect(self.slot) |
---|
22 | elif hasattr(widget, signal): |
---|
23 | getattr(widget, signal).connect(self.slot) |
---|
24 | else: |
---|
25 | widget.signal.connect(slot) |
---|
26 | except AttributeError: |
---|
27 | msg = "Wrong construction of QtSignalSpy instance" |
---|
28 | raise RuntimeError, msg |
---|
29 | |
---|
30 | def slot(self, *args, **kwargs): |
---|
31 | """ |
---|
32 | Record emitted signal. |
---|
33 | """ |
---|
34 | self._recorder[self._count] = { |
---|
35 | 'args' : args, |
---|
36 | 'kwargs' : kwargs, |
---|
37 | } |
---|
38 | |
---|
39 | self._count += 1 |
---|
40 | self._signal = [args, kwargs] |
---|
41 | |
---|
42 | def signal(self, index=None): |
---|
43 | if index == None: |
---|
44 | return self._signal |
---|
45 | else: |
---|
46 | return self._signal[index] |
---|
47 | |
---|
48 | def count(self): |
---|
49 | return self._count |
---|
50 | |
---|
51 | def called(self): |
---|
52 | return self._recorder |
---|
Note: See
TracBrowser
for help on using the repository browser.