This commit is contained in:
yumoqing 2020-12-21 19:29:53 +08:00
parent 402b1ae1da
commit 5026669000
2 changed files with 37 additions and 29 deletions

View File

@ -85,10 +85,11 @@ class WrapText(Label):
class Text(Label): class Text(Label):
lang=StringProperty('') lang=StringProperty('')
otext = StringProperty('') otext = StringProperty('')
def __init__(self,i18n=False, textype='text', **kw): def __init__(self,i18n=False, textype='text', wrap=False, **kw):
self._i18n = i18n self._i18n = i18n
kwargs = kw.copy() kwargs = kw.copy()
config = getConfig() config = getConfig()
self.wrap = wrap
if config.texttypes: if config.texttypes:
attrs = config.texttypes.get('texttype',{}) attrs = config.texttypes.get('texttype',{})
kwargs.update(attrs) kwargs.update(attrs)
@ -97,6 +98,15 @@ class Text(Label):
self.i18n = I18n() self.i18n = I18n()
self.i18n.addI18nWidget(self) self.i18n.addI18nWidget(self)
self.otext = kw.get('text','') self.otext = kw.get('text','')
if self.wrap:
font_size = self.font_size
self.text_size = self.width, None
def on_size(self,o,size):
# super().on_size(o,size)
if self.wrap:
font_size = self.font_size
self.text_size = self.width, None
def on_otext(self,o,v=None): def on_otext(self,o,v=None):
if self._i18n: if self._i18n:

View File

@ -198,7 +198,7 @@ class Blocks(EventDispatcher):
with codecs.open(filename,'r','utf-8') as f: with codecs.open(filename,'r','utf-8') as f:
b = f.read() b = f.read()
dic = json.loads(b) dic = json.loads(b)
callback(None,dic) return dic
elif url.startswith('http://') or url.startswith('https://'): elif url.startswith('http://') or url.startswith('https://'):
""" """
h = HTTPDataHandler(url,method=method,params=params, h = HTTPDataHandler(url,method=method,params=params,
@ -210,7 +210,7 @@ class Blocks(EventDispatcher):
try: try:
hc = HttpClient() hc = HttpClient()
resp=hc(url,method=method,params=params,files=files) resp=hc(url,method=method,params=params,files=files)
callback(None,resp) return resp
except Exception as e: except Exception as e:
errback(None,e) errback(None,e)
else: else:
@ -219,8 +219,7 @@ class Blocks(EventDispatcher):
return self.getUrlData(url,method=method, return self.getUrlData(url,method=method,
params=params, params=params,
files=files, files=files,
callback=callback, **kw)
errback=errback, **kw)
def strValueExpr(self,s:str,localnamespace:dict={}): def strValueExpr(self,s:str,localnamespace:dict={}):
if not s.startswith('py::'): if not s.startswith('py::'):
@ -409,16 +408,19 @@ class Blocks(EventDispatcher):
target = Blocks.getWidgetById(desc.get('target','self'),widget) target = Blocks.getWidgetById(desc.get('target','self'),widget)
add_mode = desc.get('mode','replace') add_mode = desc.get('mode','replace')
opts = desc.get('options').copy() opts = desc.get('options').copy()
d = self.getActionData(widget,desc)
p = opts.get('params',{}).copy() p = opts.get('params',{}).copy()
if len(args) >= 1 and isinstance(args[0],dict): if len(args) >= 1 and isinstance(args[0],dict):
p.update(p) p.update(args[0])
p.update(d) d = self.getActionData(widget,desc)
if d:
p.update(d)
print('p=',p,'d=',d)
opts['params'] = p opts['params'] = p
d = { d = {
'widgettype' : 'urlwidget' 'widgettype' : 'urlwidget',
'options': opts
} }
d['options'] = opts print('desc=',d)
def doit(target,add_mode,o,w): def doit(target,add_mode,o,w):
if add_mode == 'replace': if add_mode == 'replace':
@ -436,7 +438,8 @@ class Blocks(EventDispatcher):
def getActionData(self,widget,desc,*args): def getActionData(self,widget,desc,*args):
data = {} data = {}
if desc.get('datawidget',False): if desc.get('datawidget',False):
dwidget = Blocks.getWidgetById(desc.get('datawidget','self'),widget) dwidget = Blocks.getWidgetById(desc.get('datawidget','self'),
from_widget=widget)
if dwidget and hasattr(dwidget,'getValue'): if dwidget and hasattr(dwidget,'getValue'):
data = dwidget.getValue() data = dwidget.getValue()
if desc.get('keymapping'): if desc.get('keymapping'):
@ -444,7 +447,8 @@ class Blocks(EventDispatcher):
return data return data
def registedfunctionAction(self, widget, desc, *args): def registedfunctionAction(self, widget, desc, *args):
target = Blocks.getWidgetById(desc.get('target','self'),widget) target = Blocks.getWidgetById(desc.get('target','self'),
from_widget=widget)
rf = RegisterFunction() rf = RegisterFunction()
name = desc.get('rfname') name = desc.get('rfname')
func = rf.get(name) func = rf.get(name)
@ -462,7 +466,8 @@ class Blocks(EventDispatcher):
script = desc.get('script') script = desc.get('script')
if not script: if not script:
return return
target = Blocks.getWidgetById(desc.get('target','self'),widget) target = Blocks.getWidgetById(desc.get('target','self'),
from_widget=widget)
d = self.getActionData(widget,desc) d = self.getActionData(widget,desc)
ns = { ns = {
"self":target, "self":target,
@ -509,29 +514,22 @@ class Blocks(EventDispatcher):
if hasattr(widget,'ready'): if hasattr(widget,'ready'):
widget.ready() widget.ready()
def doerr(o,e): while desc['widgettype'] == "urlwidget":
print('***blocks.py:wigetBuild() failed,desc=',desc)
self.dispatch('on_failed',e)
print_exc()
print(e)
if name == 'urlwidget':
opts = desc.get('options',{}).copy() opts = desc.get('options',{}).copy()
addon = desc.get('extend') extend = desc.get('extend')
addon = None
if desc.get('extend'):
addon = desc.get('extend').copy()
url = opts.get('url') url = opts.get('url')
if url is None: if url is None:
self.dispatch('on_failed',Exception('miss url')) self.dispatch('on_failed',Exception('miss url'))
return
def cb(addon,o,d):
if addon is not None:
d = dictExtend(d,addon)
doit(d)
if opts.get('url'): if opts.get('url'):
del opts['url'] del opts['url']
self.getUrlData(url,callback=partial(cb,addon), desc = self.getUrlData(url,**opts)
errback=doerr,**opts) if addon:
return desc = dictExtend(desc,addon)
doit(desc) doit(desc)
@classmethod @classmethod