From e51ef48a304725233ea94a03fde9ee53b6e38802 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 9 Jan 2020 17:52:02 +0800 Subject: [PATCH] bugfix --- kivyblocks/blocks.py | 2 +- kivyblocks/blocksapp.py | 14 +++----- kivyblocks/form.py | 9 +++-- kivyblocks/login.py | 62 ++++++++++++++++++++++++---------- kivyblocks/pagescontainer.py | 4 ++- kivyblocks/responsivelayout.py | 1 + kivyblocks/threadcall.py | 2 +- kivyblocks/toolbar.py | 2 +- kivyblocks/vplayer.py | 18 ++++++---- test/conf/config.json | 3 ++ 10 files changed, 76 insertions(+), 41 deletions(-) diff --git a/kivyblocks/blocks.py b/kivyblocks/blocks.py index 1e1f638..ae084c9 100755 --- a/kivyblocks/blocks.py +++ b/kivyblocks/blocks.py @@ -409,7 +409,7 @@ class Blocks: desc, parenturl = self.getUrlData(opts,parenturl) if not isinstance(desc,dict): print("getUrlData() return error data",opts,parenturl) - alert(str(dict) + 'format error') + # alert(str(desc) + 'format error',title='widgetBuild()') return None desc = self.valueExpr(desc) desc['parenturl'] = parenturl diff --git a/kivyblocks/blocksapp.py b/kivyblocks/blocksapp.py index a4d7c68..0c1d6bb 100644 --- a/kivyblocks/blocksapp.py +++ b/kivyblocks/blocksapp.py @@ -37,30 +37,24 @@ def signal_handler(signal, frame): signal.signal(signal.SIGINT, signal_handler) + class BlocksApp(App): def build(self): - x = PageContainer() + config = getConfig() + self.config = config self.userinfo = {} self.title = 'Test Title' self.blocks = Blocks() - config = getConfig() - self.config = config self.workers = Workers(maxworkers=config.maxworkers or 80) Window.bind(on_request_close=self.on_close) self.workers.start() self.hc = HttpClient() WindowBase.softinput_mode='below_target' + x = PageContainer() Clock.schedule_once(self.build1) print('build() called......') return x - def setUserInfo(self,uinfo): - d = {} - d['userid'] = uinfo['userid'] - d['password'] = uinfo.get('password','') - d['authcode'] = uinfo.get('authcode','') - self.userinfo = d - def on_start(self): print('on_start() called ...') diff --git a/kivyblocks/form.py b/kivyblocks/form.py index 39141c4..f1caf19 100644 --- a/kivyblocks/form.py +++ b/kivyblocks/form.py @@ -204,7 +204,7 @@ class Form(BoxLayout): self.options = options BoxLayout.__init__(self, orientation='vertical') self.widget_ids = {} - self.cols = self.options_cols = self.options['cols'] + self.cols = self.options_cols = self.options.get('cols',1) if isHandHold() and Window.width < Window.height: self.cols = 1 self.inputwidth = Window.width / self.cols @@ -217,8 +217,11 @@ class Form(BoxLayout): if self.initflag: return self.toolbar = Toolbar(ancestor=self,**self.options.get('toolbar',defaultToolbar())) - self.fsc = VResponsiveLayout(cols=self.cols, - box_width=self.inputwidth) + self.fsc = VResponsiveLayout( + self.inputwidth, + self.cols + ) + print('box_width=%d,cols=%d' % (self.inputwidth, self.cols)) self.add_widget(self.toolbar) self.add_widget(self.fsc) self.register_event_type('on_submit') diff --git a/kivyblocks/login.py b/kivyblocks/login.py index ab629da..9dbbb7b 100644 --- a/kivyblocks/login.py +++ b/kivyblocks/login.py @@ -1,7 +1,27 @@ from kivy.app import App +from kivy.core.window import Window from kivy.uix.popup import Popup from appPublic.Singleton import SingletonDecorator from appPublic.registerfunction import RegisterFunction +from appPublic.rsa import RSA +# from .form import Form + +class ServerInfo: + def __init__(self): + self.rsaEngine = RSA() + config = getConfig() + url = '%s%s' % (config.uihome, config.publickey_url) + hc = App.get_running_app().hc + d = hc.get(url) + self.publickey = self.rsaEngine. publickeyFromText(d) + + def encode(self,uinfo): + if uinfo['authmethod'] == 'password': + authinfo = '%s::%s::%s' % (uinfo['authmethod'], uinfo['userid'], uinfo['password']) + txt = self.serverinfo.encode(authinfo) + x = self.rsaEngine.encode(self.publickey, txt) + return x + return None logformdesc = { "widgettype":"Form", @@ -39,39 +59,45 @@ logformdesc = { @SingletonDecorator class LoginForm(Popup): def __init__(self): - super().__init__() + super().__init__(size_hint=(0.8,0.8)) + app = App.get_running_app() + print('here ..1............') self.content = app.blocks.widgetBuild(logformdesc) + # self.content.bind(on_submit=setipUserInfo) + print('here ..2............',self.content) self.title = 'login' self.blockCalls = [] self.open_status = False + print('here ..3............') self.content.bind(on_submit=self.on_submit) - - def needlogin(self, url,method,params,headers,callback=None,errback=None): - self.blockCalls.append([url, method, params,headers,callback,errback]) - if self.open_status: - return - self.open_status = True + self.content.bind(on_cancel=self.on_submit) + print('here ..4............') self.open() - - def recall(self): - app = App.get_running_app() - for url, method, params, headers,callback, errback in self.blockCalls: - app.hc(url, method=pethod,params=params,headers=headers, - callback=callback,errback=errback) - + def close(self): self.open_status = False self.dismiss() def on_submit(self,o,v): self.dismiss() + + def on_cancel(self,o,v): + self.dismiss() -def setupUserInfo(userinfo): +def setupUserInfo(obj, userinfo): app = App.get_running_app() - app.setUserInfo(userinfo) - lf = LoginForm() - lf.recall() + if not hasattr(app, 'serverinfo'): + app.serverinfo = ServerInfo() + + if userinfo.get('password',False): + userinfo['authmethod'] = 'password' + authinfo = app.serverinfo.encode(userinfo) + headers = { + "authorization":authinfo + } + login_url = '%s%s' % (app.config.uihome, app.config.login_url) + app.hc.get(login_url,headers=headers) rf = RegisterFunction() rf.register('setupUserInfo',setupUserInfo) diff --git a/kivyblocks/pagescontainer.py b/kivyblocks/pagescontainer.py index 9ed33e0..88531bf 100644 --- a/kivyblocks/pagescontainer.py +++ b/kivyblocks/pagescontainer.py @@ -53,7 +53,9 @@ class PageContainer(FloatLayout): return w = self.pageWidgets[-1] try: - w.beforeDestroy() + print(' ******* del last widget begin******') + del w + print(' ******* del last widget end ******') except: pass self.pageWidgets = self.pageWidgets[:-1] diff --git a/kivyblocks/responsivelayout.py b/kivyblocks/responsivelayout.py index 9f80d98..7801fa2 100644 --- a/kivyblocks/responsivelayout.py +++ b/kivyblocks/responsivelayout.py @@ -14,6 +14,7 @@ class VResponsiveLayout(ScrollView): self.box_cols = cols super(VResponsiveLayout, self).__init__(**kw) self.options = kw + print('VResponsiveLayout():cols=',self.org_cols,'box_width=',self.box_width) self._inner = GridLayout(cols=self.org_cols, padding=2, spacing=2,size_hint=(1,None)) super(VResponsiveLayout,self).add_widget(self._inner) diff --git a/kivyblocks/threadcall.py b/kivyblocks/threadcall.py index cbdd752..2f55175 100644 --- a/kivyblocks/threadcall.py +++ b/kivyblocks/threadcall.py @@ -123,7 +123,7 @@ class HttpClient: return cb(None,resp) except NeedLogin as e: lf = LoginForm() - lf.needlogin(url,method,params,files,headers,callback,errback) + lf.open() return None except Exception as e: if errback is not None: diff --git a/kivyblocks/toolbar.py b/kivyblocks/toolbar.py index cae7aa2..ff874c9 100644 --- a/kivyblocks/toolbar.py +++ b/kivyblocks/toolbar.py @@ -101,7 +101,7 @@ class Toolbar(GridLayout): opt.img_size = self.opts.img_size opt.text_size = self.opts.text_size purl = None - if ancestor: + if ancestor and hasattr(ancestor, 'parenturl'): purl = ancestor.parenturl opt.img_src = absurl(opt.img_src,purl) tool = Tool(ancestor=ancestor, **opt) diff --git a/kivyblocks/vplayer.py b/kivyblocks/vplayer.py index 18201a7..a857c4c 100644 --- a/kivyblocks/vplayer.py +++ b/kivyblocks/vplayer.py @@ -49,7 +49,7 @@ class VPlayer(FloatLayout): can_changevolume=True ): super().__init__() - self.allow_screensaver = False + Window.allow_screensaver = False print(self,vfile) self._video = Video(allow_stretch=True,pos_hint={'x': 0, 'y': 0},size_hint=(1,1)) self.add_widget(self._video) @@ -92,6 +92,16 @@ class VPlayer(FloatLayout): self._video.bind(on_touch_down=self.show_hide_menu) self.register_event_type('on_playend') + def __del__(self): + print('********** delete VPlayer instance ********') + self._video.state = 'stop' + if self.update_task: + self.update_task.cancel() + self.update_task = None + Window.allow_screensaver = True + del self._video + self._video = None + def play(self,o=None,v=None): if self.curplay >= 0: self._video.source = self.playlist[self.curplay] @@ -168,11 +178,7 @@ class VPlayer(FloatLayout): def beforeDestroy(self): try: - self.pause() - if self.update_task: - self.update_task.cancel() - self.update_task = None - del self._video + del self except Exception as e: print_exc() diff --git a/test/conf/config.json b/test/conf/config.json index 7b6884d..ce22fb4 100644 --- a/test/conf/config.json +++ b/test/conf/config.json @@ -9,6 +9,9 @@ }, "font_name":"normal", "uihome":"http://www.bsppo.com:10080", + "i18n_url":"/public/i18n", + "publickey_url":"/public/publickey", + "login_url":"/public/publickey", "udws":[ "/udw/udws.uidesc" ],