Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
b02e1bcf
Commit
b02e1bcf
authored
4 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
MNT: idle uses its own [can]havegui implementations
parent
e465d22a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/idle.py
+36
-16
36 additions, 16 deletions
fsl/utils/idle.py
with
36 additions
and
16 deletions
fsl/utils/idle.py
+
36
−
16
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
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment