This commit is contained in:
yumoqing 2022-01-01 06:14:49 +08:00
parent 5f0a2d3b6a
commit 2a4e29c4bf
3 changed files with 2993 additions and 4064 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,8 +6,6 @@ from kivy.core.window import Window
from kivy.graphics import Color
from kivycalendar import DatePicker
from .responsivelayout import VResponsiveLayout
from .widgetExt.inputext import FloatInput,IntegerInput, \
StrInput,SelectInput, BoolInput, AmountInput, Password
from .baseWidget import *
from .utils import *
from .i18n import I18n
@ -17,6 +15,7 @@ from .dataloader import DataGraber
from .ready import WidgetReady
from .widget_css import WidgetCSS
from .dateinput import DateInput
from .uitype import get_input_builder
"""
form options
@ -51,75 +50,11 @@ form options
}
"""
uitypes = {
"str":{
"orientation":"horizontal",
"wclass":StrInput,
},
"string":{
"orientation":"horizontal",
"wclass":StrInput,
},
"password":{
"orientation":"horizontal",
"wclass":Password,
},
"int":{
"orientation":"horizontal",
"wclass":IntegerInput,
},
"number":{
"orientation":"horizontal",
"wclass":IntegerInput,
},
"float":{
"orientation":"horizontal",
"wclass":FloatInput,
},
"amount":{
"orientation":"horizontal",
"wclass":AmountInput,
},
"date":{
"orientation":"horizontal",
"wclass":DateInput,
},
"time":{
"orientation":"horizontal",
"wclass":StrInput,
},
"bool":{
"orientation":"horizontal",
"wclass":BoolInput,
},
"code":{
"orientation":"horizontal",
"wclass":SelectInput,
},
"text":{
"orientation":"horizontal",
"wclass":StrInput,
"options":{
"multiline":True,
"height":4,
}
},
"teleno":{
"orientation":"horizontal",
"wclass":StrInput,
},
"email":{
"orientation":"horizontal",
"wclass":StrInput,
},
}
class InputBox(BoxLayout):
def __init__(self, form, **options):
self.form = form
self.options = options
self.uitype = options.get('uitype',options.get('datatype','string'))
self.uidef = uitypes[self.uitype]
orientation = self.uidef['orientation']
self.uitype = options.get('uitype',options.get('datatype','str'))
width = self.form.inputwidth
height = self.form.inputheight
if self.uitype == 'text':
@ -129,7 +64,7 @@ class InputBox(BoxLayout):
self.labelwidth = self.form.labelwidth
kwargs = {
"orientation":orientation,
"orientation":'horizontal',
}
if height<=1:
kwargs['size_hint_y'] = height
@ -159,17 +94,12 @@ class InputBox(BoxLayout):
"size_hint_y":None,
"height":CSize(2)
}
if self.labelwidth<=1:
opts['size_hint_x'] = self.labelwidth
else:
opts['size_hint_x'] = None
opts['width'] = self.labelwidth
bl = BoxLayout(**opts)
self.add_widget(bl)
label = self.options.get('label',self.options.get('name'))
kwargs = {
"i18n":True,
"text":label,
"otext":label,
"font_size":CSize(1),
}
self.labeltext = Text(**kwargs)
@ -180,17 +110,11 @@ class InputBox(BoxLayout):
size_hint_x=None,
width=CSize(1))
bl.add_widget(star)
options = self.uidef.get('options',{}).copy()
options.update(self.options.get('uiparams',{}))
options['allow_copy'] = True
options['width'] = options.get('width',1)
options['height'] = options.get('height',1)
options['csscls'] = self.form.input_css
if self.options.get('hint_text'):
options['hint_text'] = i18n(self.options.get('hint_text'))
Logger.info('Form: uitype=%s', self.uitype)
self.input_widget = self.uidef['wclass'](**options)
options = self.options.copy()
options['hint_text'] = i18n(self.options.get('hint_text'))
f = get_input_builder(self.uitype)
self.input_widget = f(options)
if self.options.get('readonly'):
self.input_widget.disabled = True
if self.options.get('value'):
@ -200,6 +124,12 @@ class InputBox(BoxLayout):
self.input_widget.widget_id = self.options['name']
self.add_widget(self.input_widget)
if self.labelwidth<=1:
self.labeltext.size_hint_x = self.labelwidth
self.input_widget.size_hint_x = 1 - self.labelwidth
else:
self.labeltext.size_hint_x = None
self.labeltext.width = CSize(self.labelwidth)
self.initflag = True
self.input_widget.bind(on_focus=self.on_focus)

View File

