kivy/examples/widgets/tabbed_panel_test.py

100 lines
2.6 KiB
Python
Raw Normal View History

2012-01-24 11:07:31 +00:00
'''
TabbedPannel
======
Test of the widget TabbedPannel.
'''
from kivy.app import App
from kivy.animation import Animation
from kivy.clock import Clock
2012-01-24 11:07:31 +00:00
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
2012-01-24 11:07:31 +00:00
from kivy.uix.tabbedpannel import TabbedPannel
from kivy.properties import ObjectProperty
from kivy.lang import Builder
2012-01-24 11:07:31 +00:00
Builder.load_string('''
<cut_copy_paste>
size_hint: (None, None)
size: (350, 250)
pos_hint: {'center_x': .25, 'y': .55}
tab_pos: 'top_left'
2012-01-24 13:40:03 +00:00
tab_height: 20
tab_width: 70
2012-01-24 11:07:31 +00:00
default_tab_text: 'tab1'
default_content: cut
BubbleButton:
id: cut
text: 'Cut'
BubbleButton:
id: copy
text: 'Copy'
BubbleButton:
id: paste
text: 'Paste'
Tab_Heading:
text: 'tab2'
on_release: root.change_tab_contents(copy)
Tab_Heading:
text: 'tab3'
on_release: root.change_tab_contents(paste)
#Tab_Heading:
# text: 'tab4'
# on_release: root.clear_widgets()
#Tab_Heading:
# text: 'tab5'
# on_release: root.clear_widgets()
2012-01-24 11:07:31 +00:00
''')
class cut_copy_paste(TabbedPannel):
default_content = ObjectProperty(None)
def on_default_tab(self, *l):
self.change_tab_contents(self.default_content)
def change_tab_contents(self, *l):
anim = Animation( color=(1, 1, 1, 0), d =.27, t = 'in_back')
def start_anim(*l):
anim.start(self.content.children[0])
start_anim()
2012-01-24 11:07:31 +00:00
self.clear_widgets()
self.add_widget(l[0])
anim = Animation( color = (1, 1, 1, 1), d =.27, t = 'in_quad')
start_anim()
2012-01-24 11:07:31 +00:00
class TabShowcase(FloatLayout):
def __init__(self, **kwargs):
super(TabShowcase, self).__init__(**kwargs)
self.but = Button(text='Press to show Tabbed Pannel')
2012-01-24 11:07:31 +00:00
self.but.bind(on_release=self.show_tab)
self.add_widget(self.but)
def show_tab(self, *l):
if not hasattr(self, 'tab'):
self.tab = tab = cut_copy_paste()
self.add_widget(tab)
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)
self.tab.tab_pos = values[(index + 1) % len(values)]
self.but.text='Tabs in \'%s\' position,\n press to change to next pos'\
%self.tab.tab_pos
2012-01-24 11:07:31 +00:00
class TestTabApp(App):
def build(self):
return TabShowcase()
if __name__ in ('__main__', '__android__'):
TestTabApp().run()