2012-01-24 11:07:31 +00:00
|
|
|
'''
|
2012-03-19 13:08:47 +00:00
|
|
|
TabbedPanel
|
2012-01-31 12:21:26 +00:00
|
|
|
============
|
2012-01-24 11:07:31 +00:00
|
|
|
|
2012-03-19 14:51:29 +00:00
|
|
|
Test of the widget TabbedPanel showing all capabilities.
|
2012-01-24 11:07:31 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
from kivy.app import App
|
2012-01-24 22:42:31 +00:00
|
|
|
from kivy.animation import Animation
|
|
|
|
from kivy.uix.floatlayout import FloatLayout
|
2012-03-19 14:00:25 +00:00
|
|
|
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelHeader
|
2012-04-09 10:24:24 +00:00
|
|
|
from kivy.factory import Factory
|
|
|
|
|
2012-04-09 16:32:46 +00:00
|
|
|
|
2012-04-09 10:24:24 +00:00
|
|
|
class StandingHeader(TabbedPanelHeader):
|
|
|
|
pass
|
|
|
|
|
2012-04-09 16:32:46 +00:00
|
|
|
|
2012-07-01 11:07:13 +00:00
|
|
|
class CloseableHeader(TabbedPanelHeader):
|
2012-04-09 10:24:24 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
Factory.register('StandingHeader', cls = StandingHeader)
|
2012-07-01 11:07:13 +00:00
|
|
|
Factory.register('CloseableHeader', cls = CloseableHeader)
|
2012-02-25 20:54:59 +00:00
|
|
|
|
2012-01-24 22:42:31 +00:00
|
|
|
from kivy.lang import Builder
|
2012-02-25 20:54:59 +00:00
|
|
|
|
2012-01-24 11:07:31 +00:00
|
|
|
Builder.load_string('''
|
2012-01-30 10:12:02 +00:00
|
|
|
<TabShowcase>
|
|
|
|
but: _but
|
|
|
|
Button:
|
|
|
|
id: _but
|
2012-03-19 13:08:47 +00:00
|
|
|
text: 'Press to show Tabbed Panel'
|
2012-01-30 10:12:02 +00:00
|
|
|
on_release: root.show_tab()
|
|
|
|
|
2012-04-09 10:24:24 +00:00
|
|
|
<StandingHeader>
|
|
|
|
color: 0,0,0,0
|
|
|
|
Scatter:
|
|
|
|
do_translation: False
|
|
|
|
do_scale: False
|
|
|
|
do_rotation: False
|
|
|
|
auto_bring_to_front: False
|
|
|
|
rotation: 70
|
|
|
|
size_hint: None, None
|
|
|
|
size: lbl.size
|
2012-04-09 15:37:36 +00:00
|
|
|
center_x: root.center_x
|
2012-07-01 11:07:13 +00:00
|
|
|
center_y: root.center_y
|
2012-04-09 10:24:24 +00:00
|
|
|
Label:
|
|
|
|
id: lbl
|
|
|
|
text: root.text
|
|
|
|
size: root.size
|
|
|
|
pos: 0,0
|
|
|
|
|
|
|
|
<PanelLeft>
|
|
|
|
size_hint: (.45, .45)
|
|
|
|
pos_hint: {'center_x': .25, 'y': .55}
|
|
|
|
#replace the default tab with our custom tab
|
2012-07-02 18:00:30 +00:00
|
|
|
default_tab_cls: sh.__class__
|
2012-07-01 11:07:13 +00:00
|
|
|
default_tab_content: default_content
|
2012-04-09 10:24:24 +00:00
|
|
|
tab_width: 40
|
|
|
|
tab_height: 70
|
2012-01-27 13:48:09 +00:00
|
|
|
FloatLayout:
|
2012-04-09 10:24:24 +00:00
|
|
|
RstDocument:
|
2012-04-09 05:41:35 +00:00
|
|
|
id: default_content
|
2012-06-09 21:33:17 +00:00
|
|
|
text: '\\n'.join(("Standing tabs", "-------------",\
|
|
|
|
"Tabs in \\'%s\\' position" %root.tab_pos))
|
2012-04-09 10:24:24 +00:00
|
|
|
Image:
|
|
|
|
id: tab_2_content
|
|
|
|
pos:self.parent.pos
|
|
|
|
size: self.parent.size
|
|
|
|
source: 'data/images/defaulttheme-0.png'
|
|
|
|
Image:
|
|
|
|
id: tab_3_content
|
|
|
|
pos:self.parent.pos
|
|
|
|
size: self.parent.size
|
|
|
|
source: 'data/images/image-loading.gif'
|
|
|
|
StandingHeader:
|
2012-07-02 18:00:30 +00:00
|
|
|
id: sh
|
2012-04-09 10:24:24 +00:00
|
|
|
content: tab_2_content
|
|
|
|
text: 'tab 2'
|
|
|
|
StandingHeader:
|
|
|
|
content: tab_3_content
|
|
|
|
text: 'tab 3'
|
|
|
|
|
2012-07-01 11:07:13 +00:00
|
|
|
<CloseableHeader>
|
2012-04-09 10:24:24 +00:00
|
|
|
color: 0,0,0,0
|
2012-04-09 15:37:36 +00:00
|
|
|
# variable tab_width
|
|
|
|
text: 'tabx'
|
|
|
|
size_hint_x: None
|
|
|
|
width: self.texture_size[0] + 40
|
2012-04-09 10:24:24 +00:00
|
|
|
BoxLayout:
|
|
|
|
pos: root.pos
|
|
|
|
size_hint: None, None
|
|
|
|
size: root.size
|
2012-04-09 15:37:36 +00:00
|
|
|
padding: 3
|
2012-04-09 10:24:24 +00:00
|
|
|
Label:
|
|
|
|
id: lbl
|
|
|
|
text: root.text
|
|
|
|
BoxLayout:
|
|
|
|
size_hint: None, 1
|
2012-07-01 16:30:46 +00:00
|
|
|
orientation: 'vertical'
|
2012-04-09 15:37:36 +00:00
|
|
|
width: 22
|
2012-04-09 10:24:24 +00:00
|
|
|
Widget:
|
|
|
|
Button:
|
|
|
|
border: 0,0,0,0
|
|
|
|
background_normal: 'tools/theming/defaulttheme/close.png'
|
|
|
|
on_release: root.panel.remove_widget(root)
|
|
|
|
Widget:
|
|
|
|
|
|
|
|
|
|
|
|
<PanelRight>
|
|
|
|
tab_pos: 'top_right'
|
|
|
|
size_hint: (.45, .45)
|
|
|
|
pos_hint: {'center_x': .75, 'y': .55}
|
2012-07-02 18:00:30 +00:00
|
|
|
#replace the default tab with our custom tab
|
2012-04-09 10:24:24 +00:00
|
|
|
default_tab: def_tab
|
2012-04-09 15:37:36 +00:00
|
|
|
#allow variable tab width
|
|
|
|
tab_width: None
|
2012-04-09 10:24:24 +00:00
|
|
|
FloatLayout:
|
|
|
|
RstDocument:
|
|
|
|
id: default_content
|
2012-07-01 11:07:13 +00:00
|
|
|
text: '\\n'.join(("Closeable tabs", "---------------",\
|
2012-06-09 21:33:17 +00:00
|
|
|
"- The tabs above are also scrollable",\
|
|
|
|
"- Tabs in \\'%s\\' position" %root.tab_pos))
|
2012-04-09 10:24:24 +00:00
|
|
|
Image:
|
|
|
|
id: tab_2_content
|
|
|
|
pos:self.parent.pos
|
|
|
|
size: self.parent.size
|
|
|
|
source: 'data/images/defaulttheme-0.png'
|
2012-06-08 12:09:33 +00:00
|
|
|
BoxLayout:
|
2012-04-09 10:24:24 +00:00
|
|
|
id: tab_3_content
|
2012-01-27 13:48:09 +00:00
|
|
|
pos:self.parent.pos
|
|
|
|
size: self.parent.size
|
2012-06-08 12:09:33 +00:00
|
|
|
BubbleButton:
|
|
|
|
text: 'Press to add new tab'
|
|
|
|
on_release: root.add_header()
|
|
|
|
BubbleButton:
|
|
|
|
text: 'Press set this tab as default'
|
|
|
|
on_release: root.default_tab = tab3
|
2012-07-01 11:07:13 +00:00
|
|
|
CloseableHeader:
|
2012-04-09 10:24:24 +00:00
|
|
|
id: def_tab
|
2012-04-09 15:37:36 +00:00
|
|
|
text: 'default tab'
|
2012-04-09 10:24:24 +00:00
|
|
|
content:default_content
|
|
|
|
panel: root
|
2012-07-01 11:07:13 +00:00
|
|
|
CloseableHeader:
|
2012-04-09 10:24:24 +00:00
|
|
|
text: 'tab2'
|
|
|
|
content: tab_2_content
|
|
|
|
panel: root
|
2012-07-01 11:07:13 +00:00
|
|
|
CloseableHeader:
|
2012-06-08 12:09:33 +00:00
|
|
|
id: tab3
|
2012-04-09 10:24:24 +00:00
|
|
|
text: 'tab3'
|
|
|
|
content: tab_3_content
|
|
|
|
panel: root
|
2012-07-01 11:07:13 +00:00
|
|
|
CloseableHeader:
|
2012-04-09 15:37:36 +00:00
|
|
|
panel: root
|
2012-07-01 11:07:13 +00:00
|
|
|
CloseableHeader:
|
2012-04-09 15:37:36 +00:00
|
|
|
panel: root
|
2012-07-01 11:07:13 +00:00
|
|
|
CloseableHeader:
|
2012-04-09 15:37:36 +00:00
|
|
|
panel: root
|
2012-07-01 11:07:13 +00:00
|
|
|
CloseableHeader:
|
2012-04-09 15:37:36 +00:00
|
|
|
panel: root
|
2012-07-01 11:07:13 +00:00
|
|
|
CloseableHeader:
|
2012-04-09 15:37:36 +00:00
|
|
|
panel: root
|
2012-07-01 11:07:13 +00:00
|
|
|
CloseableHeader:
|
2012-04-09 15:37:36 +00:00
|
|
|
panel: root
|
2012-07-01 11:07:13 +00:00
|
|
|
CloseableHeader:
|
2012-04-09 15:37:36 +00:00
|
|
|
panel: root
|
2012-04-09 10:24:24 +00:00
|
|
|
|
|
|
|
<PanelbLeft>
|
|
|
|
tab_pos: 'bottom_left'
|
|
|
|
size_hint: (.45, .45)
|
|
|
|
pos_hint: {'center_x': .25, 'y': .02}
|
|
|
|
default_tab_text: 'Settings'
|
|
|
|
default_tab_content: default_content
|
|
|
|
FloatLayout:
|
|
|
|
RstDocument:
|
|
|
|
id: default_content
|
2012-06-09 21:33:17 +00:00
|
|
|
text: '\\n'.join(("Normal tabs", "-------------",\
|
|
|
|
"Tabs in \\'%s\\' position" %root.tab_pos))
|
2012-01-27 13:48:09 +00:00
|
|
|
Image:
|
2012-04-09 05:41:35 +00:00
|
|
|
id: tab_2_content
|
2012-06-08 16:40:05 +00:00
|
|
|
pos: self.parent.pos
|
2012-01-27 13:48:09 +00:00
|
|
|
size: self.parent.size
|
|
|
|
source: 'data/images/defaulttheme-0.png'
|
|
|
|
Image:
|
2012-04-09 05:41:35 +00:00
|
|
|
id: tab_3_content
|
2012-01-27 13:48:09 +00:00
|
|
|
pos:self.parent.pos
|
|
|
|
size: self.parent.size
|
|
|
|
source: 'data/images/image-loading.gif'
|
2012-03-19 14:00:25 +00:00
|
|
|
TabbedPanelHeader:
|
2012-01-24 11:07:31 +00:00
|
|
|
text: 'tab2'
|
2012-04-09 05:41:35 +00:00
|
|
|
content: tab_2_content
|
2012-03-19 14:00:25 +00:00
|
|
|
TabbedPanelHeader:
|
2012-01-24 11:07:31 +00:00
|
|
|
text: 'tab3'
|
2012-04-09 05:41:35 +00:00
|
|
|
content: tab_3_content
|
2012-04-09 10:24:24 +00:00
|
|
|
|
|
|
|
<PanelbRight>
|
|
|
|
tab_pos: 'right_top'
|
|
|
|
size_hint: (.45, .45)
|
|
|
|
pos_hint: {'center_x': .75, 'y': .02}
|
|
|
|
default_tab: def_tab
|
2012-04-09 16:32:46 +00:00
|
|
|
tab_height: img.width
|
2012-04-09 10:24:24 +00:00
|
|
|
FloatLayout:
|
|
|
|
RstDocument:
|
|
|
|
id: default_content
|
2012-06-09 21:33:17 +00:00
|
|
|
text: '\\n'.join(("Image tabs","-------------",\
|
|
|
|
"1. Normal image tab","2. Image with Text","3. Rotated Image",\
|
|
|
|
"4. Tabs in \\'%s\\' position" %root.tab_pos))
|
2012-04-09 10:24:24 +00:00
|
|
|
Image:
|
|
|
|
id: tab_2_content
|
|
|
|
pos:self.parent.pos
|
|
|
|
size: self.parent.size
|
|
|
|
source: 'data/images/defaulttheme-0.png'
|
2012-04-09 15:37:36 +00:00
|
|
|
VideoPlayer:
|
2012-04-09 10:24:24 +00:00
|
|
|
id: tab_3_content
|
|
|
|
pos:self.parent.pos
|
|
|
|
size: self.parent.size
|
2012-04-09 15:37:36 +00:00
|
|
|
source: 'softboy.avi'
|
2012-04-09 16:32:46 +00:00
|
|
|
TabbedPanelHeader:
|
2012-04-09 10:24:24 +00:00
|
|
|
id: def_tab
|
|
|
|
content:default_content
|
2012-04-09 16:32:46 +00:00
|
|
|
border: 0, 0, 0, 0
|
|
|
|
background_down: 'softboy.png'
|
|
|
|
background_normal:'sequenced_images/data/images/info.png'
|
|
|
|
TabbedPanelHeader:
|
|
|
|
id: tph
|
2012-04-09 10:24:24 +00:00
|
|
|
content: tab_2_content
|
2012-04-09 16:32:46 +00:00
|
|
|
BoxLayout:
|
|
|
|
pos: tph.pos
|
|
|
|
size: tph.size
|
2012-07-01 16:30:46 +00:00
|
|
|
orientation: 'vertical'
|
2012-04-09 16:32:46 +00:00
|
|
|
Image:
|
|
|
|
source: 'sequenced_images/data/images/info.png'\
|
|
|
|
if tph.state == 'normal' else 'softboy.png'
|
|
|
|
Label:
|
|
|
|
text: 'text & img'
|
|
|
|
TabbedPanelHeader:
|
2012-06-08 12:09:33 +00:00
|
|
|
id: my_header
|
2012-04-09 10:24:24 +00:00
|
|
|
content: tab_3_content
|
2012-04-09 16:32:46 +00:00
|
|
|
Scatter:
|
|
|
|
do_translation: False
|
|
|
|
do_scale: False
|
|
|
|
do_rotation: False
|
|
|
|
auto_bring_to_front: False
|
|
|
|
rotation: 90
|
|
|
|
size_hint: None, None
|
|
|
|
size: img.size
|
2012-06-08 12:09:33 +00:00
|
|
|
center: my_header.center
|
2012-04-09 16:32:46 +00:00
|
|
|
Image:
|
|
|
|
id: img
|
|
|
|
source: 'sequenced_images/data/images/info.png'\
|
2012-06-08 12:09:33 +00:00
|
|
|
if my_header.state == 'normal' else 'softboy.png'
|
|
|
|
size: my_header.size
|
2012-04-09 16:32:46 +00:00
|
|
|
allow_stretch: True
|
|
|
|
keep_ratio: False
|
2012-01-24 11:07:31 +00:00
|
|
|
''')
|
|
|
|
|
|
|
|
|
2012-04-09 05:41:35 +00:00
|
|
|
class Tp(TabbedPanel):
|
|
|
|
#override tab switching method to animate on tab switch
|
2012-07-01 16:30:46 +00:00
|
|
|
def switch_to(self, header):
|
2012-04-09 05:41:35 +00:00
|
|
|
anim = Animation(color=(1, 1, 1, 0), d =.24, t = 'in_out_quad')
|
|
|
|
|
|
|
|
def start_anim(_anim, child, in_complete, *lt):
|
|
|
|
if hasattr(child, 'color'):
|
|
|
|
_anim.start(child)
|
|
|
|
elif not in_complete:
|
|
|
|
_on_complete()
|
|
|
|
|
|
|
|
def _on_complete(*lt):
|
|
|
|
if hasattr(header.content, 'color'):
|
|
|
|
header.content.color = (0, 0, 0, 0)
|
2012-04-09 16:32:46 +00:00
|
|
|
anim = Animation(color =
|
|
|
|
(1, 1, 1, 1), d =.23, t = 'in_out_quad')
|
2012-04-09 05:41:35 +00:00
|
|
|
start_anim(anim, header.content, True)
|
2012-06-08 16:40:05 +00:00
|
|
|
super(Tp, self).switch_to(header)
|
2012-04-09 05:41:35 +00:00
|
|
|
|
|
|
|
anim.bind(on_complete = _on_complete)
|
2012-04-09 16:32:46 +00:00
|
|
|
if self.content:
|
2012-07-01 19:33:37 +00:00
|
|
|
start_anim(anim, self.current_tab.content, False)
|
2012-04-09 05:41:35 +00:00
|
|
|
else:
|
|
|
|
_on_complete()
|
|
|
|
|
2012-04-09 16:32:46 +00:00
|
|
|
|
2012-04-09 10:24:24 +00:00
|
|
|
class PanelLeft(Tp):
|
|
|
|
pass
|
2012-04-09 05:41:35 +00:00
|
|
|
|
2012-04-09 16:32:46 +00:00
|
|
|
|
2012-04-09 10:24:24 +00:00
|
|
|
class PanelRight(Tp):
|
2012-06-08 08:50:03 +00:00
|
|
|
|
|
|
|
def add_header(self):
|
2012-07-01 11:07:13 +00:00
|
|
|
self.add_widget(CloseableHeader(panel = self))
|
2012-04-09 05:41:35 +00:00
|
|
|
|
2012-04-09 16:32:46 +00:00
|
|
|
|
2012-04-09 10:24:24 +00:00
|
|
|
class PanelbLeft(Tp):
|
|
|
|
pass
|
2012-01-24 11:07:31 +00:00
|
|
|
|
2012-04-09 16:32:46 +00:00
|
|
|
|
2012-04-09 10:24:24 +00:00
|
|
|
class PanelbRight(Tp):
|
|
|
|
pass
|
2012-01-24 11:07:31 +00:00
|
|
|
|
2012-04-09 16:32:46 +00:00
|
|
|
|
2012-01-30 10:12:02 +00:00
|
|
|
class TabShowcase(FloatLayout):
|
2012-01-24 11:07:31 +00:00
|
|
|
|
2012-04-09 05:41:35 +00:00
|
|
|
def show_tab(self):
|
2012-01-24 11:07:31 +00:00
|
|
|
if not hasattr(self, 'tab'):
|
2012-07-01 12:21:20 +00:00
|
|
|
self.tab = tab = PanelLeft()
|
|
|
|
self.add_widget(tab)
|
|
|
|
self.tab1 = tab = PanelRight()
|
|
|
|
self.add_widget(tab)
|
2012-06-08 08:50:03 +00:00
|
|
|
self.tab2 = tab = PanelbRight()
|
2012-04-09 10:24:24 +00:00
|
|
|
self.add_widget(tab)
|
2012-07-01 12:21:20 +00:00
|
|
|
self.tab3 = tab = PanelbLeft()
|
|
|
|
self.add_widget(tab)
|
2012-06-08 12:09:33 +00:00
|
|
|
self.but.text = \
|
|
|
|
'Tabs in variable positions, press to change to top_left'
|
2012-01-24 11:07:31 +00:00
|
|
|
else:
|
|
|
|
values = ('left_top', 'left_mid', 'left_bottom', 'top_left',
|
|
|
|
'top_mid', 'top_right', 'right_top', 'right_mid',
|
|
|
|
'right_bottom', 'bottom_left', 'bottom_mid', 'bottom_right')
|
|
|
|
index = values.index(self.tab.tab_pos)
|
2012-07-01 12:21:20 +00:00
|
|
|
self.tab.tab_pos = self.tab1.tab_pos = self.tab2.tab_pos\
|
|
|
|
= self.tab3.tab_pos = values[(index + 1) % len(values)]
|
2012-06-08 16:40:05 +00:00
|
|
|
self.but.text = 'Tabs in \'%s\' position,' %self.tab.tab_pos\
|
2012-06-08 12:09:33 +00:00
|
|
|
+ '\n press to change to next pos'
|
2012-01-24 11:07:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestTabApp(App):
|
|
|
|
|
|
|
|
def build(self):
|
|
|
|
return TabShowcase()
|
|
|
|
|
2012-07-29 19:43:01 +00:00
|
|
|
if __name__ == '__main__':
|
2012-02-28 10:46:34 +00:00
|
|
|
TestTabApp().run()
|