Mercurial > libervia-desktop-kivy
comparison cagou/core/common_widgets.py @ 324:4374cb741eb5
core (common widgets): added a DelayedBoxLayout class:
DelayedBoxLayout delay the sizing, this is useful when sizing is complex and resource
consuming.
Thanks to https://blog.kivy.org/2019/07/a-delayed-resize-layout-in-kivy/
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Dec 2019 13:23:03 +0100 |
parents | 772c170b47a9 |
children | 51520ce98154 |
comparison
equal
deleted
inserted
replaced
323:5bd583d00594 | 324:4374cb741eb5 |
---|---|
23 from kivy.uix.label import Label | 23 from kivy.uix.label import Label |
24 from kivy.uix.boxlayout import BoxLayout | 24 from kivy.uix.boxlayout import BoxLayout |
25 from cagou.core.menu import TouchMenuItemBehaviour | 25 from cagou.core.menu import TouchMenuItemBehaviour |
26 from kivy import properties | 26 from kivy import properties |
27 from kivy.metrics import dp | 27 from kivy.metrics import dp |
28 from kivy.clock import Clock | |
28 from cagou import G | 29 from cagou import G |
29 from sat.core import log as logging | 30 from sat.core import log as logging |
30 | 31 |
31 log = logging.getLogger(__name__) | 32 log = logging.getLogger(__name__) |
33 | |
34 | |
35 class DelayedBoxLayout(BoxLayout): | |
36 """A BoxLayout with delayed layout, to avoid slowing down during resize""" | |
37 # XXX: thanks to Alexander Taylor for his blog post at | |
38 # https://blog.kivy.org/2019/07/a-delayed-resize-layout-in-kivy/ | |
39 | |
40 do_layout_event = properties.ObjectProperty(None, allownone=True) | |
41 layout_delay_s = properties.NumericProperty(0.2) | |
42 | |
43 def do_layout(self, *args, **kwargs): | |
44 if self.do_layout_event is not None: | |
45 self.do_layout_event.cancel() | |
46 real_do_layout = super().do_layout | |
47 self.do_layout_event = Clock.schedule_once( | |
48 lambda dt: real_do_layout(*args, **kwargs), | |
49 self.layout_delay_s) | |
32 | 50 |
33 | 51 |
34 class Identities(object): | 52 class Identities(object): |
35 | 53 |
36 def __init__(self, entity_ids): | 54 def __init__(self, entity_ids): |