This commit is contained in:
yumoqing 2022-02-12 16:14:54 +08:00
parent 1fc1b2f155
commit 32e2f2ac1c

View File

@ -14,6 +14,7 @@ from kivyblocks.utils import CSize, SUPER, blockImage
from kivyblocks.baseWidget import Box, Text from kivyblocks.baseWidget import Box, Text
from kivyblocks.widget_css import WidgetCSS from kivyblocks.widget_css import WidgetCSS
from .uitype.factory import UiFactory, get_value from .uitype.factory import UiFactory, get_value
from .command_action import cmd_action
class TinyText(Text): class TinyText(Text):
def __init__(self, **kw): def __init__(self, **kw):
@ -104,7 +105,6 @@ class _TextBehavior:
if self.text is None: if self.text is None:
return return
if not self.txt_w: if not self.txt_w:
self.create_text_widget()
return return
if self.txt_w: if self.txt_w:
self.txt_w.text = self.text self.txt_w.text = self.text
@ -121,11 +121,35 @@ class ClickableIconText(_IconBehavior, _TextBehavior, ClickableBox):
self.txt_w = None self.txt_w = None
self.img_w = None self.img_w = None
SUPER(ClickableIconText, self, kw) SUPER(ClickableIconText, self, kw)
self.create_text_widget()
self.build_icon() self.build_icon()
self.create_text_widget()
class CommandBox(ClickableIconText): class CommandBox(ClickableIconText):
value = DictProperty(None) value = DictProperty(None)
target = StringProperty(None)
datawidget = StringProperty(None)
datamethod = StringProperty(None)
url = StringProperty(None)
rfname = StringProperty(None)
method = StringProperty(None)
script = StringProperty(None)
actions = DictProperty(None)
def on_press(self, *args):
if self.datawidget is None:
self.datawidget = 'self'
self.datamethod = 'getValue'
desc = dict(target=self.target,
datawidget = self.datawidget,
datamethod = self.method,
url=self.url,
rfname = self.rfname,
method = self.method,
script = self.script,
actions = self.actions
)
cmd_action(desc, self)
def setValue(self, value:dict): def setValue(self, value:dict):
self.value = value self.value = value
@ -298,15 +322,26 @@ def build_cmdbox_view(desc, rec=None):
vd = None vd = None
if rec is not None: if rec is not None:
vd = {f:rec.get(f) for f in desc.get('data') } vd = {f:rec.get(f) for f in desc.get('data') }
text = desc.get('label') kw = {
source = desc.get('icon') 'text' : desc.get('label'),
img_kw = desc.get('img_kw') 'source' : desc.get('icon'),
x = CommandBox(text=text, source=source, img_kw=img_kw) 'img_kw' : desc.get('img_kw'),
'rfname':desc.get('rfname'),
'script':desc.get('script'),
'target':desc.get('target'),
'datawidget':desc.get('datawidget'),
'datamethod':desc.get('datamethod'),
'method':desc.get('method'),
'url':desc.get('url')
}
if desc.get('uiparams'):
kw.update(desc.get('uiparams'))
x = CommandBox(**kw)
x.setValue(vd) x.setValue(vd)
return x return x
UiFactory.register('checkbox', build_checkbox, build_checkbox) UiFactory.register('checkbox', build_checkbox, build_checkbox)
UiFactory.register('cmdbox', None, build_cmdbox_view) UiFactory.register('cmdbox', build_cmdbox_view, build_cmdbox_view)
r = Factory.register r = Factory.register
r('CommandBox', CommandBox) r('CommandBox', CommandBox)