From cc0a9444ea6bea46e965a137d66656d6576991aa Mon Sep 17 00:00:00 2001 From: dessant Date: Fri, 27 Jun 2014 07:12:56 +0300 Subject: [PATCH 1/7] Add bar_inactive_color property for ScrollView Lets the user set the color and opacity of the scroll bar, when no scroll is happening. In addition, the same values will be used, when scroll_type = ['content']. --- kivy/uix/scrollview.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/kivy/uix/scrollview.py b/kivy/uix/scrollview.py index db6fc4c2f..bec3a626e 100644 --- a/kivy/uix/scrollview.py +++ b/kivy/uix/scrollview.py @@ -294,6 +294,16 @@ class ScrollView(StencilView): to [.7, .7, .7, .9]. ''' + bar_inactive_color = ListProperty([.7, .7, .7, .2]) + '''Color of horizontal / vertical scroll bar (in RGBA format), when no + scroll is happening. + + .. versionadded:: 1.8.1 + + :attr:`bar_inactive_color` is a + :class:`~kivy.properties.ListProperty` and defaults to [.7, .7, .7, .2]. + ''' + bar_width = NumericProperty('2dp') '''Width of the horizontal / vertical scroll bar. The width is interpreted as a height for the horizontal bar. @@ -396,7 +406,7 @@ class ScrollView(StencilView): # private, for internal use only _viewport = ObjectProperty(None, allownone=True) - bar_alpha = NumericProperty(1.) + _bar_color = ListProperty([0, 0, 0, 0]) def _set_viewport_size(self, instance, value): self.viewport_size = value @@ -793,18 +803,16 @@ class ScrollView(StencilView): vp.pos = 0, 0 self.g_translate.xy = x, y - # new in 1.2.0, show bar when scrolling happen - # and slowly remove them when no scroll is happening. - self.bar_alpha = 1. - Animation.stop_all(self, 'bar_alpha') - Clock.unschedule(self._start_decrease_alpha) - Clock.schedule_once(self._start_decrease_alpha, .5) + # New in 1.2.0, show bar when scrolling happens and (changed in 1.8.1) + # fade to bar_inactive_color when no scroll is happening. + self._bar_color = self.bar_color + Animation.stop_all(self, '_bar_color') + Clock.unschedule(self._change_bar_color) + Clock.schedule_once(self._change_bar_color, .5) - def _start_decrease_alpha(self, *l): - self.bar_alpha = 1. - # show bars if scroll_type != content - bar_alpha = .2 if self.scroll_type != ['content'] else 0 - Animation(bar_alpha=bar_alpha, d=.5, t='out_quart').start(self) + def _change_bar_color(self, *l): + bar_color = self.bar_inactive_color + Animation(_bar_color=bar_color, d=.5, t='out_quart').start(self) # # Private From 6daa28eb51e1e7e1fc0d77449a1ea81febcdb49c Mon Sep 17 00:00:00 2001 From: dessant Date: Fri, 27 Jun 2014 07:14:43 +0300 Subject: [PATCH 2/7] update ScrollView kv definition --- kivy/data/style.kv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kivy/data/style.kv b/kivy/data/style.kv index f0eca72e8..9f3049424 100644 --- a/kivy/data/style.kv +++ b/kivy/data/style.kv @@ -914,12 +914,12 @@ : canvas.after: Color: - rgba: self.bar_color[:3] + [self.bar_color[3] * self.bar_alpha if (self.do_scroll_y and self.viewport_size[1]>self.height) else 0] + rgba: self._bar_color if (self.do_scroll_y and self.viewport_size[1]>self.height) else [0, 0, 0, 0] Rectangle: pos: (self.right - self.bar_width - self.bar_margin) if self.bar_pos_y == 'right' else (self.x + self.bar_margin), self.y + self.height * self.vbar[0] size: min(self.bar_width, self.width), self.height * self.vbar[1] Color: - rgba: self.bar_color[:3] + [self.bar_color[3] * self.bar_alpha if (self.do_scroll_x and self.viewport_size[0] > self.width) else 0] + rgba: self._bar_color if (self.do_scroll_x and self.viewport_size[0] > self.width) else [0, 0, 0, 0] Rectangle: pos: self.x + self.width * self.hbar[0], (self.y + self.bar_margin) if self.bar_pos_x == 'bottom' else (self.top - self.bar_margin - self.bar_width) size: self.width * self.hbar[1], min(self.bar_width, self.height) From 0ee003b24c0e40248e1d5fe618d0130ef5bb575a Mon Sep 17 00:00:00 2001 From: dessant Date: Sun, 29 Jun 2014 17:43:50 +0300 Subject: [PATCH 3/7] pep8 fix --- kivy/data/style.kv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kivy/data/style.kv b/kivy/data/style.kv index 9f3049424..c0f51af08 100644 --- a/kivy/data/style.kv +++ b/kivy/data/style.kv @@ -914,7 +914,7 @@ : canvas.after: Color: - rgba: self._bar_color if (self.do_scroll_y and self.viewport_size[1]>self.height) else [0, 0, 0, 0] + rgba: self._bar_color if (self.do_scroll_y and self.viewport_size[1] > self.height) else [0, 0, 0, 0] Rectangle: pos: (self.right - self.bar_width - self.bar_margin) if self.bar_pos_y == 'right' else (self.x + self.bar_margin), self.y + self.height * self.vbar[0] size: min(self.bar_width, self.width), self.height * self.vbar[1] From cb26d1f451088779d8507e488fb4362eb3166190 Mon Sep 17 00:00:00 2001 From: dessant Date: Sun, 29 Jun 2014 18:17:10 +0300 Subject: [PATCH 4/7] bind bar_color and bar_inactive_color to their respective states --- kivy/uix/scrollview.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/kivy/uix/scrollview.py b/kivy/uix/scrollview.py index bec3a626e..2449903a3 100644 --- a/kivy/uix/scrollview.py +++ b/kivy/uix/scrollview.py @@ -805,14 +805,21 @@ class ScrollView(StencilView): # New in 1.2.0, show bar when scrolling happens and (changed in 1.8.1) # fade to bar_inactive_color when no scroll is happening. + self.unbind(bar_inactive_color=self.change_bar_color) + self.bind(bar_color=self.change_bar_color) self._bar_color = self.bar_color + Clock.unschedule(self._trigger_inactive_color) Animation.stop_all(self, '_bar_color') - Clock.unschedule(self._change_bar_color) - Clock.schedule_once(self._change_bar_color, .5) + Clock.schedule_once(self._trigger_inactive_color, .5) - def _change_bar_color(self, *l): - bar_color = self.bar_inactive_color - Animation(_bar_color=bar_color, d=.5, t='out_quart').start(self) + def _bind_inactive_bar_color(self, *l): + self.unbind(bar_color=self.change_bar_color) + self.bind(bar_inactive_color=self.change_bar_color) + Animation( + _bar_color=self.bar_inactive_color, d=.5, t='out_quart').start(self) + + def _change_bar_color(self, inst, value): + self._bar_color = value # # Private From 448bc1cb3412854f7ec3316172d0edea71caf209 Mon Sep 17 00:00:00 2001 From: dessant Date: Sun, 29 Jun 2014 18:23:08 +0300 Subject: [PATCH 5/7] fix method name --- kivy/uix/scrollview.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kivy/uix/scrollview.py b/kivy/uix/scrollview.py index 2449903a3..a91be1b17 100644 --- a/kivy/uix/scrollview.py +++ b/kivy/uix/scrollview.py @@ -808,9 +808,9 @@ class ScrollView(StencilView): self.unbind(bar_inactive_color=self.change_bar_color) self.bind(bar_color=self.change_bar_color) self._bar_color = self.bar_color - Clock.unschedule(self._trigger_inactive_color) + Clock.unschedule(self._bind_inactive_bar_color) Animation.stop_all(self, '_bar_color') - Clock.schedule_once(self._trigger_inactive_color, .5) + Clock.schedule_once(self._bind_inactive_bar_color, .5) def _bind_inactive_bar_color(self, *l): self.unbind(bar_color=self.change_bar_color) From ebc2ce8c77756a2be8ece70109c0ae5e9ff19735 Mon Sep 17 00:00:00 2001 From: dessant Date: Sun, 29 Jun 2014 18:27:24 +0300 Subject: [PATCH 6/7] fix binded method name --- kivy/uix/scrollview.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kivy/uix/scrollview.py b/kivy/uix/scrollview.py index a91be1b17..2a2846928 100644 --- a/kivy/uix/scrollview.py +++ b/kivy/uix/scrollview.py @@ -805,16 +805,16 @@ class ScrollView(StencilView): # New in 1.2.0, show bar when scrolling happens and (changed in 1.8.1) # fade to bar_inactive_color when no scroll is happening. - self.unbind(bar_inactive_color=self.change_bar_color) - self.bind(bar_color=self.change_bar_color) + self.unbind(bar_inactive_color=self._change_bar_color) + self.bind(bar_color=self._change_bar_color) self._bar_color = self.bar_color Clock.unschedule(self._bind_inactive_bar_color) Animation.stop_all(self, '_bar_color') Clock.schedule_once(self._bind_inactive_bar_color, .5) def _bind_inactive_bar_color(self, *l): - self.unbind(bar_color=self.change_bar_color) - self.bind(bar_inactive_color=self.change_bar_color) + self.unbind(bar_color=self._change_bar_color) + self.bind(bar_inactive_color=self._change_bar_color) Animation( _bar_color=self.bar_inactive_color, d=.5, t='out_quart').start(self) From 724ffcf3870d1681c5e6d4c511b7b1039ca963bf Mon Sep 17 00:00:00 2001 From: dessant Date: Mon, 30 Jun 2014 20:22:15 +0300 Subject: [PATCH 7/7] unschedule bar color change before unbinding --- kivy/uix/scrollview.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kivy/uix/scrollview.py b/kivy/uix/scrollview.py index 2a2846928..37994a533 100644 --- a/kivy/uix/scrollview.py +++ b/kivy/uix/scrollview.py @@ -805,11 +805,11 @@ class ScrollView(StencilView): # New in 1.2.0, show bar when scrolling happens and (changed in 1.8.1) # fade to bar_inactive_color when no scroll is happening. + Clock.unschedule(self._bind_inactive_bar_color) self.unbind(bar_inactive_color=self._change_bar_color) + Animation.stop_all(self, '_bar_color') self.bind(bar_color=self._change_bar_color) self._bar_color = self.bar_color - Clock.unschedule(self._bind_inactive_bar_color) - Animation.stop_all(self, '_bar_color') Clock.schedule_once(self._bind_inactive_bar_color, .5) def _bind_inactive_bar_color(self, *l):