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
Michiel Cottaar
fslpy
Commits
b02e1bcf
Commit
b02e1bcf
authored
Feb 17, 2021
by
Paul McCarthy
🚵
Browse files
MNT: idle uses its own [can]havegui implementations
parent
e465d22a
Changes
1
Hide whitespace changes
Inline
Side-by-side
fsl/utils/idle.py
View file @
b02e1bcf
...
...
@@ -90,6 +90,34 @@ log = logging.getLogger(__name__)
class
IdleTask
(
object
):
@
functools
.
lru_cache
()
def
_canHaveGui
():
"""Return ``True`` if wxPython is installed, and a display is available,
``False`` otherwise.
"""
# Determine if a display is available. We do
# this once at init (instead of on-demand in
# the canHaveGui method) because calling the
# IsDisplayAvailable function will cause the
# application to steal focus under OSX!
try
:
import
wx
return
wx
.
App
.
IsDisplayAvailable
()
except
ImportError
:
return
False
def
_haveGui
():
"""Return ``True`` if wxPython is installed, a display is available, and
a ``wx.App`` exists, ``False`` otherwise.
"""
try
:
import
wx
return
_canHaveGui
()
and
(
wx
.
GetApp
()
is
not
None
)
except
ImportError
:
return
False
"""Container object used by the :class:`IdleLoop` class.
Used to encapsulate information about a queued task.
"""
...
...
@@ -370,8 +398,6 @@ class IdleLoop(object):
``timeout``, or ``alwaysQueue``.
"""
from
fsl.utils.platform
import
platform
as
fslplatform
schedtime
=
time
.
time
()
timeout
=
kwargs
.
pop
(
'timeout'
,
0
)
after
=
kwargs
.
pop
(
'after'
,
0
)
...
...
@@ -380,18 +406,15 @@ class IdleLoop(object):
skipIfQueued
=
kwargs
.
pop
(
'skipIfQueued'
,
False
)
alwaysQueue
=
kwargs
.
pop
(
'alwaysQueue'
,
False
)
canHaveGui
=
fslplatform
.
canHaveGui
haveGui
=
fslplatform
.
haveGui
# If there is no possibility of a
# gui being available in the future
# (determined by canHaveGui), then
# (determined by
_
canHaveGui), then
# alwaysQueue is ignored.
alwaysQueue
=
alwaysQueue
and
canHaveGui
alwaysQueue
=
alwaysQueue
and
_
canHaveGui
()
# We don't have wx - run the task
# directly/synchronously.
if
self
.
__neverQueue
or
not
(
haveGui
or
alwaysQueue
):
if
self
.
__neverQueue
or
not
(
_
haveGui
()
or
alwaysQueue
):
time
.
sleep
(
after
)
log
.
debug
(
'Running idle task directly'
)
task
(
*
args
,
**
kwargs
)
...
...
@@ -611,11 +634,13 @@ def block(secs, delta=0.01, until=None):
determins when calls to ``block`` will return.
"""
havewx
=
_haveGui
()
def
defaultUntil
():
return
False
def
tick
():
if
fslplatform
.
have
Gui
:
if
have
wx
:
import
wx
wx
.
YieldIfNeeded
()
time
.
sleep
(
delta
)
...
...
@@ -623,8 +648,6 @@ def block(secs, delta=0.01, until=None):
if
until
is
None
:
until
=
defaultUntil
from
fsl.utils.platform
import
platform
as
fslplatform
start
=
time
.
time
()
while
(
time
.
time
()
-
start
)
<
secs
:
tick
()
...
...
@@ -653,12 +676,11 @@ def run(task, onFinish=None, onError=None, name=None):
the return value will be ``None``.
"""
from
fsl.utils.platform
import
platform
as
fslplatform
if
name
is
None
:
name
=
getattr
(
task
,
'__name__'
,
'<unknown>'
)
haveWX
=
fslplatform
.
haveGui
haveWX
=
_
haveGui
()
# Calls the onFinish or onError handler
def
callback
(
cb
,
*
args
,
**
kwargs
):
...
...
@@ -727,14 +749,12 @@ def wait(threads, task, *args, **kwargs):
a keyword argument called ``wait_direct``.
"""
from
fsl.utils.platform
import
platform
as
fslplatform
direct
=
kwargs
.
pop
(
'wait_direct'
,
False
)
if
not
isinstance
(
threads
,
abc
.
Sequence
):
threads
=
[
threads
]
haveWX
=
fslplatform
.
haveGui
haveWX
=
_
haveGui
()
def
joinAll
():
log
.
debug
(
'Wait thread joining on all targets'
)
...
...
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