From 2da40112bb5a6dca573dff7bdb06c2711048d5b7 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 3 May 2020 13:14:27 +0800 Subject: [PATCH] bugfix --- kivyblocks/baseWidget.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/kivyblocks/baseWidget.py b/kivyblocks/baseWidget.py index a842b10..8f3b1fb 100755 --- a/kivyblocks/baseWidget.py +++ b/kivyblocks/baseWidget.py @@ -51,6 +51,7 @@ from kivycalendar import DatePicker from kivy.factory import Factory from appPublic.dictObject import DictObject +from appPublic.folderUtils import listFile from .widgetExt.scrollwidget import ScrollWidget from .widgetExt.binstateimage import BinStateImage @@ -91,6 +92,44 @@ class PressableLabel(ButtonBehavior, Text): def on_press(self): pass +class FILEDataHandler(EventDispatcher): + def __init__(self, url, subfixes=[],params={}): + self.url = url + self.subfixes=subfixes + self.params = params + self.page_rows = self.params.get('page_rows',60) + self.page = self.params.get('page',1) + if not url.startswith('file://'): + raise Exception('%s is not a file url' % url) + self.files = [i for i in listFile(url[7:],suffixs=subfixes, \ + rescursive=self.params.get('rescursive',False)) ] + self.total_files = len(self.files) + x = 0 if self.total_files % self.page_rows == 0 else 1 + self.total_pages = self.total_files / self.page_rows + x + self.register_event_type('on_success') + self.register_event_type('on_error') + + def on_success(self,d): + return + + def on_error(self,e): + return + + def handle(self,params={}): + d = {} + d['total'] = self.total_files + d['rows'] = [] + p = self.params.copy() + p.update(params) + page = p.get('page') + for i in range(self.page_rows): + try: + r = self.files[page * self.page_rows + i] + d['rows'].append({'filename':r}) + except: + break + self.dispatch('on_success',d) + class HTTPDataHandler(EventDispatcher): def __init__(self, url,method='GET',params={}, headers={},