This commit is contained in:
yumoqing 2021-02-18 14:39:03 +08:00
parent f6cdb7343b
commit 11d02d218e
5 changed files with 95 additions and 19 deletions

View File

@ -153,6 +153,9 @@ class Text(Label):
kwargs = kw.copy()
config = getConfig()
self.wrap = wrap
if kwargs.get('font_size') and texttype=='text':
pass
else:
kwargs.update(fontsize)
super().__init__(**kwargs)
if self._i18n:

View File

@ -310,7 +310,20 @@ class Blocks(EventDispatcher):
raise NotExistsObject(widgetClass)
if desc.get('id'):
widget.widget_id = desc.get('id')
id = desc.get('id')
if id.startswith('app.'):
app = App.get_running_app()
id = id[4:]
setattr(app, id, widget)
if id.startswith('root.'):
app = App.get_running_app()
id = id[5:]
setattr(app.root, id, widget)
if '.' in id:
Logger.info('widget id(%s) can not contain "."', id)
else:
widget.widget_id = id
widget.build_desc = desc
self.build_attributes(widget,desc)
@ -377,7 +390,7 @@ class Blocks(EventDispatcher):
for a in desc['actions']:
new_desc = mydesc.copy()
new_desc.update(a)
self.unication(widget,new_desc, **args)
self.uniaction(widget,new_desc, *args)
def uniaction(self,widget,desc, *args):
Logger.info('Block: uniaction() called, desc=%s', str(desc))
@ -396,7 +409,7 @@ class Blocks(EventDispatcher):
if acttype == 'event':
return self.eventAction(widget, desc, *args)
if acttype == 'multiple':
return self.MultipleAction(widget, desc, *args)
return self.multipleAction(widget, desc, *args)
alert("actiontype(%s) invalid" % acttype,title='error')

View File

@ -23,6 +23,29 @@ from .ready import WidgetReady
from .toolbar import Toolbar
from .bgcolorbehavior import BGColorBehavior
def field_widget(desc, rec):
uitype = desc.get('uitype', 'str')
if uitype in [ 'str' 'date', 'time', 'timestamp' ]:
return BLabel(text = str(desc['value']),
font_size=CSize(1),wrap=True,
halign='left', valign='middle'
)
if uitype in [ 'long', 'int','integer' ]:
return BLabel(text=str(desc['value']),
font_size=CSize(1), wrap=True,
halign='right', valign='middle'
)
if uitype == 'float':
f = '%%.0%df' % desc.get('dec',2)
return BLabel(text=f % float(desc['value']),
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)
@ -59,14 +82,11 @@ class Cell(BoxLayout):
return
if desc['header']:
bl = Text(i18n=True, text=str(desc['value']),
font_size=CSize(1),
halign='left'
font_size=CSize(1),wrap=True,
halign='left', valign='middle'
)
else:
bl = BLabel(text = str(desc['value']),
font_size=CSize(1),
halign='left'
)
bl = field_widget(desc,self.row.row_data)
self.add_widget(bl)
bl.bind(on_press=self.cell_press)
@ -156,8 +176,10 @@ class Body(ScrollWidget):
self.clear_widgets()
def delRowById(self,id):
row = self.idRow[id]
row = self.idRow.get(id)
if row:
self.remove_widget(row)
if self.idRow.get(id):
del self.idRow[id]
def getRowData(self,rowid):
@ -382,11 +404,12 @@ class DataGrid(WidgetReady, BGColorBehavior, BoxLayout):
self.toolbar = Toolbar(**tb)
def on_selected(self,row):
print("DataGrid():on_selected fire", self.widget_id or 'not widget_id seted')
print("DataGrid():on_selected fire")
def loadData(self,**kwargs):
page = kwargs.get('page',1)
self.dataloader.do_search(None,{})
def loadData(self,*args, **kwargs):
print('args=', args, 'kwargs=',kwargs)
kwargs['page'] = 1
self.dataloader.do_search(None,kwargs)
def createDataGridPart(self):
self.freeze_part = None

View File

@ -1,5 +1,8 @@
import kivy
from kivy.utils import platform
from appPublic.registerfunction import RegisterFunction
from .baseWidget import *
from .tree import Tree, TextTree, PopupMenu
from .toolbar import ToolPage, Toolbar
@ -103,3 +106,27 @@ r('ToggleItems',ToggleItems)
if platform == 'android':
r('PhoneButton',PhoneButton)
r('AWebView',AWebView)
def register_widget(name, klass):
try:
Factory.regiter(name, klass)
except:
Logger.info(f'Plugin : register_widget():{name} register error')
def register_registerfunction(name, func):
rf = RegisterFunction()
try:
rf.register(name, func)
except Exception as e:
Logger.info(f'Plugin : register_registerfunction():{name} register error({e})')
print_exc()
def register_blocks(name, value):
b = Factory.Blocks()
try:
b.register_widget(name, value)
except:
Logger.info(f'plugin : register_blocks():{name} register error')

View File

@ -10,6 +10,7 @@ from kivy.clock import Clock
from kivy.factory import Factory
from appPublic.dictObject import DictObject
from appPublic.registerfunction import RegisterFunction
from .widgetExt.scrollwidget import ScrollWidget
from .utils import *
@ -222,9 +223,18 @@ class ToolPage(BGColorBehavior, BoxLayout):
t = self.get_tool_by_name(name)
w = self.content_widgets.get(name)
if w is None or t.fresh:
if t.url:
w = self.build_widget(t.url)
self.content_widgets[name] = w
return
if t.rfname:
rf = RegisterFunction()
f = rf.get(t.rfname)
if f:
return f()
return
if w:
print('toolbar.py: Use old widget')
self.content.clear_widgets()
self.content.add_widget(w)