This commit is contained in:
yumoqing 2021-01-26 13:59:30 +08:00
parent 94d898ce13
commit 51315fdaee
6 changed files with 74 additions and 19 deletions

View File

@ -20,10 +20,11 @@ class BGColorBehavior(object):
fg,bg= getColors(color_level,selected=True) fg,bg= getColors(color_level,selected=True)
self.selected_bgcolor = bg self.selected_bgcolor = bg
self.selected_fgcolor = fg self.selected_fgcolor = fg
self.on_bgcolor() # self.on_bgcolor()
self.bind(size=self.onSize_bgcolor_behavior, self.bind(size=self.onSize_bgcolor_behavior,
pos=self.onSize_bgcolor_behavior) pos=self.onSize_bgcolor_behavior)
self.bind(children=self.on_bgcolor)
def onSize_bgcolor_behavior(self,o,v=None): def onSize_bgcolor_behavior(self,o,v=None):
if not hasattr(self,'rect'): if not hasattr(self,'rect'):

View File

@ -543,11 +543,15 @@ class Blocks(EventDispatcher):
return None return None
# desc = self.valueExpr(desc) # desc = self.valueExpr(desc)
try:
widget = self.w_build(desc) widget = self.w_build(desc)
self.dispatch('on_built',widget) self.dispatch('on_built',widget)
if hasattr(widget,'ready'): if hasattr(widget,'ready'):
widget.ready() widget.ready()
return widget return widget
except Exception as e:
self.dispatch('on_failed',e)
return None
if not (isinstance(desc, DictObject) or isinstance(desc, dict)): if not (isinstance(desc, DictObject) or isinstance(desc, dict)):
print('Block: desc must be a dict object', print('Block: desc must be a dict object',
@ -555,7 +559,8 @@ class Blocks(EventDispatcher):
self.dispatch('on_failed',Exception('miss url')) self.dispatch('on_failed',Exception('miss url'))
return return
while desc['widgettype'] == "urlwidget": widgettype = desc.get('widgettype')
while widgettype == "urlwidget":
opts = desc.get('options',{}).copy() opts = desc.get('options',{}).copy()
extend = desc.get('extend') extend = desc.get('extend')
addon = None addon = None
@ -578,6 +583,11 @@ class Blocks(EventDispatcher):
if addon: if addon:
desc = dictExtend(desc,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) return doit(desc)
@classmethod @classmethod

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -22,8 +22,10 @@ from .graph import Graph, MeshLinePlot, MeshStemPlot, LinePlot, \
from .mapview import MapView from .mapview import MapView
from .chart2d import Chart2d from .chart2d import Chart2d
from .message import Conform from .message import Conform
from .pagepanel import PagePanel
r = Factory.register r = Factory.register
r('PagePanel', PagePanel)
r('Conform', Conform) r('Conform', Conform)
r('Chart2d', Chart2d) r('Chart2d', Chart2d)
r('Popup', Popup) r('Popup', Popup)

View File

@ -7,6 +7,7 @@ from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label from kivy.uix.label import Label
from kivy.app import App from kivy.app import App
from kivy.clock import Clock from kivy.clock import Clock
from kivy.factory import Factory
from appPublic.dictObject import DictObject from appPublic.dictObject import DictObject
@ -107,15 +108,17 @@ class Toolbar(BoxLayout):
""" """
Toolpage options Toolpage options
{ {
img_size=1.5, img_size:1.5,
text_size=0.7, text_size:0.7,
tool_at:"left","right","top","bottom", tool_at:"left","right","top","bottom",
color_level=0, color_level:0,
show_name:
tools:[ tools:[
{ {
"name":"myid", "name":"myid",
"img_src":"gggggg", "img_src":"gggggg",
"text":"gggggg" "text":"gggggg"
"flush":true
"url":"ggggggggg" "url":"ggggggggg"
}, },
... ...
@ -123,12 +126,21 @@ Toolpage options
""" """
class ToolPage(BGColorBehavior, BoxLayout): 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) self.opts = DictObject(**opts)
if tool_at in [ 'top','bottom']: if tool_at in [ 'top','bottom']:
orient = 'vertical' orient = 'vertical'
else: else:
orient = 'horizontal' 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.color_level=self.opts.color_level or 0
self.sub_radius = self.opts.radius self.sub_radius = self.opts.radius
self.tool_at = tool_at self.tool_at = tool_at
@ -139,7 +151,14 @@ class ToolPage(BGColorBehavior, BoxLayout):
self.content = None self.content = None
self.toolbar = None self.toolbar = None
self.init() 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): def on_size(self,obj,size):
if self.content is None: if self.content is None:
@ -153,13 +172,6 @@ class ToolPage(BGColorBehavior, BoxLayout):
self.content.height = self.height self.content.height = self.height
self.content.width = self.width - self.toolbar.width 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): def init(self):
self.initFlag = True self.initFlag = True
self.mywidgets = {} self.mywidgets = {}
@ -185,4 +197,34 @@ class ToolPage(BGColorBehavior, BoxLayout):
else: else:
self.add_widget(self.content) self.add_widget(self.content)
self.add_widget(self.toolbar) 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)