From 466e5cf3b88a8d2d4c8b90665f7a9c1a6d4a35be Mon Sep 17 00:00:00 2001 From: Legikaloz Date: Thu, 2 Aug 2012 14:56:16 +0200 Subject: [PATCH 01/21] Step property to use slider with fixed intervals --- kivy/uix/slider.py | 363 +++++++++++++++++++++++---------------------- 1 file changed, 188 insertions(+), 175 deletions(-) diff --git a/kivy/uix/slider.py b/kivy/uix/slider.py index 90e31f660..0040e2f2e 100644 --- a/kivy/uix/slider.py +++ b/kivy/uix/slider.py @@ -1,175 +1,188 @@ -''' -Slider -====== - -.. image:: images/slider.jpg - -The :class:`Slider` widget looks like a scrollbar. It supports horizontal and -vertical orientation, min/max and a default value. - -To create a slider from -100 to 100 starting at 25:: - - from kivy.uix.slider import Slider - s = Slider(min=-100, max=100, value=25) - -To create a vertical slider:: - - from kivy.uix.slider import Slider - s = Slider(orientation='vertical') - -''' -__all__ = ('Slider', ) - -from kivy.uix.widget import Widget -from kivy.properties import NumericProperty, AliasProperty, OptionProperty, \ - ReferenceListProperty - - -class Slider(Widget): - '''Class for creating Slider widget. - - Check module documentation for more details. - ''' - - value = NumericProperty(0.) - '''Current value used for the slider. - - :data:`value` is a :class:`~kivy.properties.NumericProperty`, default to 0. - ''' - - min = NumericProperty(0.) - '''Minimum value allowed for :data:`value`. - - :data:`min` is a :class:`~kivy.properties.NumericProperty`, default to 0. - ''' - - max = NumericProperty(100.) - '''Maximum value allowed for :data:`value`. - - :data:`max` is a :class:`~kivy.properties.NumericProperty`, default to 100. - ''' - - padding = NumericProperty(10) - '''Padding of the slider. The padding is used for graphical representation - and interaction. It prevents the cursor from going out of the bounds of the slider - bounding box. - - By default, padding is 10. The range of the slider is reduced from padding * - 2 on the screen. It allows drawing a cursor of 20px width, without having the - cursor going out of the widget. - - :data:`padding` is a :class:`~kivy.properties.NumericProperty`, default to - 10. - ''' - - orientation = OptionProperty('horizontal', options=( - 'vertical', 'horizontal')) - '''Orientation of the slider. - - :data:`orientation` is an :class:`~kivy.properties.OptionProperty`, default - to 'horizontal'. Can take a value of 'vertical' or 'horizontal'. - ''' - - range = ReferenceListProperty(min, max) - '''Range of the slider, in the format (minimum value, maximum value):: - - >>> slider = Slider(min=10, max=80) - >>> slider.range - [10, 80] - >>> slider.range = (20, 100) - >>> slider.min - 20 - >>> slider.max - 100 - - :data:`range` is a :class:`~kivy.properties.ReferenceListProperty` of - (:data:`min`, :data:`max`) - ''' - - def get_norm_value(self): - vmin = self.min - d = self.max - vmin - if d == 0: - return 0 - return (self.value - vmin) / float(d) - - def set_norm_value(self, value): - vmin = self.min - self.value = value * (self.max - vmin) + vmin - value_normalized = AliasProperty(get_norm_value, set_norm_value, - bind=('value', 'min', 'max')) - '''Normalized value inside the :data:`range` (min/max) to 0-1 range:: - - >>> slider = Slider(value=50, min=0, max=100) - >>> slider.value - 50 - >>> slider.value_normalized - 0.5 - >>> slider.value = 0 - >>> slider.value_normalized - 0 - >>> slider.value = 1 - >>> slider.value_normalized - 1 - - You can also use it for setting the real value without knowing the minimum - and maximum:: - - >>> slider = Slider(min=0, max=200) - >>> slider.value_normalized = .5 - >>> slider.value - 100 - >>> slider.value_normalized = 1. - >>> slider.value - 200 - - :data:`value_normalized` is an :class:`~kivy.properties.AliasProperty`. - ''' - - def get_value_pos(self): - padding = self.padding - x = self.x - y = self.y - nval = self.value_normalized - if self.orientation == 'horizontal': - return (x + padding + nval * (self.width - 2 * padding), y) - else: - return (x, y + padding + nval * (self.height - 2 * padding)) - - def set_value_pos(self, pos): - x = min(self.right, max(pos[0], self.x)) - y = min(self.top, max(pos[1], self.y)) - if self.orientation == 'horizontal': - if self.width == 0: - self.value_normalized = 0 - else: - self.value_normalized = (x - self.x) / float(self.width) - else: - if self.height == 0: - self.value_normalized = 0 - else: - self.value_normalized = (y - self.y) / float(self.height) - value_pos = AliasProperty(get_value_pos, set_value_pos, - bind=('x', 'y', 'width', 'height', 'min', - 'max', 'value_normalized', 'orientation')) - '''Position of the internal cursor, based on the normalized value. - - :data:`value_pos` is an :class:`~kivy.properties.AliasProperty`. - ''' - - def on_touch_down(self, touch): - if self.collide_point(*touch.pos): - touch.grab(self) - self.value_pos = touch.pos - return True - - def on_touch_move(self, touch): - if touch.grab_current == self: - self.value_pos = touch.pos - return True - - def on_touch_up(self, touch): - if touch.grab_current == self: - self.value_pos = touch.pos - return True - +''' +Slider +====== + +.. image:: images/slider.jpg + +The :class:`Slider` widget looks like a scrollbar. It supports horizontal and +vertical orientation, min/max and a default value. + +To create a slider from -100 to 100 starting at 25:: + + from kivy.uix.slider import Slider + s = Slider(min=-100, max=100, value=25) + +To create a vertical slider:: + + from kivy.uix.slider import Slider + s = Slider(orientation='vertical') + +''' +__all__ = ('Slider', ) + +from kivy.uix.widget import Widget +from kivy.properties import NumericProperty, AliasProperty, OptionProperty, \ + ReferenceListProperty + + +class Slider(Widget): + '''Class for creating Slider widget. + + Check module documentation for more details. + ''' + + value = NumericProperty(0.) + '''Current value used for the slider. + + :data:`value` is a :class:`~kivy.properties.NumericProperty`, default to 0. + ''' + + min = NumericProperty(0.) + '''Minimum value allowed for :data:`value`. + + :data:`min` is a :class:`~kivy.properties.NumericProperty`, default to 0. + ''' + + max = NumericProperty(100.) + '''Maximum value allowed for :data:`value`. + + :data:`max` is a :class:`~kivy.properties.NumericProperty`, default to 100. + ''' + + padding = NumericProperty(10) + '''Padding of the slider. The padding is used for graphical representation + and interaction. It prevents the cursor from going out of the bounds of the slider + bounding box. + + By default, padding is 10. The range of the slider is reduced from padding * + 2 on the screen. It allows drawing a cursor of 20px width, without having the + cursor going out of the widget. + + :data:`padding` is a :class:`~kivy.properties.NumericProperty`, default to + 10. + ''' + + orientation = OptionProperty('horizontal', options=( + 'vertical', 'horizontal')) + '''Orientation of the slider. + + :data:`orientation` is an :class:`~kivy.properties.OptionProperty`, default + to 'horizontal'. Can take a value of 'vertical' or 'horizontal'. + ''' + + range = ReferenceListProperty(min, max) + '''Range of the slider, in the format (minimum value, maximum value):: + + >>> slider = Slider(min=10, max=80) + >>> slider.range + [10, 80] + >>> slider.range = (20, 100) + >>> slider.min + 20 + >>> slider.max + 100 + + :data:`range` is a :class:`~kivy.properties.ReferenceListProperty` of + (:data:`min`, :data:`max`) + ''' + + step = NumericProperty(1) + '''Step size of the slider + Determines the size of each interval or step the slider takes between + min and max. If the value range can't be evenly divisible by step the + last step will be capped by slider.max + :data:`step` is a :class:`~kivy.properties.NumericProperty`, default to + 1. + ''' + + def get_norm_value(self): + vmin = self.min + d = self.max - vmin + if d == 0: + return 0 + return (self.value - vmin) / float(d) + + def set_norm_value(self, value): + vmin = self.min + val = value * (self.max - vmin) + vmin + if self.step == 1: + self.value = val + else: + self.value = min(round((val-vmin)/self.step)*self.step,self.max) # value aligned to step or self.max + value_normalized = AliasProperty(get_norm_value, set_norm_value, + bind=('value', 'min', 'max')) + '''Normalized value inside the :data:`range` (min/max) to 0-1 range:: + + >>> slider = Slider(value=50, min=0, max=100) + >>> slider.value + 50 + >>> slider.value_normalized + 0.5 + >>> slider.value = 0 + >>> slider.value_normalized + 0 + >>> slider.value = 1 + >>> slider.value_normalized + 1 + + You can also use it for setting the real value without knowing the minimum + and maximum:: + + >>> slider = Slider(min=0, max=200) + >>> slider.value_normalized = .5 + >>> slider.value + 100 + >>> slider.value_normalized = 1. + >>> slider.value + 200 + + :data:`value_normalized` is an :class:`~kivy.properties.AliasProperty`. + ''' + + def get_value_pos(self): + padding = self.padding + x = self.x + y = self.y + nval = self.value_normalized + if self.orientation == 'horizontal': + return (x + padding + nval * (self.width - 2 * padding), y) + else: + return (x, y + padding + nval * (self.height - 2 * padding)) + + def set_value_pos(self, pos): + x = min(self.right, max(pos[0], self.x)) + y = min(self.top, max(pos[1], self.y)) + if self.orientation == 'horizontal': + if self.width == 0: + self.value_normalized = 0 + else: + self.value_normalized = (x - self.x) / float(self.width) + else: + if self.height == 0: + self.value_normalized = 0 + else: + self.value_normalized = (y - self.y) / float(self.height) + value_pos = AliasProperty(get_value_pos, set_value_pos, + bind=('x', 'y', 'width', 'height', 'min', + 'max', 'value_normalized', 'orientation')) + '''Position of the internal cursor, based on the normalized value. + + :data:`value_pos` is an :class:`~kivy.properties.AliasProperty`. + ''' + + def on_touch_down(self, touch): + if self.collide_point(*touch.pos): + touch.grab(self) + self.value_pos = touch.pos + return True + + def on_touch_move(self, touch): + if touch.grab_current == self: + self.value_pos = touch.pos + return True + + def on_touch_up(self, touch): + if touch.grab_current == self: + self.value_pos = touch.pos + return True + From 094d9f97eae7d35ac6b7937b8224a7239d1a13fd Mon Sep 17 00:00:00 2001 From: Legikaloz Date: Thu, 2 Aug 2012 15:03:11 +0200 Subject: [PATCH 02/21] Revert "Step property to use slider with fixed intervals" This reverts commit 466e5cf3b88a8d2d4c8b90665f7a9c1a6d4a35be. --- kivy/uix/slider.py | 363 ++++++++++++++++++++++----------------------- 1 file changed, 175 insertions(+), 188 deletions(-) diff --git a/kivy/uix/slider.py b/kivy/uix/slider.py index 0040e2f2e..90e31f660 100644 --- a/kivy/uix/slider.py +++ b/kivy/uix/slider.py @@ -1,188 +1,175 @@ -''' -Slider -====== - -.. image:: images/slider.jpg - -The :class:`Slider` widget looks like a scrollbar. It supports horizontal and -vertical orientation, min/max and a default value. - -To create a slider from -100 to 100 starting at 25:: - - from kivy.uix.slider import Slider - s = Slider(min=-100, max=100, value=25) - -To create a vertical slider:: - - from kivy.uix.slider import Slider - s = Slider(orientation='vertical') - -''' -__all__ = ('Slider', ) - -from kivy.uix.widget import Widget -from kivy.properties import NumericProperty, AliasProperty, OptionProperty, \ - ReferenceListProperty - - -class Slider(Widget): - '''Class for creating Slider widget. - - Check module documentation for more details. - ''' - - value = NumericProperty(0.) - '''Current value used for the slider. - - :data:`value` is a :class:`~kivy.properties.NumericProperty`, default to 0. - ''' - - min = NumericProperty(0.) - '''Minimum value allowed for :data:`value`. - - :data:`min` is a :class:`~kivy.properties.NumericProperty`, default to 0. - ''' - - max = NumericProperty(100.) - '''Maximum value allowed for :data:`value`. - - :data:`max` is a :class:`~kivy.properties.NumericProperty`, default to 100. - ''' - - padding = NumericProperty(10) - '''Padding of the slider. The padding is used for graphical representation - and interaction. It prevents the cursor from going out of the bounds of the slider - bounding box. - - By default, padding is 10. The range of the slider is reduced from padding * - 2 on the screen. It allows drawing a cursor of 20px width, without having the - cursor going out of the widget. - - :data:`padding` is a :class:`~kivy.properties.NumericProperty`, default to - 10. - ''' - - orientation = OptionProperty('horizontal', options=( - 'vertical', 'horizontal')) - '''Orientation of the slider. - - :data:`orientation` is an :class:`~kivy.properties.OptionProperty`, default - to 'horizontal'. Can take a value of 'vertical' or 'horizontal'. - ''' - - range = ReferenceListProperty(min, max) - '''Range of the slider, in the format (minimum value, maximum value):: - - >>> slider = Slider(min=10, max=80) - >>> slider.range - [10, 80] - >>> slider.range = (20, 100) - >>> slider.min - 20 - >>> slider.max - 100 - - :data:`range` is a :class:`~kivy.properties.ReferenceListProperty` of - (:data:`min`, :data:`max`) - ''' - - step = NumericProperty(1) - '''Step size of the slider - Determines the size of each interval or step the slider takes between - min and max. If the value range can't be evenly divisible by step the - last step will be capped by slider.max - :data:`step` is a :class:`~kivy.properties.NumericProperty`, default to - 1. - ''' - - def get_norm_value(self): - vmin = self.min - d = self.max - vmin - if d == 0: - return 0 - return (self.value - vmin) / float(d) - - def set_norm_value(self, value): - vmin = self.min - val = value * (self.max - vmin) + vmin - if self.step == 1: - self.value = val - else: - self.value = min(round((val-vmin)/self.step)*self.step,self.max) # value aligned to step or self.max - value_normalized = AliasProperty(get_norm_value, set_norm_value, - bind=('value', 'min', 'max')) - '''Normalized value inside the :data:`range` (min/max) to 0-1 range:: - - >>> slider = Slider(value=50, min=0, max=100) - >>> slider.value - 50 - >>> slider.value_normalized - 0.5 - >>> slider.value = 0 - >>> slider.value_normalized - 0 - >>> slider.value = 1 - >>> slider.value_normalized - 1 - - You can also use it for setting the real value without knowing the minimum - and maximum:: - - >>> slider = Slider(min=0, max=200) - >>> slider.value_normalized = .5 - >>> slider.value - 100 - >>> slider.value_normalized = 1. - >>> slider.value - 200 - - :data:`value_normalized` is an :class:`~kivy.properties.AliasProperty`. - ''' - - def get_value_pos(self): - padding = self.padding - x = self.x - y = self.y - nval = self.value_normalized - if self.orientation == 'horizontal': - return (x + padding + nval * (self.width - 2 * padding), y) - else: - return (x, y + padding + nval * (self.height - 2 * padding)) - - def set_value_pos(self, pos): - x = min(self.right, max(pos[0], self.x)) - y = min(self.top, max(pos[1], self.y)) - if self.orientation == 'horizontal': - if self.width == 0: - self.value_normalized = 0 - else: - self.value_normalized = (x - self.x) / float(self.width) - else: - if self.height == 0: - self.value_normalized = 0 - else: - self.value_normalized = (y - self.y) / float(self.height) - value_pos = AliasProperty(get_value_pos, set_value_pos, - bind=('x', 'y', 'width', 'height', 'min', - 'max', 'value_normalized', 'orientation')) - '''Position of the internal cursor, based on the normalized value. - - :data:`value_pos` is an :class:`~kivy.properties.AliasProperty`. - ''' - - def on_touch_down(self, touch): - if self.collide_point(*touch.pos): - touch.grab(self) - self.value_pos = touch.pos - return True - - def on_touch_move(self, touch): - if touch.grab_current == self: - self.value_pos = touch.pos - return True - - def on_touch_up(self, touch): - if touch.grab_current == self: - self.value_pos = touch.pos - return True - +''' +Slider +====== + +.. image:: images/slider.jpg + +The :class:`Slider` widget looks like a scrollbar. It supports horizontal and +vertical orientation, min/max and a default value. + +To create a slider from -100 to 100 starting at 25:: + + from kivy.uix.slider import Slider + s = Slider(min=-100, max=100, value=25) + +To create a vertical slider:: + + from kivy.uix.slider import Slider + s = Slider(orientation='vertical') + +''' +__all__ = ('Slider', ) + +from kivy.uix.widget import Widget +from kivy.properties import NumericProperty, AliasProperty, OptionProperty, \ + ReferenceListProperty + + +class Slider(Widget): + '''Class for creating Slider widget. + + Check module documentation for more details. + ''' + + value = NumericProperty(0.) + '''Current value used for the slider. + + :data:`value` is a :class:`~kivy.properties.NumericProperty`, default to 0. + ''' + + min = NumericProperty(0.) + '''Minimum value allowed for :data:`value`. + + :data:`min` is a :class:`~kivy.properties.NumericProperty`, default to 0. + ''' + + max = NumericProperty(100.) + '''Maximum value allowed for :data:`value`. + + :data:`max` is a :class:`~kivy.properties.NumericProperty`, default to 100. + ''' + + padding = NumericProperty(10) + '''Padding of the slider. The padding is used for graphical representation + and interaction. It prevents the cursor from going out of the bounds of the slider + bounding box. + + By default, padding is 10. The range of the slider is reduced from padding * + 2 on the screen. It allows drawing a cursor of 20px width, without having the + cursor going out of the widget. + + :data:`padding` is a :class:`~kivy.properties.NumericProperty`, default to + 10. + ''' + + orientation = OptionProperty('horizontal', options=( + 'vertical', 'horizontal')) + '''Orientation of the slider. + + :data:`orientation` is an :class:`~kivy.properties.OptionProperty`, default + to 'horizontal'. Can take a value of 'vertical' or 'horizontal'. + ''' + + range = ReferenceListProperty(min, max) + '''Range of the slider, in the format (minimum value, maximum value):: + + >>> slider = Slider(min=10, max=80) + >>> slider.range + [10, 80] + >>> slider.range = (20, 100) + >>> slider.min + 20 + >>> slider.max + 100 + + :data:`range` is a :class:`~kivy.properties.ReferenceListProperty` of + (:data:`min`, :data:`max`) + ''' + + def get_norm_value(self): + vmin = self.min + d = self.max - vmin + if d == 0: + return 0 + return (self.value - vmin) / float(d) + + def set_norm_value(self, value): + vmin = self.min + self.value = value * (self.max - vmin) + vmin + value_normalized = AliasProperty(get_norm_value, set_norm_value, + bind=('value', 'min', 'max')) + '''Normalized value inside the :data:`range` (min/max) to 0-1 range:: + + >>> slider = Slider(value=50, min=0, max=100) + >>> slider.value + 50 + >>> slider.value_normalized + 0.5 + >>> slider.value = 0 + >>> slider.value_normalized + 0 + >>> slider.value = 1 + >>> slider.value_normalized + 1 + + You can also use it for setting the real value without knowing the minimum + and maximum:: + + >>> slider = Slider(min=0, max=200) + >>> slider.value_normalized = .5 + >>> slider.value + 100 + >>> slider.value_normalized = 1. + >>> slider.value + 200 + + :data:`value_normalized` is an :class:`~kivy.properties.AliasProperty`. + ''' + + def get_value_pos(self): + padding = self.padding + x = self.x + y = self.y + nval = self.value_normalized + if self.orientation == 'horizontal': + return (x + padding + nval * (self.width - 2 * padding), y) + else: + return (x, y + padding + nval * (self.height - 2 * padding)) + + def set_value_pos(self, pos): + x = min(self.right, max(pos[0], self.x)) + y = min(self.top, max(pos[1], self.y)) + if self.orientation == 'horizontal': + if self.width == 0: + self.value_normalized = 0 + else: + self.value_normalized = (x - self.x) / float(self.width) + else: + if self.height == 0: + self.value_normalized = 0 + else: + self.value_normalized = (y - self.y) / float(self.height) + value_pos = AliasProperty(get_value_pos, set_value_pos, + bind=('x', 'y', 'width', 'height', 'min', + 'max', 'value_normalized', 'orientation')) + '''Position of the internal cursor, based on the normalized value. + + :data:`value_pos` is an :class:`~kivy.properties.AliasProperty`. + ''' + + def on_touch_down(self, touch): + if self.collide_point(*touch.pos): + touch.grab(self) + self.value_pos = touch.pos + return True + + def on_touch_move(self, touch): + if touch.grab_current == self: + self.value_pos = touch.pos + return True + + def on_touch_up(self, touch): + if touch.grab_current == self: + self.value_pos = touch.pos + return True + From 4c9c1a5aac721184c7a33d2aa532e798137b5fe1 Mon Sep 17 00:00:00 2001 From: legikaloz Date: Thu, 2 Aug 2012 16:23:22 +0300 Subject: [PATCH 03/21] Step property to use slider with fixed intervals --- kivy/uix/slider.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kivy/uix/slider.py b/kivy/uix/slider.py index 90e31f660..b0d3ef7cd 100644 --- a/kivy/uix/slider.py +++ b/kivy/uix/slider.py @@ -86,6 +86,15 @@ class Slider(Widget): (:data:`min`, :data:`max`) ''' + step = NumericProperty(1) + '''Step size of the slider + Determines the size of each interval or step the slider takes between + min and max. If the value range can't be evenly divisible by step the + last step will be capped by slider.max + :data:`step` is a :class:`~kivy.properties.NumericProperty`, default to + 1. + ''' + def get_norm_value(self): vmin = self.min d = self.max - vmin @@ -95,7 +104,11 @@ class Slider(Widget): def set_norm_value(self, value): vmin = self.min - self.value = value * (self.max - vmin) + vmin + val = value * (self.max - vmin) + vmin + if self.step == 1: + self.value = val + else: + self.value = min(round((val-vmin)/self.step)*self.step,self.max) value_normalized = AliasProperty(get_norm_value, set_norm_value, bind=('value', 'min', 'max')) '''Normalized value inside the :data:`range` (min/max) to 0-1 range:: From 5ed599e63095c73c6e38c33310a985f3ac1833f5 Mon Sep 17 00:00:00 2001 From: legikaloz Date: Wed, 8 Aug 2012 23:59:52 +0300 Subject: [PATCH 04/21] Step property type and check changed --- kivy/uix/slider.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kivy/uix/slider.py b/kivy/uix/slider.py index b0d3ef7cd..1a4ff1f79 100644 --- a/kivy/uix/slider.py +++ b/kivy/uix/slider.py @@ -22,7 +22,7 @@ __all__ = ('Slider', ) from kivy.uix.widget import Widget from kivy.properties import NumericProperty, AliasProperty, OptionProperty, \ - ReferenceListProperty + ReferenceListProperty, BoundedNumericProperty class Slider(Widget): @@ -86,11 +86,14 @@ class Slider(Widget): (:data:`min`, :data:`max`) ''' - step = NumericProperty(1) + step = BoundedNumericProperty(0, min=0) '''Step size of the slider Determines the size of each interval or step the slider takes between min and max. If the value range can't be evenly divisible by step the last step will be capped by slider.max + + .. versionadded:: 1.4.0 + :data:`step` is a :class:`~kivy.properties.NumericProperty`, default to 1. ''' @@ -105,7 +108,7 @@ class Slider(Widget): def set_norm_value(self, value): vmin = self.min val = value * (self.max - vmin) + vmin - if self.step == 1: + if self.step > 0: self.value = val else: self.value = min(round((val-vmin)/self.step)*self.step,self.max) From f712354df71b6a1613829fc1a468415645d923b3 Mon Sep 17 00:00:00 2001 From: legikaloz Date: Thu, 9 Aug 2012 00:13:30 +0300 Subject: [PATCH 05/21] mistyped relation @111 --- kivy/uix/slider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kivy/uix/slider.py b/kivy/uix/slider.py index 1a4ff1f79..662470712 100644 --- a/kivy/uix/slider.py +++ b/kivy/uix/slider.py @@ -108,7 +108,7 @@ class Slider(Widget): def set_norm_value(self, value): vmin = self.min val = value * (self.max - vmin) + vmin - if self.step > 0: + if self.step == 0: self.value = val else: self.value = min(round((val-vmin)/self.step)*self.step,self.max) From 8429c706772cf835347674bced615179a648a9ef Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Thu, 23 Aug 2012 11:56:28 -0500 Subject: [PATCH 06/21] fix issue #647 uix.screenmanager: add remove_widget function to remove screens added with add_widget --- kivy/uix/screenmanager.py | 81 +++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/kivy/uix/screenmanager.py b/kivy/uix/screenmanager.py index 98edbe3d9..394104ca7 100644 --- a/kivy/uix/screenmanager.py +++ b/kivy/uix/screenmanager.py @@ -11,8 +11,8 @@ Screen Manager The screen manager is a widget dedicated to manage multiple screens on your application. The default :class:`ScreenManager` displays only one -:class:`Screen` at time, and use a :class:`TransitionBase` to switch from one to -another Screen. +:class:`Screen` at time, and use a :class:`TransitionBase` to switch from one +to another Screen. Multiple transitions are supported, based of moving the screen coordinate / scale, or even do fancy animation using custom shaders. @@ -102,9 +102,10 @@ You can easily switch to a new transition by changing the .. note:: Currently, all Shader based Transition doesn't have any anti-aliasing. This - is because we are using FBO, and don't have any logic to do supersampling on - them. This is a know issue, and working to have a transparent implementation - that will give the same result as it would be rendered on the screen. + is because we are using FBO, and don't have any logic to do supersampling + on them. This is a know issue, and working to have a transparent + implementation that will give the same result as it would be rendered on + the screen. To be more concrete, if you see sharped-text during the animation, it's normal. @@ -145,7 +146,7 @@ class Screen(RelativeLayout): :data:`name` is a :class:`~kivy.properties.StringProperty`, default to '' ''' - manager = ObjectProperty() + manager = ObjectProperty(None, allownone=True) '''Screen manager object, set when the screen is added within a manager. :data:`manager` is a :class:`~kivy.properties.ObjectProperty`, default to @@ -156,8 +157,8 @@ class Screen(RelativeLayout): '''Value that represent the completion of the current transition, if any is occuring. - If a transition is going on, whatever is the mode, the value will got from 0 - to 1. If you want to know if it's an entering or leaving animation, check + If a transition is going on, whatever is the mode, the value will got from + 0 to 1. If you want to know if it's an entering or leaving animation, check the :data:`transition_state` :data:`transition_progress` is a :class:`~kivy.properties.NumericProperty`, @@ -212,8 +213,8 @@ class TransitionBase(EventDispatcher): duration = NumericProperty(.7) '''Duration in seconds of the transition. - :class:`duration` is a :class:`~kivy.properties.NumericProperty`, default to - .7 (= 700ms) + :class:`duration` is a :class:`~kivy.properties.NumericProperty`, default + to .7 (= 700ms) ''' manager = ObjectProperty() @@ -226,8 +227,8 @@ class TransitionBase(EventDispatcher): is_active = BooleanProperty() '''Indicate if the transition is currently active - :data:`is_active` is a :class:`~kivy.properties.BooleanProperty`, default to - False, read-only. + :data:`is_active` is a :class:`~kivy.properties.BooleanProperty`, default + to False, read-only. ''' # privates @@ -299,12 +300,11 @@ class TransitionBase(EventDispatcher): class ShaderTransition(TransitionBase): - '''Transition class that use a Shader for animating the transition between 2 - screens. By default, this class doesn't any assign fragment/vertex shader. - - If you want to create your own fragment shader for transition, you need to - declare the header yourself, and include the "t", "tex_in" and "tex_out" - uniform:: + '''Transition class that use a Shader for animating the transition between + 2 screens. By default, this class doesn't any assign fragment/vertex + shader. If you want to create your own fragment shader for transition, you + need to declare the header yourself, and include the "t", "tex_in" and + "tex_out" uniform:: # Create your own transition. This is shader implement a "fading" # transition. @@ -389,8 +389,8 @@ class SlideTransition(TransitionBase): direction = OptionProperty('left', options=('left', 'right', 'up', 'down')) '''Direction of the transition. - :data:`direction` is an :class:`~kivy.properties.OptionProperty`, default to - left. Can be one of 'left', 'right', 'up' or 'down'. + :data:`direction` is an :class:`~kivy.properties.OptionProperty`, default + to left. Can be one of 'left', 'right', 'up' or 'down'. ''' def on_progress(self, progression): @@ -524,8 +524,8 @@ class ScreenManager(FloatLayout): sm.add_widget(Screen(name='first')) sm.add_widget(Screen(name='second')) - # by default, the first added screen will be showed. If you want to show - # another one, just set the current string: + # by default, the first added screen will be showed. If you want to + show # another one, just set the current string: sm.current = 'second' ''' @@ -536,15 +536,15 @@ class ScreenManager(FloatLayout): For example, if you want to change to a :class:`WipeTransition`:: - from kivy.uix.screenmanager import ScreenManager, Screen, WipeTransition + from kivy.uix.screenmanager import ScreenManager, Screen, + WipeTransition sm = ScreenManager(transition=WipeTransition()) sm.add_widget(Screen(name='first')) sm.add_widget(Screen(name='second')) - # by default, the first added screen will be showed. If you want to show - # another one, just set the current string: - sm.current = 'second' + # by default, the first added screen will be showed. If you want to + show another one, just set the current string: sm.current = 'second' ''' screens = ListProperty() @@ -598,6 +598,23 @@ class ScreenManager(FloatLayout): if self.current is None: self.current = screen.name + def remove_widget(self, *l): + screen = l[0] + if not isinstance(screen, Screen): + raise ScreenManagerException( + 'ScreenManager uses remove_widget only to remove' + + 'screens added via add_widget! use real_remove_widget.') + + if not screen in self.screens: + return + if self.current_screen == screen: + other = self.next() + if other: + self.current = other + screen.manager = None + screen.unbind(name=self._screen_name_changed) + self.screens.remove(screen) + def real_add_widget(self, *l): # ensure screen is removed from it's previous parent before adding' if l[0].parent: @@ -674,7 +691,6 @@ class ScreenManager(FloatLayout): if __name__ == '__main__': from kivy.app import App from kivy.uix.button import Button - from kivy.lang import Builder Builder.load_string(''' : canvas: @@ -701,7 +717,10 @@ if __name__ == '__main__': #d = ('left', 'up', 'down', 'right') #di = d.index(self.sm.transition.direction) #self.sm.transition.direction = d[(di + 1) % len(d)] - self.sm.current = 'test2' if self.sm.current == 'test1' else 'test1' + self.sm.current = self.sm.next() + + def remove_screen(self, *l): + self.sm.remove_widget(self.sm.get_screen('test1')) def build(self): root = FloatLayout() @@ -712,9 +731,13 @@ if __name__ == '__main__': btn = Button(size_hint=(None, None)) btn.bind(on_release=self.change_view) + + btn2 = Button(size_hint=(None, None), x=100) + btn2.bind(on_release=self.remove_screen) + root.add_widget(sm) root.add_widget(btn) + root.add_widget(btn2) return root TestApp().run() - From c3a0f48828e5b4968908e084631be308f52f7f6b Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Thu, 23 Aug 2012 12:02:49 -0500 Subject: [PATCH 07/21] fix issue #648: uix.screenmanager: dont propagate touch event sduriong transition --- kivy/uix/screenmanager.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/kivy/uix/screenmanager.py b/kivy/uix/screenmanager.py index 394104ca7..6a8933f96 100644 --- a/kivy/uix/screenmanager.py +++ b/kivy/uix/screenmanager.py @@ -224,7 +224,7 @@ class TransitionBase(EventDispatcher): None, read-only. ''' - is_active = BooleanProperty() + is_active = BooleanProperty(False) '''Indicate if the transition is currently active :data:`is_active` is a :class:`~kivy.properties.BooleanProperty`, default @@ -688,6 +688,21 @@ class ScreenManager(FloatLayout): continue child.pos = value + def on_touch_down(self, touch): + if self.transition.is_active: + return False + return super(ScreenManager, self).on_touch_down(touch) + + def on_touch_move(self, touch): + if self.transition.is_active: + return False + return super(ScreenManager, self).on_touch_move(touch) + + def on_touch_up(self, touch): + if self.transition.is_active: + return False + return super(ScreenManager, self).on_touch_up(touch) + if __name__ == '__main__': from kivy.app import App from kivy.uix.button import Button From dc70c6d359968d4bc21c66cbc4656e08ad9b91ce Mon Sep 17 00:00:00 2001 From: "Edwin Marshall (aspidites)" Date: Tue, 28 Aug 2012 01:31:23 -0400 Subject: [PATCH 08/21] - fixes issue #649, simpler alternative to pull request # 651 --- kivy/core/text/__init__.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/kivy/core/text/__init__.py b/kivy/core/text/__init__.py index 25aa8834f..157c2e793 100644 --- a/kivy/core/text/__init__.py +++ b/kivy/core/text/__init__.py @@ -396,19 +396,16 @@ class LabelBase(object): sz[1] + self.options['padding_y'] * 2 def _get_text(self): - return self._text + try: + return self._text.decode('utf8') + except AttributeError: + # python 3 support + return str(self._text) def _set_text(self, text): - if text == self._text: - return - # try to automaticly decode unicode - try: - self._text = text.decode('utf8') - except: - try: - self._text = str(text) - except: - self._text = text + if text != self._text: + self._text = text + text = property(_get_text, _set_text, doc='Get/Set the text') label = property(_get_text, _set_text, doc='Get/Set the text') From 28c543f0e900fe3dc6ef38f59b64c14247d69cee Mon Sep 17 00:00:00 2001 From: "Edwin Marshall (aspidites)" Date: Tue, 28 Aug 2012 11:17:50 -0400 Subject: [PATCH 09/21] - return text if already unicode --- kivy/core/text/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kivy/core/text/__init__.py b/kivy/core/text/__init__.py index 157c2e793..bfadf80f5 100644 --- a/kivy/core/text/__init__.py +++ b/kivy/core/text/__init__.py @@ -401,6 +401,8 @@ class LabelBase(object): except AttributeError: # python 3 support return str(self._text) + except UnicodeEncodeError: + return self._text def _set_text(self, text): if text != self._text: From 57808f435718a1948da32e7d7c1f25d241c15186 Mon Sep 17 00:00:00 2001 From: Waldo Bronchart Date: Thu, 30 Aug 2012 23:50:12 +0200 Subject: [PATCH 10/21] Fixed bug with Camera widget in .kv file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The resolution property is not initialized before _on_index() is called. So the app crashes because [-1, -1] is not a supported resolution. ... Camera:     resolution: (640, 480)     index: 0 --- kivy/uix/camera.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kivy/uix/camera.py b/kivy/uix/camera.py index 81eb5dfb9..c707a9cf1 100644 --- a/kivy/uix/camera.py +++ b/kivy/uix/camera.py @@ -96,6 +96,8 @@ class Camera(Image): self._camera = None if self.index < 0: return + if self.resolution[0] < 0 or self.resolution[1] < 0: + return self._camera = CoreCamera(index=self.index, resolution=self.resolution, stopped=True) self._camera.bind(on_load=self._camera_loaded) From 55bc83f68a5bff79d149283151fc106e3dffbf0f Mon Sep 17 00:00:00 2001 From: "Edwin Marshall (aspidites)" Date: Thu, 30 Aug 2012 22:11:24 -0400 Subject: [PATCH 11/21] - instruct user to install nose from pip, not nosetest, fixes #655 --- doc/sources/installation/installation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/sources/installation/installation.rst b/doc/sources/installation/installation.rst index 16520c864..ea975ebc4 100644 --- a/doc/sources/installation/installation.rst +++ b/doc/sources/installation/installation.rst @@ -129,7 +129,7 @@ one .) Kivy tests are based on nosetest, that you can install from your package manager or using pip : - $ pip install nosetest + $ pip install nose to run the test suite, do : From 33c48fd87b907c3bbb1396f874a81e87dc82f423 Mon Sep 17 00:00:00 2001 From: Qua-non Date: Fri, 31 Aug 2012 17:08:16 +0530 Subject: [PATCH 12/21] DOC: mention issues with adreno 200/205 based devices on Android 2.3.x in FAQ --- doc/sources/faq.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/sources/faq.rst b/doc/sources/faq.rst index e0be489c3..ad693de45 100644 --- a/doc/sources/faq.rst +++ b/doc/sources/faq.rst @@ -63,6 +63,15 @@ This message error can happen in many cases. Ensure that: In case of USB Mass Storage mode error, and if you don't want to keep unplugging the device, set the usb option to Power. +Crash on touch interaction on Android 2.3.x +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +There have been reports of crashes on Adreno 200/205 based devices. +Apps otherwise run fine but crash when interacted with/through the screen. + +These reports also mentioned the issue being resolved when moving to a ICS or +higher rom. + Is it possible to have a kiosk app on android 3.0 ? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From cb3f1f5aa483c125e5109c5c604727fbac21c84d Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Sun, 2 Sep 2012 12:53:30 +0200 Subject: [PATCH 13/21] scrollview: fix initial mousewheel scrolling. closes #645 --- kivy/uix/scrollview.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kivy/uix/scrollview.py b/kivy/uix/scrollview.py index 1e93e2ef0..8293bde23 100644 --- a/kivy/uix/scrollview.py +++ b/kivy/uix/scrollview.py @@ -106,7 +106,7 @@ class ScrollView(StencilView): def __init__(self, **kwargs): self._touch = False self._tdx = self._tdy = self._ts = self._tsn = 0 - self._scroll_y_mouse = 0 + self._scroll_y_mouse = 1 super(ScrollView, self).__init__(**kwargs) self.bind(scroll_x=self.update_from_scroll, scroll_y=self.update_from_scroll, From 1d6079925494e0cfacb3cc0e0d97675e83a26904 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Sun, 2 Sep 2012 13:08:19 +0200 Subject: [PATCH 14/21] step pr: pep8 + add it to the demo --- examples/demo/showcase/showcase.kv | 10 ++++++---- kivy/uix/slider.py | 23 ++++++++++++----------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/examples/demo/showcase/showcase.kv b/examples/demo/showcase/showcase.kv index ac6b43bd6..41f0efcc8 100644 --- a/examples/demo/showcase/showcase.kv +++ b/examples/demo/showcase/showcase.kv @@ -208,25 +208,27 @@ text: 'Sliders' Slider: - value: 33 + value: 25 size_hint_y: None height: 50 Slider: - value: 66 + value: 75 size_hint_y: None height: 50 + step: 25 BoxLayout: Slider: orientation: 'vertical' - value: 33 + value: 25 Slider: orientation: 'vertical' - value: 66 + value: 75 + step: 25 HSeparator: text: 'Progress Bar' diff --git a/kivy/uix/slider.py b/kivy/uix/slider.py index af2dd37c8..936ee0dbb 100644 --- a/kivy/uix/slider.py +++ b/kivy/uix/slider.py @@ -87,15 +87,15 @@ class Slider(Widget): ''' step = BoundedNumericProperty(0, min=0) - '''Step size of the slider - Determines the size of each interval or step the slider takes between - min and max. If the value range can't be evenly divisible by step the - last step will be capped by slider.max - + '''Step size of the slider. + .. versionadded:: 1.4.0 - - :data:`step` is a :class:`~kivy.properties.NumericProperty`, default to - 1. + + Determines the size of each interval or step the slider takes between + min and max. If the value range can't be evenly divisible by step the + last step will be capped by slider.max + + :data:`step` is a :class:`~kivy.properties.NumericProperty`, default to 1. ''' def get_norm_value(self): @@ -107,13 +107,14 @@ class Slider(Widget): def set_norm_value(self, value): vmin = self.min + step = self.step val = value * (self.max - vmin) + vmin - if self.step == 0: + if step == 0: self.value = val else: - self.value = min(round((val-vmin)/self.step)*self.step,self.max) + self.value = min(round((val - vmin) / step) * step, self.max) value_normalized = AliasProperty(get_norm_value, set_norm_value, - bind=('value', 'min', 'max')) + bind=('value', 'min', 'max', 'step')) '''Normalized value inside the :data:`range` (min/max) to 0-1 range:: >>> slider = Slider(value=50, min=0, max=100) From 6a45d09fd07335b24b162614e3cc87a7b1e5b06c Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Sun, 2 Sep 2012 13:50:42 +0200 Subject: [PATCH 15/21] typo --- kivy/core/text/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kivy/core/text/__init__.py b/kivy/core/text/__init__.py index bfadf80f5..e2dfca6fe 100644 --- a/kivy/core/text/__init__.py +++ b/kivy/core/text/__init__.py @@ -153,7 +153,7 @@ class LabelBase(object): def resolve_font_name(self): options = self.options - fontname = self.options['font_name'] + fontname = options['font_name'] fonts = self._fonts fontscache = self._fonts_cache From 8479fdbda00e35888b7ed43d22e48dcdd6ec6e10 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Sun, 2 Sep 2012 13:59:51 +0200 Subject: [PATCH 16/21] bump to 1.4.0 --- kivy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kivy/__init__.py b/kivy/__init__.py index b638db6b2..8819b75f9 100644 --- a/kivy/__init__.py +++ b/kivy/__init__.py @@ -28,7 +28,7 @@ __all__ = ( 'kivy_config_fn', 'kivy_usermodules_dir', ) -__version__ = '1.4.0-dev' +__version__ = '1.4.0' import sys import shutil From b4be8d0cac53b9acc4b36e695dd93d95a49fccd4 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Sun, 2 Sep 2012 14:00:18 +0200 Subject: [PATCH 17/21] bump to 1.4.1-dev --- kivy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kivy/__init__.py b/kivy/__init__.py index 8819b75f9..2a6a013e8 100644 --- a/kivy/__init__.py +++ b/kivy/__init__.py @@ -28,7 +28,7 @@ __all__ = ( 'kivy_config_fn', 'kivy_usermodules_dir', ) -__version__ = '1.4.0' +__version__ = '1.4.1-dev' import sys import shutil From fb2b4e166d36cf349de41200cf3546753f01642e Mon Sep 17 00:00:00 2001 From: Qua-non Date: Mon, 3 Sep 2012 15:56:44 +0530 Subject: [PATCH 18/21] UIX: TextInput fix typo and command for undo for bkspc closes #664 --- kivy/uix/textinput.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kivy/uix/textinput.py b/kivy/uix/textinput.py index cc9d9fa79..c6dfbb75c 100644 --- a/kivy/uix/textinput.py +++ b/kivy/uix/textinput.py @@ -199,7 +199,7 @@ class TextInput(Widget): self._selection_finished = True self._selection_touch = None self.selection_text = '' - self.__selection_from = None + self._selection_from = None self._selection_to = None self._bubble = None self._lines_flags = [] @@ -419,7 +419,7 @@ class TextInput(Widget): self._selection = True self.delete_selection(True) elif undo_type == 'bkspc': - substring = x_item['undo_command'][2:] + substring = x_item['undo_command'][2:][0] self.insert_text(substring, True) else: # delsel From 7b6992a9ab8973d2deea4fe9fe5b250123290d81 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Mon, 3 Sep 2012 13:24:28 +0200 Subject: [PATCH 19/21] add carousel in the factory registers --- kivy/factory_registers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kivy/factory_registers.py b/kivy/factory_registers.py index 1de8ae812..e020e7ce5 100644 --- a/kivy/factory_registers.py +++ b/kivy/factory_registers.py @@ -80,6 +80,7 @@ r('Button', module='kivy.uix.button') r('Bubble', module='kivy.uix.bubble') r('BubbleButton', module='kivy.uix.bubble') r('Camera', module='kivy.uix.camera') +r('Carousel', module='kivy.uix.carousel') r('CheckBox', module='kivy.uix.checkbox') r('DropDown', module='kivy.uix.dropdown') r('FloatLayout', module='kivy.uix.floatlayout') From b783cf9e84c91753acd579cb409098e0b600f4e3 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Mon, 3 Sep 2012 16:49:34 +0200 Subject: [PATCH 20/21] add carousel doc (again..) --- kivy/uix/carousel.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kivy/uix/carousel.py b/kivy/uix/carousel.py index d5684ffa4..a43777cf4 100644 --- a/kivy/uix/carousel.py +++ b/kivy/uix/carousel.py @@ -9,6 +9,20 @@ where you can swipe between slides. You can add any content to the carousel and use it horizontally or verticaly. The carousel can display pages in loop or not. +Example:: + + class Example1(App): + + def build(self): + carousel = Carousel(direction='right') + for i in range(10): + src = "http://placehold.it/480x270.png&text=slide-%d&.png" % i + image = Factory.AsyncImage(source=src, allow_stretch=True) + carousel.add_widget(image) + return carousel + + Example1().run() + ''' __all__ = ('Carousel', ) @@ -22,6 +36,8 @@ from kivy.properties import BooleanProperty, OptionProperty, AliasProperty, \ class Carousel(StencilView): + '''Carousel class. See module documentation for more information. + ''' slides = ListProperty([]) ''' List of slides inside the carousel. The slides are added when a From 47d1fe9b5e136278d958a2b4175c3fdbc0edffa6 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Mon, 3 Sep 2012 17:02:57 +0200 Subject: [PATCH 21/21] fix carousel doc (again..) --- kivy/uix/carousel.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kivy/uix/carousel.py b/kivy/uix/carousel.py index a43777cf4..805949c56 100644 --- a/kivy/uix/carousel.py +++ b/kivy/uix/carousel.py @@ -40,10 +40,10 @@ class Carousel(StencilView): ''' slides = ListProperty([]) - ''' List of slides inside the carousel. The slides are added when a - widget is added to Carousel using add_widget(). + '''List of slides inside the carousel. The slides are added when a widget is + added to Carousel using add_widget(). - :data: `slides` is a list of `~kivy.ui.relativelayout.RelativeLayout` + :data:`slides` is a list of :class:`~kivy.ui.relativelayout.RelativeLayout` widgets containing the content added through add_widget. '''