Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_wid_remote.py @ 305:b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
the XMLUI panel was added to the StackLayout used for discovery, resulting in a bad
sizing. This patch fixes this by moving discovery panel to a new widget, and adding a main
BoxLayout where the XMLUI panel are added.
The XMLUI close callback is now handled properly.
fix 325
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 19 Jul 2019 17:13:05 +0200 |
parents | 1b835bcfa663 |
children | e2afbec1d178 |
comparison
equal
deleted
inserted
replaced
304:00e2bcf0d9df | 305:b2727877bad4 |
---|---|
32 from cagou.core import xmlui | 32 from cagou.core import xmlui |
33 from sat_frontends.tools import jid | 33 from sat_frontends.tools import jid |
34 from kivy import properties | 34 from kivy import properties |
35 from kivy.uix.label import Label | 35 from kivy.uix.label import Label |
36 from kivy.uix.boxlayout import BoxLayout | 36 from kivy.uix.boxlayout import BoxLayout |
37 from kivy.uix.floatlayout import FloatLayout | |
37 from kivy.core.window import Window | 38 from kivy.core.window import Window |
38 from cagou import G | 39 from cagou import G |
39 from functools import partial | 40 from functools import partial |
40 | 41 |
41 | 42 |
144 G.host, data[u'xmlui'], callback=self.xmluiCb, profile=profile) | 145 G.host, data[u'xmlui'], callback=self.xmluiCb, profile=profile) |
145 if isinstance(xml_ui, xmlui.XMLUIDialog): | 146 if isinstance(xml_ui, xmlui.XMLUIDialog): |
146 self.main_wid.showRootWidget() | 147 self.main_wid.showRootWidget() |
147 xml_ui.show() | 148 xml_ui.show() |
148 else: | 149 else: |
149 xml_ui.size_hint_y = None | 150 xml_ui.setCloseCb(self.onClose) |
150 self.main_wid.layout.clear_widgets() | |
151 self.main_wid.layout.add_widget(xml_ui) | 151 self.main_wid.layout.add_widget(xml_ui) |
152 else: | 152 else: |
153 if data: | 153 if data: |
154 log.warning(_(u"Unhandled data: {data}").format(data=data)) | 154 log.warning(_(u"Unhandled data: {data}").format(data=data)) |
155 self.main_wid.showRootWidget() | 155 self.main_wid.showRootWidget() |
156 | 156 |
157 def onClose(self, __, reason): | |
158 if reason == C.XMLUI_DATA_CANCELLED: | |
159 self.main_wid.showRootWidget() | |
160 else: | |
161 self.main_wid.layout.clear_widgets() | |
162 | |
157 def adHocRunCb(self, data): | 163 def adHocRunCb(self, data): |
158 xml_ui = xmlui.create(G.host, data, callback=self.xmluiCb, profile=self.profile) | 164 xml_ui = xmlui.create(G.host, data, callback=self.xmluiCb, profile=self.profile) |
159 xml_ui.size_hint_y = None | 165 xml_ui.setCloseCb(self.onClose) |
160 self.main_wid.layout.add_widget(xml_ui) | 166 self.main_wid.layout.add_widget(xml_ui) |
161 | 167 |
162 def do_item_action(self, touch): | 168 def do_item_action(self, touch): |
163 self.main_wid.layout.clear_widgets() | 169 self.main_wid.layout.clear_widgets() |
164 G.host.bridge.adHocRun(self.entity_jid, u'', self.profile, | 170 G.host.bridge.adHocRun(self.entity_jid, u'', self.profile, |
165 callback=self.adHocRunCb, errback=self.main_wid.errback) | 171 callback=self.adHocRunCb, errback=self.main_wid.errback) |
172 | |
173 | |
174 class DevicesLayout(FloatLayout): | |
175 """Layout used to show devices""" | |
176 layout = properties.ObjectProperty() | |
166 | 177 |
167 | 178 |
168 class RemoteControl(quick_widgets.QuickWidget, cagou_widget.CagouWidget, FilterBehavior, | 179 class RemoteControl(quick_widgets.QuickWidget, cagou_widget.CagouWidget, FilterBehavior, |
169 TouchMenuBehaviour): | 180 TouchMenuBehaviour): |
170 SINGLE=False | 181 SINGLE=False |
174 quick_widgets.QuickWidget.__init__(self, host, target, profiles) | 185 quick_widgets.QuickWidget.__init__(self, host, target, profiles) |
175 cagou_widget.CagouWidget.__init__(self) | 186 cagou_widget.CagouWidget.__init__(self) |
176 FilterBehavior.__init__(self) | 187 FilterBehavior.__init__(self) |
177 TouchMenuBehaviour.__init__(self) | 188 TouchMenuBehaviour.__init__(self) |
178 Window.bind(on_keyboard=self.key_input) | 189 Window.bind(on_keyboard=self.key_input) |
190 self.stack_layout = None | |
179 self.showRootWidget() | 191 self.showRootWidget() |
180 | 192 |
181 def errback(self, failure_): | 193 def errback(self, failure_): |
182 """Generic errback which add a warning note and go back to root widget""" | 194 """Generic errback which add a warning note and go back to root widget""" |
183 G.host.addNote( | 195 G.host.addNote( |
191 self.showRootWidget() | 203 self.showRootWidget() |
192 return True | 204 return True |
193 | 205 |
194 def showRootWidget(self): | 206 def showRootWidget(self): |
195 self.layout.clear_widgets() | 207 self.layout.clear_widgets() |
208 devices_layout = DevicesLayout() | |
209 self.stack_layout = devices_layout.layout | |
210 self.layout.add_widget(devices_layout) | |
196 found = [] | 211 found = [] |
197 self.get_remotes(found) | 212 self.get_remotes(found) |
198 self.discover_devices(found) | 213 self.discover_devices(found) |
199 | 214 |
200 def adHocRemotesGetCb(self, remotes_data, found): | 215 def adHocRemotesGetCb(self, remotes_data, found): |
243 | 258 |
244 def show_devices(self, found): | 259 def show_devices(self, found): |
245 remotes_data, (entities_services, entities_own, entities_roster) = found | 260 remotes_data, (entities_services, entities_own, entities_roster) = found |
246 if remotes_data: | 261 if remotes_data: |
247 title = _(u"media players remote controls") | 262 title = _(u"media players remote controls") |
248 self.layout.add_widget(CategorySeparator(text=title)) | 263 self.stack_layout.add_widget(CategorySeparator(text=title)) |
249 | 264 |
250 for remote_data in remotes_data: | 265 for remote_data in remotes_data: |
251 device_jid, node, name = remote_data | 266 device_jid, node, name = remote_data |
252 wid = RemoteItemWidget(device_jid, node, name, self) | 267 wid = RemoteItemWidget(device_jid, node, name, self) |
253 self.layout.add_widget(wid) | 268 self.stack_layout.add_widget(wid) |
254 | 269 |
255 for entities_map, title in ((entities_services, | 270 for entities_map, title in ((entities_services, |
256 _(u'services')), | 271 _(u'services')), |
257 (entities_own, | 272 (entities_own, |
258 _(u'your devices')), | 273 _(u'your devices')), |
259 (entities_roster, | 274 (entities_roster, |
260 _(u'your contacts devices'))): | 275 _(u'your contacts devices'))): |
261 if entities_map: | 276 if entities_map: |
262 self.layout.add_widget(CategorySeparator(text=title)) | 277 self.stack_layout.add_widget(CategorySeparator(text=title)) |
263 for entity_str, entity_ids in entities_map.iteritems(): | 278 for entity_str, entity_ids in entities_map.iteritems(): |
264 entity_jid = jid.JID(entity_str) | 279 entity_jid = jid.JID(entity_str) |
265 item = RemoteDeviceWidget( | 280 item = RemoteDeviceWidget( |
266 self, entity_jid, Identities(entity_ids)) | 281 self, entity_jid, Identities(entity_ids)) |
267 self.layout.add_widget(item) | 282 self.stack_layout.add_widget(item) |
268 if (not remotes_data and not entities_services and not entities_own | 283 if (not remotes_data and not entities_services and not entities_own |
269 and not entities_roster): | 284 and not entities_roster): |
270 self.layout.add_widget(Label( | 285 self.stack_layout.add_widget(Label( |
271 size_hint=(1, 1), | 286 size_hint=(1, 1), |
272 halign='center', | 287 halign='center', |
273 text_size=self.size, | 288 text_size=self.size, |
274 text=_(u"No sharing device found"))) | 289 text=_(u"No sharing device found"))) |