From 097dff7d8eea922fafd04a2b36a7ba6a62fea022 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Wed, 18 Mar 2015 11:54:12 +0000
Subject: [PATCH] Atlas functions return None if ATLAS_DIR is not available.
 ImageSelectPanel works if image list is empty

---
 fsl/data/atlases.py                      | 8 ++++++++
 fsl/fslview/controls/imageselectpanel.py | 8 +++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/fsl/data/atlases.py b/fsl/data/atlases.py
index 41e7e0905..32e633f7e 100644
--- a/fsl/data/atlases.py
+++ b/fsl/data/atlases.py
@@ -84,6 +84,8 @@ def listAtlases(refresh=False):
                   :attr:`ATLAS_DESCRIPTIONS`).
     """
 
+    if ATLAS_DIR is None:
+        return []
 
     if len(ATLAS_DESCRIPTIONS) == 0:
         refresh = True
@@ -109,6 +111,9 @@ def getAtlasDescription(atlasID):
     """Returns an :class:`AtlasDescription` instance describing the
     atlas with the given ``atlasID``.
     """
+
+    if ATLAS_DIR is None:
+        return None
     
     if len(ATLAS_DESCRIPTIONS) == 0:
         listAtlases()
@@ -124,6 +129,9 @@ def loadAtlas(atlasID, loadSummary=False):
                       loaded. Otherwise, if the atlas is probabilistic,
                       a 4D :class:`ProbabilisticAtlas` image is loaded.
     """
+
+    if ATLAS_DIR is None:
+        return None
     
     if len(ATLAS_DESCRIPTIONS) == 0:
         listAtlases()
diff --git a/fsl/fslview/controls/imageselectpanel.py b/fsl/fslview/controls/imageselectpanel.py
index 4d0793b2c..4ba65e62f 100644
--- a/fsl/fslview/controls/imageselectpanel.py
+++ b/fsl/fslview/controls/imageselectpanel.py
@@ -163,11 +163,13 @@ class ImageSelectPanel(fslpanel.FSLViewPanel):
 
         allImages = self._displayCtx.getOrderedImages()
         image     = self._displayCtx.getSelectedImage()
-        idx       = allImages.index(image)
         nimgs     = len(allImages)
+        
+        if nimgs > 0: idx = allImages.index(image)
+        else:         idx = -1
 
-        self._prevButton.Enable(nimgs > 0 and idx != 0)
-        self._nextButton.Enable(nimgs > 0 and idx != nimgs - 1)
+        self._prevButton.Enable(nimgs > 0 and idx > 0)
+        self._nextButton.Enable(nimgs > 0 and idx < nimgs - 1)
 
         if self._imageLabel is None:
             return
-- 
GitLab