This commit is contained in:
yumoqing 2021-01-23 06:13:42 +08:00
parent b9c975ef48
commit b87cd5af45
4 changed files with 26 additions and 10 deletions

View File

@ -150,18 +150,30 @@ class Blocks(EventDispatcher):
globals()[name] = widget globals()[name] = widget
def buildAction(self,widget,desc): def buildAction(self,widget,desc):
self.action_id += 1 conform_desc = desc.get('conform')
fname = 'action%d' % self.action_id blocks = Blocks()
if not conform_desc:
return partial(blocks.uniaction, widget, desc)
l = { l = {
} }
body="""def %s(widget,obj=None, *args, **kw): body="""def action(widget, *args, **kw):
jsonstr='''%s''' jsonstr='''%s'''
desc = json.loads(jsonstr) desc = json.loads(jsonstr)
conform_desc = desc.get('conform')
blocks = Blocks() blocks = Blocks()
blocks.uniaction(widget, desc,*args, **kw) if not conform_desc:
""" % (fname, json.dumps(desc)) blocks.uniaction(widget, desc,*args, **kw)
return
w = blocks.widgetBuild({
"widgettype":"Conform",
"options":conform_desc
})
w.bind(on_conform=partial(blocks.uniaction, widget, desc))
w.open()
print('Conform show.....')
""" % (json.dumps(desc))
exec(body,globals(),l) exec(body,globals(),l)
f = l.get(fname,None) f = l.get('action',None)
if f is None: if f is None:
raise Exception('None Function') raise Exception('None Function')
func =partial(f,widget) func =partial(f,widget)
@ -358,6 +370,8 @@ class Blocks(EventDispatcher):
def uniaction(self,widget,desc, *args): def uniaction(self,widget,desc, *args):
Logger.info('Block: uniaction() called, desc=%s', str(desc)) Logger.info('Block: uniaction() called, desc=%s', str(desc))
acttype = desc.get('actiontype') acttype = desc.get('actiontype')
if acttype=='blocks': if acttype=='blocks':
return self.blocksAction(widget,desc, *args) return self.blocksAction(widget,desc, *args)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -21,8 +21,10 @@ from .graph import Graph, MeshLinePlot, MeshStemPlot, LinePlot, \
PointPlot PointPlot
from .mapview import MapView from .mapview import MapView
from .chart2d import Chart2d from .chart2d import Chart2d
from .message import Conform
r = Factory.register r = Factory.register
r('Conform', Conform)
r('Chart2d', Chart2d) r('Chart2d', Chart2d)
r('Popup', Popup) r('Popup', Popup)
r('Graph', Graph) r('Graph', Graph)

View File

@ -85,12 +85,12 @@ class ToggleItems(BGColorBehavior, BoxLayout):
for desc in items_desc: for desc in items_desc:
c = PressableBox(**kw) c = PressableBox(**kw)
d = desc.get('data')
if d:
c.setValue(d)
self.item_widgets.append(c) self.item_widgets.append(c)
self.add_widget(c) self.add_widget(c)
c.bind(on_press=self.select_item) c.bind(on_press=self.select_item)
if desc.get('data'):
c.setValue(desc['data'])
b = Factory.Blocks() b = Factory.Blocks()
def cb(c,o,w): def cb(c,o,w):
c.add_widget(w) c.add_widget(w)
@ -107,7 +107,7 @@ class ToggleItems(BGColorBehavior, BoxLayout):
self.register_event_type('on_press') self.register_event_type('on_press')
def on_press(self,v=None): def on_press(self,v=None):
print('Toggle on_changed fired') print('Toggle on_press fired')
pass pass
def select_item(self,o=None): def select_item(self,o=None):