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

GUI-related platform properties are determined dynamically instead of at

initialisation. Async.idle still honours after argument, even if a
wx application is not running.
parent 7ecd9f6d
No related branches found
No related tags found
No related merge requests found
...@@ -307,9 +307,9 @@ def idle(task, *args, **kwargs): ...@@ -307,9 +307,9 @@ def idle(task, *args, **kwargs):
All other arguments are passed through to the task function. All other arguments are passed through to the task function.
If a ``wx.App`` is not running, the ``after``, ``timeout``, ``name`` If a ``wx.App`` is not running, the ``timeout``, ``name`` and
and ``skipIfQueued`` arguments are ignored, and the task is called ``skipIfQueued`` arguments are ignored. Instead, the call will sleep for
directly. ``after`` seconds, and then the ``task`` is called directly.
.. note:: If the ``after`` argument is used, there is no guarantee that .. note:: If the ``after`` argument is used, there is no guarantee that
...@@ -368,6 +368,7 @@ def idle(task, *args, **kwargs): ...@@ -368,6 +368,7 @@ def idle(task, *args, **kwargs):
_idleQueueSet.add(name) _idleQueueSet.add(name)
else: else:
time.sleep(after)
log.debug('Running idle task directly') log.debug('Running idle task directly')
task(*args, **kwargs) task(*args, **kwargs)
......
...@@ -34,6 +34,13 @@ builtin_platform = importlib.import_module('platform') ...@@ -34,6 +34,13 @@ builtin_platform = importlib.import_module('platform')
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
WX_UNKNOWN = 0
"""Identifier for the :attr:`Platform.wxFlavour` and
:attr:`Platform.wxPlatform` properties indicating an unknown/undetermined
flavour/platform.
"""
WX_PYTHON = 1 WX_PYTHON = 1
"""Identifier for the :attr:`Platform.wxFlavour` property, indicating that """Identifier for the :attr:`Platform.wxFlavour` property, indicating that
we are running standard wx Python. we are running standard wx Python.
...@@ -93,6 +100,7 @@ class Platform(notifier.Notifier): ...@@ -93,6 +100,7 @@ class Platform(notifier.Notifier):
# For things which 'from fsl.utils.platform import platform', # For things which 'from fsl.utils.platform import platform',
# these identifiers are available on the platform instance # these identifiers are available on the platform instance
self.WX_UNKNOWN = WX_UNKNOWN
self.WX_PYTHON = WX_PYTHON self.WX_PYTHON = WX_PYTHON
self.WX_PHOENIX = WX_PHOENIX self.WX_PHOENIX = WX_PHOENIX
self.WX_MAC_COCOA = WX_MAC_COCOA self.WX_MAC_COCOA = WX_MAC_COCOA
...@@ -100,52 +108,10 @@ class Platform(notifier.Notifier): ...@@ -100,52 +108,10 @@ class Platform(notifier.Notifier):
self.WX_GTK = WX_GTK self.WX_GTK = WX_GTK
self.__fsldir = os.environ.get('FSLDIR', None) self.__fsldir = os.environ.get('FSLDIR', None)
self.__haveGui = False
self.__canHaveGui = False
self.__inSSHSession = False self.__inSSHSession = False
self.__wxFlavour = None
self.__wxPlatform = None
self.__glVersion = None self.__glVersion = None
self.__glRenderer = None self.__glRenderer = None
try:
import wx
self.__canHaveGui = True
if wx.GetApp() is not None:
self.__haveGui = True
except ImportError:
pass
# If we have a GUI, get some
# info about the wx platform
if self.__haveGui:
pi = [t.lower() for t in wx.PlatformInfo]
isPhoenix = False
for tag in pi:
if 'phoenix' in tag:
isPhoenix = True
break
if isPhoenix: self.__wxFlavour = WX_PHOENIX
else: self.__wxFlavour = WX_PYTHON
if any(['cocoa' in p for p in pi]): platform = WX_MAC_COCOA
elif any(['carbon' in p for p in pi]): platform = WX_MAC_CARBON
elif any(['gtk' in p for p in pi]): platform = WX_GTK
else: platform = None
self.__wxPlatform = platform
if self.__wxPlatform is None:
log.warning('Could not determine wx platform from '
'information: {}'.format(pi))
# If one of these environment # If one of these environment
# variables is set, then we're # variables is set, then we're
# probably running over SSH. # probably running over SSH.
...@@ -172,13 +138,22 @@ class Platform(notifier.Notifier): ...@@ -172,13 +138,22 @@ class Platform(notifier.Notifier):
@property @property
def haveGui(self): def haveGui(self):
"""``True`` if we are running with a GUI, ``False`` otherwise. """ """``True`` if we are running with a GUI, ``False`` otherwise. """
return self.__haveGui try:
import wx
return self.canHaveGui and wx.GetApp() is not None
except ImportError:
return False
@property @property
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. """
return self.__canHaveGui
try:
import wx
return wx.App.IsDisplayAvailable()
except ImportError:
return False
@property @property
...@@ -191,18 +166,52 @@ class Platform(notifier.Notifier): ...@@ -191,18 +166,52 @@ class Platform(notifier.Notifier):
@property @property
def wxPlatform(self): def wxPlatform(self):
"""One of :data:`WX_MAC_COCOA`, :data:`WX_MAC_CARBON`, or """One of :data:`WX_UNKNOWN`, :data:`WX_MAC_COCOA`,
:data:`WX_GTK`, indicating the wx platform. :data:`WX_MAC_CARBON`, or :data:`WX_GTK`, indicating the wx platform.
""" """
return self.__wxPlatform
if not self.haveGui:
return WX_UNKNOWN
import wx
pi = [t.lower() for t in wx.PlatformInfo]
for tag in pi:
if any(['cocoa' in p for p in pi]): platform = WX_MAC_COCOA
elif any(['carbon' in p for p in pi]): platform = WX_MAC_CARBON
elif any(['gtk' in p for p in pi]): platform = WX_GTK
else: platform = WX_UNKNOWN
if platform is WX_UNKNOWN:
log.warning('Could not determine wx platform from '
'information: {}'.format(pi))
return platform
@property @property
def wxFlavour(self): def wxFlavour(self):
"""One of :data:`WX_PYTHON` or :data:`WX_PHOENIX`, indicating the wx """One of :data:`WX_UNKNOWN`, :data:`WX_PYTHON` or :data:`WX_PHOENIX`,
flavour. indicating the wx flavour.
""" """
return self.__wxFlavour
if not self.haveGui:
return WX_UNKNOWN
import wx
pi = [t.lower() for t in wx.PlatformInfo]
isPhoenix = False
for tag in pi:
if 'phoenix' in tag:
isPhoenix = True
break
if isPhoenix: return WX_PHOENIX
else: return WX_PYTHON
@property @property
......
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