From 845f31b41695860885466f32f8a4880bf7cfc8d3 Mon Sep 17 00:00:00 2001 From: "Eric S. Bullington" Date: Mon, 6 Aug 2012 10:52:16 -0400 Subject: [PATCH 1/2] Modified spinner to close on (re-)click --- kivy/uix/spinner.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kivy/uix/spinner.py b/kivy/uix/spinner.py index 2ed45a64f..ecb01d6cd 100644 --- a/kivy/uix/spinner.py +++ b/kivy/uix/spinner.py @@ -96,6 +96,7 @@ class Spinner(Button): def __init__(self, **kwargs): self._dropdown = None + self._is_down = False super(Spinner, self).__init__(**kwargs) self.bind( on_release=self._open_dropdown, @@ -116,7 +117,6 @@ class Spinner(Button): def _update_dropdown(self, *largs): dp = self._dropdown cls = self.option_cls - dp.clear_widgets() for value in self.values: item = cls(text=value) @@ -124,8 +124,13 @@ class Spinner(Button): dp.add_widget(item) def _open_dropdown(self, *largs): - self._dropdown.open(self) + if not self._is_down: + self._dropdown.open(self) + self._is_down = True + else: + self._dropdown.dismiss() + self._is_down = False def _on_dropdown_select(self, instance, data, *largs): self.text = data - + self._is_down = False From 4d28733b91753cc50c9168a68489c84d40073d71 Mon Sep 17 00:00:00 2001 From: "Eric S. Bullington" Date: Mon, 6 Aug 2012 12:30:12 -0400 Subject: [PATCH 2/2] Changed is_down Boolean property to is_open --- kivy/uix/dropdown.py | 8 ++++++++ kivy/uix/spinner.py | 9 ++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/kivy/uix/dropdown.py b/kivy/uix/dropdown.py index 94ded676b..acc9f19c4 100644 --- a/kivy/uix/dropdown.py +++ b/kivy/uix/dropdown.py @@ -139,6 +139,14 @@ class DropDown(ScrollView): default to True. ''' + is_open = BooleanProperty(False) + '''By default, the dropdown is not open. Set to True to expand the dropdown + by default. + + :data: `is_open` is a :class: `~kivy.properties.BooleanProperty`, + default to False. + ''' + attach_to = ObjectProperty(allownone=True) '''(internal) Property that will be set to the widget on which the drop down list is attached to. diff --git a/kivy/uix/spinner.py b/kivy/uix/spinner.py index ecb01d6cd..45939c7d4 100644 --- a/kivy/uix/spinner.py +++ b/kivy/uix/spinner.py @@ -96,7 +96,6 @@ class Spinner(Button): def __init__(self, **kwargs): self._dropdown = None - self._is_down = False super(Spinner, self).__init__(**kwargs) self.bind( on_release=self._open_dropdown, @@ -124,13 +123,13 @@ class Spinner(Button): dp.add_widget(item) def _open_dropdown(self, *largs): - if not self._is_down: + if not self._dropdown.is_open: self._dropdown.open(self) - self._is_down = True + self._dropdown.is_open = True else: self._dropdown.dismiss() - self._is_down = False + self._dropdown.is_open = False def _on_dropdown_select(self, instance, data, *largs): self.text = data - self._is_down = False + self._dropdown.is_open = False