diff --git a/kivyblocks/bgcolorbehavior.py b/kivyblocks/bgcolorbehavior.py index b71bbd0..8fd1881 100644 --- a/kivyblocks/bgcolorbehavior.py +++ b/kivyblocks/bgcolorbehavior.py @@ -20,10 +20,11 @@ class BGColorBehavior(object): fg,bg= getColors(color_level,selected=True) self.selected_bgcolor = bg self.selected_fgcolor = fg - self.on_bgcolor() + # self.on_bgcolor() self.bind(size=self.onSize_bgcolor_behavior, pos=self.onSize_bgcolor_behavior) + self.bind(children=self.on_bgcolor) def onSize_bgcolor_behavior(self,o,v=None): if not hasattr(self,'rect'): diff --git a/kivyblocks/blocks.py b/kivyblocks/blocks.py index 6a712e1..e7b36fd 100755 --- a/kivyblocks/blocks.py +++ b/kivyblocks/blocks.py @@ -543,11 +543,15 @@ class Blocks(EventDispatcher): return None # desc = self.valueExpr(desc) - widget = self.w_build(desc) - self.dispatch('on_built',widget) - if hasattr(widget,'ready'): - widget.ready() - return widget + try: + widget = self.w_build(desc) + self.dispatch('on_built',widget) + if hasattr(widget,'ready'): + widget.ready() + return widget + except Exception as e: + self.dispatch('on_failed',e) + return None if not (isinstance(desc, DictObject) or isinstance(desc, dict)): print('Block: desc must be a dict object', @@ -555,7 +559,8 @@ class Blocks(EventDispatcher): self.dispatch('on_failed',Exception('miss url')) return - while desc['widgettype'] == "urlwidget": + widgettype = desc.get('widgettype') + while widgettype == "urlwidget": opts = desc.get('options',{}).copy() extend = desc.get('extend') addon = None @@ -578,6 +583,11 @@ class Blocks(EventDispatcher): if addon: desc = dictExtend(desc,addon) + widgettype = desc.get('widgettype') + if widgettype is None: + print('Block: desc must be a dict object', + desc,type(desc)) + return None return doit(desc) @classmethod diff --git a/kivyblocks/imgs/backword.png b/kivyblocks/imgs/backword.png new file mode 100644 index 0000000..6c1a60b Binary files /dev/null and b/kivyblocks/imgs/backword.png differ diff --git a/kivyblocks/imgs/right_menu.png b/kivyblocks/imgs/right_menu.png new file mode 100644 index 0000000..07f638d Binary files /dev/null and b/kivyblocks/imgs/right_menu.png differ diff --git a/kivyblocks/register.py b/kivyblocks/register.py index 168bb95..f0fe8ac 100644 --- a/kivyblocks/register.py +++ b/kivyblocks/register.py @@ -22,8 +22,10 @@ from .graph import Graph, MeshLinePlot, MeshStemPlot, LinePlot, \ from .mapview import MapView from .chart2d import Chart2d from .message import Conform +from .pagepanel import PagePanel r = Factory.register +r('PagePanel', PagePanel) r('Conform', Conform) r('Chart2d', Chart2d) r('Popup', Popup) diff --git a/kivyblocks/toolbar.py b/kivyblocks/toolbar.py index 8b7f6b8..72dbd6c 100644 --- a/kivyblocks/toolbar.py +++ b/kivyblocks/toolbar.py @@ -7,6 +7,7 @@ from kivy.uix.gridlayout import GridLayout from kivy.uix.label import Label from kivy.app import App from kivy.clock import Clock +from kivy.factory import Factory from appPublic.dictObject import DictObject @@ -107,15 +108,17 @@ class Toolbar(BoxLayout): """ Toolpage options { - img_size=1.5, - text_size=0.7, + img_size:1.5, + text_size:0.7, tool_at:"left","right","top","bottom", - color_level=0, + color_level:0, + show_name: tools:[ { "name":"myid", "img_src":"gggggg", "text":"gggggg" + "flush":true "url":"ggggggggg" }, ... @@ -123,12 +126,21 @@ Toolpage options """ class ToolPage(BGColorBehavior, BoxLayout): - def __init__(self,color_level=-1,radius=[],tool_at='top', **opts): + def __init__(self,color_level=-1,radius=[], + show_name=None, tool_at='top', **opts): self.opts = DictObject(**opts) if tool_at in [ 'top','bottom']: orient = 'vertical' else: orient = 'horizontal' + names = [i.name for i in self.opts.tools] + + if not show_name or \ + not show_name not in names: + show_name = self.opts.tools[0].name + + self.content_widgets = {} + self.show_name = show_name self.color_level=self.opts.color_level or 0 self.sub_radius = self.opts.radius self.tool_at = tool_at @@ -139,8 +151,15 @@ class ToolPage(BGColorBehavior, BoxLayout): self.content = None self.toolbar = None self.init() - # self.show_firstpage() + Clock.schedule_once(self.show_page, 0.5) + def show_page(self, *args): + toggle_items = self.toolbar.toggle_items + for c in toggle_items.children: + cvalue = c.getValue() + if cvalue == self.show_name: + c.dispatch('on_press') + def on_size(self,obj,size): if self.content is None: return @@ -153,13 +172,6 @@ class ToolPage(BGColorBehavior, BoxLayout): self.content.height = self.height self.content.width = self.width - self.toolbar.width - def showPage(self,obj): - self._show_page(obj.opts) - - def show_firstpage(self,t=None): - d = self.children[0] - d.dispatch('on_press', d) - def init(self): self.initFlag = True self.mywidgets = {} @@ -185,4 +197,34 @@ class ToolPage(BGColorBehavior, BoxLayout): else: self.add_widget(self.content) self.add_widget(self.toolbar) + toggle_items = self.toolbar.toggle_items + for t in toggle_items.children: + t.bind(on_press=self.on_press_handle) + + def get_tool_by_name(self,name): + for t in self.opts.tools: + if t.name == name: + return t + return None + + def build_widget(self, url): + desc = { + "widgettype":"urlwidget", + "options":{ + "url":url + } + } + b = Factory.Blocks() + return b.widgetBuild(desc) + + def on_press_handle(self, o): + name = o.getValue() + 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 w: + self.content.clear_widgets() + self.content.add_widget(w)