bugfix
This commit is contained in:
parent
d636382665
commit
05989c381e
@ -67,6 +67,7 @@ from .utils import NeedLogin, InsufficientPrivilege, HTTPError
|
|||||||
from .login import LoginForm
|
from .login import LoginForm
|
||||||
from .tab import TabsPanel
|
from .tab import TabsPanel
|
||||||
from .qrdata import QRCodeWidget
|
from .qrdata import QRCodeWidget
|
||||||
|
from .threadcall import HttpClient
|
||||||
|
|
||||||
if platform == 'android':
|
if platform == 'android':
|
||||||
from .widgetExt.phonebutton import PhoneButton
|
from .widgetExt.phonebutton import PhoneButton
|
||||||
@ -144,26 +145,22 @@ class HTTPDataHandler(EventDispatcher):
|
|||||||
self.headers = headers
|
self.headers = headers
|
||||||
self.files=files
|
self.files=files
|
||||||
self.stream=stream
|
self.stream=stream
|
||||||
self.hc = App.get_running_app().hc
|
|
||||||
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,v):
|
||||||
|
print('HTTPDataHandler():',self.url,'finished...')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def on_error(self,e):
|
def on_error(self,e):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def onSuccess(self,o,v):
|
def onSuccess(self,o,v):
|
||||||
# print(__file__,'onSuccess():v=',v)
|
print(self.url,'onSuccess() called')
|
||||||
self.dispatch('on_success',v)
|
self.dispatch('on_success',v)
|
||||||
|
|
||||||
def onError(self,o,e):
|
def onError(self,o,e):
|
||||||
if isinstance(e,NeedLogin):
|
print(self.url,'onError():v=',e)
|
||||||
lf = LoginForm()
|
|
||||||
lf.bind(on_setupuser=self.redo)
|
|
||||||
lf.open()
|
|
||||||
return
|
|
||||||
self.dispatch('on_error',e)
|
self.dispatch('on_error',e)
|
||||||
print_exc()
|
print_exc()
|
||||||
print('[****][*********] onError Called',e)
|
print('[****][*********] onError Called',e)
|
||||||
@ -176,7 +173,9 @@ class HTTPDataHandler(EventDispatcher):
|
|||||||
p.update(params)
|
p.update(params)
|
||||||
h = self.headers
|
h = self.headers
|
||||||
h.update(headers)
|
h.update(headers)
|
||||||
self.hc(self.url,method=self.method,
|
hc = HttpClient()
|
||||||
|
print('HTTPDataHandler():',self.url,'handling....')
|
||||||
|
hc(self.url,method=self.method,
|
||||||
params=p,
|
params=p,
|
||||||
headers=h,
|
headers=h,
|
||||||
files=self.files,
|
files=self.files,
|
||||||
|
@ -37,6 +37,7 @@ from .ready import WidgetReady
|
|||||||
from .bgcolorbehavior import BGColorBehavior
|
from .bgcolorbehavior import BGColorBehavior
|
||||||
from .orientationlayout import OrientationLayout
|
from .orientationlayout import OrientationLayout
|
||||||
from kivyblocks import doubleface
|
from kivyblocks import doubleface
|
||||||
|
from .threadcall import HttpClient
|
||||||
|
|
||||||
def showError(e):
|
def showError(e):
|
||||||
print('error',e)
|
print('error',e)
|
||||||
@ -197,11 +198,19 @@ class Blocks(EventDispatcher):
|
|||||||
dic = json.loads(b)
|
dic = json.loads(b)
|
||||||
callback(None,dic)
|
callback(None,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,
|
||||||
files=files)
|
files=files)
|
||||||
h.bind(on_success=callback)
|
h.bind(on_success=callback)
|
||||||
h.bind(on_error=errback)
|
h.bind(on_error=errback)
|
||||||
h.handle()
|
h.handle()
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
hc = HttpClient()
|
||||||
|
resp=hc(url,method=method,params=params,files=files)
|
||||||
|
callback(None,resp)
|
||||||
|
except Exception as e:
|
||||||
|
errback(None,e)
|
||||||
else:
|
else:
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
url = config.uihome + url
|
url = config.uihome + url
|
||||||
@ -277,13 +286,11 @@ class Blocks(EventDispatcher):
|
|||||||
raise Exception(desc)
|
raise Exception(desc)
|
||||||
|
|
||||||
widgetClass = desc['widgettype']
|
widgetClass = desc['widgettype']
|
||||||
opts = desc.get('options',{})
|
opts = desc.get('options',{}).copy()
|
||||||
widget = None
|
widget = None
|
||||||
try:
|
try:
|
||||||
klass = wrap_ready(widgetClass)
|
klass = wrap_ready(widgetClass)
|
||||||
widget = klass(**opts)
|
widget = klass(**opts)
|
||||||
if desc.get('parenturl'):
|
|
||||||
widget.parenturl = desc.get('parenturl')
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Error:',widgetClass,'not registered')
|
print('Error:',widgetClass,'not registered')
|
||||||
print_exc()
|
print_exc()
|
||||||
@ -297,48 +304,49 @@ class Blocks(EventDispatcher):
|
|||||||
return widget
|
return widget
|
||||||
|
|
||||||
def build_rest(self, widget,desc,t=None):
|
def build_rest(self, widget,desc,t=None):
|
||||||
bcnt = 0
|
self.subwidget_total = len(desc.get('subwidgets',[]))
|
||||||
btotal = len(desc.get('subwidgets',[]))
|
self.subwidgets = None * self.subwidget_total
|
||||||
params={
|
|
||||||
'blocks':self,
|
|
||||||
'bcnt':bcnt,
|
|
||||||
'btotal':btotal,
|
|
||||||
'desc':desc,
|
|
||||||
'widget':widget
|
|
||||||
}
|
|
||||||
def doit(params,o,w):
|
def doit(params,o,w):
|
||||||
params['bcnt'] += 1
|
|
||||||
bcnt = params['bcnt']
|
|
||||||
btotal = params['btotal']
|
|
||||||
blocks = params['blocks']
|
|
||||||
desc = params['desc']
|
desc = params['desc']
|
||||||
widget = params['widget']
|
widget = params['widget']
|
||||||
if hasattr(widget,'parenturl'):
|
self.subwidgets[params['pos']] = w
|
||||||
w.parenturl = widget.parenturl
|
self.subwidget_cnt += 1
|
||||||
widget.add_widget(w)
|
if None not in self.subwidgets:
|
||||||
# print('bcnt=',bcnt,'btotal=',btotal,'desc=',desc)
|
for w in self.subwidgets:
|
||||||
if bcnt >= btotal:
|
widget.add_widget(w)
|
||||||
for b in desc.get('binds',[]):
|
for b in desc.get('binds',[]):
|
||||||
# print('buildBind() called',b)
|
kw = b.copy()
|
||||||
blocks.buildBind(widget,b)
|
self.buildBind(widget,kw)
|
||||||
|
|
||||||
def doerr(o,e):
|
def doerr(o,e):
|
||||||
|
print('doerr() called' ,self.subwidget_cnt,'-----')
|
||||||
|
self.subwidget_cnt += 1
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
f = partial(doit,params)
|
pos = 0
|
||||||
for sw in desc.get('subwidgets',[]):
|
for sw in desc.get('subwidgets',[]):
|
||||||
|
params={
|
||||||
|
'desc':desc,
|
||||||
|
'widget':widget,
|
||||||
|
'pos':pos
|
||||||
|
}
|
||||||
|
f = partial(doit,params)
|
||||||
b = Blocks()
|
b = Blocks()
|
||||||
b.bind(on_built=f)
|
b.bind(on_built=f)
|
||||||
b.bind(on_failed=doerr)
|
b.bind(on_failed=doerr)
|
||||||
b.widgetBuild(sw)
|
kw = sw.copy()
|
||||||
|
b.widgetBuild(kw)
|
||||||
|
|
||||||
if btotal == 0:
|
if self.subwidget_total == 0:
|
||||||
for b in desc.get('binds',[]):
|
for b in desc.get('binds',[]):
|
||||||
|
kw = b.copy()
|
||||||
self.buildBind(widget,b)
|
self.buildBind(widget,b)
|
||||||
|
|
||||||
def buildBind(self,widget,desc):
|
def buildBind(self,widget,desc):
|
||||||
wid = desc.get('wid','self')
|
wid = desc.get('wid','self')
|
||||||
w = Blocks.getWidgetById(desc.get('wid','self'),from_widget=widget)
|
w = Blocks.getWidgetById(desc.get('wid','self'),from_widget=widget)
|
||||||
|
if not w:
|
||||||
|
print(desc.get('wid','self'),'not found via Blocks.getWidgetById()')
|
||||||
event = desc.get('event')
|
event = desc.get('event')
|
||||||
if event is None:
|
if event is None:
|
||||||
return
|
return
|
||||||
@ -363,9 +371,9 @@ class Blocks(EventDispatcher):
|
|||||||
def blocksAction(self,widget,desc, *args):
|
def blocksAction(self,widget,desc, *args):
|
||||||
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')
|
opts = desc.get('options').copy()
|
||||||
d = self.getActionData(widget,desc)
|
d = self.getActionData(widget,desc)
|
||||||
p = opts.get('options',{})
|
p = opts.get('options',{}).copy()
|
||||||
p.update(d)
|
p.update(d)
|
||||||
opts['options'] = p
|
opts['options'] = p
|
||||||
def doit(target,add_mode,o,w):
|
def doit(target,add_mode,o,w):
|
||||||
@ -384,9 +392,9 @@ class Blocks(EventDispatcher):
|
|||||||
def urlwidgetAction(self,widget,desc, *args):
|
def urlwidgetAction(self,widget,desc, *args):
|
||||||
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')
|
opts = desc.get('options').copy()
|
||||||
d = self.getActionData(widget,desc)
|
d = self.getActionData(widget,desc)
|
||||||
p = opts.get('params',{})
|
p = opts.get('params',{}).copy()
|
||||||
p.update(d)
|
p.update(d)
|
||||||
opts['params'] = p
|
opts['params'] = p
|
||||||
d = {
|
d = {
|
||||||
@ -423,10 +431,10 @@ class Blocks(EventDispatcher):
|
|||||||
name = desc.get('rfname')
|
name = desc.get('rfname')
|
||||||
func = rf.get(name)
|
func = rf.get(name)
|
||||||
if func is None:
|
if func is None:
|
||||||
print('rfname(%s) not found' % name,rf.registKW)
|
print('rfname(%s) not found' % name)
|
||||||
raise Exception('rfname(%s) not found' % name)
|
raise Exception('rfname(%s) not found' % name)
|
||||||
|
|
||||||
params = desc.get('params',{})
|
params = desc.get('params',{}).copy()
|
||||||
d = self.getActionData(widget,desc)
|
d = self.getActionData(widget,desc)
|
||||||
params.update(d)
|
params.update(d)
|
||||||
# print('registedfunctionAction(),params=',params)
|
# print('registedfunctionAction(),params=',params)
|
||||||
@ -442,7 +450,7 @@ class Blocks(EventDispatcher):
|
|||||||
"self":target,
|
"self":target,
|
||||||
"args":args
|
"args":args
|
||||||
}
|
}
|
||||||
ns.update(d)
|
ns.update(d)
|
||||||
self.eval(script, ns)
|
self.eval(script, ns)
|
||||||
|
|
||||||
def methodAction(self, widget, desc, *args):
|
def methodAction(self, widget, desc, *args):
|
||||||
@ -450,7 +458,7 @@ class Blocks(EventDispatcher):
|
|||||||
target = Blocks.getWidgetById(desc.get('target','self'),widget)
|
target = Blocks.getWidgetById(desc.get('target','self'),widget)
|
||||||
if hasattr(target,method):
|
if hasattr(target,method):
|
||||||
f = getattr(target, method)
|
f = getattr(target, method)
|
||||||
kwargs = desc.get('options',{})
|
kwargs = desc.get('options',{}).copy()
|
||||||
d = self.getActionData(widget,desc)
|
d = self.getActionData(widget,desc)
|
||||||
kwargs.update(d)
|
kwargs.update(d)
|
||||||
f(*args, **kwargs)
|
f(*args, **kwargs)
|
||||||
@ -463,43 +471,36 @@ class Blocks(EventDispatcher):
|
|||||||
{
|
{
|
||||||
widgettype:<registered widget>,
|
widgettype:<registered widget>,
|
||||||
id:widget id,
|
id:widget id,
|
||||||
options:
|
options:{}
|
||||||
subwidgets:[
|
subwidgets:[
|
||||||
]
|
]
|
||||||
binds:[
|
binds:[
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
name = desc['widgettype']
|
||||||
|
|
||||||
def doit(desc):
|
def doit(desc):
|
||||||
# Logger.info("blocks:%s",str(desc))
|
|
||||||
desc = self.valueExpr(desc)
|
desc = self.valueExpr(desc)
|
||||||
# Logger.info("blocks:%s",str(desc))
|
widget = self.__build(desc)
|
||||||
try:
|
self.dispatch('on_built',widget)
|
||||||
widget = self.__build(desc)
|
if hasattr(widget,'ready'):
|
||||||
self.dispatch('on_built',widget)
|
widget.ready()
|
||||||
if hasattr(widget,'ready'):
|
|
||||||
widget.ready()
|
|
||||||
except Exception as e:
|
|
||||||
print_exc()
|
|
||||||
doerr(None,e)
|
|
||||||
return
|
|
||||||
|
|
||||||
def doerr(o,e):
|
def doerr(o,e):
|
||||||
print('blocks.py:wigetBuild() failed,desc=',desc)
|
print('***blocks.py:wigetBuild() failed,desc=',desc)
|
||||||
self.dispatch('on_failed',e)
|
self.dispatch('on_failed',e)
|
||||||
|
print_exc()
|
||||||
|
print(e)
|
||||||
|
|
||||||
name = desc['widgettype']
|
|
||||||
if name == 'urlwidget':
|
if name == 'urlwidget':
|
||||||
opts = desc.get('options')
|
opts = desc.get('options').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'))
|
||||||
|
|
||||||
def cb(o,d):
|
def cb(o,d):
|
||||||
try:
|
doit(d)
|
||||||
doit(d)
|
|
||||||
except Exception as e:
|
|
||||||
doerr(None,e)
|
|
||||||
|
|
||||||
if opts.get('url'):
|
if opts.get('url'):
|
||||||
del opts['url']
|
del opts['url']
|
||||||
@ -517,8 +518,6 @@ class Blocks(EventDispatcher):
|
|||||||
if from_widget is None:
|
if from_widget is None:
|
||||||
from_widget = app.root
|
from_widget = app.root
|
||||||
if hasattr(from_widget,'widget_id'):
|
if hasattr(from_widget,'widget_id'):
|
||||||
print('Blocks.getWidgetById():widget_id=',
|
|
||||||
from_widget.widget_id,'id=',id)
|
|
||||||
if from_widget.widget_id == id:
|
if from_widget.widget_id == id:
|
||||||
return from_widget
|
return from_widget
|
||||||
for c in from_widget.children:
|
for c in from_widget.children:
|
||||||
|
@ -374,6 +374,10 @@ class DataGrid(WidgetReady, BoxLayout):
|
|||||||
def on_selected(self,row):
|
def on_selected(self,row):
|
||||||
self.selected_row = row
|
self.selected_row = row
|
||||||
|
|
||||||
|
def loadData(self,**kwargs):
|
||||||
|
page = kwargs.get('page',1)
|
||||||
|
self.dataloader.do_search(None,{})
|
||||||
|
|
||||||
def createDataGridPart(self):
|
def createDataGridPart(self):
|
||||||
self.freeze_part = None
|
self.freeze_part = None
|
||||||
self.normal_part = None
|
self.normal_part = None
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from kivy.factory import Factory
|
||||||
from kivy.logger import Logger
|
from kivy.logger import Logger
|
||||||
from kivy.uix.textinput import TextInput
|
from kivy.uix.textinput import TextInput
|
||||||
from kivy.uix.boxlayout import BoxLayout
|
from kivy.uix.boxlayout import BoxLayout
|
||||||
@ -283,9 +284,9 @@ class Form(BGColorBehavior, BoxLayout):
|
|||||||
self.fsc.add_widget(w)
|
self.fsc.add_widget(w)
|
||||||
self.fieldWidgets.append(w)
|
self.fieldWidgets.append(w)
|
||||||
w.bind(on_ready=self.makeInputLink)
|
w.bind(on_ready=self.makeInputLink)
|
||||||
wid = Blocks.getWidgetById('__submit',from_widget=self)
|
wid = Factory.Blocks.getWidgetById('__submit',from_widget=self)
|
||||||
wid.bind(on_press=self.on_submit_button)
|
wid.bind(on_press=self.on_submit_button)
|
||||||
wid = Blocks.getWidgetById('__clear',from_widget=self)
|
wid = Factory.Blocks.getWidgetById('__clear',from_widget=self)
|
||||||
wid.bind(on_press=self.on_clear_button)
|
wid.bind(on_press=self.on_clear_button)
|
||||||
|
|
||||||
def makeInputLink(self,o,v=None):
|
def makeInputLink(self,o,v=None):
|
||||||
|
@ -20,13 +20,6 @@ class NewVideo(BGColorBehavior, Video):
|
|||||||
Window.allow_screensaver = False
|
Window.allow_screensaver = False
|
||||||
set_log_callback(self.ffplayerLog)
|
set_log_callback(self.ffplayerLog)
|
||||||
|
|
||||||
def on_state(self,*args):
|
|
||||||
print('new state = ',self.state)
|
|
||||||
if self.state == 'play':
|
|
||||||
Window.allow_screensaver = False
|
|
||||||
else:
|
|
||||||
Window.allow_screensaver = True
|
|
||||||
|
|
||||||
def ffplayerLog(self, msg, level):
|
def ffplayerLog(self, msg, level):
|
||||||
msg = msg.strip()
|
msg = msg.strip()
|
||||||
if msg:
|
if msg:
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# -*- coding=utf-8 -*-
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from threading import Thread, Lock, BoundedSemaphore
|
from threading import Thread, Lock, BoundedSemaphore
|
||||||
import requests
|
import requests
|
||||||
@ -29,14 +31,17 @@ class ThreadCall(Thread,EventDispatcher):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
|
# print('ThreadCall()',self.args,'start...')
|
||||||
self.rez = self.target(*self.args,**self.kwargs)
|
self.rez = self.target(*self.args,**self.kwargs)
|
||||||
self.dispatch('on_result',self.rez)
|
self.dispatch('on_result',self.rez)
|
||||||
|
# print('ThreadCall()',*self.args,'finished...')
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# print('ThreadCall()',*self.args,'Error...')
|
||||||
self.dispatch('on_error',e)
|
self.dispatch('on_error',e)
|
||||||
|
|
||||||
def on_result(self, v):
|
def on_result(self, v):
|
||||||
pass
|
pass # print('ThreadCall():on_result() called,v=',v)
|
||||||
|
|
||||||
def on_error(self,e):
|
def on_error(self,e):
|
||||||
pass
|
pass
|
||||||
@ -71,8 +76,11 @@ class Workers(Thread):
|
|||||||
callee,callback,errback,kwargs = task
|
callee,callback,errback,kwargs = task
|
||||||
x = ThreadCall(callee,kwargs=kwargs)
|
x = ThreadCall(callee,kwargs=kwargs)
|
||||||
x.bind(on_result=callback)
|
x.bind(on_result=callback)
|
||||||
|
"""
|
||||||
|
并发的时候,只有一个callback会被调用
|
||||||
|
"""
|
||||||
if errback:
|
if errback:
|
||||||
x.bind(on_error=errback)
|
x.bind(on_error=errback)
|
||||||
x.start()
|
x.start()
|
||||||
|
|
||||||
def add(self,callee,callback,errback=None,kwargs={}):
|
def add(self,callee,callback,errback=None,kwargs={}):
|
||||||
@ -109,6 +117,7 @@ class HttpClient(Http_Client):
|
|||||||
"stream":stream,
|
"stream":stream,
|
||||||
"headers":headers
|
"headers":headers
|
||||||
}
|
}
|
||||||
|
|
||||||
self.workers.add(self.webcall,callback,errback,kwargs=kwargs)
|
self.workers.add(self.webcall,callback,errback,kwargs=kwargs)
|
||||||
|
|
||||||
def get(self, url, params={}, headers={}, callback=None, errback=None):
|
def get(self, url, params={}, headers={}, callback=None, errback=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user