This commit is contained in:
yumoqing 2021-07-15 13:58:28 +08:00
parent db2cf3f860
commit 9c41413d55
2 changed files with 52 additions and 6 deletions

View File

@ -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

View File

@ -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)