Browse Source

wxGUI/animation: fix case when there is only one map

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58190 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 11 years ago
parent
commit
0051ba3232
2 changed files with 15 additions and 5 deletions
  1. 5 3
      gui/wxpython/animation/anim.py
  2. 10 2
      gui/wxpython/animation/frame.py

+ 5 - 3
gui/wxpython/animation/anim.py

@@ -51,6 +51,8 @@ class Animation(wx.EvtHandler):
 
     def GetFrame(self, index):
         """!Returns animation frame"""
+        if len(self.frames) <= 1:  # special case handling (only 1 map)
+            return self.frames[0]
         return self.frames[index]
 
     def GetCount(self):
@@ -100,7 +102,7 @@ class Animation(wx.EvtHandler):
         if not self.IsActive():
             return
         self.currentIndex = 0
-        self.callbackEndAnimation(self.currentIndex, self.frames[self.currentIndex])
+        self.callbackEndAnimation(self.currentIndex, self.GetFrame(self.currentIndex))
 
     def _arrivedToEnd(self):
         """!Decides which action to do after animation end (stop, repeat)."""
@@ -129,7 +131,7 @@ class Animation(wx.EvtHandler):
         if not self.IsActive():
             return
 
-        self.callbackUpdateFrame(self.currentIndex, self.frames[self.currentIndex])
+        self.callbackUpdateFrame(self.currentIndex, self.GetFrame(self.currentIndex))
         if self.orientation == Orientation.FORWARD:
             self.currentIndex += 1
             if self.currentIndex == self.count:
@@ -144,7 +146,7 @@ class Animation(wx.EvtHandler):
         if not self.IsActive():
             return
         self.currentIndex = index
-        self.callbackUpdateFrame(self.currentIndex, self.frames[self.currentIndex])
+        self.callbackUpdateFrame(self.currentIndex, self.GetFrame(self.currentIndex))
 
     def PreviousFrameIndex(self):
         if not self.IsActive():

+ 10 - 2
gui/wxpython/animation/frame.py

@@ -347,6 +347,8 @@ class AnimationSliderBase(wx.Panel):
         self.callbackFrameIndexChanged = callback
 
     def EnableSlider(self, enable = True):
+        if enable and self.framesCount <= 1:
+            enable = False  # we don't want to enable it
         self.enable = enable
         self.slider.Enable(enable)
         self.indexField.Enable(enable)
@@ -401,7 +403,10 @@ class SimpleAnimationSlider(AnimationSliderBase):
 
     def _setFrames(self, count):
         self.framesCount = count
-        self.slider.SetRange(0, self.framesCount - 1)
+        if self.framesCount > 1:
+            self.slider.SetRange(0, self.framesCount - 1)
+        else:
+            self.EnableSlider(False)
         self._setLabel()
 
     def _setLabel(self):
@@ -460,7 +465,10 @@ class TimeAnimationSlider(AnimationSliderBase):
     def _setFrames(self, timeLabels):
         self.timeLabels = timeLabels
         self.framesCount = len(timeLabels)
-        self.slider.SetRange(0, self.framesCount - 1)
+        if self.framesCount > 1:
+            self.slider.SetRange(0, self.framesCount - 1)
+        else:
+            self.EnableSlider(False)
         self._setLabel()
         # TODO: fix setting index values, until then:
         self.indexField.Disable()