Mercurial > libervia-desktop-kivy
comparison cagou/core/xmlui.py @ 241:661b9cf7b4e4
xmlui: scroll/size fixes:
- VerticalContainer and TabsPanelContainer are now put in ScrollView
- the height hack in TabsContainer has been removed has it is not needed anymore (minimum_height is now available)
- remove the empty widget which was added at the end of main panel, it's better to have the UI taking the whole container height
- fixed height for TextWidget,LabelWidget and JidWidget
- better scrollbar for VerticalContainer and TabsPanelContainer
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 03 Jan 2019 10:42:43 +0100 |
parents | ca86954b3788 |
children | 50f7c000b4ae |
comparison
equal
deleted
inserted
replaced
240:f555b10712d7 | 241:661b9cf7b4e4 |
---|---|
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from .constants import Const as C | 21 from .constants import Const as C |
22 from sat.core.log import getLogger | 22 from sat.core.log import getLogger |
23 log = getLogger(__name__) | 23 log = getLogger(__name__) |
24 from sat_frontends.tools import xmlui | 24 from sat_frontends.tools import xmlui |
25 from kivy.uix.scrollview import ScrollView | |
25 from kivy.uix.boxlayout import BoxLayout | 26 from kivy.uix.boxlayout import BoxLayout |
26 from kivy.uix.gridlayout import GridLayout | 27 from kivy.uix.gridlayout import GridLayout |
27 from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem | 28 from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem |
28 from kivy.uix.textinput import TextInput | 29 from kivy.uix.textinput import TextInput |
29 from kivy.uix.label import Label | 30 from kivy.uix.label import Label |
276 | 277 |
277 | 278 |
278 ## Containers ## | 279 ## Containers ## |
279 | 280 |
280 | 281 |
281 class VerticalContainer(xmlui.VerticalContainer, BoxLayout): | 282 class VerticalContainer(xmlui.VerticalContainer, ScrollView): |
283 layout = properties.ObjectProperty(None) | |
282 | 284 |
283 def __init__(self, xmlui_parent): | 285 def __init__(self, xmlui_parent): |
284 self.xmlui_parent = xmlui_parent | 286 self.xmlui_parent = xmlui_parent |
285 BoxLayout.__init__(self, orientation="vertical") | 287 ScrollView.__init__(self) |
286 | 288 |
287 def _xmluiAppend(self, widget): | 289 def _xmluiAppend(self, widget): |
288 self.add_widget(widget) | 290 self.layout.add_widget(widget) |
289 | 291 |
290 | 292 |
291 class PairsContainer(xmlui.PairsContainer, GridLayout): | 293 class PairsContainer(xmlui.PairsContainer, GridLayout): |
292 | 294 |
293 def __init__(self, xmlui_parent): | 295 def __init__(self, xmlui_parent): |
301 class LabelContainer(PairsContainer, xmlui.LabelContainer): | 303 class LabelContainer(PairsContainer, xmlui.LabelContainer): |
302 pass | 304 pass |
303 | 305 |
304 | 306 |
305 class TabsPanelContainer(TabbedPanelItem): | 307 class TabsPanelContainer(TabbedPanelItem): |
308 layout = properties.ObjectProperty(None) | |
306 | 309 |
307 def _xmluiAppend(self, widget): | 310 def _xmluiAppend(self, widget): |
308 self.add_widget(widget) | 311 self.layout.add_widget(widget) |
309 | 312 |
310 | 313 |
311 class TabsContainer(xmlui.TabsContainer, TabbedPanel): | 314 class TabsContainer(xmlui.TabsContainer, TabbedPanel): |
312 | 315 |
313 def __init__(self, xmlui_parent): | 316 def __init__(self, xmlui_parent): |
314 self.xmlui_parent = xmlui_parent | 317 self.xmlui_parent = xmlui_parent |
315 xmlui_panel = xmlui_parent | |
316 while not isinstance(xmlui_panel, XMLUIPanel): | |
317 xmlui_panel = xmlui_panel.xmlui_parent | |
318 xmlui_panel.addPostTreat(self._postTreat) | |
319 TabbedPanel.__init__(self, do_default_tab=False) | 318 TabbedPanel.__init__(self, do_default_tab=False) |
320 | 319 |
321 def _xmluiAddTab(self, label, selected): | 320 def _xmluiAddTab(self, label, selected): |
322 tab = TabsPanelContainer(text=label) | 321 tab = TabsPanelContainer(text=label) |
323 self.add_widget(tab) | 322 self.add_widget(tab) |
324 return tab | 323 return tab |
325 | |
326 def _postTreat(self): | |
327 """bind minimum height of tabs' content so self.height is adapted""" | |
328 # we need to do this in postTreat because contents exists after UI construction | |
329 for t in self.tab_list: | |
330 t.content.bind(minimum_height=self._updateHeight) | |
331 | |
332 def _updateHeight(self, instance, height): | |
333 """Called after UI is constructed (so height can be calculated)""" | |
334 # needed because TabbedPanel doesn't have a minimum_height property | |
335 self.height = max([t.content.minimum_height for t in self.tab_list]) + self.tab_height + 5 | |
336 | 324 |
337 | 325 |
338 class AdvancedListRow(GridLayout): | 326 class AdvancedListRow(GridLayout): |
339 global_index = 0 | 327 global_index = 0 |
340 index = properties.ObjectProperty() | 328 index = properties.ObjectProperty() |
512 | 500 |
513 class XMLUIPanel(xmlui.XMLUIPanel, BoxLayout): | 501 class XMLUIPanel(xmlui.XMLUIPanel, BoxLayout): |
514 widget_factory = WidgetFactory() | 502 widget_factory = WidgetFactory() |
515 | 503 |
516 def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, ignore=None, whitelist=None, profile=C.PROF_KEY_NONE): | 504 def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, ignore=None, whitelist=None, profile=C.PROF_KEY_NONE): |
517 BoxLayout.__init__(self, orientation="vertical") | 505 BoxLayout.__init__(self) |
518 self.close_cb = None | 506 self.close_cb = None |
519 self._post_treats = [] # list of callback to call after UI is constructed | 507 self._post_treats = [] # list of callback to call after UI is constructed |
520 xmlui.XMLUIPanel.__init__(self, | 508 xmlui.XMLUIPanel.__init__(self, |
521 host, | 509 host, |
522 parsed_xml, | 510 parsed_xml, |
567 self.add_widget(cancel_btn) | 555 self.add_widget(cancel_btn) |
568 elif self.type == 'param': | 556 elif self.type == 'param': |
569 self.save_btn = FormButton(text=_(u"Save"), disabled=True) | 557 self.save_btn = FormButton(text=_(u"Save"), disabled=True) |
570 self.save_btn.bind(on_press=self._saveButtonCb) | 558 self.save_btn.bind(on_press=self._saveButtonCb) |
571 self.add_widget(self.save_btn) | 559 self.add_widget(self.save_btn) |
572 self.add_widget(Widget()) # to have elements on the top | |
573 | 560 |
574 def show(self, *args, **kwargs): | 561 def show(self, *args, **kwargs): |
575 if not self.user_action and not kwargs.get("force", False): | 562 if not self.user_action and not kwargs.get("force", False): |
576 G.host.addNotifUI(self) | 563 G.host.addNotifUI(self) |
577 else: | 564 else: |