"""
Sleep without freezing the graphical user interface.
"""
import time
from .threading import Thread
from .threading import Worker
[docs]class SleepWorker(Worker):
def __init__(self, seconds):
"""The :class:`~msl.qt.threading.Worker` class for :class:`Sleep`.
Delays execution for a certain number of seconds without
freezing the graphical user interface.
Parameters
----------
seconds : :class:`float`
The number of seconds to sleep for.
"""
super(SleepWorker, self).__init__()
self.seconds = seconds
[docs] def process(self):
"""Calls :func:`time.sleep`."""
time.sleep(self.seconds)
[docs]class Sleep(Thread):
def __init__(self):
"""Sleep without freezing the graphical user interface.
The following example illustrates how one can use :class:`Sleep`
and keep the GUI active:
.. literalinclude:: ../../msl/examples/qt/loop_until_abort_sleep.py
Example
-------
To run this example enter the following::
>>> from msl.examples.qt import LoopExampleSleep # doctest: +SKIP
>>> loop = LoopExampleSleep() # doctest: +SKIP
>>> loop.start() # doctest: +SKIP
"""
super(Sleep, self).__init__(SleepWorker)