From 402b1ae1daad299ce61419b1ae1b9f23c82a800e Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 19 Dec 2020 16:58:09 +0800 Subject: [PATCH] bugfi --- kivyblocks/blocks.py | 22 ++++++++++++++++++++-- kivyblocks/boxViewer.py | 6 +++--- kivyblocks/toggleitems.py | 3 ++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/kivyblocks/blocks.py b/kivyblocks/blocks.py index 025c31c..c16b026 100755 --- a/kivyblocks/blocks.py +++ b/kivyblocks/blocks.py @@ -190,6 +190,9 @@ class Blocks(EventDispatcher): callback=None, errback=None,**kw): + if url is None: + errback(None,Exception('url is None')) + if url.startswith('file://'): filename = url[7:] with codecs.open(filename,'r','utf-8') as f: @@ -299,9 +302,25 @@ class Blocks(EventDispatcher): widget.widget_id = desc.get('id') widget.build_desc = desc + self.build_attributes(widget,desc) self.build_rest(widget,desc) return widget + def build_attributes(self,widget,desc,t=None): + excludes = ['widgettype','options','subwidgets','binds'] + for k,v in [(k,v) for k,v in desc.items() if k not in excludes]: + if isinstance(v,dict) and v.get('widgettype'): + b = Blocks() + w = b.w_build(v) + if hasattr(widgets,k): + aw = getattr(widget,k) + if isinstance(aw,Layout): + aw.add_widget(w) + continue + setattr(widget,k,w) + continue + setattr(widget,k,v) + def build_rest(self, widget,desc,t=None): self.subwidget_total = len(desc.get('subwidgets',[])) self.subwidgets = [ None for i in range(self.subwidget_total)] @@ -478,7 +497,6 @@ class Blocks(EventDispatcher): } """ name = desc['widgettype'] - print('desc=',desc,'type=',type(desc)) def doit(desc): if not isinstance(desc,dict): @@ -498,7 +516,7 @@ class Blocks(EventDispatcher): print(e) if name == 'urlwidget': - opts = desc.get('options').copy() + opts = desc.get('options',{}).copy() addon = desc.get('extend') url = opts.get('url') if url is None: diff --git a/kivyblocks/boxViewer.py b/kivyblocks/boxViewer.py index 64b68f9..36bd6e3 100644 --- a/kivyblocks/boxViewer.py +++ b/kivyblocks/boxViewer.py @@ -40,15 +40,15 @@ class BoxViewer(WidgetReady, BoxLayout): remind = ['toolbar', 'dataloader', 'orientation', - 'viewer', 'boxwidth', 'boxheight', 'color_level', 'radius', - 'viewer_url' + 'viewer_url', 'viewer' ] kwargs = {k:v for k,v in options.items() if k not in remind } + print('BoxViewer():kwargs=',kwargs) BoxLayout.__init__(self, orientation='vertical', **kwargs) WidgetReady.__init__(self) self.selected_data = None @@ -157,7 +157,7 @@ class BoxViewer(WidgetReady, BoxLayout): if self.options.get('viewer_url'): desc = { "widgettype":"urlwidget", - "optons":{ + "options":{ "params":rec, "method":"GET", "url":self.options.get('viewer_url') diff --git a/kivyblocks/toggleitems.py b/kivyblocks/toggleitems.py index baab162..d1daec6 100644 --- a/kivyblocks/toggleitems.py +++ b/kivyblocks/toggleitems.py @@ -11,6 +11,7 @@ from kivyblocks.utils import CSize class PressableBox(BGColorBehavior, TouchRippleButtonBehavior, BoxLayout): def __init__(self,border_width=1, color_level=-1, + user_data=None, radius=[], **kw): BoxLayout.__init__(self, padding=[border_width, @@ -22,7 +23,7 @@ class PressableBox(BGColorBehavior, TouchRippleButtonBehavior, BoxLayout): BGColorBehavior.__init__(self,color_level=color_level, radius=radius) self.border_width = border_width - self.user_data = None + self.user_data = user_data self.unselected() def on_press(self,o=None):