Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TabsLayout(BoxLayout):
- def __init__(self, **kwargs):
- super(TabsLayout, self).__init__(**kwargs)
- self.tab1 = MDFlatButton()
- self.tab2 = MDFlatButton()
- self.tab1.text = 'News'
- self.tab1.name = 'tab1'
- self.tab1.text_color = (1, 1, 1, 1) # white color
- self.tab2.text = 'Livescores'
- self.tab2.name = 'tab2'
- self.tab2.text_color = (1, 1, 1, 1) # white color
- if 'parent_layout' in kwargs:
- self.tab1.bind(on_release=kwargs['parent_layout'].change_screen)
- self.tab2.bind(on_release=kwargs['parent_layout'].change_screen)
- self.add_widget(self.tab1)
- self.add_widget(self.tab2)
- with self.canvas.after:
- Color(1, 1, 1, 1) # set the colour to white
- self.rect = Rectangle(pos=(self.tab1.x, self.tab1.y),
- size=(self.tab1.width,
- dp(4)))
- class MainToolBar(Toolbar):
- dots_menu = ObjectProperty()
- sm = ObjectProperty()
- add_tabs = ObjectProperty()
- def __init__(self, **kwargs):
- super(MainToolBar, self).__init__(**kwargs)
- Clock.schedule_once(self.my_init, -1)
- def my_init(self, dt):
- self.dots_menu = DotsMenu()
- self.id = 'toolbar'
- self.title = 'Futsal World'
- self.left_action_items = [['menu', lambda x: app.nav_drawer.toggle()]]
- self.right_action_items = [['more-vert', lambda x: self.dots_menu.open(self.ids.right_actions)]]
- self.size_hint_y = .2
- self.add_tabs.add_widget(TabsLayout(parent_layout=self))
- def change_screen(self, instance):
- print instance.parent
- self.move_rect(instance)
- if instance.name == 'tab1':
- app.root.ids['sm'].change_screen('News')
- if instance.name == 'tab2':
- if not app.root.ids['sm'].has_screen('Livescores'):
- app.root.ids['sm'].add_widget(LiveScoresScreen())
- app.root.ids['sm'].change_screen('Livescores')
- else:
- app.root.ids['sm'].change_screen('Livescores')
- def move_rect(self, instance):
- animation = Animation(size=(instance.width, dp(4)), duration=.4)
- animation &= Animation(pos=(instance.x, instance.y), duration=.4)
- print instance.parent.rect
- animation.start(instance.parent.rect)
Advertisement
Add Comment
Please, Sign In to add comment