2012-01-24 11:07:31 +00:00
|
|
|
'''
|
|
|
|
TabbedPannel
|
|
|
|
======
|
|
|
|
|
|
|
|
Test of the widget TabbedPannel.
|
|
|
|
'''
|
|
|
|
|
|
|
|
from kivy.app import App
|
2012-01-24 22:42:31 +00:00
|
|
|
from kivy.animation import Animation
|
|
|
|
from kivy.clock import Clock
|
2012-01-24 11:07:31 +00:00
|
|
|
from kivy.uix.button import Button
|
2012-01-24 22:42:31 +00:00
|
|
|
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
|
|
|
|
|
2012-01-24 22:42:31 +00:00
|
|
|
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}
|
2012-01-24 21:08:36 +00:00
|
|
|
tab_pos: 'top_left'
|
2012-01-24 13:40:03 +00:00
|
|
|
tab_height: 20
|
2012-01-24 20:27:07 +00:00
|
|
|
tab_width: 70
|
2012-01-24 11:07:31 +00:00
|
|
|
default_tab_text: 'tab1'
|
|
|
|
default_content: cut
|
2012-01-27 13:48:09 +00:00
|
|
|
FloatLayout:
|
|
|
|
BubbleButton:
|
|
|
|
id: cut
|
|
|
|
pos:self.parent.pos
|
|
|
|
size: self.parent.size
|
|
|
|
text: 'Cut'
|
|
|
|
Image:
|
|
|
|
id: copy
|
|
|
|
color: 1, 1, 1, 0
|
|
|
|
pos:self.parent.pos
|
|
|
|
size: self.parent.size
|
|
|
|
source: 'data/images/defaulttheme-0.png'
|
|
|
|
Image:
|
|
|
|
id: paste
|
|
|
|
color: 1, 1, 1, 0
|
|
|
|
pos:self.parent.pos
|
|
|
|
size: self.parent.size
|
|
|
|
source: 'data/images/image-loading.gif'
|
2012-01-24 11:07:31 +00:00
|
|
|
Tab_Heading:
|
|
|
|
text: 'tab2'
|
|
|
|
on_release: root.change_tab_contents(copy)
|
|
|
|
Tab_Heading:
|
|
|
|
text: 'tab3'
|
|
|
|
on_release: root.change_tab_contents(paste)
|
2012-01-24 21:08:36 +00:00
|
|
|
#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):
|
2012-01-28 10:20:44 +00:00
|
|
|
anim = Animation(color=(1, 1, 1, 0), d =.24, t = 'in_back')
|
2012-01-24 22:42:31 +00:00
|
|
|
|
2012-01-27 13:48:09 +00:00
|
|
|
def start_anim(_anim, *lt):
|
|
|
|
_anim.start(l[0])
|
|
|
|
|
|
|
|
def _on_complete(*lt):
|
2012-01-28 10:20:44 +00:00
|
|
|
if l[0].parent:
|
|
|
|
l[0].parent.remove_widget(l[0])
|
2012-01-27 13:48:09 +00:00
|
|
|
self.clear_widgets()
|
|
|
|
self.add_widget(l[0])
|
2012-01-28 10:20:44 +00:00
|
|
|
anim = Animation(color = (1, 1, 1, 1), d =.23, t = 'in_quad')
|
2012-01-27 13:48:09 +00:00
|
|
|
start_anim(anim)
|
|
|
|
|
|
|
|
anim.bind(on_complete = _on_complete)
|
2012-01-28 10:03:36 +00:00
|
|
|
start_anim(anim)
|
2012-01-24 11:07:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TabShowcase(FloatLayout):
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super(TabShowcase, self).__init__(**kwargs)
|
2012-01-24 21:08:36 +00:00
|
|
|
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)]
|
2012-01-28 10:20:44 +00:00
|
|
|
self.but.text = 'Tabs in\'%s\' position,\n press to change to next pos'\
|
2012-01-24 21:08:36 +00:00
|
|
|
%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()
|