2n2u

Untitled

Apr 11th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.38 KB | None | 0 0
  1. class TabsLayout(BoxLayout):
  2.     def __init__(self, **kwargs):
  3.         super(TabsLayout, self).__init__(**kwargs)
  4.         self.tab1 = MDFlatButton()
  5.         self.tab2 = MDFlatButton()
  6.         self.tab1.text = 'News'
  7.         self.tab1.name = 'tab1'
  8.         self.tab1.text_color = (1, 1, 1, 1)  # white color
  9.         self.tab2.text = 'Livescores'
  10.         self.tab2.name = 'tab2'
  11.         self.tab2.text_color = (1, 1, 1, 1)  # white color
  12.         if 'parent_layout' in kwargs:
  13.             self.tab1.bind(on_release=kwargs['parent_layout'].change_screen)
  14.             self.tab2.bind(on_release=kwargs['parent_layout'].change_screen)
  15.         self.add_widget(self.tab1)
  16.         self.add_widget(self.tab2)
  17.  
  18.         with self.canvas.after:
  19.             Color(1, 1, 1, 1)  # set the colour to white
  20.             self.rect = Rectangle(pos=(self.tab1.x, self.tab1.y),
  21.                                   size=(self.tab1.width,
  22.                                         dp(4)))
  23.  
  24. class MainToolBar(Toolbar):
  25.     dots_menu = ObjectProperty()
  26.     sm = ObjectProperty()
  27.     add_tabs = ObjectProperty()
  28.  
  29.     def __init__(self, **kwargs):
  30.         super(MainToolBar, self).__init__(**kwargs)
  31.         Clock.schedule_once(self.my_init, -1)
  32.  
  33.     def my_init(self, dt):
  34.         self.dots_menu = DotsMenu()
  35.         self.id = 'toolbar'
  36.         self.title = 'Futsal World'
  37.         self.left_action_items = [['menu', lambda x: app.nav_drawer.toggle()]]
  38.         self.right_action_items = [['more-vert', lambda x: self.dots_menu.open(self.ids.right_actions)]]
  39.         self.size_hint_y = .2
  40.         self.add_tabs.add_widget(TabsLayout(parent_layout=self))
  41.  
  42.     def change_screen(self, instance):
  43.         print instance.parent
  44.         self.move_rect(instance)
  45.         if instance.name == 'tab1':
  46.             app.root.ids['sm'].change_screen('News')
  47.         if instance.name == 'tab2':
  48.             if not app.root.ids['sm'].has_screen('Livescores'):
  49.                 app.root.ids['sm'].add_widget(LiveScoresScreen())
  50.                 app.root.ids['sm'].change_screen('Livescores')
  51.             else:
  52.                 app.root.ids['sm'].change_screen('Livescores')
  53.  
  54.     def move_rect(self, instance):
  55.         animation = Animation(size=(instance.width, dp(4)), duration=.4)
  56.         animation &= Animation(pos=(instance.x, instance.y), duration=.4)
  57.         print instance.parent.rect
  58.         animation.start(instance.parent.rect)
Advertisement
Add Comment
Please, Sign In to add comment