bugfix
This commit is contained in:
parent
15aa886368
commit
3a273096c2
@ -75,6 +75,7 @@ from .i18n import I18n
|
|||||||
from .widget_css import WidgetCSS
|
from .widget_css import WidgetCSS
|
||||||
from .ready import WidgetReady
|
from .ready import WidgetReady
|
||||||
from .utils import CSize
|
from .utils import CSize
|
||||||
|
from .swipebehavior import SwipeBehavior
|
||||||
|
|
||||||
if platform == 'android':
|
if platform == 'android':
|
||||||
from .widgetExt.phonebutton import PhoneButton
|
from .widgetExt.phonebutton import PhoneButton
|
||||||
@ -97,10 +98,15 @@ class HBox(Box):
|
|||||||
|
|
||||||
|
|
||||||
class VBox(Box):
|
class VBox(Box):
|
||||||
def __init__(self,color_level=-1,radius=[],**kw):
|
def __init__(self,**kw):
|
||||||
kw.update({'orientation':'vertical'})
|
kw.update({'orientation':'vertical'})
|
||||||
Box.__init__(self, **kw)
|
Box.__init__(self, **kw)
|
||||||
|
|
||||||
|
class SwipeBox(SwipeBehavior, Box):
|
||||||
|
def __init__(self, **kw):
|
||||||
|
super(SwipeBox, self).__init__(**kw)
|
||||||
|
|
||||||
|
|
||||||
class Text(Label):
|
class Text(Label):
|
||||||
lang=StringProperty('')
|
lang=StringProperty('')
|
||||||
otext = StringProperty('')
|
otext = StringProperty('')
|
||||||
@ -272,10 +278,10 @@ class FILEDataHandler(EventDispatcher):
|
|||||||
self.register_event_type('on_success')
|
self.register_event_type('on_success')
|
||||||
self.register_event_type('on_error')
|
self.register_event_type('on_error')
|
||||||
|
|
||||||
def on_success(self,d):
|
def on_success(self,*args):
|
||||||
return
|
return
|
||||||
|
|
||||||
def on_error(self,e):
|
def on_error(self, *args):
|
||||||
return
|
return
|
||||||
|
|
||||||
def handle(self,params={}):
|
def handle(self,params={}):
|
||||||
@ -297,7 +303,7 @@ class FILEDataHandler(EventDispatcher):
|
|||||||
self.dispatch('on_success',d)
|
self.dispatch('on_success',d)
|
||||||
|
|
||||||
class HTTPDataHandler(EventDispatcher):
|
class HTTPDataHandler(EventDispatcher):
|
||||||
def __init__(self, url,method='GET',params={},
|
def __init__(self, url='',method='GET',params={},
|
||||||
headers={},
|
headers={},
|
||||||
files={},
|
files={},
|
||||||
stream=False
|
stream=False
|
||||||
@ -312,11 +318,11 @@ class HTTPDataHandler(EventDispatcher):
|
|||||||
self.register_event_type('on_success')
|
self.register_event_type('on_success')
|
||||||
self.register_event_type('on_error')
|
self.register_event_type('on_error')
|
||||||
|
|
||||||
def on_success(self,v):
|
def on_success(self,*args):
|
||||||
print('HTTPDataHandler():',self.url,'finished...')
|
print('HTTPDataHandler():',self.url,'finished...')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_error(self,e):
|
def on_error(self,*args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def onSuccess(self,o,v):
|
def onSuccess(self,o,v):
|
||||||
@ -348,6 +354,34 @@ class HTTPDataHandler(EventDispatcher):
|
|||||||
errback=self.onError)
|
errback=self.onError)
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPSeriesData(HTTPDataHandler):
|
||||||
|
def __init__(self, rows=20, page=1, **kw):
|
||||||
|
super(HTTPSeriesData, self).__init__(**kw)
|
||||||
|
self.rows = rows
|
||||||
|
self.page = page
|
||||||
|
self.maxpage = 999999
|
||||||
|
|
||||||
|
def load(self, page=1, **params):
|
||||||
|
self.params.update(params)
|
||||||
|
if page == 1:
|
||||||
|
self.maxpage = 999999
|
||||||
|
self.page = page
|
||||||
|
params = {
|
||||||
|
'page': self.page,
|
||||||
|
'rows': self.rows
|
||||||
|
}
|
||||||
|
self.handle(params=params)
|
||||||
|
|
||||||
|
def loadPrevious(self, **params):
|
||||||
|
self.params.update(params)
|
||||||
|
if self.page > 0:
|
||||||
|
self.load(page=self.page - 1)
|
||||||
|
|
||||||
|
def loadNext(self, **params):
|
||||||
|
self.params.update(params)
|
||||||
|
if self.page < self.maxpage:
|
||||||
|
self.load(page=self.page + 1)
|
||||||
|
|
||||||
def getDataHandler(url,**kwargs):
|
def getDataHandler(url,**kwargs):
|
||||||
if url.startswith('file://'):
|
if url.startswith('file://'):
|
||||||
return FILEDataHandler(url,**kwargs)
|
return FILEDataHandler(url,**kwargs)
|
||||||
|
@ -357,13 +357,8 @@ class Blocks(EventDispatcher):
|
|||||||
# Logger.info('Block: %s bind built', str(desc))
|
# Logger.info('Block: %s bind built', str(desc))
|
||||||
|
|
||||||
def multipleAction(self, widget, desc, *args):
|
def multipleAction(self, widget, desc, *args):
|
||||||
mydesc = {
|
desc1 = {k:v for k, v in desc.items() if k != 'actions'}
|
||||||
'wid':desc['wid'],
|
mydesc = desc1.copy()
|
||||||
'event':desc['event']
|
|
||||||
}
|
|
||||||
if desc.get('conform'):
|
|
||||||
mydesc['conform'] = desc.get('conform')
|
|
||||||
|
|
||||||
for a in desc['actions']:
|
for a in desc['actions']:
|
||||||
new_desc = mydesc.copy()
|
new_desc = mydesc.copy()
|
||||||
new_desc.update(a)
|
new_desc.update(a)
|
||||||
@ -398,7 +393,7 @@ class Blocks(EventDispatcher):
|
|||||||
str(desc))
|
str(desc))
|
||||||
return
|
return
|
||||||
params = desc.get('params',{})
|
params = desc.get('params',{})
|
||||||
d = self.getActionData(widget,desc)
|
d = self.getActionData(widget,desc, *args)
|
||||||
if d:
|
if d:
|
||||||
params.update(d)
|
params.update(d)
|
||||||
try:
|
try:
|
||||||
@ -417,7 +412,7 @@ class Blocks(EventDispatcher):
|
|||||||
target = self.get_target(widget, desc)
|
target = self.get_target(widget, desc)
|
||||||
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)
|
d = self.getActionData(widget,desc, *args)
|
||||||
p = opts.get('options',{}).copy()
|
p = opts.get('options',{}).copy()
|
||||||
if d:
|
if d:
|
||||||
p.update(d)
|
p.update(d)
|
||||||
@ -445,7 +440,7 @@ class Blocks(EventDispatcher):
|
|||||||
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(args[0])
|
p.update(args[0])
|
||||||
d = self.getActionData(widget,desc)
|
d = self.getActionData(widget, desc, *args)
|
||||||
if d:
|
if d:
|
||||||
p.update(d)
|
p.update(d)
|
||||||
opts['params'] = p
|
opts['params'] = p
|
||||||
@ -471,23 +466,11 @@ class Blocks(EventDispatcher):
|
|||||||
|
|
||||||
def getActionData(self,widget,desc,*args):
|
def getActionData(self,widget,desc,*args):
|
||||||
data = {}
|
data = {}
|
||||||
if desc.get('datawidget',False):
|
rtdesc = self.build_rtdesc(desc)
|
||||||
dwidget = Blocks.getWidgetById(desc.get('datawidget','self'),
|
rt = self.get_rtdata(widget, rtdesc, *args)
|
||||||
from_widget=widget)
|
data.update(rt)
|
||||||
if dwidget is None:
|
|
||||||
Logger.info('Block: desc(%s) datawidget not defined',
|
|
||||||
str(desc))
|
|
||||||
method = desc.get('datamethod','getValue')
|
|
||||||
largs = desc.get('dataargs',[]),
|
|
||||||
kwargs = desc.get('datakwargs',{})
|
|
||||||
if hasattr(dwidget, method):
|
|
||||||
f = getattr(dwidget, method)
|
|
||||||
data = f(**kwargs)
|
|
||||||
if desc.get('keymapping'):
|
if desc.get('keymapping'):
|
||||||
data = keyMapping(data, desc.get('keymapping'))
|
data = keyMapping(data, desc.get('keymapping'))
|
||||||
else:
|
|
||||||
Logger.info('Block: desc(%s) datawidget has not %s',
|
|
||||||
str(desc), method)
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def registedfunctionAction(self, widget, desc, *args):
|
def registedfunctionAction(self, widget, desc, *args):
|
||||||
@ -501,7 +484,7 @@ class Blocks(EventDispatcher):
|
|||||||
raise Exception('rfname(%s) not found' % name)
|
raise Exception('rfname(%s) not found' % name)
|
||||||
|
|
||||||
params = desc.get('params',{}).copy()
|
params = desc.get('params',{}).copy()
|
||||||
d = self.getActionData(widget,desc)
|
d = self.getActionData(widget,desc, *args)
|
||||||
if d:
|
if d:
|
||||||
params.update(d)
|
params.update(d)
|
||||||
func(target, *args, **params)
|
func(target, *args, **params)
|
||||||
@ -513,7 +496,7 @@ class Blocks(EventDispatcher):
|
|||||||
str(desc))
|
str(desc))
|
||||||
return
|
return
|
||||||
target = self.get_target(widget, desc)
|
target = self.get_target(widget, desc)
|
||||||
d = self.getActionData(widget,desc)
|
d = self.getActionData(widget,desc, *args)
|
||||||
ns = {
|
ns = {
|
||||||
"self":target,
|
"self":target,
|
||||||
"args":args
|
"args":args
|
||||||
@ -526,6 +509,67 @@ class Blocks(EventDispatcher):
|
|||||||
print_exc()
|
print_exc()
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
def build_rtdesc(self, desc):
|
||||||
|
rtdesc = desc.get('rtdata')
|
||||||
|
if not rtdesc:
|
||||||
|
if desc.get('datatarget'):
|
||||||
|
rtdesc = {}
|
||||||
|
rtdesc['target'] = desc['datatarget']
|
||||||
|
if desc.get('datascript'):
|
||||||
|
rtdesc['script'] = desc.get('datacript')
|
||||||
|
else:
|
||||||
|
rtdesc['method'] = desc.get('datamethod', 'getValue')
|
||||||
|
rtdesc['kwargs'] = desc.get('datakwargs', {})
|
||||||
|
else:
|
||||||
|
return {}
|
||||||
|
return rtdesc
|
||||||
|
|
||||||
|
def get_rtdata(self, widget, desc, *args):
|
||||||
|
"""
|
||||||
|
desc descript follow attributes
|
||||||
|
{
|
||||||
|
"target", a target name from widget
|
||||||
|
"method", a method name, default is 'getValue',
|
||||||
|
"script", script to handle the data
|
||||||
|
"kwargs":" a dict arguments, default is {}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
if desc is None or desc == {}:
|
||||||
|
return {}
|
||||||
|
kwargs = desc.get('kwargs', {})
|
||||||
|
if not isinstance(kwargs, dict):
|
||||||
|
kwargs = {}
|
||||||
|
w = None
|
||||||
|
if len(args) > 0:
|
||||||
|
w = args[0]
|
||||||
|
target = desc.get('target')
|
||||||
|
if target:
|
||||||
|
w = self.getWidgetById(target, from_widget=widget)
|
||||||
|
if w is None:
|
||||||
|
return {}
|
||||||
|
script = desc.get('script')
|
||||||
|
if script:
|
||||||
|
ns = {
|
||||||
|
"self":w,
|
||||||
|
"args":args,
|
||||||
|
"kwargs":kwargs
|
||||||
|
}
|
||||||
|
d = self.eval(script, ns)
|
||||||
|
return d
|
||||||
|
|
||||||
|
method = desc.get('method', 'getValue')
|
||||||
|
if not hasattr(w, 'method'):
|
||||||
|
return {}
|
||||||
|
f = getattr(w, method)
|
||||||
|
try:
|
||||||
|
r = f(*args, **kwargs)
|
||||||
|
if isinstance(r, dict):
|
||||||
|
return r
|
||||||
|
return {}
|
||||||
|
except:
|
||||||
|
return {}
|
||||||
|
|
||||||
def methodAction(self, widget, desc, *args):
|
def methodAction(self, widget, desc, *args):
|
||||||
method = desc.get('method')
|
method = desc.get('method')
|
||||||
target = self.get_target(widget, desc)
|
target = self.get_target(widget, desc)
|
||||||
@ -533,10 +577,14 @@ class Blocks(EventDispatcher):
|
|||||||
Logger.info('Block: methodAction():desc(%s) target not found',
|
Logger.info('Block: methodAction():desc(%s) target not found',
|
||||||
str(desc))
|
str(desc))
|
||||||
return
|
return
|
||||||
|
if method is None:
|
||||||
|
Logger.info('Block: methodAction():desc(%s) method not found',
|
||||||
|
str(desc))
|
||||||
|
return
|
||||||
if hasattr(target,method):
|
if hasattr(target,method):
|
||||||
f = getattr(target, method)
|
f = getattr(target, method)
|
||||||
kwargs = desc.get('options',{}).copy()
|
kwargs = desc.get('options',{}).copy()
|
||||||
d = self.getActionData(widget,desc)
|
d = self.getActionData(widget,desc, *args)
|
||||||
if d:
|
if d:
|
||||||
kwargs.update(d)
|
kwargs.update(d)
|
||||||
f(*args, **kwargs)
|
f(*args, **kwargs)
|
||||||
@ -568,6 +616,9 @@ class Blocks(EventDispatcher):
|
|||||||
try:
|
try:
|
||||||
widget = self.w_build(desc)
|
widget = self.w_build(desc)
|
||||||
self.dispatch('on_built',widget)
|
self.dispatch('on_built',widget)
|
||||||
|
if hasattr(widget,'ready'):
|
||||||
|
print('##widget has ready .........')
|
||||||
|
widget.ready = True
|
||||||
return widget
|
return widget
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print_exc()
|
print_exc()
|
||||||
@ -596,6 +647,23 @@ class Blocks(EventDispatcher):
|
|||||||
|
|
||||||
if opts.get('url'):
|
if opts.get('url'):
|
||||||
del opts['url']
|
del opts['url']
|
||||||
|
rtdesc = self.build_rtdesc(opts)
|
||||||
|
"""
|
||||||
|
rtdesc = opts.get('rtdata')
|
||||||
|
if not rtdesc:
|
||||||
|
if opts.get('datatarget'):
|
||||||
|
rtdesc = {}
|
||||||
|
rtdesc['target'] = opts['datatarget']
|
||||||
|
rtdesc['method'] = opts.get('datamethod', 'getValue')
|
||||||
|
rtdesc['args'] = opts.get('dataargs', [])
|
||||||
|
rtdesc['kwargs'] = opts.get('datakwargs', {})
|
||||||
|
"""
|
||||||
|
if rtdesc:
|
||||||
|
rtdata = self.get_rtdata(None, rtdesc)
|
||||||
|
params = opts.get('params', {})
|
||||||
|
params.update(rtdata)
|
||||||
|
opts['params'] = params
|
||||||
|
|
||||||
desc = self.getUrlData(url,**opts)
|
desc = self.getUrlData(url,**opts)
|
||||||
if not (isinstance(desc, DictObject) or \
|
if not (isinstance(desc, DictObject) or \
|
||||||
isinstance(desc, dict)):
|
isinstance(desc, dict)):
|
||||||
@ -624,11 +692,6 @@ class Blocks(EventDispatcher):
|
|||||||
return from_widget
|
return from_widget
|
||||||
if hasattr(from_widget, id):
|
if hasattr(from_widget, id):
|
||||||
w = getattr(from_widget,id)
|
w = getattr(from_widget,id)
|
||||||
if isinstance(w,Widget):
|
|
||||||
return w
|
|
||||||
if id[0] == '-':
|
|
||||||
w = getattr(from_widget,id[1:])
|
|
||||||
if isinstance(w,Widget):
|
|
||||||
return w
|
return w
|
||||||
|
|
||||||
if id[0] == '-':
|
if id[0] == '-':
|
||||||
|
@ -34,10 +34,14 @@ if kivy.platform in ['win','linux', 'macosx']:
|
|||||||
from .camerawithmic import CameraWithMic
|
from .camerawithmic import CameraWithMic
|
||||||
from .scrollpanel import ScrollPanel
|
from .scrollpanel import ScrollPanel
|
||||||
from .udp_widget import UdpWidget
|
from .udp_widget import UdpWidget
|
||||||
|
from .paging import PageLoader
|
||||||
|
|
||||||
r = Factory.register
|
r = Factory.register
|
||||||
if kivy.platform in ['win','linux', 'macosx']:
|
if kivy.platform in ['win','linux', 'macosx']:
|
||||||
r('ScreenWithMic', ScreenWithMic)
|
r('ScreenWithMic', ScreenWithMic)
|
||||||
|
r('HTTPSeriesData', HTTPSeriesData)
|
||||||
|
r('HTTPDataHandler', HTTPDataHandler)
|
||||||
|
r('PageLoader', PageLoader)
|
||||||
r('UdpWidget', UdpWidget)
|
r('UdpWidget', UdpWidget)
|
||||||
r('ScrollPanel', ScrollPanel)
|
r('ScrollPanel', ScrollPanel)
|
||||||
r('TextInput', TextInput)
|
r('TextInput', TextInput)
|
||||||
@ -109,6 +113,7 @@ r('Modal',Modal)
|
|||||||
r('TimedModal',TimedModal)
|
r('TimedModal',TimedModal)
|
||||||
r('HBox',HBox)
|
r('HBox',HBox)
|
||||||
r('VBox',VBox)
|
r('VBox',VBox)
|
||||||
|
r('SwipeBox',SwipeBox)
|
||||||
r('ToggleItems',ToggleItems)
|
r('ToggleItems',ToggleItems)
|
||||||
if platform == 'android':
|
if platform == 'android':
|
||||||
r('PhoneButton',PhoneButton)
|
r('PhoneButton',PhoneButton)
|
||||||
|
Loading…
Reference in New Issue
Block a user