Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fslpy
Commits
69297c6f
Commit
69297c6f
authored
May 08, 2019
by
Paul McCarthy
🚵
Browse files
ENH: New idle.block function
parent
e1254a9f
Changes
1
Hide whitespace changes
Inline
Side-by-side
fsl/utils/idle.py
View file @
69297c6f
...
@@ -19,6 +19,7 @@ Idle tasks
...
@@ -19,6 +19,7 @@ Idle tasks
.. autosummary::
.. autosummary::
:nosignatures:
:nosignatures:
block
idle
idle
idleWhen
idleWhen
inIdle
inIdle
...
@@ -377,6 +378,29 @@ def cancelIdle(taskName):
...
@@ -377,6 +378,29 @@ def cancelIdle(taskName):
_idleQueueDict
[
taskName
].
timeout
=
-
1
_idleQueueDict
[
taskName
].
timeout
=
-
1
def
block
(
secs
,
delta
=
0.01
):
"""Blocks for the specified number of seconds, yielding to the main ``wx``
loop.
If ``wx`` is not available, or a ``wx`` application is not running, this
function is equivalent to ``time.sleep(secs)``.
:arg secs: Time in seconds to block
:arg delta: Time in seconds to sleep between successive yields to ``wx``.
"""
from
fsl.utils.platform
import
platform
as
fslplatform
if
not
fslplatform
.
haveGui
:
time
.
sleep
(
secs
)
else
:
import
wx
start
=
time
.
time
()
while
(
time
.
time
()
-
start
)
<
secs
:
wx
.
YieldIfNeeded
()
time
.
sleep
(
delta
)
def
idle
(
task
,
*
args
,
**
kwargs
):
def
idle
(
task
,
*
args
,
**
kwargs
):
"""Run the given task on a ``wx.EVT_IDLE`` event.
"""Run the given task on a ``wx.EVT_IDLE`` event.
...
@@ -556,7 +580,7 @@ def idleWhen(func, condition, *args, **kwargs):
...
@@ -556,7 +580,7 @@ def idleWhen(func, condition, *args, **kwargs):
def
wait
(
threads
,
task
,
*
args
,
**
kwargs
):
def
wait
(
threads
,
task
,
*
args
,
**
kwargs
):
"""Creates and starts a new ``Thread`` which waits for all of the ``Thread``
"""Creates and starts a new ``Thread`` which waits for all of the ``Thread``
instances to fin
s
ih (by ``join``ing them), and then runs the given
instances to fini
s
h (by ``join``ing them), and then runs the given
``task`` via :func:`idle`.
``task`` via :func:`idle`.
If the ``direct`` parameter is ``True``, or a ``wx.App`` is not running,
If the ``direct`` parameter is ``True``, or a ``wx.App`` is not running,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment