diff --git a/kivyblocks/baseWidget.py b/kivyblocks/baseWidget.py index 155ce21..5e8d240 100755 --- a/kivyblocks/baseWidget.py +++ b/kivyblocks/baseWidget.py @@ -153,7 +153,10 @@ class Text(Label): kwargs = kw.copy() config = getConfig() self.wrap = wrap - kwargs.update(fontsize) + if kwargs.get('font_size') and texttype=='text': + pass + else: + kwargs.update(fontsize) super().__init__(**kwargs) if self._i18n: self.i18n = I18n() diff --git a/kivyblocks/blocks.py b/kivyblocks/blocks.py index c0906da..cd9f359 100755 --- a/kivyblocks/blocks.py +++ b/kivyblocks/blocks.py @@ -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') diff --git a/kivyblocks/dg.py b/kivyblocks/dg.py index d5cea4f..b88a74f 100644 --- a/kivyblocks/dg.py +++ b/kivyblocks/dg.py @@ -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,9 +176,11 @@ class Body(ScrollWidget): self.clear_widgets() def delRowById(self,id): - row = self.idRow[id] - self.remove_widget(row) - del 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): return self.idRow[rowid].row_data @@ -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 diff --git a/kivyblocks/register.py b/kivyblocks/register.py index f6cef3e..774bf3b 100644 --- a/kivyblocks/register.py +++ b/kivyblocks/register.py @@ -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') + + diff --git a/kivyblocks/toolbar.py b/kivyblocks/toolbar.py index 72dbd6c..ba64007 100644 --- a/kivyblocks/toolbar.py +++ b/kivyblocks/toolbar.py @@ -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: - w = self.build_widget(t.url) - self.content_widgets[name] = w + 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)