From def5e656329f0ba6178520f3bc2a8444a2df5d1d Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Fri, 4 Mar 2016 15:56:09 +0000 Subject: [PATCH] FSLDIR was being set from fsl.utils.settings after AtlasPanel was created, so AtlasPanel was not being initialised with atlas list. Fixed, and also added some notes for possible future method to keep track of changes to FSLDIR (and solve my disabled 'Add standsard' menu item issue).. --- fsl/__init__.py | 43 +++++++++++++++++++---------------------- fsl/fsleyes/platform.py | 32 ++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/fsl/__init__.py b/fsl/__init__.py index f990fd04d..0ddd27658 100644 --- a/fsl/__init__.py +++ b/fsl/__init__.py @@ -104,11 +104,16 @@ def _runGUITool(fslTool, toolArgv): """ import wx - fslEnvActive = 'FSLDIR' in os.environ - - # Create a wx.App before init(), - # in case it does GUI stuff. - app = wx.App() + # Create the wx.App object befor fslTool.init, + # in case it does GUI stuff. Also create a dummy + # frame - if we don't create a dummy frame, the + # wx.MainLoop call below will just return + # immediately. + # + # The buildGUI function below will kill the dummy + # frame when it has created the real interface. + app = wx.App() + dummyFrame = wx.Frame(None) # Call the tool's init # function if there is one @@ -144,29 +149,24 @@ def _runGUITool(fslTool, toolArgv): ctx = None # Build the GUI - frame = _buildGUI(toolNamespace, fslTool, ctx, fslEnvActive) + frame = _buildGUI(toolNamespace, fslTool, ctx) frame.Show() # See comment about the # dummy frame below dummyFrame.Destroy() - _fslDirWarning(frame, fslTool.toolName, fslEnvActive) - - time.sleep(0.1) + # Sleep a bit so the main thread (on + # which wx.MainLoop is running) can + # start. + time.sleep(0.01) + wx.CallAfter(_fslDirWarning, + None, + fslTool.toolName, + 'FSLDIR' in os.environ) wx.CallAfter(realBuild) - # Create the wx.App object, and create a dummy - # frame. If we don't create a dummy frame, the - # wx.MainLoop call will just return immediately. - # The buildGUI function above will kill the dummy - # frame when it has created the real interface. - dummyFrame = wx.Frame(None) - threading.Thread(target=buildGUI).start() - - # The wx.App was created above, - # before calling fslTool.init() app.MainLoop() @@ -575,16 +575,13 @@ def _fslDirWarning(parent, toolName, fslEnvActive): log.warn(warnmsg) -def _buildGUI(args, fslTool, toolCtx, fslEnvActive): +def _buildGUI(args, fslTool, toolCtx): """Builds a :mod:`wx` GUI for the tool. :arg fslTool: The ``FSLTool`` instance (see :func:`_loadFSLTool`). :arg toolCtx: The tool context, as returned by the ``FSLTool.context`` function. - - :arg fslEnvActive: Set to ``True`` if ``$FSLDIR`` is set, ``False`` - otherwise. """ import wx diff --git a/fsl/fsleyes/platform.py b/fsl/fsleyes/platform.py index 9575f46e2..305873b86 100644 --- a/fsl/fsleyes/platform.py +++ b/fsl/fsleyes/platform.py @@ -5,6 +5,8 @@ # Author: Paul McCarthy <pauldmccarthy@gmail.com> # +import os + haveGui = False wxFlavour = None wxPlatform = None @@ -16,18 +18,28 @@ WX_PHOENIX = 2 WX_MAC = 1 WX_GTK = 2 +class Platform(object): + def __init__(self): -try: - import wx - haveGui = True - -except ImportError: - haveGui = False + self.haveGui = False + self.wxFlavour = None + self.wxPlatform = None + try: + import wx + self.haveGui = True -if 'phoenix' in wx.PlatformInformation: wxFlavour = WX_PHOENIX -else: wxFlavour = WX_PYTHON + except ImportError: + pass + if self.haveGui: + if 'phoenix' in wx.PlatformInformation: + self.wxFlavour = WX_PHOENIX + + if 'MAC' in wx.Platform: + self.wxPlatform = WX_MAC -if 'MAC' in wx.Platform: wxPlatform = WX_MAC -elif 'GTK' in wx.Platform: wxPlatform = WX_GTK + # TODO Make Platform a notifier, so + # things can register to listen + # for changes to $FSLDIR + self.fsldir = os.environ['FSLDIR'] -- GitLab