@ -6,10 +6,17 @@ to auto construct the form widget and record show widget.
we use a register machinans to maintian the ui type information to build the view widget and input widget
"""
import ujson as json
from kivy.factory import Factory
from kivy.uix.label import Label
from appPublic.myTE import string_template_render
from kivyblocks.utils import CSize
from .baseWidget import WrapText, Text
from .widgetExt.inputext import FloatInput,IntegerInput, \
StrInput,SelectInput, BoolInput, AmountInput, Password
view_widget_builders = {
}
@ -30,7 +37,8 @@ def get_view_builder(uitype):
view_widget_builders.get('str', None))
def build_view_widget(desc, rec = None):
if desc.get('viewer'):
viewer = desc.get('viewer')
if viewer:
if isinstance(viewer,dict):
viewer = json.dumps(viewer)
rendered = string_template_render(viewer, rec)
@ -52,38 +60,67 @@ def get_value(desc, rec=None):
return rec.get(desc['name'])
return desc.get('value', desc.get('defaultvalue', ''))
def build_view_text_widget(desc, rec=None):
def build_view_str_widget(desc, rec=None):
txt = get_value(desc, rec=rec)
return Factory.Text(text=str(txt),
return Label(text=str(txt) if txt else '',
font_size=CSize(1),
wrap=True,
halign='left',
valign='middle')
view_register('str', build_view_text_widget)
view_register('date', build_view_text_widget)
view_register('time', build_view_text_widget)
view_register('timestamp', build_view_text_widget)
view_register('str', build_view_str_widget)
view_register('date', build_view_str_widget)
view_register('time', build_view_str_widget)
view_register('timestamp', build_view_str_widget)
def build_view_text_widget(desc, rec=None):
txt = get_value(desc, rec=rec)
return WrapText(text=str(txt) if txt else '',
font_size=CSize(1),
halign='left',
valign='middle')
view_register('text', build_view_text_widget)
def build_view_passwd_widget(desc, rec=None):
return Label(text='*',
font_size=CSize(1),
halign='left',
valign='middle')
view_register('password', build_view_passwd_widget)
def build_view_bool_widget(desc, rec=None):
v = get_value(desc, rec)
if v is not None:
return Label(text='True' if v else 'False',
font_size=CSize(1),
halign='left',
valign='middle')
default_value = desc.get('nullvalue','')
return Label(text=default_value,
font_size=CSize(1),
halign='left',
valign='middle')
view_register('bool', build_view_bool_widget)
def build_view_int_widget(desc, rec=None):
v = get_value(desc, rec=rec)
return Text(text=str(v),
default_value = desc.get('nullvalue','')
return Label(text=str(v) if v is not None else default_value,
font_size=CSize(1),
wrap=True,
halign='right',
valign='middle'
)
view_register('int', build_view_int_widget)
view_register('long', build_view_int_widget)
view_register('integer', build_view_int_widget)
def build_view_float_widget(desc, rec=None):
v = get_value(desc, rec=rec)
f = '%%.0%df' % desc.get('dec',2)
return Text(text=f % float(v),
default_value = desc.get('nullvalue','')
return Label(text=f % float(v) if v is not None else default_value,
font_size=CSize(1),
wrap=True,
halign='right',
valign='middle'
)
@ -95,6 +132,7 @@ def build_view_code_widget(desc, rec=None):
vf = desc.get('valueField','value')
v = rec.get(tf,rec.get(vf, ' '))
return Text(text=v,
i18n=True,
font_size = CSize(1),
wrap=True,
halign='center',
@ -103,4 +141,130 @@ def build_view_code_widget(desc, rec=None):
view_register('code', build_view_code_widget)
def amount_str(v, dec):
f = '%%.0%df' % dec
s = f % v
parts = s.split('.')
p_int = parts[0]
subs = []
if p_int[0] == '-':
subs.append('-')
p_int = p_int[1:]
l = [i for i in p_int]
l.reverse()
k = []
for i,c in enumerate(l):
if i and (i) % 3 == 0:
k.append(',')
k.append(c)
k.reverse()
subs.append(''.join(k))
if len(parts) > 1:
subs.append(f'.{parts[1]}')
return ''.join(subs)
def build_view_amount_widget(desc, rec=None):
v = get_value(desc, rec=rec)
defaultvalue = desc.get('nullvalue', '')
if v:
f = '%%.0%df' % desc.get('dec',2)
return Label(text=amount_str(v, dec),
font_size=CSize(1),
halign='right',
valign='middle'
)
view_register('amount', build_view_amount_widget)
def build_input_str_widget(desc, rec=None):
v = get_value(desc, rec=rec)
kw = desc.get('uiparams', {})
w = StrInput(**kw)
if v:
w.setValue(v)
return w
input_register('str', build_input_str_widget)
def build_input_text_widget(desc, rec=None):
v = get_value(desc, rec=rec)
kw = desc.get('uiparams', {})
kw['multiline'] = True
w = StrInput(**kw)
if v:
w.setValue(v)
return w
input_register('text', build_input_text_widget)
def build_input_int_widget(desc, rec=None):
v = get_value(desc, rec=rec)
kw = desc.get('uiparams', {})
w = IntegerInput(**kw)
if v:
w.setValue(v)
return w
input_register('int', build_input_int_widget)
input_register('time', build_input_int_widget)
def build_input_float_widget(desc, rec=None):
v = get_value(desc, rec=rec)
kw = desc.get('uiparams', {})
w = FloatInput(**kw)
if v:
w.setValue(v)
return w
input_register('float', build_input_float_widget)
def build_input_amount_widget(desc, rec=None):
v = get_value(desc, rec=rec)
kw = desc.get('uiparams', {})
w = AmountInput(**kw)
if v:
w.setValue(v)
return w
input_register('amount', build_input_amount_widget)
def build_input_date_widget(desc, rec=None):
v = get_value(desc, rec=rec)
kw = desc.get('uiparams', {})
w = DateInput(**kw)
if v:
w.setValue(v)
return w
input_register('date', build_input_date_widget)
def build_input_bool_widget(desc, rec=None):
v = get_value(desc, rec=rec)
kw = desc.get('uiparams', {})
w = BoolInput(**kw)
if v:
w.setValue(v)
return w
input_register('bool', build_input_bool_widget)
def build_input_code_widget(desc, rec=None):
v = get_value(desc, rec=rec)
kw = desc.get('uiparams', {})
w = SelectInput(**kw)
if v:
w.setValue(v)
return w
input_register('code', build_input_code_widget)
def build_input_password_widget(desc, rec=None):
v = get_value(desc, rec=rec)
kw = desc.get('uiparams', {})
w = Password(**kw)
if v:
w.setValue(v)
return w
input_register('password', build_input_password_widget)