Merge branch 'master' of ssh://github.com/tito/kivy

This commit is contained in:
Mathieu Virbel 2010-11-07 00:40:18 -04:00
commit 07611a12eb
3 changed files with 43 additions and 16 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 224 B

View File

@ -17,6 +17,7 @@
size: self.texture_size
pos: root.center[0] - self.texture_size[0] / 2., root.center[1] - self.texture_size[1] / 2.
<Slider>:
canvas:
Color:
@ -28,11 +29,5 @@
Color:
rgb: (.7, .2, .5)
Rectangle:
pos: self.handle_pos
pos: self.value_pos
size: (20,self.height)

View File

@ -4,13 +4,9 @@ Slider:
'''
__all__ = ('Slider', )
from kivy.uix.widget import Widget
from kivy.c_ext.properties import NumericProperty, AliasProperty
class Slider(Widget):
def __init__(self, **kwargs):
super(Slider, self).__init__(**kwargs)
@ -24,9 +20,45 @@ class Slider(Widget):
#: Maximum value of the slider (used for rendering)
max = NumericProperty(100)
def _handle_pos(self):
'x,y position of the slider handle'
offset = (self.value - self.min) / (self.width/(self.max-self.min))
return [self.x+offset, self.x, self.y]
handle_pos = AliasProperty(_handle_pos, None)
#: Range of the slider. same as (self.min, self.max)
def get_range(self):
return (self.min, self.max)
def set_range(self, range):
self.min, self.max = range
range = AliasProperty(get_range, set_range, bind=(min, max))
#: The value of the slide normalized to the range [min - max]
def get_norm_value(self):
return (self.value - self.min) / float(self.max-self.min)
def set_norm_value(self, n_val):
self.value = n_val*(self.max-self.min) + self.min
value_normalized = AliasProperty(get_norm_value, set_norm_value, bind=(value, min, max))
#: The value of the slider mapped to the screen position between self.x and self.right
def get_value_pos(self):
return (self.x + self.value_normalized*self.width, self.y)
def set_value_pos(self, pos):
self.value_normalized = (pos[0] - self.x) / float(self.width)
value_pos = AliasProperty(get_value_pos, set_value_pos, bind=(value, min, max, value_normalized))
#: on touch_down handler. if inside slider: grab touch, set value based on touch pos
def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
touch.grab(self)
self.value_pos = touch.pos
return True
#: on_touch_move handler. set value based on where the touch occured
def on_touch_move(self, touch):
if touch.grab_current == self:
self.value_pos = touch.pos
return True
#: on_touch_up handler. set value based on touch pos, and ungrab touch
def on_touch_up(self, touch):
if touch.grab_current == self:
self.value_pos = touch.pos
return True