diff cagou/core/xmlui.py @ 251:1f579baf787a

xmlui: some design improvments + use ScrollView + BoxLayout instead of DropDown for ListWidget: there are some trouble with the ScrollView inside the ScrollView which need to be addressed
author Goffi <goffi@goffi.org>
date Sat, 26 Jan 2019 20:24:48 +0100
parents 50f7c000b4ae
children 1b835bcfa663
line wrap: on
line diff
--- a/cagou/core/xmlui.py	Sat Jan 26 20:24:48 2019 +0100
+++ b/cagou/core/xmlui.py	Sat Jan 26 20:24:48 2019 +0100
@@ -31,7 +31,6 @@
 from kivy.uix.button import Button
 from kivy.uix.togglebutton import ToggleButton
 from kivy.uix.widget import Widget
-from kivy.uix.dropdown import DropDown
 from kivy.uix.switch import Switch
 from kivy import properties
 from cagou import G
@@ -131,13 +130,13 @@
     value = properties.StringProperty()
 
     def on_release(self):
-        super(ListWidgetItem, self).on_release()
         parent = self.parent
-        while parent is not None and not isinstance(parent, DropDown):
+        while parent is not None and not isinstance(parent, ListWidget):
             parent = parent.parent
 
-        if parent is not None and parent.attach_to is not None:
+        if parent is not None:
             parent.select(self)
+        return super(ListWidgetItem, self).on_release()
 
     @property
     def selected(self):
@@ -148,16 +147,12 @@
         self.state = 'down' if value else 'normal'
 
 
-class ListWidget(xmlui.ListWidget, Button):
+class ListWidget(xmlui.ListWidget, ScrollView):
+    layout = properties.ObjectProperty()
 
     def __init__(self, _xmlui_parent, options, selected, flags):
-        Button.__init__(self)
-        self.text = _(u"open list")
-        self._dropdown = DropDown()
-        self._dropdown.auto_dismiss = False
-        self._dropdown.bind(on_select = self.on_select)
+        ScrollView.__init__(self)
         self.multi = 'single' not in flags
-        self._dropdown.dismiss_on_select = not self.multi
         self._values = []
         for option in options:
             self.addValue(option)
@@ -166,26 +161,9 @@
 
     @property
     def items(self):
-        return self._dropdown.children[0].children
+        return self.layout.children
 
-    def on_touch_down(self, touch):
-        # we simulate auto-dismiss ourself because dropdown
-        # will dismiss even if attached button is touched
-        # resulting in a dismiss just before a toggle in on_release
-        # so the dropbox would always be opened, we don't want that!
-        if super(ListWidget, self).on_touch_down(touch):
-            return True
-        if self._dropdown.parent:
-            self._dropdown.dismiss()
-
-    def on_release(self):
-        if self._dropdown.parent is not None:
-            # we want to close a list already opened
-            self._dropdown.dismiss()
-        else:
-            self._dropdown.open(self)
-
-    def on_select(self, drop_down, item):
+    def select(self, item):
         if not self.multi:
             self._xmluiSelectValues([item.value])
         if self._on_change is not None:
@@ -200,7 +178,7 @@
         item = ListWidgetItem()
         item.value, item.text = option
         item.selected = selected
-        self._dropdown.add_widget(item)
+        self.layout.add_widget(item)
 
     def _xmluiSelectValue(self, value):
         self._xmluiSelectValues([value])