kivyblocks/kivyblocks/tab.py

63 lines
1.3 KiB
Python
Raw Normal View History

2020-04-24 18:35:30 +08:00
"""
{
2020-07-24 14:32:32 +08:00
"widgettype":"TabsPanel",
2020-07-23 21:21:23 +08:00
"options":{
"tab_pos":"top_left"
2020-07-24 14:32:32 +08:00
"tabs":[
{
"text":"tab1",
"icon":"/img/hhhh.png",
"refresh_press":Fasle,
"content":{
"widgettype":"urlwidegt",
"url":"reggtY",
}
},
{
2020-04-24 18:35:30 +08:00
}
2020-07-24 14:32:32 +08:00
]
},
2020-04-24 18:35:30 +08:00
}
"""
2020-12-04 15:29:17 +08:00
from appPublic.uniqueID import getID
2020-07-24 20:44:08 +08:00
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem
2020-07-23 21:21:23 +08:00
from kivy.clock import Clock
2020-07-23 21:34:49 +08:00
from kivy.factory import Factory
2020-07-24 14:32:32 +08:00
from .bgcolorbehavior import BGColorBehavior
2020-04-24 18:35:30 +08:00
2020-07-23 21:21:23 +08:00
class TabsPanel(BGColorBehavior, TabbedPanel):
2020-12-02 12:38:53 +08:00
def __init__(self,color_level=-1,
radius=[],
2020-12-04 15:29:17 +08:00
tabs=[],
2020-12-02 12:38:53 +08:00
**options):
2020-12-04 15:29:17 +08:00
self.tabs_list = tabs
2020-12-02 12:38:53 +08:00
TabbedPanel.__init__(self,**options)
BGColorBehavior.__init__(self,color_level=color_level,
radius=radius)
2020-07-24 20:44:08 +08:00
Clock.schedule_once(self.add_tabs,0)
2020-07-23 21:21:23 +08:00
2020-12-04 15:29:17 +08:00
def newname(self):
return getID()
def add_tab(self,name,text,desc):
2020-07-23 21:21:23 +08:00
def add(o,w):
2020-12-04 15:29:17 +08:00
if not hasattr(w,'widget_id'):
w.widget_id = name
2020-07-23 21:21:23 +08:00
self.add_widget(TabbedPanelItem(text=text,content=w))
2020-07-24 14:32:32 +08:00
blocks = Factory.Blocks()
2020-07-23 21:21:23 +08:00
blocks.bind(on_built=add)
2020-11-19 12:22:16 +08:00
blocks.widgetBuild(desc)
2020-07-23 21:21:23 +08:00
def add_tabs(self,*args):
for d in self.tabs_list:
2020-12-04 15:29:17 +08:00
name = d.get('name',self.newname())
2020-07-23 21:21:23 +08:00
text = d['text']
desc = d['content']
2020-12-04 15:29:17 +08:00
self.add_tab(name,text,desc)
2020-07-23 21:21:23 +08:00
2020-07-23 21:34:49 +08:00
if __name__ == '__main__':
from kivy.app import App
pass