Skip to content
Snippets Groups Projects
Commit 59f253e7 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Open standard action enables itself when the FSLDIR changes.

parent ea86c585
No related branches found
No related tags found
No related merge requests found
...@@ -62,6 +62,7 @@ import subprocess ...@@ -62,6 +62,7 @@ import subprocess
import fsl.tools as tools import fsl.tools as tools
import fsl.utils.settings as fslsettings import fsl.utils.settings as fslsettings
import fsl.utils.platform as fslplatform
import fsl.version import fsl.version
...@@ -566,7 +567,8 @@ def _fslDirWarning(parent, toolName, fslEnvActive): ...@@ -566,7 +567,8 @@ def _fslDirWarning(parent, toolName, fslEnvActive):
fsldir = fslsettings.read('fsldir') fsldir = fslsettings.read('fsldir')
if fsldir is not None: if fsldir is not None:
os.environ['FSLDIR'] = fsldir os.environ['FSLDIR'] = fsldir
fslplatform.platform.fsldir = fsldir
return return
if haveGui: if haveGui:
...@@ -581,8 +583,9 @@ def _fslDirWarning(parent, toolName, fslEnvActive): ...@@ -581,8 +583,9 @@ def _fslDirWarning(parent, toolName, fslEnvActive):
log.debug('Setting $FSLDIR to {} (specified ' log.debug('Setting $FSLDIR to {} (specified '
'by user)'.format(fsldir)) 'by user)'.format(fsldir))
os.environ['FSLDIR'] = fsldir fslplatform.platform.fsldir = fsldir
fslsettings.write('fsldir', fsldir) os.environ[ 'FSLDIR'] = fsldir
fslsettings.write( 'fsldir', fsldir)
wx.CallLater(500, warn) wx.CallLater(500, warn)
......
...@@ -9,10 +9,11 @@ to load in standard space images from the ``$FSLDIR/data/standard/`` directory. ...@@ -9,10 +9,11 @@ to load in standard space images from the ``$FSLDIR/data/standard/`` directory.
""" """
import os
import os.path as op import os.path as op
import action from . import action
import fsl.utils.platform as fslplatform
class OpenStandardAction(action.Action): class OpenStandardAction(action.Action):
...@@ -33,16 +34,40 @@ class OpenStandardAction(action.Action): ...@@ -33,16 +34,40 @@ class OpenStandardAction(action.Action):
self.__overlayList = overlayList self.__overlayList = overlayList
self.__displayCtx = displayCtx self.__displayCtx = displayCtx
# disable this action self.__setStandardDir()
# if $FSLDIR is not set
fsldir = os.environ.get('FSLDIR', None) # If FSLDIR is not set, the setStandardDir
# disables this action. But we'll listen
# for changes to FSLDIR, in case it gets
# set later on.
fslplatform.platform.register(
'{}_{}'.format(type(self).__name__, id(self)),
self.__setStandardDir)
def destroy(self):
"""Must be called when this ``OpenStandardAction`` is no longer
needed. Performs some clean-up.
"""
fslplatform.platform.deregister(
'{}_{}'.format(type(self).__name__, id(self)))
def __setStandardDir(self, *a):
"""Called by :meth:`__init__`, and when the
:attr:`~fsl.utils.Platform.fsldir` property is changed. Updates
the path to the FSLDIR standard directory.
"""
fsldir = fslplatform.platform.fsldir
if fsldir is not None: if fsldir is not None:
self.__stddir = op.join(fsldir, 'data', 'standard') self.__stddir = op.join(fsldir, 'data', 'standard')
else: else:
self.__stddir = None self.__stddir = None
self.enabled = False
self.enabled = self.__stddir is not None
def __openStandard(self): def __openStandard(self):
"""Calls the :meth:`.OverlayList.addOverlays` method. If the user """Calls the :meth:`.OverlayList.addOverlays` method. If the user
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment