diff cagou/core/common_widgets.py @ 329:51520ce98154

common_widgets (DelayedBoxLayout), chat: don't delay layout on new message: DelayedBoxLayout has a new `dont_delay_next_layouts` property to skip delaying for the next X sizing. This is used in chat widget to avoid unpleasant flickering when a new message is sent or received.
author Goffi <goffi@goffi.org>
date Fri, 20 Dec 2019 12:29:37 +0100
parents 4374cb741eb5
children 3002704318e3
line wrap: on
line diff
--- a/cagou/core/common_widgets.py	Fri Dec 20 12:29:37 2019 +0100
+++ b/cagou/core/common_widgets.py	Fri Dec 20 12:29:37 2019 +0100
@@ -39,14 +39,20 @@
 
     do_layout_event = properties.ObjectProperty(None, allownone=True)
     layout_delay_s = properties.NumericProperty(0.2)
+    #: set this to X to force next X layouts to be done without delay
+    dont_delay_next_layouts = properties.NumericProperty(0)
 
     def do_layout(self, *args, **kwargs):
         if self.do_layout_event is not None:
             self.do_layout_event.cancel()
-        real_do_layout = super().do_layout
-        self.do_layout_event = Clock.schedule_once(
-            lambda dt: real_do_layout(*args, **kwargs),
-            self.layout_delay_s)
+        if self.dont_delay_next_layouts>0:
+            self.dont_delay_next_layouts-=1
+            super().do_layout()
+        else:
+            real_do_layout = super().do_layout
+            self.do_layout_event = Clock.schedule_once(
+                lambda dt: real_do_layout(*args, **kwargs),
+                self.layout_delay_s)
 
 
 class Identities(object):