comparison src/cagou/plugins/plugin_wid_widget_selector.py @ 16:ba14b596b90e

host can now be get as a global value: instead of always copying host from class to class, it can now be gotten from a global class with: from cagou import G then G.host will give host. This will probably be used on the long term on all SàT (backend + frontends). As host is currently needed in several places (most importantly in QuickFrontend), the argument is still present, and must be there even is unused on class inheriting from QuickSomething.
author Goffi <goffi@goffi.org>
date Sat, 09 Jul 2016 18:41:52 +0200
parents 56838ad5c84b
children 790dbc5c4e89
comparison
equal deleted inserted replaced
15:56838ad5c84b 16:ba14b596b90e
26 from kivy.uix.listview import ListView 26 from kivy.uix.listview import ListView
27 from kivy.adapters.listadapter import ListAdapter 27 from kivy.adapters.listadapter import ListAdapter
28 from kivy import properties 28 from kivy import properties
29 from kivy.uix.behaviors import ButtonBehavior 29 from kivy.uix.behaviors import ButtonBehavior
30 from cagou.core import cagou_widget 30 from cagou.core import cagou_widget
31 from cagou import G
31 32
32 33
33 PLUGIN_INFO = { 34 PLUGIN_INFO = {
34 "name": _(u"widget selector"), 35 "name": _(u"widget selector"),
35 "import_name": C.WID_SELECTOR, 36 "import_name": C.WID_SELECTOR,
41 class WidgetSelItem(ButtonBehavior, BoxLayout): 42 class WidgetSelItem(ButtonBehavior, BoxLayout):
42 plugin_info = properties.DictProperty() 43 plugin_info = properties.DictProperty()
43 44
44 def __init__(self, **kwargs): 45 def __init__(self, **kwargs):
45 super(WidgetSelItem, self).__init__(**kwargs) 46 super(WidgetSelItem, self).__init__(**kwargs)
46 self.host = kwargs['host']
47 47
48 def select(self, *args): 48 def select(self, *args):
49 log.debug(u"widget selection: {}".format(self.plugin_info["name"])) 49 log.debug(u"widget selection: {}".format(self.plugin_info["name"]))
50 factory = self.plugin_info["factory"] 50 factory = self.plugin_info["factory"]
51 self.host.switchWidget(self, factory(self.host, self.plugin_info, None, None)) 51 G.host.switchWidget(self, factory(self.plugin_info, None, None))
52 52
53 def deselect(self, *args): 53 def deselect(self, *args):
54 pass 54 pass
55 55
56 56
57 class WidgetSelector(cagou_widget.CagouWidget): 57 class WidgetSelector(cagou_widget.CagouWidget):
58 58
59 def __init__(self, host): 59 def __init__(self):
60 super(WidgetSelector, self).__init__(host) 60 super(WidgetSelector, self).__init__()
61 self.host = host
62 self.adapter = ListAdapter( 61 self.adapter = ListAdapter(
63 data=host.getPluggedWidgets(except_cls=self.__class__), 62 data=G.host.getPluggedWidgets(except_cls=self.__class__),
64 cls=WidgetSelItem, 63 cls=WidgetSelItem,
65 args_converter=self.dataConverter, 64 args_converter=self.dataConverter,
66 selection_mode='single', 65 selection_mode='single',
67 allow_empty_selection=True, 66 allow_empty_selection=True,
68 ) 67 )
69 self.add_widget(ListView(adapter=self.adapter)) 68 self.add_widget(ListView(adapter=self.adapter))
70 69
71 @classmethod 70 @classmethod
72 def factory(cls, host, plugin_info, target, profiles): 71 def factory(cls, plugin_info, target, profiles):
73 return cls(host) 72 return cls()
74 73
75 def dataConverter(self, idx, plugin_info): 74 def dataConverter(self, idx, plugin_info):
76 return { 75 return {"plugin_info": plugin_info}
77 "host": self.host,
78 "plugin_info": plugin_info,
79 }
80 76
81 77
82 PLUGIN_INFO["factory"] = WidgetSelector.factory 78 PLUGIN_INFO["factory"] = WidgetSelector.factory