comparison src/cagou/core/cagou_widget.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 29b507826eed
comparison
equal deleted inserted replaced
15:56838ad5c84b 16:ba14b596b90e
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 kivy.uix.button import Button 23 from kivy.uix.button import Button
24 from kivy.uix.boxlayout import BoxLayout 24 from kivy.uix.boxlayout import BoxLayout
25 from kivy.uix.dropdown import DropDown 25 from kivy.uix.dropdown import DropDown
26 from cagou import G
26 27
27 28
28 class HeaderWidgetButton(Button): 29 class HeaderWidgetButton(Button):
29 pass 30 pass
30 31
31 32
32 class HeaderWidgetSelector(DropDown): 33 class HeaderWidgetSelector(DropDown):
33 34
34 def __init__(self, cagou_widget): 35 def __init__(self, cagou_widget):
35 super(HeaderWidgetSelector, self).__init__() 36 super(HeaderWidgetSelector, self).__init__()
36 host = cagou_widget.host 37 for plugin_info in G.host.getPluggedWidgets(except_cls=cagou_widget.__class__):
37 for plugin_info in host.getPluggedWidgets(except_cls=cagou_widget.__class__):
38 btn = HeaderWidgetButton(text=plugin_info["name"]) 38 btn = HeaderWidgetButton(text=plugin_info["name"])
39 btn.bind(on_release=lambda btn, plugin_info=plugin_info: cagou_widget.switchWidget(plugin_info)) 39 btn.bind(on_release=lambda btn, plugin_info=plugin_info: cagou_widget.switchWidget(plugin_info))
40 self.add_widget(btn) 40 self.add_widget(btn)
41 41
42 42
43 class CagouWidget(BoxLayout): 43 class CagouWidget(BoxLayout):
44 44
45 def __init__(self, host): 45 def __init__(self):
46 self.host = host
47 BoxLayout.__init__(self, orientation="vertical") 46 BoxLayout.__init__(self, orientation="vertical")
48 self.selector = HeaderWidgetSelector(self) 47 self.selector = HeaderWidgetSelector(self)
49 48
50 def switchWidget(self, plugin_info): 49 def switchWidget(self, plugin_info):
51 self.selector.dismiss() 50 self.selector.dismiss()
52 factory = plugin_info["factory"] 51 factory = plugin_info["factory"]
53 new_widget = factory(self.host, plugin_info, None, None) 52 new_widget = factory(plugin_info, None, None)
54 self.host.switchWidget(self, new_widget) 53 G.host.switchWidget(self, new_widget)