changeset 169:6a288d4a493f

widget selector: replaced deprecated ListView by BoxLayout
author Goffi <goffi@goffi.org>
date Sat, 28 Apr 2018 20:19:53 +0200
parents 397f2fb67aab
children f4522b7c3318
files cagou/plugins/plugin_wid_widget_selector.kv cagou/plugins/plugin_wid_widget_selector.py
diffstat 2 files changed, 36 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_widget_selector.kv	Sat Apr 28 16:22:50 2018 +0200
+++ b/cagou/plugins/plugin_wid_widget_selector.kv	Sat Apr 28 20:19:53 2018 +0200
@@ -17,14 +17,26 @@
 <WidgetSelItem>:
     size_hint: (1, None)
     height: dp(40)
+    item: item
     Widget:
-    Image:
-        source: root.plugin_info["icon_medium"]
-        allow_stretch: True
-        keep_ratio: True
-        width: self.texture_size[0]
-    Label:
-        text: root.plugin_info["name"]
-        bold: True
-        font_size: sp(20)
+    BoxLayout:
+        id: item
+        size_hint: None, 1
+        spacing: dp(10)
+        Image:
+            source: root.plugin_info["icon_medium"]
+            allow_stretch: True
+            keep_ratio: True
+            size_hint: None, 1
+        Label:
+            text: root.plugin_info["name"]
+            bold: True
+            valign: 'middle'
+            font_size: sp(20)
+            size_hint: None, 1
+            width: self.texture_size[0]
     Widget:
+
+
+<WidgetSelector>:
+    spacing: dp(10)
--- a/cagou/plugins/plugin_wid_widget_selector.py	Sat Apr 28 16:22:50 2018 +0200
+++ b/cagou/plugins/plugin_wid_widget_selector.py	Sat Apr 28 20:19:53 2018 +0200
@@ -22,9 +22,8 @@
 log = logging.getLogger(__name__)
 from sat.core.i18n import _
 from cagou.core.constants import Const as C
+from kivy.uix.widget import Widget
 from kivy.uix.boxlayout import BoxLayout
-from kivy.uix.listview import ListView
-from kivy.adapters.listadapter import ListAdapter
 from kivy import properties
 from kivy.uix.behaviors import ButtonBehavior
 from cagou.core import cagou_widget
@@ -43,38 +42,34 @@
 
 class WidgetSelItem(ButtonBehavior, BoxLayout):
     plugin_info = properties.DictProperty()
+    item = properties.ObjectProperty()
 
-    def __init__(self, **kwargs):
-        super(WidgetSelItem, self).__init__(**kwargs)
-
-    def select(self, *args):
+    def on_release(self, *args):
         log.debug(u"widget selection: {}".format(self.plugin_info["name"]))
         factory = self.plugin_info["factory"]
         G.host.switchWidget(self, factory(self.plugin_info, None, profiles=iter(G.host.profiles)))
 
-    def deselect(self, *args):
-        pass
-
 
 class WidgetSelector(cagou_widget.CagouWidget):
 
     def __init__(self):
         super(WidgetSelector, self).__init__()
-        self.adapter = ListAdapter(
-            data=G.host.getPluggedWidgets(except_cls=self.__class__),
-            cls=WidgetSelItem,
-            args_converter=self.dataConverter,
-            selection_mode='single',
-            allow_empty_selection=True,
-           )
-        self.add_widget(ListView(adapter=self.adapter))
+        self.items = []
+        for plugin_info in G.host.getPluggedWidgets(except_cls=self.__class__):
+            item = WidgetSelItem(plugin_info=plugin_info)
+            self.items.append(item.item)
+            item.item.bind(minimum_width=self.adjust_width)
+            self.add_widget(item)
+        self.add_widget(Widget())
+
+    def adjust_width(self, label, texture_size):
+        width = max([i.minimum_width for i in self.items])
+        for i in self.items:
+            i.width = width
 
     @classmethod
     def factory(cls, plugin_info, target, profiles):
         return cls()
 
-    def dataConverter(self, idx, plugin_info):
-        return {"plugin_info": plugin_info}
-
 
 PLUGIN_INFO["factory"] = WidgetSelector.factory