-
Notifications
You must be signed in to change notification settings - Fork 0
/
customlayout.py
27 lines (22 loc) · 886 Bytes
/
customlayout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from kivy.uix.relativelayout import RelativeLayout
class CustomLayout(RelativeLayout):
def __init__(self, **kwargs):
super(CustomLayout, self).__init__(**kwargs)
self._pages = None
self._current_page = 0
def add_page(self, widget):
try:
self._pages.append(widget)
except AttributeError as e:
self.add_widget(widget)
self._pages = [widget]
def next_page(self):
self.remove_widget(self._pages[self._current_page])
self._current_page += 1
# throws IndexError if no more pages
self.add_widget(self._pages[self._current_page])
def prev_page(self):
self.remove_widget(self._pages[self._current_page])
self._current_page -= 1
# throws IndexError if we tried to go past the beginning
self.add_widget(self._pages[self._current_page])