This commit is contained in:
yumoqing 2022-01-30 00:08:49 +08:00
parent c1b7768fdd
commit 4f9748308c
3 changed files with 79 additions and 48 deletions

View File

@ -22,13 +22,15 @@ from functools import partial
from appPublic.dictExt import dictExtend from appPublic.dictExt import dictExtend
from kivy.app import App from kivy.app import App
from kivy.factory import Factory from kivy.factory import Factory
from kivy.clock import Clock
from kivy.utils import platform from kivy.utils import platform
from kivy.uix.boxlayout import BoxLayout from kivy.uix.boxlayout import BoxLayout
from kivy.graphics import Fbo, Color, Rectangle from kivy.graphics import Fbo, Color, Rectangle
from kivy.properties import NumericProperty, StringProperty, DictProperty
from .responsivelayout import VResponsiveLayout from .responsivelayout import VResponsiveLayout
from .toolbar import Toolbar from .toolbar import Toolbar
from .paging import Paging, RelatedLoader from .paging import Paging, RelatedLoader
from .utils import CSize from .utils import CSize, SUPER
from .ready import WidgetReady from .ready import WidgetReady
from .baseWidget import VBox from .baseWidget import VBox
@ -36,50 +38,53 @@ from .baseWidget import VBox
class BoxViewer(VBox): class BoxViewer(VBox):
toolbar = DictProperty(None) toolbar = DictProperty(None)
dataloader = DictProperty(None) dataloader = DictProperty(None)
boxwidth = NumericProperty(0.48) boxwidth = NumericProperty(None)
boxwidth_c = NumericProperty(None)
boxheight = NumericProperty(None) boxheight = NumericProperty(None)
boxheight_c = NumericProperty(None)
viewer = DictProperty(None) viewer = DictProperty(None)
viewer_url = StringProperty(None) viewer_url = StringProperty(None)
viewer_css = StringProperty('viewer_css') viewer_css = StringProperty('viewer_css')
def __init__(self, **options): def __init__(self, **options):
self.options = options
self.subwidgets = [] self.subwidgets = []
self.toolbar = None self.toolbar_w = None
self.dataloader = None self._dataloader = None
self.initflag = False self.initflag = False
remind = ['toolbar',
'dataloader',
'orientation',
'boxwidth',
'boxheight',
'viewer_url',
'viewer'
]
SUPER(BoxViewer, self, options) SUPER(BoxViewer, self, options)
self.selected_data = None self.selected_data = None
self.box_width = CSize(self.boxwidth)
self.box_height = CSize(self.boxheight)
self.viewContainer = VResponsiveLayout(box_width=self.box_width) self.viewContainer = VResponsiveLayout(box_width=self.box_width)
if self.toolbar: if self.toolbar:
self.toolbar_w = Toolbar(self.toolbar) self.toolbar_w = Toolbar(self.toolbar)
lopts = self.dataloader.get('options', {}).copy() lopts = self.dataloader.get('options', {}).copy()
self.dataloader = RelatedLoader(target=self,**lopts) self._dataloader = RelatedLoader(target=self,**lopts)
self.dataloader.bind(on_deletepage=self.deleteWidgets) self._dataloader.bind(on_deletepage=self.deleteWidgets)
self.dataloader.bind(on_pageloaded=self.addPageWidgets) self._dataloader.bind(on_pageloaded=self.addPageWidgets)
self.dataloader.bind(on_newbegin=self.deleteAllWidgets) self._dataloader.bind(on_newbegin=self.deleteAllWidgets)
self.params = lopts.get('params',{}) self.params = lopts.get('params',{})
if self.toolbar_w: if self.toolbar_w:
self.add_widget(self.toolbar_w) self.add_widget(self.toolbar_w)
if self.dataloader.widget: if self._dataloader.widget:
self.add_widget(self.dataloader.widget) self.add_widget(self._dataloader.widget)
self.dataloader.widget.bind(on_submit=self.getParams) self._dataloader.widget.bind(on_submit=self.getParams)
self.add_widget(self.viewContainer) self.add_widget(self.viewContainer)
self.register_event_type('on_selected') self.register_event_type('on_selected')
self.bind(size=self.resetCols, self.bind(size=self.resetCols,
pos=self.resetCols) pos=self.resetCols)
self.viewContainer.bind(on_scroll_stop=self.on_scroll_stop) self.viewContainer.bind(on_scroll_stop=self.on_scroll_stop)
def on_boxheight(self, *args):
self.box_height = self.boxheight
def on_boxheight_c(self, *args):
self.box_height = CSize(self.boxheight_c)
def on_boxwidth_c(self, *args):
self.box_width = CSize(self.boxwidth_c)
def on_boxwidth(self, *args):
self.box_width = self.boxwidth
def key_handle(self,keyinfo): def key_handle(self,keyinfo):
print('keyinfo=',keyinfo,'...................') print('keyinfo=',keyinfo,'...................')
@ -91,7 +96,7 @@ class BoxViewer(VBox):
self.subwidgets = [] self.subwidgets = []
def getShowRows(self): def getShowRows(self):
wc = int(self.viewContainer.width / self.box_width) wc = self.viewContainer.get_cols()
hc = int(self.viewContainer.height / self.box_height) hc = int(self.viewContainer.height / self.box_height)
self.show_rows = wc * hc self.show_rows = wc * hc
@ -140,14 +145,14 @@ class BoxViewer(VBox):
self.subwidgets += widgets self.subwidgets += widgets
self.dataloader.bufferObjects(page, widgets) self._dataloader.bufferObjects(page, widgets)
x = self.dataloader.getLocater() x = self._dataloader.getLocater()
self.locater(x) self.locater(x)
def loadData(self, **kw): def loadData(self, **kw):
self.params = kw self.params = kw
self.deleteAllWidgets(None) self.deleteAllWidgets(None)
self.dataloader.loadPage(1) self._dataloader.loadPage(1)
self.initflag = True self.initflag = True
def deleteWidgets(self,o,data): def deleteWidgets(self,o,data):
@ -165,14 +170,14 @@ class BoxViewer(VBox):
h = 0 h = 0
if self.toolbar: if self.toolbar:
h += self.toolbar.height h += self.toolbar.height
if self.dataloader.widget: if self._dataloader.widget:
h += self.dataloader.widget.height h += self._dataloader.widget.height
self.viewContainer.height = self.height - h self.viewContainer.height = self.height - h
self.viewContainer.setCols() self.viewContainer.setCols()
self.getShowRows() self.getShowRows()
if not self.initflag: if not self.initflag:
self.dataloader.loadPage(1) self._dataloader.loadPage(1)
self.initflag = True self.initflag = True
def showObject(self, holders, rec,index=0): def showObject(self, holders, rec,index=0):
@ -195,17 +200,17 @@ class BoxViewer(VBox):
self.subwidgets.append(box) self.subwidgets.append(box)
holders.append(box) holders.append(box)
desc = {} desc = {}
if self.options.get('viewer_url'): if self.viewer_url:
desc = { desc = {
"widgettype":"urlwidget", "widgettype":"urlwidget",
"options":{ "options":{
"params":rec, "params":rec,
"method":"GET", "method":"GET",
"url":self.options.get('viewer_url') "url":self.viewer_url
} }
} }
else: else:
desc = self.options.get('viewer').copy() desc = self.viewer.copy()
if desc['widgettype'] == 'urlwidget': if desc['widgettype'] == 'urlwidget':
desc = dictExtend(desc,{'options':{'params':rec}}) desc = dictExtend(desc,{'options':{'params':rec}})
else: else:
@ -219,9 +224,9 @@ class BoxViewer(VBox):
def on_scroll_stop(self,o,v=None): def on_scroll_stop(self,o,v=None):
if o.scroll_y <= 0.001: if o.scroll_y <= 0.001:
self.dataloader.loadNextPage() self._dataloader.loadNextPage()
if o.scroll_y >= 0.999: if o.scroll_y >= 0.999:
self.dataloader.loadPreviousPage() self._dataloader.loadPreviousPage()
def select_record(self,o,v=None): def select_record(self,o,v=None):
for w in self.subwidgets: for w in self.subwidgets:
@ -236,7 +241,7 @@ class BoxViewer(VBox):
"caller":self, "caller":self,
"page_rows":1, "page_rows":1,
"page":self.selected_data['__posInSet__'], "page":self.selected_data['__posInSet__'],
"dataurl":self.options['dataloader']['options']['dataurl'], "dataurl":self.dataloader['options']['dataurl'],
"params":self.params "params":self.params
} }
return d return d

