This commit is contained in:
yumoqing 2020-08-25 10:17:49 +08:00
parent 938deb6307
commit d0165915a7
3 changed files with 41 additions and 17 deletions

View File

@ -34,6 +34,7 @@ from .newvideo import Video
from .qrcodereader import QRCodeReader from .qrcodereader import QRCodeReader
from .ready import WidgetReady from .ready import WidgetReady
from .bgcolorbehavior import BGColorBehavior from .bgcolorbehavior import BGColorBehavior
from .orientationlayout import OrientationLayout
def showError(e): def showError(e):
print('error',e) print('error',e)
@ -492,7 +493,8 @@ class Blocks(EventDispatcher):
except Exception as e: except Exception as e:
doerr(None,e) doerr(None,e)
del opts['url'] if opts.get('url'):
del opts['url']
self.getUrlData(url,callback=cb,errback=doerr,**opts) self.getUrlData(url,callback=cb,errback=doerr,**opts)
return return
doit(desc) doit(desc)
@ -524,3 +526,4 @@ class Blocks(EventDispatcher):
Factory.register('Blocks',Blocks) Factory.register('Blocks',Blocks)
Factory.register('Video',Video) Factory.register('Video',Video)
Factory.register('OrientationLayout', OrientationLayout)

View File

@ -2,16 +2,16 @@ from kivy.factory import Factory
from kivy.uix.widget import Widget from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout from kivy.uix.boxlayout import BoxLayout
from kivyblocks.blocks import Blocks from kivy.clock import Clock
from kivyblocks.swipebehavior import SwipeBehavior from kivyblocks.swipebehavior import SwipeBehavior
from kivyblocks.ready import WidgetReady from kivyblocks.ready import WidgetReady
class OrientationleLayout(WidgetReady, SwipeBehavior, FloatLayout): class OrientationLayout(WidgetReady, SwipeBehavior, FloatLayout):
""" """
TwinStyleLayout layout two widget verical when parital orientation TwinStyleLayout layout two widget verical when parital orientation
and second widget hide when it is in landscape and second widget hide when it is in landscape
""" """
def __init__(self, main_widet=None, second_widget=None, **kw): def __init__(self, main_widget=None, second_widget=None, **kw):
self.main_widget = main_widget self.main_widget = main_widget
self.second_widget = second_widget self.second_widget = second_widget
self.widget_main = main_widget self.widget_main = main_widget
@ -20,6 +20,19 @@ class OrientationleLayout(WidgetReady, SwipeBehavior, FloatLayout):
FloatLayout.__init__(self, **kw) FloatLayout.__init__(self, **kw)
SwipeBehavior.__init__(self) SwipeBehavior.__init__(self)
WidgetReady.__init__(self) WidgetReady.__init__(self)
Clock.schedule_once(self.build_children,0)
def build_children(self, *args):
if isinstance(self.main_widget, dict):
blocks = Factory.Blocks()
blocks.bind(on_built=self.main_widget_built)
blocks.bind(on_failed=self.widget_build_failed)
blocks.widgetBuild(self.main_widget, ancestor=self)
if isinstance(self.second_widget, dict):
blocks = Factory.Blocks()
blocks.bind(on_built=self.second_widget_built)
blocks.bind(on_failed=self.widget_build_failed)
blocks.widgetBuild(self.second_widget, ancestor=self)
self.bind(on_swipe_left=self.toggle_second) self.bind(on_swipe_left=self.toggle_second)
self.bind(on_swipe_right=self.toggle_second) self.bind(on_swipe_right=self.toggle_second)
@ -27,6 +40,7 @@ class OrientationleLayout(WidgetReady, SwipeBehavior, FloatLayout):
return self.width > self.height return self.width > self.height
def toggle_second(self,*args): def toggle_second(self,*args):
print('toggle_second() called ..')
if self.isLandscape(): if self.isLandscape():
if self.widget_second in self.children: if self.widget_second in self.children:
self.remove_widget(self.widget_second) self.remove_widget(self.widget_second)
@ -35,16 +49,6 @@ class OrientationleLayout(WidgetReady, SwipeBehavior, FloatLayout):
self.on_size(self.size) self.on_size(self.size)
def on_ready(self,*args): def on_ready(self,*args):
if isinstance(main_widget, dict):
blocks = Blocks()
blocks.bind(on_built=self.main_widget_built)
blocks.bind(on_failed=self.widget_build_failed)
blocks.widgetBuild(main_widget, ancestor=self)
if isinstance(second_widget, dict):
blocks = Blocks()
blocks.bind(on_built=self.second_widget_built)
blocks.bind(on_failed=self.widget_build_failed)
blocks.widgetBuild(second_widget, ancestor=self)
self.two_widget_layout() self.two_widget_layout()
def on_size(self,*args): def on_size(self,*args):
@ -70,8 +74,12 @@ class OrientationleLayout(WidgetReady, SwipeBehavior, FloatLayout):
self.widget_second.width = self.width * self.height / self.width self.widget_second.width = self.width * self.height / self.width
self.widget_second.pos = (0,0) self.widget_second.pos = (0,0)
self.widget_second.opacity = 0.6 self.widget_second.opacity = 0.6
if not self.widget_main in self.children:
self.add_widget(self.widget_main)
if self.widget_second in self.children: if self.widget_second in self.children:
self.remove_widget(self.widget_second) self.remove_widget(self.widget_second)
print('main_widget:width=%.02f,height=%.02f,pos=(%.02f,%.02f)' % (self.widget_main.width,self.widget_main.height,*self.widget_main.pos))
print('second_widget:width=%.02f,height=%.02f,pos=(%.02f,%.02f)' % (self.widget_second.width,self.widget_second.height,*self.widget_second.pos))
def vertical_layout(self): def vertical_layout(self):
self.widget_main.width = self.width self.widget_main.width = self.width
@ -81,17 +89,26 @@ class OrientationleLayout(WidgetReady, SwipeBehavior, FloatLayout):
self.widget_second.height = self.height - self.widget_main.height self.widget_second.height = self.height - self.widget_main.height
self.widget_second.pos = (0,0) self.widget_second.pos = (0,0)
self.widget_second.opacity = 1 self.widget_second.opacity = 1
if not self.widget_main in self.children:
self.add_widget(self.widget_main)
if not self.widget_second in self.children:
self.add_widget(self.widget_second)
print('main_widget:width=%.02f,height=%.02f,pos=(%.02f,%.02f)' % (self.widget_main.width,self.widget_main.height,*self.widget_main.pos))
print('second_widget:width=%.02f,height=%.02f,pos=(%.02f,%.02f)' % (self.widget_second.width,self.widget_second.height,*self.widget_second.pos))
def main_widget_built(self,o,w): def main_widget_built(self,o,w):
print('main_widget_built() called ...')
self.widget_main = w self.widget_main = w
if isinstance(self.widget_main, Widget) and isinstance(self.widget_second, Widget): if isinstance(self.widget_main, Widget) and isinstance(self.widget_second, Widget):
self.ready() self.reready()
def second_widget_bult(self,o,w): def second_widget_built(self,o,w):
print('second_widget_built() called ...')
self.widget_second = w self.widget_second = w
if isinstance(self.widget_main, Widget) and isinstance(self.widget_second, Widget): if isinstance(self.widget_main, Widget) and isinstance(self.widget_second, Widget):
self.ready() print('ready() called ..')
self.reready()
def widget_build_failed(self, o, e): def widget_build_failed(self, o, e):
pass pass

View File

@ -13,3 +13,7 @@ class WidgetReady(EventDispatcher):
return return
self.dispatch('on_ready') self.dispatch('on_ready')
self._ready = True self._ready = True
def reready(self):
self._ready = False
self.ready()