From ae3bd438f0aedfc9c64c0d269b57cd18eab83891 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Mon, 1 Aug 2016 16:23:39 +0100 Subject: [PATCH] Platform.haveGui is only true if a wx.App is running. New Platform.canHaveGui, can be used to tell whether we are able to create a GUI. Async modified to use platform.haveGui instead of performing its own test. --- fsl/utils/async.py | 9 ++------- fsl/utils/platform.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/fsl/utils/async.py b/fsl/utils/async.py index bddc86a28..8ab9a7b6a 100644 --- a/fsl/utils/async.py +++ b/fsl/utils/async.py @@ -88,13 +88,8 @@ def _haveWX(): """Returns ``True`` if we are running within a ``wx`` application, ``False`` otherwise. """ - - try: - import wx - return wx.GetApp() is not None - - except ImportError: - return False + import fsl.utils.platform as fslplatform + return fslplatform.platform.haveGui def run(task, onFinish=None, onError=None, name=None): diff --git a/fsl/utils/platform.py b/fsl/utils/platform.py index e0effb699..ad4fe6a51 100644 --- a/fsl/utils/platform.py +++ b/fsl/utils/platform.py @@ -79,6 +79,7 @@ class Platform(notifier.Notifier): frozen fsldir haveGui + canHaveGui inSSHSession wxPlatform wxFlavour @@ -100,6 +101,7 @@ class Platform(notifier.Notifier): self.__fsldir = os.environ.get('FSLDIR', None) self.__haveGui = False + self.__canHaveGui = False self.__inSSHSession = False self.__wxFlavour = None self.__wxPlatform = None @@ -107,8 +109,13 @@ class Platform(notifier.Notifier): self.__glRenderer = None try: + import wx - self.__haveGui = True + + self.__canHaveGui = True + + if wx.GetApp() is not None: + self.__haveGui = True except ImportError: pass @@ -168,6 +175,12 @@ class Platform(notifier.Notifier): return self.__haveGui + @property + def canHaveGui(self): + """``True`` if it is possible to create a GUI, ``False`` otherwise. """ + return self.__canHaveGui + + @property def inSSHSession(self): """``True`` if this application is running over an SSH session, -- GitLab