This commit is contained in:
yumoqing 2021-02-18 18:45:44 +08:00
parent 11d02d218e
commit 39bd3e0791
2 changed files with 43 additions and 4 deletions

View File

@ -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,6 +104,7 @@ class Cell(BoxLayout):
)
else:
bl = field_widget(desc,self.row.row_data)
if bl:
self.add_widget(bl)
bl.bind(on_press=self.cell_press)
@ -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

View File

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