From c1b7768fdda830d4e7cbd42f46477a7ab449c9d0 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 29 Jan 2022 22:54:46 +0800 Subject: [PATCH] bugfix --- kivyblocks/boxViewer.py | 44 ++++++------- kivyblocks/chart2d.py | 133 ---------------------------------------- kivyblocks/register.py | 16 ----- 3 files changed, 20 insertions(+), 173 deletions(-) delete mode 100644 kivyblocks/chart2d.py diff --git a/kivyblocks/boxViewer.py b/kivyblocks/boxViewer.py index ae6beca..253b06a 100644 --- a/kivyblocks/boxViewer.py +++ b/kivyblocks/boxViewer.py @@ -24,20 +24,27 @@ from kivy.app import App from kivy.factory import Factory from kivy.utils import platform from kivy.uix.boxlayout import BoxLayout -from kivy.graphics import Fbo +from kivy.graphics import Fbo, Color, Rectangle from .responsivelayout import VResponsiveLayout from .toolbar import Toolbar from .paging import Paging, RelatedLoader from .utils import CSize from .ready import WidgetReady +from .baseWidget import VBox -class BoxViewer(WidgetReady, BoxLayout): +class BoxViewer(VBox): + toolbar = DictProperty(None) + dataloader = DictProperty(None) + boxwidth = NumericProperty(0.48) + boxheight = NumericProperty(None) + viewer = DictProperty(None) + viewer_url = StringProperty(None) + viewer_css = StringProperty('viewer_css') def __init__(self, **options): self.options = options self.subwidgets = [] self.toolbar = None - self.parenturl = None self.dataloader = None self.initflag = False remind = ['toolbar', @@ -45,44 +52,33 @@ class BoxViewer(WidgetReady, BoxLayout): 'orientation', 'boxwidth', 'boxheight', - 'color_level', - 'radius', 'viewer_url', 'viewer' ] - kwargs = {k:v for k,v in options.items() if k not in remind } - print('BoxViewer():kwargs=',kwargs) - BoxLayout.__init__(self, orientation='vertical', **kwargs) - WidgetReady.__init__(self) + SUPER(BoxViewer, self, options) self.selected_data = None - self.radius = self.options.get('radius',[]) - self.box_width = CSize(options['boxwidth']) - self.box_height = CSize(options['boxheight']) + self.box_width = CSize(self.boxwidth) + self.box_height = CSize(self.boxheight) self.viewContainer = VResponsiveLayout(box_width=self.box_width) - if options.get('toolbar'): - self.toolbar = Toolbar(options['toolbar']) - lopts = options['dataloader'].copy() - if lopts.get('options'): - lopts = lopts.get('options') + if self.toolbar: + self.toolbar_w = Toolbar(self.toolbar) + lopts = self.dataloader.get('options', {}).copy() self.dataloader = RelatedLoader(target=self,**lopts) self.dataloader.bind(on_deletepage=self.deleteWidgets) self.dataloader.bind(on_pageloaded=self.addPageWidgets) self.dataloader.bind(on_newbegin=self.deleteAllWidgets) - self.params = self.options['dataloader']['options'].get('params',{}) + self.params = lopts.get('params',{}) - if self.toolbar: - self.add_widget(self.toolbar) + if self.toolbar_w: + self.add_widget(self.toolbar_w) if self.dataloader.widget: self.add_widget(self.dataloader.widget) - self.dataloader.bind(on_submit=self.getParams) + self.dataloader.widget.bind(on_submit=self.getParams) self.add_widget(self.viewContainer) self.register_event_type('on_selected') self.bind(size=self.resetCols, pos=self.resetCols) self.viewContainer.bind(on_scroll_stop=self.on_scroll_stop) - # use_keyboard() will block the python - # no reason !!!! - # self.use_keyboard() def key_handle(self,keyinfo): print('keyinfo=',keyinfo,'...................') diff --git a/kivyblocks/chart2d.py b/kivyblocks/chart2d.py deleted file mode 100644 index ed66a9f..0000000 --- a/kivyblocks/chart2d.py +++ /dev/null @@ -1,133 +0,0 @@ -import math -from kivyblocks.graph import * -from kivy.utils import get_color_from_hex as rgb -from .threadcall import HttpClient - -class Chart2d(Graph): - """ - json format: - { - "widgettype":"Chart2d", - "options":{ - "xlabel":"Xlabel", - "ylable":"Ylabel", - "x_ticks_minor":1, - "x_ticks_major":5, - "y_ticks_minor":1, - "y_ticks_major":5, - "x_grid_label":true, - "y_grid_label":true, - "padding":5, - "xlog":false, - "ylog":false, - "x_grid":true, - "y_grid":true, - "xmin":0, - "xmax":100, - "ymax":100, - "ymin":1, - "x_field":"xxx", - "dataurl":"xxx", - "charts":[ - { - "y_field":"yy", - "color":"efefef", - "charttype":"LinePlot" - } - ] - - } - } - """ - plotmappings={ - "line":LinePlot, - "hbar":BarPlot - } - default_options = { - "x_grid_label":True, - "y_grid_label":True, - "xlabel":"Xlabel", - "ylabel":"Ylabel", - "xmin":0, - "xmax":100, - "ymax":100, - "ymin":1, - "x_grid":True, - "y_grid":True, - "padding":5, - "xlog":False, - "ylog":False, - 'x_ticks_minor':1, - 'x_ticks_major':5, - "y_ticks_minor":1, - "y_ticks_major":5, - 'label_options': { - 'color': rgb('444444'), # color of tick labels and titles - 'bold': True}, - 'background_color': rgb('f8f8f2'), # canvas background color - 'tick_color': rgb('808080'), # ticks and grid - 'border_color': rgb('808080') # border drawn around each graph - } - - def __init__(self, dataurl='', - data=None, - x_field='', - params={}, - headers={}, - charts=[], - **kw): - self._dataurl = dataurl - self._params = params - self._headers = {} - self.x_field = x_field - self._data = data - if not self._data: - self._data = self.get_data() - print('_data=',self._data, 'url=', self._dataurl) - xmax = len(self._data) - ymax = 0 - xvalue = [ self._data[i][self.x_field] for i in range(xmax) ] - self._charts = charts - print('charts=', charts) - plots = [] - for c in charts: - plotKlass = self.plotmappings.get(c['charttype']) - if not plotKlass: - print('charttype not defined', c) - continue - yvalue = [self._data[i][c['y_field']] for i in range(xmax)] - print('yvalue=', yvalue) - color = rgb(c.get('color','d8d8d8')) - plot = plotKlass(color=color) - plot.points = [(i,yvalue[i]) for i in range(xmax)] - plots.append(plot) - maxv = max(yvalue) - if ymax < maxv: - ymax = maxv - - gkw = self.default_options.copy() - gkw.update(kw) - gkw['ymax'] = math.ceil(ymax) - gkw['y_ticks_minor'] = gkw['ymax'] / 10 - gkw['y_ticks_major'] = gkw['ymax'] / 2 - gkw['x_ticks_minor'] = 1 - if gkw['x_ticks_major'] > xmax: - gkw['x_ticks_major'] = xmax - gkw['xmax'] = xmax - print('gkw=', gkw) - Graph.__init__(self, **gkw) - - print('plots=', plots) - for p in plots: - print('points=', p.points) - self.add_plot(p) - if hasattr(p,'bind_to_graph'): - p.bind_to_graph(self) - - def get_data(self): - hc = HttpClient() - d = hc.get(self._dataurl, - params=self._params, - headers=self._headers) - return d - diff --git a/kivyblocks/register.py b/kivyblocks/register.py index 573cda7..e1e0986 100644 --- a/kivyblocks/register.py +++ b/kivyblocks/register.py @@ -23,11 +23,7 @@ from .tab import TabsPanel from .qrdata import QRCodeWidget # from .kivycamera import KivyCamera from .filebrowser import FileLoaderBrowser -from .graph import Graph, MeshLinePlot, MeshStemPlot, LinePlot, \ - SmoothLinePlot, ContourPlot, BarPlot, HBar, VBar, ScatterPlot, \ - PointPlot from .mapview import MapView -from .chart2d import Chart2d from .message import Conform from .pagepanel import PagePanel from .markdown import Markdown @@ -59,19 +55,7 @@ r('QrReader', QrReader) r('Markdown', Markdown) r('PagePanel', PagePanel) r('Conform', Conform) -r('Chart2d', Chart2d) r('Popup', Popup) -r('Graph', Graph) -r('MeshLinePlot', MeshLinePlot) -r('MeshStemPlot', MeshStemPlot) -r('LinePlot', LinePlot) -r('SmoothLinePlot', SmoothLinePlot) -r('ContourPlot', ContourPlot) -r('BarPlot', BarPlot) -r('HBar', HBar) -r('VBar', VBar) -r('ScatterPlot', ScatterPlot) -r('PointPlot', PointPlot) r('MapView', MapView) r('DataGrid',DataGrid) r('FileLoaderBrowser',FileLoaderBrowser)