From 39bd3e079162433a5ef17c3066103e33868856c1 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 18 Feb 2021 18:45:44 +0800 Subject: [PATCH] bugfix --- kivyblocks/dg.py | 26 +++++++++++++++++++++++--- kivyblocks/markdown.py | 21 ++++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/kivyblocks/dg.py b/kivyblocks/dg.py index b88a74f..7e6a35c 100644 --- a/kivyblocks/dg.py +++ b/kivyblocks/dg.py @@ -1,4 +1,5 @@ import time +import ujson as json from kivy.uix.gridlayout import GridLayout from kivy.uix.boxlayout import BoxLayout from kivy.uix.scrollview import ScrollView @@ -14,6 +15,7 @@ from kivy.factory import Factory from appPublic.dictObject import DictObject from appPublic.timecost import TimeCost from appPublic.uniqueID import getID +from appPublic.myTE import string_template_render from .utils import CSize, setSizeOptions, loading, loaded, absurl, alert from .baseWidget import Text @@ -24,7 +26,20 @@ from .toolbar import Toolbar from .bgcolorbehavior import BGColorBehavior def field_widget(desc, rec): + viewer = desc.get('viewer') + if viewer: + if not isinstance(viewer,'str'): + viewer = json.dumps(viewer) + rendered = string_template_render(desc.get('viewer'), rec) + dic = json.loads(rendered) + print('field_widget(), dic=', dic) + if dic is None: + return None + return Factory.Blocks(dic) + uitype = desc.get('uitype', 'str') + if uitype is None: + uitype = desc.get('datatype') if uitype in [ 'str' 'date', 'time', 'timestamp' ]: return BLabel(text = str(desc['value']), font_size=CSize(1),wrap=True, @@ -41,11 +56,13 @@ def field_widget(desc, rec): font_size=CSize(1), wrap=True, halign='right', valign='middle' ) + return BLabel(text = str(desc['value']), font_size=CSize(1),wrap=True, halign='left', valign='middle' ) + class BLabel(ButtonBehavior, Text): def __init__(self, **kw): ButtonBehavior.__init__(self) @@ -87,8 +104,9 @@ class Cell(BoxLayout): ) else: bl = field_widget(desc,self.row.row_data) - self.add_widget(bl) - bl.bind(on_press=self.cell_press) + if bl: + self.add_widget(bl) + bl.bind(on_press=self.cell_press) def cell_press(self,obj): self.row.selected() @@ -150,7 +168,9 @@ class Header(WidgetReady, BGColorBehavior, ScrollWidget): def init(self,t): rd = [ f.copy() for f in self.part.rowdesc ] - [ f.update({'value':self.part.fields[i]['label']}) for i,f in enumerate(rd) ] + [ f.update({'value':self.part.fields[i].get('label', \ + self.part.fields[i].get('name'))}) \ + for i,f in enumerate(rd) ] self.header = Row(self.part,rd,header=True) self.add_widget(self.header) self.height = self.header.height diff --git a/kivyblocks/markdown.py b/kivyblocks/markdown.py index 493914d..de485e8 100644 --- a/kivyblocks/markdown.py +++ b/kivyblocks/markdown.py @@ -53,10 +53,29 @@ description file format def update(self, o, text): print('text=',text, type(text)) + text = ''.join(text.split('\r')) + """ + org_boxs = re.findall(r"\n```\n(.*)\n```\n", text) + org_boxs_widget = [ \ + Factory.Blocks().widgetBuild({ \ + "widgettype":f"Title{level}", \ + "options":{ \ + "text":txt, \ + "size_hint_x":None, \ + "width":self.width, \ + "size_hint_y":None, \ + "markup":True, \ + "bgcolor":self.options.source_bgcolor, \ + "wrap":True, \ + "halign":"left", \ + "valign":"middle" \ + } \ + }) for t in org_boxs ] + other_texts = re.split(r"\n```\n(.*)\n```\n", text) + """ if not text: return for l in text.split('\n'): - l = ''.join([i for i in l if i != '\r']) self.parse_line(l) def parse_title(self, txt, level):