View File

@ -262,14 +262,7 @@ class Form(WidgetCSS, WidgetReady, BoxLayout):
self.input_width = CSize(self.inputwidth) self.input_width = CSize(self.inputwidth)
self._cols = -1 # auto calculate self._cols = -1 # auto calculate
return return
if self.cols is not None: self.input_width = self.inputwidth
self._cols = self.cols
if self.inputwidth is None:
self.input_width = -1
else:
self.input_width = CSize(self.inputwidth)
return
self.input_width = -1
self._cols = 1 self._cols = 1
def set_grid_attrs(self): def set_grid_attrs(self):

View File

@ -7,11 +7,16 @@ from kivy.uix.gridlayout import GridLayout
from kivy.graphics import Color, Ellipse,Rectangle from kivy.graphics import Color, Ellipse,Rectangle
from kivy.clock import Clock from kivy.clock import Clock
from .utils import CSize, isHandHold, show_widget_info from .utils import CSize, isHandHold, show_widget_info
from .widget_css import WidgetCSS
from .ready import WidgetReady
class VResponsiveLayout(ScrollView): class VResponsiveLayout(WidgetCSS, WidgetReady, ScrollView):
box_width = NumericProperty(1) box_width = NumericProperty(None)
box_width_c = NumericProperty(None)
def __init__(self, **kw): def __init__(self, **kw):
self._inner = None self._inner = None
self.col_width = None
self.col_width_hint = False
super(VResponsiveLayout, self).__init__(**kw) super(VResponsiveLayout, self).__init__(**kw)
self.options = kw self.options = kw
self._inner = GridLayout(cols=1, padding=2, self._inner = GridLayout(cols=1, padding=2,
@ -24,17 +29,45 @@ class VResponsiveLayout(ScrollView):
self.setCols() self.setCols()
self.bind(pos=self.setCols,size=self.setCols) self.bind(pos=self.setCols,size=self.setCols)
def on_box_width_c(self, *args):
if self.box_width:
return
self.col_width = CSize(self.box_width)
self.col_width_hint = False
self.set_cols()
def on_box_width(self, *args): def on_box_width(self, *args):
if not self._inner: if not self._inner:
return return
if self.box_width <= 1: if self.box_width <= 1:
self._inner.col_default_width = self.width * self.box_width self.col_width = self.box_width
self.col_width_hint = self.box_width
else: else:
self._inner.col_default_width = self.box_width self.col_width = self.box_width
self.col_width_hint = False
self.set_cols()
def calculate_col_width(self):
# cnt * col_width + 2*padding + (cnt-1) * spacing = width
w = self._inner
width = w.width - 2 * w.padding
return width * self.col_width
def get_col_width(self):
return self._inner.col_default_width
def get_cols(self):
return self._inner.cols
def set_col_width_cnt(self):
if self.col_width_hint:
self._inner.col_default_width = self.calc_col_width()
else:
self._inner.col_default_width = self.col_width
self.setCols()
for w in self._inner.children: for w in self._inner.children:
w.size_hint_x = None w.size_hint_x = None
w.width = self._inner.col_default_width w.width = self._inner.col_default_width
self.setCols()
def on_orientation(self,o): def on_orientation(self,o):
self.setCols() self.setCols()