This commit is contained in:
yumoqing 2022-01-13 16:18:03 +08:00
parent 07bea7bb61
commit 0b2a01cec6
20 changed files with 141 additions and 38 deletions

BIN
kivyblocks/.uitype.py.swp Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,6 +2,7 @@
import os import os
import sys import sys
from kivy.resources import resource_add_path from kivy.resources import resource_add_path
from kivy.config import Config
resource_add_path(os.path.join(os.path.dirname(__file__),'./ttf')) resource_add_path(os.path.join(os.path.dirname(__file__),'./ttf'))
Config.set('kivy', 'default_font', [ Config.set('kivy', 'default_font', [
'msgothic', 'msgothic',
@ -17,7 +18,6 @@ from appPublic.uniqueID import getID
from appPublic.rsa import RSA from appPublic.rsa import RSA
from kivy.factory import Factory from kivy.factory import Factory
from kivy.config import Config
from kivy.metrics import sp,dp,mm from kivy.metrics import sp,dp,mm
from kivy.core.window import WindowBase, Window from kivy.core.window import WindowBase, Window
from kivy.clock import Clock from kivy.clock import Clock

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -8,6 +8,8 @@ we use a register machinans to maintian the ui type information to build the vie
import ujson as json import ujson as json
from kivy.factory import Factory from kivy.factory import Factory
from kivy.properties import NumericProperty, StringProperty, \
BooleanProperty
from kivy.uix.label import Label from kivy.uix.label import Label
from appPublic.myTE import string_template_render from appPublic.myTE import string_template_render
@ -17,6 +19,36 @@ from .baseWidget import WrapText, Text
from .widgetExt.inputext import FloatInput,IntegerInput, \ from .widgetExt.inputext import FloatInput,IntegerInput, \
StrInput,SelectInput, BoolInput, AmountInput, Password StrInput,SelectInput, BoolInput, AmountInput, Password
class StringView(Label):
def __init__(self, **kw):
super(StringView, self).__init__(**kw)
self.wrap = True
self.halign = 'left'
self.valign = 'middle'
def getValue(self):
return self.text
def setValue(self, v):
self.text = str(v)
class PasswordView(StringView):
def __init__(self, text='*', **kw):
super(PasswordView, self).__init__(text=text, **kw)
def getValue(self):
return None
def setValue(self, v):
pass
class TextView(WrapText):
def getValue(self):
return self.text
def setValue(self, v):
self.text = v
view_widget_builders = { view_widget_builders = {
} }
@ -62,7 +94,7 @@ def get_value(desc, rec=None):
def build_view_str_widget(desc, rec=None): def build_view_str_widget(desc, rec=None):
txt = get_value(desc, rec=rec) txt = get_value(desc, rec=rec)
return Label(text=str(txt) if txt else '', return StringView(text=str(txt) if txt else '',
font_size=CSize(1), font_size=CSize(1),
halign='left', halign='left',
valign='middle') valign='middle')
@ -74,7 +106,7 @@ view_register('timestamp', build_view_str_widget)
def build_view_text_widget(desc, rec=None): def build_view_text_widget(desc, rec=None):
txt = get_value(desc, rec=rec) txt = get_value(desc, rec=rec)
return WrapText(text=str(txt) if txt else '', return TextView(text=str(txt) if txt else '',
font_size=CSize(1), font_size=CSize(1),
halign='left', halign='left',
valign='middle') valign='middle')
@ -82,32 +114,74 @@ def build_view_text_widget(desc, rec=None):
view_register('text', build_view_text_widget) view_register('text', build_view_text_widget)
def build_view_passwd_widget(desc, rec=None): def build_view_passwd_widget(desc, rec=None):
return Label(text='*', return PasswordView(text='*',
font_size=CSize(1), font_size=CSize(1),
halign='left', halign='left',
valign='middle') valign='middle')
view_register('password', build_view_passwd_widget) view_register('password', build_view_passwd_widget)
class BoolView(Label):
value = BooleanProperty(False)
def __init__(self, text='', **kw):
super(BoolView, self).__init__(text='', **kw)
self.wrap = True
self.halign = 'center'
self.valign = 'middle'
def on_value(self, *args):
if self.value:
self.text = 'true'
else:
self.text = 'false'
def getValue(self):
return self.value
def setValue(self, v):
self.value = v
def build_view_bool_widget(desc, rec=None): def build_view_bool_widget(desc, rec=None):
v = get_value(desc, rec) v = get_value(desc, rec)
if v is not None: if v is not None:
return Label(text='True' if v else 'False', return BoolView(value=v,
font_size=CSize(1), font_size=CSize(1),
halign='left', halign='left',
valign='middle') valign='middle')
default_value = desc.get('nullvalue','') default_value = desc.get('nullvalue',False)
return Label(text=default_value, return BoolView(value=default_Value,
font_size=CSize(1), font_size=CSize(1),
halign='left', halign='left',
valign='middle') valign='middle')
view_register('bool', build_view_bool_widget) view_register('bool', build_view_bool_widget)
class IntView(Text):
value = NumericProperty(None)
nullstr = StringProperty('')
def __init__(self, **kw):
super(IntView, self).__init__(text='', **kw)
self.wrap = True
self.halign = 'right'
self.valign = 'middle'
def on_value(self, *args):
if self.value is not None:
self.text = str(v)
else:
self.text = self.nullstr
def setValue(self, v):
self.value = v
def getValue(self):
return self.value
def build_view_int_widget(desc, rec=None): def build_view_int_widget(desc, rec=None):
v = get_value(desc, rec=rec) v = get_value(desc, rec=rec)
default_value = desc.get('nullvalue','') return IntValue(value=v,
return Label(text=str(v) if v is not None else default_value, nullstr=desc.get('nullstr',''),
font_size=CSize(1), font_size=CSize(1),
halign='right', halign='right',
valign='middle' valign='middle'
@ -115,11 +189,33 @@ def build_view_int_widget(desc, rec=None):
view_register('int', build_view_int_widget) view_register('int', build_view_int_widget)
class FloatView(Text):
value = NumericProperty(None)
nullstr = StringProperty('')
dec = NumericProperty(2)
def __init__(self, **kw):
super(FloatView, self).__init__(text=self.nullstr, **kw)
self.wrap = True
self.halign = 'right'
self.valign = 'middle'
def on_value(self, *args):
if self.value is None:
self.text = self.bullstr
f = '%%.0%df' % self.dec
self.text = f % self.value
def getValue(self):
return self.value
def setValue(self, v):
self.value = v
def build_view_float_widget(desc, rec=None): def build_view_float_widget(desc, rec=None):
v = get_value(desc, rec=rec) v = get_value(desc, rec=rec)
f = '%%.0%df' % desc.get('dec',2) return FloatView(value=v,
default_value = desc.get('nullvalue','') dec=desc.get('dec', 2),
return Label(text=f % float(v) if v is not None else default_value, nullstr=desc.get('nullstr',''),
font_size=CSize(1), font_size=CSize(1),
halign='right', halign='right',
valign='middle' valign='middle'
@ -141,9 +237,16 @@ def build_view_code_widget(desc, rec=None):
view_register('code', build_view_code_widget) view_register('code', build_view_code_widget)
def amount_str(v, dec): class AmountView(FloatView):
f = '%%.0%df' % dec def on_value(self, *args):
s = f % v if self.value is None:
self.text = self.nullstr
else:
self.text = self.amount_str()
def amount_str(self):
f = '%%.0%df' % self.dec
s = f % self.value
parts = s.split('.') parts = s.split('.')
p_int = parts[0] p_int = parts[0]
subs = [] subs = []
@ -165,10 +268,10 @@ def amount_str(v, dec):
def build_view_amount_widget(desc, rec=None): def build_view_amount_widget(desc, rec=None):
v = get_value(desc, rec=rec) v = get_value(desc, rec=rec)
defaultvalue = desc.get('nullvalue', '') defaultvalue = desc.get('nullstr', '')
if v: return Amount(value=v,
f = '%%.0%df' % desc.get('dec',2) dec=desc.get('dec', 2),
return Label(text=amount_str(v, dec), nullstr=defaultvale,
font_size=CSize(1), font_size=CSize(1),
halign='right', halign='right',
valign='middle' valign='middle'