From 940171bf9dc8b34c38cf851effd300b115f44a6c Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 10 Jun 2021 08:45:49 +0800 Subject: [PATCH] bugfix --- kivyblocks/blocks.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/kivyblocks/blocks.py b/kivyblocks/blocks.py index 266160e..31aca6e 100755 --- a/kivyblocks/blocks.py +++ b/kivyblocks/blocks.py @@ -389,7 +389,7 @@ class Blocks(EventDispatcher): alert("actiontype(%s) invalid" % acttype,title='error') def eventAction(self, widget, desc, *args): - target = Blocks.getWidgetById(desc.get('target','self'),widget) + target = self.get_target(widget, desc) event = desc.get('dispatch_event') if not event: Logger.info('Block: eventAction():desc(%s) miss dispatch_event', @@ -405,9 +405,14 @@ class Blocks(EventDispatcher): Logger.info(f'Block: eventAction():dispatch {event} error') print_exc() return - + + def get_target(self, widget, desc): + if not desc.get('target'): + return None + return Blocks.getWidgetById(desc.get('target'),from_widget=widget) + def blocksAction(self,widget,desc, *args): - target = Blocks.getWidgetById(desc.get('target','self'),widget) + target = self.get_target(widget, desc) add_mode = desc.get('mode','replace') opts = desc.get('options').copy() d = self.getActionData(widget,desc) @@ -432,7 +437,7 @@ class Blocks(EventDispatcher): b.widgetBuild(opts) def urlwidgetAction(self,widget,desc, *args): - target = Blocks.getWidgetById(desc.get('target','self'),widget) + target = self.get_target(widget, desc) add_mode = desc.get('mode','replace') opts = desc.get('options').copy() p = opts.get('params',{}).copy() @@ -480,8 +485,7 @@ class Blocks(EventDispatcher): return data def registedfunctionAction(self, widget, desc, *args): - target = Blocks.getWidgetById(desc.get('target','self'), - from_widget=widget) + target = self.get_target(widget, desc) rf = RegisterFunction() name = desc.get('rfname') func = rf.get(name) @@ -502,8 +506,7 @@ class Blocks(EventDispatcher): Logger.info('Block: scriptAction():desc(%s) target not found', str(desc)) return - target = Blocks.getWidgetById(desc.get('target','self'), - from_widget=widget) + target = self.get_target(widget, desc) d = self.getActionData(widget,desc) ns = { "self":target, @@ -519,7 +522,7 @@ class Blocks(EventDispatcher): def methodAction(self, widget, desc, *args): method = desc.get('method') - target = Blocks.getWidgetById(desc.get('target','self'),widget) + target = self.get_target(widget, desc) if target is None: Logger.info('Block: methodAction():desc(%s) target not found', str(desc))