/usr/share/pyshared/kivy/uix/checkbox.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 | '''
CheckBox
========
.. versionadded:: 1.4.0
.. image:: images/checkbox.png
:align: right
:class:`CheckBox` is a specific two-state button that can be either checked or
unchecked. If the CheckBox is in a Group, it becomes a Radio button.
As with the :class:`~kivy.uix.togglebutton.ToggleButton`, only one Radio button
at a time can be selected when the :data:`CheckBox.group` is set.
An example usage::
from kivy.uix.checkbox import CheckBox
# ...
def on_checkbox_active(checkbox, value):
if value:
print 'The checkbox', checkbox, 'is active'
else:
print 'The checkbox', checkbox, 'is inactive'
checkbox = CheckBox()
checkbox.bind(active=on_checkbox_active)
'''
__all__ = ('CheckBox', )
from weakref import ref
from kivy.uix.widget import Widget
from kivy.properties import BooleanProperty, ObjectProperty
class CheckBox(Widget):
'''CheckXox class, see module documentation for more information.
'''
active = BooleanProperty(False)
'''Indicates if the switch is active or inactive.
:data:`active` is a :class:`~kivy.properties.BooleanProperty`, default to
False.
'''
__groups = {}
group = ObjectProperty(None, allownone=True)
'''Group of the checkbox. If None, no group will be used (the checkbox is
independent). If specified, :data:`group` must be a hashable object, like
a string. Only one checkbox in a group can be active.
:data:`group` is a :class:`~kivy.properties.ObjectProperty`
'''
def __init__(self, **kwargs):
self._previous_group = None
super(CheckBox, self).__init__(**kwargs)
def on_group(self, *largs):
groups = CheckBox.__groups
if self._previous_group:
group = groups[self._previous_group]
for item in group[:]:
if item() is self:
group.remove(item)
break
group = self._previous_group = self.group
if group not in groups:
groups[group] = []
r = ref(self, CheckBox._clear_groups)
groups[group].append(r)
def _release_group(self, current):
if self.group is None:
return
group = self.__groups[self.group]
for item in group[:]:
widget = item()
if widget is None:
group.remove(item)
if widget is current:
continue
widget.active = False
def _toggle_active(self):
self._release_group(self)
self.active = not self.active
def on_touch_down(self, touch):
if not self.collide_point(*touch.pos):
return
self._toggle_active()
return True
@staticmethod
def _clear_groups(wk):
# auto flush the element when the weak reference have been deleted
groups = CheckBox.__groups
for group in groups.values():
if wk in group:
group.remove(wk)
break
|