Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_wid_widget_selector.py @ 169:6a288d4a493f
widget selector: replaced deprecated ListView by BoxLayout
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 Apr 2018 20:19:53 +0200 |
parents | cd99f70ea592 |
children | 0ddd2b20cc6b |
comparison
equal
deleted
inserted
replaced
168:397f2fb67aab | 169:6a288d4a493f |
---|---|
20 | 20 |
21 from sat.core import log as logging | 21 from sat.core import log as logging |
22 log = logging.getLogger(__name__) | 22 log = logging.getLogger(__name__) |
23 from sat.core.i18n import _ | 23 from sat.core.i18n import _ |
24 from cagou.core.constants import Const as C | 24 from cagou.core.constants import Const as C |
25 from kivy.uix.widget import Widget | |
25 from kivy.uix.boxlayout import BoxLayout | 26 from kivy.uix.boxlayout import BoxLayout |
26 from kivy.uix.listview import ListView | |
27 from kivy.adapters.listadapter import ListAdapter | |
28 from kivy import properties | 27 from kivy import properties |
29 from kivy.uix.behaviors import ButtonBehavior | 28 from kivy.uix.behaviors import ButtonBehavior |
30 from cagou.core import cagou_widget | 29 from cagou.core import cagou_widget |
31 from cagou import G | 30 from cagou import G |
32 | 31 |
41 } | 40 } |
42 | 41 |
43 | 42 |
44 class WidgetSelItem(ButtonBehavior, BoxLayout): | 43 class WidgetSelItem(ButtonBehavior, BoxLayout): |
45 plugin_info = properties.DictProperty() | 44 plugin_info = properties.DictProperty() |
45 item = properties.ObjectProperty() | |
46 | 46 |
47 def __init__(self, **kwargs): | 47 def on_release(self, *args): |
48 super(WidgetSelItem, self).__init__(**kwargs) | |
49 | |
50 def select(self, *args): | |
51 log.debug(u"widget selection: {}".format(self.plugin_info["name"])) | 48 log.debug(u"widget selection: {}".format(self.plugin_info["name"])) |
52 factory = self.plugin_info["factory"] | 49 factory = self.plugin_info["factory"] |
53 G.host.switchWidget(self, factory(self.plugin_info, None, profiles=iter(G.host.profiles))) | 50 G.host.switchWidget(self, factory(self.plugin_info, None, profiles=iter(G.host.profiles))) |
54 | |
55 def deselect(self, *args): | |
56 pass | |
57 | 51 |
58 | 52 |
59 class WidgetSelector(cagou_widget.CagouWidget): | 53 class WidgetSelector(cagou_widget.CagouWidget): |
60 | 54 |
61 def __init__(self): | 55 def __init__(self): |
62 super(WidgetSelector, self).__init__() | 56 super(WidgetSelector, self).__init__() |
63 self.adapter = ListAdapter( | 57 self.items = [] |
64 data=G.host.getPluggedWidgets(except_cls=self.__class__), | 58 for plugin_info in G.host.getPluggedWidgets(except_cls=self.__class__): |
65 cls=WidgetSelItem, | 59 item = WidgetSelItem(plugin_info=plugin_info) |
66 args_converter=self.dataConverter, | 60 self.items.append(item.item) |
67 selection_mode='single', | 61 item.item.bind(minimum_width=self.adjust_width) |
68 allow_empty_selection=True, | 62 self.add_widget(item) |
69 ) | 63 self.add_widget(Widget()) |
70 self.add_widget(ListView(adapter=self.adapter)) | 64 |
65 def adjust_width(self, label, texture_size): | |
66 width = max([i.minimum_width for i in self.items]) | |
67 for i in self.items: | |
68 i.width = width | |
71 | 69 |
72 @classmethod | 70 @classmethod |
73 def factory(cls, plugin_info, target, profiles): | 71 def factory(cls, plugin_info, target, profiles): |
74 return cls() | 72 return cls() |
75 | 73 |
76 def dataConverter(self, idx, plugin_info): | |
77 return {"plugin_info": plugin_info} | |
78 | |
79 | 74 |
80 PLUGIN_INFO["factory"] = WidgetSelector.factory | 75 PLUGIN_INFO["factory"] = WidgetSelector.factory |