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
af99f14e
Commit
af99f14e
authored
Aug 20, 2021
by
Paul McCarthy
🚵
Browse files
RF: Only import wx on access, not when Platform obj is created
parent
f3d34686
Changes
1
Hide whitespace changes
Inline
Side-by-side
fsl/utils/platform.py
View file @
af99f14e
...
@@ -111,26 +111,15 @@ class Platform(notifier.Notifier):
...
@@ -111,26 +111,15 @@ class Platform(notifier.Notifier):
self
.
WX_MAC_CARBON
=
WX_MAC_CARBON
self
.
WX_MAC_CARBON
=
WX_MAC_CARBON
self
.
WX_GTK
=
WX_GTK
self
.
WX_GTK
=
WX_GTK
self
.
__inSSHSession
=
False
# initialise fsldir - see fsldir.setter
self
.
__inVNCSession
=
False
self
.
fsldir
=
self
.
fsldir
# These are all initialised on first access
self
.
__glVersion
=
None
self
.
__glVersion
=
None
self
.
__glRenderer
=
None
self
.
__glRenderer
=
None
self
.
__glIsSoftware
=
None
self
.
__glIsSoftware
=
None
self
.
__fslVersion
=
None
self
.
__fslVersion
=
None
self
.
__canHaveGui
=
None
# initialise fsldir - see fsldir.setter
self
.
fsldir
=
self
.
fsldir
# 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
self
.
__canHaveGui
=
wx
.
App
.
IsDisplayAvailable
()
except
ImportError
:
self
.
__canHaveGui
=
False
# If one of the SSH_/VNC environment
# If one of the SSH_/VNC environment
# variables is set, then we're probably
# variables is set, then we're probably
...
@@ -177,7 +166,7 @@ class Platform(notifier.Notifier):
...
@@ -177,7 +166,7 @@ class Platform(notifier.Notifier):
the event loop is called periodically, and so is not always running.
the event loop is called periodically, and so is not always running.
"""
"""
try
:
try
:
import
wx
import
wx
# pylint: disable=import-outside-toplevel
app
=
wx
.
GetApp
()
app
=
wx
.
GetApp
()
# TODO Previously this conditional
# TODO Previously this conditional
...
@@ -216,6 +205,17 @@ class Platform(notifier.Notifier):
...
@@ -216,6 +205,17 @@ class Platform(notifier.Notifier):
'Equivalent functionality is available in fsleyes-widgets.'
)
'Equivalent functionality is available in fsleyes-widgets.'
)
def
canHaveGui
(
self
):
def
canHaveGui
(
self
):
"""``True`` if it is possible to create a GUI, ``False`` otherwise. """
"""``True`` if it is possible to create a GUI, ``False`` otherwise. """
# Determine if a display is available. Note that
# calling the IsDisplayAvailable function will
# cause the application to steal focus under OSX!
if
self
.
__canHaveGui
is
None
:
try
:
import
wx
# pylint: disable=import-outside-toplevel
self
.
__canHaveGui
=
wx
.
App
.
IsDisplayAvailable
()
except
ImportError
:
self
.
__canHaveGui
=
False
return
self
.
__canHaveGui
return
self
.
__canHaveGui
...
@@ -261,14 +261,14 @@ class Platform(notifier.Notifier):
...
@@ -261,14 +261,14 @@ class Platform(notifier.Notifier):
if
not
self
.
canHaveGui
:
if
not
self
.
canHaveGui
:
return
WX_UNKNOWN
return
WX_UNKNOWN
import
wx
import
wx
# pylint: disable=import-outside-toplevel
pi
=
[
t
.
lower
()
for
t
in
wx
.
PlatformInfo
]
pi
=
[
t
.
lower
()
for
t
in
wx
.
PlatformInfo
]
if
any
(
[
'cocoa'
in
p
for
p
in
pi
]
):
plat
=
WX_MAC_COCOA
if
any
(
'cocoa'
in
p
for
p
in
pi
):
plat
=
WX_MAC_COCOA
elif
any
(
[
'carbon'
in
p
for
p
in
pi
]
):
plat
=
WX_MAC_CARBON
elif
any
(
'carbon'
in
p
for
p
in
pi
):
plat
=
WX_MAC_CARBON
elif
any
(
[
'gtk'
in
p
for
p
in
pi
]
):
plat
=
WX_GTK
elif
any
(
'gtk'
in
p
for
p
in
pi
):
plat
=
WX_GTK
else
:
plat
=
WX_UNKNOWN
else
:
plat
=
WX_UNKNOWN
if
plat
is
WX_UNKNOWN
:
if
plat
is
WX_UNKNOWN
:
log
.
warning
(
'Could not determine wx platform from '
log
.
warning
(
'Could not determine wx platform from '
...
@@ -290,7 +290,7 @@ class Platform(notifier.Notifier):
...
@@ -290,7 +290,7 @@ class Platform(notifier.Notifier):
if
not
self
.
canHaveGui
:
if
not
self
.
canHaveGui
:
return
WX_UNKNOWN
return
WX_UNKNOWN
import
wx
import
wx
# pylint: disable=import-outside-toplevel
pi
=
[
t
.
lower
()
for
t
in
wx
.
PlatformInfo
]
pi
=
[
t
.
lower
()
for
t
in
wx
.
PlatformInfo
]
isPhoenix
=
False
isPhoenix
=
False
...
@@ -323,7 +323,9 @@ class Platform(notifier.Notifier):
...
@@ -323,7 +323,9 @@ class Platform(notifier.Notifier):
@
property
@
property
def
fslwsl
(
self
):
def
fslwsl
(
self
):
"""Boolean flag indicating whether FSL is installed in Windows Subsystem for Linux """
"""Boolean flag indicating whether FSL is installed in Windows
Subsystem for Linux
"""
return
self
.
fsldir
is
not
None
and
self
.
fsldir
.
startswith
(
"
\\\\
wsl$"
)
return
self
.
fsldir
is
not
None
and
self
.
fsldir
.
startswith
(
"
\\\\
wsl$"
)
...
@@ -352,8 +354,9 @@ class Platform(notifier.Notifier):
...
@@ -352,8 +354,9 @@ class Platform(notifier.Notifier):
if
op
.
exists
(
versionFile
):
if
op
.
exists
(
versionFile
):
with
open
(
versionFile
,
'rt'
)
as
f
:
with
open
(
versionFile
,
'rt'
)
as
f
:
# split string at colon for new hash style versions
# split string at colon for new hash style versions
# first object in list is the non-hashed version string (e.g. 6.0.2)
# first object in list is the non-hashed version string
# if no ":hash:" then standard FSL version string is still returned
# (e.g. 6.0.2) if no ":hash:" then standard FSL version
# string is still returned
self
.
__fslVersion
=
f
.
read
().
strip
().
split
(
":"
)[
0
]
self
.
__fslVersion
=
f
.
read
().
strip
().
split
(
":"
)[
0
]
self
.
notify
(
value
=
value
)
self
.
notify
(
value
=
value
)
...
...
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