/usr/share/pyshared/kivy/uix/spinner.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 | '''
Spinner
=======
.. versionadded:: 1.4.0
.. image:: images/spinner.jpg
:align: right
Spinner is a widget that provide a quick way to select one value from a set. In
the default state, a spinner show its currently selected value. Touching the
spinner displays a dropdown menu with all other available values. from which the
user can select a new one.
Example::
from kivy.base import runTouchApp
from kivy.uix.spinner import Spinner
spinner = Spinner(
# default value showed
text='Home',
# available values
values=('Home', 'Work', 'Other', 'Custom'),
# just for positioning in our example
size_hint=(None, None),
size=(100, 44),
pos_hint={'center_x': .5, 'center_y': .5})
def show_selected_value(spinner, text):
print 'The spinner', spinner, 'have text', text
spinner.bind(text=show_selected_value)
runTouchApp(spinner)
'''
__all__ = ('Spinner', 'SpinnerOption')
from kivy.properties import ListProperty, ObjectProperty, BooleanProperty
from kivy.uix.button import Button
from kivy.uix.dropdown import DropDown
from kivy.lang import Builder
Builder.load_string('''
<SpinnerOption>:
size_hint_y: None
height: 44
<Spinner>:
background_normal: 'atlas://data/images/defaulttheme/spinner'
background_down: 'atlas://data/images/defaulttheme/spinner_pressed'
''')
class SpinnerOption(Button):
'''Special button used in the dropdown list. We just set the default
size_hint_y and height.
'''
pass
class Spinner(Button):
'''Spinner class, see module documentation for more information
'''
values = ListProperty()
'''Values that can be selected by the user. It must be a list of strings.
:data:`values` is a :class:`~kivy.properties.ListProperty`, default to [].
'''
option_cls = ObjectProperty(SpinnerOption)
'''Class used to display the options within the dropdown list displayed
under the Spinner. The `text` property in the class will represent the
value.
The option class require at least:
- one `text` property where the value will be put
- one `on_release` event that you need to trigger when the option is
touched.
:data:`option_cls` is a :class:`~kivy.properties.ObjectProperty`, default
to :class:`SpinnerOption`.
'''
dropdown_cls = ObjectProperty(DropDown)
'''Class used to display the dropdown list when the Spinner is pressed.
:data:`dropdown_cls` is a :class:`~kivy.properties.ObjectProperty`, default
to :class:`~kivy.uix.dropdown.DropDown`.
'''
is_open = BooleanProperty(False)
'''By default, the spinner is not open. Set to true to open it.
:data:`is_open` is a :class:`~kivy.properties.BooleanProperty`, default to
False.
.. versionadded:: 1.4.0
'''
def __init__(self, **kwargs):
self._dropdown = None
super(Spinner, self).__init__(**kwargs)
self.bind(
on_release=self._toggle_dropdown,
dropdown_cls=self._build_dropdown,
option_cls=self._build_dropdown,
values=self._update_dropdown)
self._build_dropdown()
def _build_dropdown(self, *largs):
if self._dropdown:
self._dropdown.unbind(on_select=self._on_dropdown_select)
self._dropdown.dismiss()
self._dropdown = None
self._dropdown = self.dropdown_cls()
self._dropdown.bind(on_select=self._on_dropdown_select)
self._update_dropdown()
def _update_dropdown(self, *largs):
dp = self._dropdown
cls = self.option_cls
dp.clear_widgets()
for value in self.values:
item = cls(text=value)
item.bind(on_release=lambda option: dp.select(option.text))
dp.add_widget(item)
def _toggle_dropdown(self, *largs):
self.is_open = not self.is_open
def _on_dropdown_select(self, instance, data, *largs):
self.text = data
self.is_open = False
def on_is_open(self, instance, value):
if value:
self._dropdown.open(self)
else:
self._dropdown.dismiss()
|