From 7bc59cfacf3a05b34c4601f085af1f22e6e00e9a Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 18 Sep 2020 15:03:49 +0800 Subject: [PATCH] bugfix --- kivyblocks/paging.py | 58 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/kivyblocks/paging.py b/kivyblocks/paging.py index 60dae41..cd2d69c 100644 --- a/kivyblocks/paging.py +++ b/kivyblocks/paging.py @@ -36,6 +36,22 @@ it fires two type of event 'on_pageloaded':fire when a page data loads success """ +class BaseLoader: + def loadPage(self,p): + pass + + def loadNextPage(self): + if self.total_page > 0 and self.curpage >=self.total_page: + return + p = self.curpage + 1 + self.loadPage(p) + + def loadPreviousPage(self): + if self.curpage <= 1: + return + p = self.curpage - 1 + self.loadPage(p) + class PageLoader(EventDispatcher): def __init__(self,target=None, **options): self.loading = False @@ -57,16 +73,6 @@ class PageLoader(EventDispatcher): self.register_event_type('on_pageloaded') self.newbegin = True - def getLocater(self): - if self.newbegin: - self.newbegin = False - return 1 - - x = 1 / self.MaxbufferPage - if self.dir != 'down': - x = 1 - x - return x - def on_newbegin(self): pass @@ -184,6 +190,16 @@ class RelatedLoader(PageLoader): self.widget = None self.register_event_type('on_deletepage') + def getLocater(self): + if self.newbegin: + self.newbegin = False + return 1 + + x = 1 / self.MaxbufferPage + if self.dir != 'down': + x = 1 - x + return x + def on_deletepage(self,d): pass @@ -304,6 +320,28 @@ class Paging(PageLoader): return self.loadPage(self.total_page) +class ListLoader(PageLoader): + def __init__(self, data_list=[],**options): + self._data_list = data_list + PageLoader.__init__(self,**options) + self.total_cnt = len(self._data_list) + t = 0 if self.total_cnt % self.page_rows == 0 else 1 + self.total_page = self.total_cnt / self.page_rows + t + + def loadPage(self,p): + if p < 1: + p = 1 + if p > self.total_page: + d = [] + else : + a = (p - 1) * self.page_rows + b = p * self.page_rows + d = self.d[a:b] + return { + "total":self.total_cnt, + "rows":d + } + class OneRecordLoader(PageLoader): def __init__(self,**options): PageLoader.__init__(self,**options)