@@ -224,7 +224,8 @@ def waitSignal(self, signal=None, timeout=1000):
224
224
with qtbot.waitSignal(signal, timeout=1000):
225
225
long_function_that_calls_signal()
226
226
227
- Can also be used to return blocker object::
227
+ Also, you can use the :class:`SignalBlocker` directly if the context
228
+ manager form is not convenient::
228
229
229
230
blocker = qtbot.waitSignal(signal, timeout=1000)
230
231
blocker.connect(other_signal)
@@ -249,21 +250,43 @@ def waitSignal(self, signal=None, timeout=1000):
249
250
return blocker
250
251
251
252
252
- class SignalBlocker :
253
+ class SignalBlocker (object ):
254
+ """
255
+ Returned by :meth:`QtBot.waitSignal` method.
256
+
257
+ .. automethod:: wait
258
+ .. automethod:: connect
259
+
260
+ :ivar int timeout: maximum time to wait for a signal to be triggered. Can
261
+ be changed before :meth:`wait` is called.
262
+ """
253
263
254
264
def __init__ (self , timeout = 1000 ):
255
265
self ._loop = QtCore .QEventLoop ()
256
266
self ._signals = []
257
267
self .timeout = timeout
258
268
259
269
def wait (self ):
270
+ """
271
+ Waits until either condition signal is triggered or
272
+ timeout is reached.
273
+
274
+ :raise ValueError: if no signals are connected and timeout is None; in
275
+ this case it would wait forever.
276
+ """
260
277
if self .timeout is None and len (self ._signals ) == 0 :
261
278
raise ValueError ("No signals or timeout specified." )
262
279
if self .timeout is not None :
263
280
QtCore .QTimer .singleShot (self .timeout , self ._loop .quit )
264
281
self ._loop .exec_ ()
265
282
266
283
def connect (self , signal ):
284
+ """
285
+ Connects to the given signal, making :meth:`wait()` return once this signal
286
+ is emitted.
287
+
288
+ :param signal: QtCore.Signal
289
+ """
267
290
signal .connect (self ._loop .quit )
268
291
self ._signals .append (signal )
269
292
0 commit comments