From 9c41413d554e4a02c4a0407995f4c6a041990ed8 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 15 Jul 2021 13:58:28 +0800 Subject: [PATCH] bugfix --- kivyblocks/boxViewer.py | 26 +++++++++++++++++++++++++- kivyblocks/dg.py | 32 +++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/kivyblocks/boxViewer.py b/kivyblocks/boxViewer.py index 48b8619..596db84 100644 --- a/kivyblocks/boxViewer.py +++ b/kivyblocks/boxViewer.py @@ -15,6 +15,8 @@ BoxViewer options: } } """ +from functools import partial + from traceback import print_exc from functools import partial from appPublic.dictExt import dictExtend @@ -52,7 +54,6 @@ class BoxViewer(WidgetReady, BoxLayout): BoxLayout.__init__(self, orientation='vertical', **kwargs) WidgetReady.__init__(self) self.selected_data = None - self.color_level = self.options.get('color_level',-1) self.radius = self.options.get('radius',[]) self.box_width = CSize(options['boxwidth']) self.box_height = CSize(options['boxheight']) @@ -91,6 +92,11 @@ class BoxViewer(WidgetReady, BoxLayout): def deleteAllWidgets(self,o): self.viewContainer.clear_widgets() self.subwidgets = [] + + def getShowRows(self): + wc = int(self.viewContainer.width / self.box_width) + hc = int(self.viewContainer.height / self.box_height) + self.show_rows = wc * hc def addPageWidgets(self,o,data): widgets = [] @@ -101,6 +107,23 @@ class BoxViewer(WidgetReady, BoxLayout): if dir == 'up': recs.reverse() idx = -1 + recs1 = recs[:self.show_rows] + recs2 = recs[self.show_rows:] + for r in recs1: + self.showObject(widgets, r, index=idx) + + data['widgets'] = widgets + data['idx'] = idx + data['data'] = recs2 + f = partial(self.add_page_delay, data) + Clock.schedule_once(f, 0) + + def add_page_delay(self, data, *args): + recs = data['data'] + page = data['page'] + idx = data['idx'] + widgets = data['widgets'] + for r in recs: self.showObject(widgets, r, index=idx) @@ -136,6 +159,7 @@ class BoxViewer(WidgetReady, BoxLayout): self.viewContainer.height = self.height - h self.viewContainer.setCols() + self.getShowRows() if not self.initflag: self.dataloader.loadPage(1) self.initflag = True diff --git a/kivyblocks/dg.py b/kivyblocks/dg.py index 3d4cd10..96c6e54 100644 --- a/kivyblocks/dg.py +++ b/kivyblocks/dg.py @@ -1,5 +1,7 @@ import time import ujson as json +from functools import partial + from kivy.logger import Logger from kivy.uix.gridlayout import GridLayout from kivy.uix.boxlayout import BoxLayout @@ -406,13 +408,14 @@ class DataGrid(WidgetReady, BoxLayout): return self.rowheight def calculateShowRows(self,t): - self.show_rows = int(self.normal_part.body.height/self.rowHeight()) - self.dataloader.setPageRows(self.show_rows) + self.getShowRows() + self.dataloader.setPageRows(self.show_rows * 2) def getShowRows(self): if self.show_rows == 0: return 60 - return self.show_rows + self.show_rows = int(self.rowHeight() / self.normal_part.body.height) + return self.show_rows * 2 def clearRows(self, *args): print('dg.py:clearRows() called') @@ -421,14 +424,33 @@ class DataGrid(WidgetReady, BoxLayout): self.normal_part.body.clearRows() def add_page(self,o,data): + dir = data['dir'] + if not self.show_rows: + self.getShowRows() + ids = [] recs = data['data'] - page = data['page'] - dir = data['dir'] idx = 0 if dir == 'up': recs.reverse() idx = -1 + recs1 = recs[:self.show_rows] + recs2 = recs[self.show_rows:] + for r in recs1: + id = self.addRow(r,index=idx) + ids.append(id) + + data['idx'] = idx + data['ids'] = ids + data['data'] = recs2 + f = partial(self.add_page_delay,data) + Clock.schedule_once(f, 0) + + def add_page_delay(self, data, *args): + recs = data['data'] + page = data['page'] + idx = data['idx'] + ids = data['ids'] for r in recs: id = self.addRow(r,index=idx) ids.append(id)