Mercurial > libervia-desktop-kivy
comparison src/widgets_handler.py @ 14:21a432afd06d
plugin system, first draft:
- widgets are now handled with plugins, ContactList and WidgetSelector have been changed to be pluggins
- everything in PLUGIN_INFO (including PLUGIN_INFO itself) is optional. Best guess is used if a value is missing
- WidgetsHandler use default widget from plugins, which is WidgetSelector for now
- PLUGIN_INFO is used in the same way as for backed plugins, with (for now) following possible keys:
- "name": human readable name
- "description": long description of what widget do
- "import_name": unique short name used as reference for import
- "main": main class name
- "factory": callback used to instanciate a widget (see Cagou._defaultFactory)
- "kv_file": path to the kv language file to load (same filename with ".kv" will be used if key is not found)
other data should be added quickly, as a path to a file used as icon
- host.getPluggedWidgets can be used to find loaded widgets. except_cls can be used to excluse a class (self.__class__ usually)
- fixed host.switchWidget when old widget is already a CagouWidget
- CagouWidget header new display the available widgets
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 09 Jul 2016 16:02:44 +0200 |
parents | 12a189fbb9ba |
children |
comparison
equal
deleted
inserted
replaced
13:12a189fbb9ba | 14:21a432afd06d |
---|---|
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 widget_selector import WidgetSelector | |
27 | 26 |
28 | 27 |
29 NEW_WIDGET_DIST = 10 | 28 NEW_WIDGET_DIST = 10 |
30 REMOVE_WIDGET_DIST = NEW_WIDGET_DIST | 29 REMOVE_WIDGET_DIST = NEW_WIDGET_DIST |
31 | 30 |
66 return super(WHSplitter, self).on_touch_up(touch) | 65 return super(WHSplitter, self).on_touch_up(touch) |
67 | 66 |
68 | 67 |
69 class WidgetsHandler(BoxLayout): | 68 class WidgetsHandler(BoxLayout): |
70 | 69 |
71 def __init__(self, host, wid, **kw): | 70 def __init__(self, host, wid=None, **kw): |
72 self.host = host | 71 self.host = host |
72 if wid is None: | |
73 wid=self.default_widget | |
73 self.vert_wid = self.hor_wid = None | 74 self.vert_wid = self.hor_wid = None |
74 BoxLayout.__init__(self, orientation="vertical", **kw) | 75 BoxLayout.__init__(self, orientation="vertical", **kw) |
75 self.blh = BoxLayout(orientation="horizontal") | 76 self.blh = BoxLayout(orientation="horizontal") |
76 self.blv = BoxLayout(orientation="vertical") | 77 self.blv = BoxLayout(orientation="vertical") |
77 self.blv.add_widget(WHSplitter(self)) | 78 self.blv.add_widget(WHSplitter(self)) |
78 self.blv.add_widget(wid) | 79 self.blv.add_widget(wid) |
79 self.blh.add_widget(WHSplitter(self, horizontal=False)) | 80 self.blh.add_widget(WHSplitter(self, horizontal=False)) |
80 self.blh.add_widget(self.blv) | 81 self.blh.add_widget(self.blv) |
81 self.add_widget(self.blh) | 82 self.add_widget(self.blh) |
83 | |
84 @property | |
85 def default_widget(self): | |
86 return self.host.default_wid['factory'](self.host, self.host.default_wid, None, None) | |
82 | 87 |
83 def removeWidget(self, vertical): | 88 def removeWidget(self, vertical): |
84 if vertical and self.vert_wid is not None: | 89 if vertical and self.vert_wid is not None: |
85 self.remove_widget(self.vert_wid) | 90 self.remove_widget(self.vert_wid) |
86 self.vert_wid = None | 91 self.vert_wid = None |
89 self.hor_wid = None | 94 self.hor_wid = None |
90 | 95 |
91 def setWidgetSize(self, vertical, size): | 96 def setWidgetSize(self, vertical, size): |
92 if vertical: | 97 if vertical: |
93 if self.vert_wid is None: | 98 if self.vert_wid is None: |
94 self.vert_wid = WidgetsHandler(self.host, WidgetSelector(self.host), size_hint=(1, None)) | 99 self.vert_wid = WidgetsHandler(self.host, self.default_widget, size_hint=(1, None)) |
95 self.add_widget(self.vert_wid, len(self.children)) | 100 self.add_widget(self.vert_wid, len(self.children)) |
96 self.vert_wid.height=size | 101 self.vert_wid.height=size |
97 else: | 102 else: |
98 if self.hor_wid is None: | 103 if self.hor_wid is None: |
99 self.hor_wid = WidgetsHandler(self.host, WidgetSelector(self.host), size_hint=(None, 1)) | 104 self.hor_wid = WidgetsHandler(self.host, self.default_widget, size_hint=(None, 1)) |
100 self.blh.add_widget(self.hor_wid, len(self.blh.children)) | 105 self.blh.add_widget(self.hor_wid, len(self.blh.children)) |
101 self.hor_wid.width=size | 106 self.hor_wid.width=size |