diff --git a/core/decorators.py b/core/decorators.py index 98b2ed9..e7b3b82 100644 --- a/core/decorators.py +++ b/core/decorators.py @@ -11,26 +11,27 @@ def scrollable(func): if width < 0 or len(text) <= width: return text + start = widget.get('scrolling.start', 0) bounce = util.format.asbool(module.parameter('scrolling.bounce', True)) scroll_speed = util.format.asint(module.parameter('scrolling.speed', 1)) - start = widget.get('scrolling.start', 0) - - if start + width > len(text): - if bounce: - widget.set('scrolling.direction', 'left') - start -= scroll_speed*2 - else: - start = 0 - elif start < 0: - if bounce: - widget.set('scrolling.direction', 'right') direction = widget.get('scrolling.direction', 'right') + if direction == 'left': scroll_speed = -scroll_speed - widget.set('scrolling.start', start + scroll_speed) - text = text[start:width+start] + if start + scroll_speed <= 0: # bounce back + widget.set('scrolling.direction', 'right') - return text + next_start = start + scroll_speed + if next_start + width > len(text): + if not bounce: + next_start = 0 + else: + next_start = start - scroll_speed + widget.set('scrolling.direction', 'left') + + widget.set('scrolling.start', next_start) + + return text[start:start+width] return wrapper # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/core/test_decorators.py b/tests/core/test_decorators.py index ddbce8a..8ce115f 100644 --- a/tests/core/test_decorators.py +++ b/tests/core/test_decorators.py @@ -44,6 +44,10 @@ class config(unittest.TestCase): self.assertEqual('cd', self.module.get(self.widget)) self.assertEqual('bc', self.module.get(self.widget)) self.assertEqual('ab', self.module.get(self.widget)) + self.assertEqual('bc', self.module.get(self.widget)) + self.assertEqual('cd', self.module.get(self.widget)) + self.assertEqual('bc', self.module.get(self.widget)) + self.assertEqual('ab', self.module.get(self.widget)) def test_nobounce(self): self.module.set('scrolling.bounce', False) @@ -53,5 +57,7 @@ class config(unittest.TestCase): self.assertEqual('bc', self.module.get(self.widget)) self.assertEqual('cd', self.module.get(self.widget)) self.assertEqual('ab', self.module.get(self.widget)) + self.assertEqual('bc', self.module.get(self.widget)) + self.assertEqual('cd', self.module.get(self.widget)) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4