comparison src/cagou/core/widgets_handler.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 02acbb297a61
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.boxlayout import BoxLayout 23 from kivy.uix.boxlayout import BoxLayout
24 from kivy.uix.button import Button 24 from kivy.uix.button import Button
25 from kivy import properties 25 from kivy import properties
26 from cagou import G
26 27
27 28
28 NEW_WIDGET_DIST = 10 29 NEW_WIDGET_DIST = 10
29 REMOVE_WIDGET_DIST = NEW_WIDGET_DIST 30 REMOVE_WIDGET_DIST = NEW_WIDGET_DIST
30 31
65 return super(WHSplitter, self).on_touch_up(touch) 66 return super(WHSplitter, self).on_touch_up(touch)
66 67
67 68
68 class WidgetsHandler(BoxLayout): 69 class WidgetsHandler(BoxLayout):
69 70
70 def __init__(self, host, wid=None, **kw): 71 def __init__(self, wid=None, **kw):
71 self.host = host
72 if wid is None: 72 if wid is None:
73 wid=self.default_widget 73 wid=self.default_widget
74 self.vert_wid = self.hor_wid = None 74 self.vert_wid = self.hor_wid = None
75 BoxLayout.__init__(self, orientation="vertical", **kw) 75 BoxLayout.__init__(self, orientation="vertical", **kw)
76 self.blh = BoxLayout(orientation="horizontal") 76 self.blh = BoxLayout(orientation="horizontal")
81 self.blh.add_widget(self.blv) 81 self.blh.add_widget(self.blv)
82 self.add_widget(self.blh) 82 self.add_widget(self.blh)
83 83
84 @property 84 @property
85 def default_widget(self): 85 def default_widget(self):
86 return self.host.default_wid['factory'](self.host, self.host.default_wid, None, None) 86 return G.host.default_wid['factory'](G.host.default_wid, None, None)
87 87
88 def removeWidget(self, vertical): 88 def removeWidget(self, vertical):
89 if vertical and self.vert_wid is not None: 89 if vertical and self.vert_wid is not None:
90 self.remove_widget(self.vert_wid) 90 self.remove_widget(self.vert_wid)
91 self.vert_wid = None 91 self.vert_wid = None
94 self.hor_wid = None 94 self.hor_wid = None
95 95
96 def setWidgetSize(self, vertical, size): 96 def setWidgetSize(self, vertical, size):
97 if vertical: 97 if vertical:
98 if self.vert_wid is None: 98 if self.vert_wid is None:
99 self.vert_wid = WidgetsHandler(self.host, self.default_widget, size_hint=(1, None)) 99 self.vert_wid = WidgetsHandler(self.default_widget, size_hint=(1, None))
100 self.add_widget(self.vert_wid, len(self.children)) 100 self.add_widget(self.vert_wid, len(self.children))
101 self.vert_wid.height=size 101 self.vert_wid.height=size
102 else: 102 else:
103 if self.hor_wid is None: 103 if self.hor_wid is None:
104 self.hor_wid = WidgetsHandler(self.host, self.default_widget, size_hint=(None, 1)) 104 self.hor_wid = WidgetsHandler(self.default_widget, size_hint=(None, 1))
105 self.blh.add_widget(self.hor_wid, len(self.blh.children)) 105 self.blh.add_widget(self.hor_wid, len(self.blh.children))
106 self.hor_wid.width=size 106 self.hor_wid.width=size