/usr/share/pyshared/kivy/uix/button.py is in python-kivy 1.7.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | '''
Button
======
.. image:: images/button.jpg
:align: right
:class:`Button` is a :class:`~kivy.uix.label.Label` with associated actions that
are triggered when the button is pressed (or released after a click/touch).
To configure the button, you can use the same properties that you can use for
the Label class::
button = Button(text='Hello world', font_size=14)
To attach a callback when the button is pressed (clicked/touched), use
:class:`~kivy.uix.widget.Widget.bind`::
def callback(instance):
print 'The button <%s> is being pressed' % instance.text
btn1 = Button(text='Hello world 1')
btn1.bind(on_press=callback)
btn2 = Button(text='Hello world 2')
btn2.bind(on_press=callback)
If you want to be notified every time the button state changes, you can attach
to the :data:`Button.state` property::
def callback(instance, value):
print 'My button <%s> state is <%s>' % (instance, value)
btn1 = Button(text='Hello world 1')
btn1.bind(state=callback)
'''
__all__ = ('Button', )
from kivy.uix.label import Label
from kivy.properties import OptionProperty, StringProperty, ListProperty
class Button(Label):
'''Button class, see module documentation for more information.
:Events:
`on_press`
Fired when the button is pressed.
`on_release`
Fired when the button is released (i.e., the touch/click that
pressed the button goes away).
'''
state = OptionProperty('normal', options=('normal', 'down'))
'''State of the button, must be one of 'normal' or 'down'.
The state is 'down' only when the button is currently touched/clicked,
otherwise 'normal'.
:data:`state` is an :class:`~kivy.properties.OptionProperty`.
'''
background_color = ListProperty([1, 1, 1, 1])
'''Background color, in the format (r, g, b, a).
.. versionadded:: 1.0.8
:data:`background_color` is a :class:`~kivy.properties.ListProperty`,
default to [1, 1, 1, 1].
'''
background_normal = StringProperty(
'atlas://data/images/defaulttheme/button')
'''Background image of the button used for default graphical representation,
when the button is not pressed.
.. versionadded:: 1.0.4
:data:`background_normal` is an :class:`~kivy.properties.StringProperty`,
default to 'atlas://data/images/defaulttheme/button'
'''
background_down = StringProperty(
'atlas://data/images/defaulttheme/button_pressed')
'''Background image of the button used for default graphical representation,
when the button is pressed.
.. versionadded:: 1.0.4
:data:`background_down` is an :class:`~kivy.properties.StringProperty`,
default to 'atlas://data/images/defaulttheme/button_pressed'
'''
border = ListProperty([16, 16, 16, 16])
'''Border used for :class:`~kivy.graphics.vertex_instructions.BorderImage`
graphics instruction. Used with :data:`background_normal` and
:data:`background_down`. Can be used for a custom background.
It must be a list of four values: (top, right, bottom, left). Read the
BorderImage instruction for more information about how to use it.
:data:`border` is a :class:`~kivy.properties.ListProperty`, default to (16,
16, 16, 16)
'''
__events__ = ('on_press', 'on_release')
def _do_press(self):
self.state = 'down'
def _do_release(self):
self.state = 'normal'
def on_touch_down(self, touch):
if super(Button, self).on_touch_down(touch):
return True
if touch.is_mouse_scrolling:
return False
if not self.collide_point(touch.x, touch.y):
return False
if self in touch.ud:
return False
touch.grab(self)
touch.ud[self] = True
self._do_press()
self.dispatch('on_press')
return True
def on_touch_move(self, touch):
if touch.grab_current is self:
return True
if super(Button, self).on_touch_move(touch):
return True
return self in touch.ud
def on_touch_up(self, touch):
if touch.grab_current is not self:
return super(Button, self).on_touch_up(touch)
assert(self in touch.ud)
touch.ungrab(self)
self._do_release()
self.dispatch('on_release')
return True
def on_press(self):
pass
def on_release(self):
pass
|