From 8b0edbcaedf80d9b280126ccadc3024b24961b83 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 1 Dec 2020 15:22:38 +0800 Subject: [PATCH] bugfix --- kivyblocks/twosides.py | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 kivyblocks/twosides.py diff --git a/kivyblocks/twosides.py b/kivyblocks/twosides.py new file mode 100644 index 0000000..5101601 --- /dev/null +++ b/kivyblocks/twosides.py @@ -0,0 +1,60 @@ +from kivy.clock import Clock +from kivy.uix.boxlayout import BoxLayout +from kivy.factory import Factory + +from kivyblocks.ready import WidgetReady + +class TwoSides(WidgetReady, BoxLayout): + def __init__(self,landscape={},portrait={},**kw): + BoxLayout.__init__(self,**kw) + WidgetReady.__init__(self) + self.parenturl = kw.get('parenturl') + self.landscape_built = False + self.portrait_built = False + self.landscape_widget = None + self.portrait_widget = None + blocks = Factory.Blocks() + blocks.bind(on_built=self.landscape_build) + blocks.widgetBuild(landscape) + blocks = Factory.Blocks() + blocks.bind(on_built=self.portrait_build) + blocks.widgetBuild(portrait) + self.on_size_task = None + self.ready_task = None + + def ready(self, *args): + if self._ready: + return + if not self.landscape_built or not self.portrait_built: + if not self.ready_task is None: + self.ready_task.cancel() + self.ready_task = Clock.schedule_once(self.ready,0.2) + return + self.dispatch('on_ready') + self._ready = True + + def landscape_build(self,o,w): + self.landscape_widget = w + self.landscape_built = True + + def portrait_build(self,o,w): + self.portrait_widget = w + self.portrait_built = True + + def on_size(self,*args): + if not self.landscape_built or not self.portrait_built: + if not self.on_size_task is None: + self.on_size_task.cancel() + self.on_size_task = Clock.schedule_once(self.on_size,0.2) + return + if self.width >= self.height: + if not self.landscape_widget in self.children: + self.clear_widgets() + self.add_widget(self.landscape_widget) + else: + if not self.portrait_widget in self.children: + self.clear_widgets() + self.add_widget(self.portrait_widget) + + +Factory.register('TwoSides',TwoSides)