From 7ecd9f6d37955ad98f2f71030e6d5a2ff284cea2 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Mon, 1 Aug 2016 18:59:26 +0100 Subject: [PATCH] settings module uses platform module to test for WX. Also bugfix - settings.read returns any specified default value even if there is no GUI. --- fsl/utils/settings.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fsl/utils/settings.py b/fsl/utils/settings.py index 8728ae0b5..fed47ac27 100644 --- a/fsl/utils/settings.py +++ b/fsl/utils/settings.py @@ -21,6 +21,8 @@ import logging +from .platform import platform as fslplatform + log = logging.getLogger(__name__) @@ -55,11 +57,10 @@ def read(name, default=None): there is no setting called ``name``. """ - try: import wx - except: return None + if not fslplatform.haveGui: + return default - if wx.GetApp() is None: - return None + import wx config = wx.Config(_CONFIG_ID) @@ -75,12 +76,11 @@ def read(name, default=None): def write(name, value): """Writes a setting with the given ``name`` and ``value``.""" - try: import wx - except: return - - if wx.GetApp() is None: + if not fslplatform.haveGui: return + import wx + value = str(value) config = wx.Config(_CONFIG_ID) @@ -91,11 +91,11 @@ def write(name, value): def delete(name): """Delete the setting with the given ``name``. """ - try: import wx - except: return - if wx.GetApp() is None: - return + if not fslplatform.haveGui: + return + + import wx config = wx.Config(_CONFIG_ID) -- GitLab