Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.lang import Builder
- from kivy.uix.screenmanager import Screen
- from kivy.uix.button import Button
- kv = """
- <PageButton>:
- on_release: self.go_to_page(self.text)
- <TableOfContentsScreen>:
- GridLayout:
- id: grid
- rows: 4
- cols: 4
- <search>:
- BoxLayout:
- orientation: 'vertical'
- BoxLayout:
- padding:10
- size_hint_y:1/9
- TextInput:
- multiline:False
- size_hint_y: None
- height: dp(48)
- hint_text:'search hymn'
- BoxLayout:
- orientation: 'vertical'
- Label:
- text:'to search from here in recycleview,'
- <ContentScreen>:
- BoxLayout:
- Button:
- size_hint_y: None
- height: dp(48)
- text: 'Home'
- on_release: app.root.ids.sm.current = 'toc'
- Button:
- text:'search'
- on_press:app.root.ids.sm.current='search'
- size_hint_y: None
- height: dp(48)
- BoxLayout:
- orientation: 'vertical'
- Label:
- id: label
- BoxLayout:
- orientation: 'vertical'
- Label:
- size_hint_y: None
- height: dp(30)
- text: 'Hymn Example'
- ScreenManager:
- id: sm
- TableOfContentsScreen:
- name: 'toc'
- ContentScreen:
- name: 'contents'
- search:
- name:'search'
- """
- class PageButton(Button):
- hymns = {'Hymn 1': {'text':'Put file names here','audio':'piano/holy.mp3'}, 'Hymn 2': 'or put the text directly',
- 'Hymn 3': 'The text of hymn 3', 'Hymn 4': 'The text of hymn 4', 'Hymn 5': 'The text of hymn 5',
- 'Hymn 6': 'The text of hymn 6', 'Hymn 7': 'The text of hymn 7', 'Hymn 8': 'The text of hymn 8',
- 'Hymn 9': 'The text of hymn 9', 'Hymn 10': 'The text of hymn 10', 'Hymn 11': 'The text of hymn 11',
- 'Hymn 12': 'The text of hymn 12', 'Hymn 13': 'The text of hymn 13', 'Hymn 14': 'The text of hymn 14',
- 'Hymn 15': 'The text of hymn 15', 'Hymn 16': 'The text of hymn 16'}
- def go_to_page(self, page):
- app = App.get_running_app()
- sm = app.root.ids.sm
- sm.current = 'contents'
- sm.get_screen('contents').ids.label.text = str(self.hymns[page])
- class TableOfContentsScreen(Screen):
- def on_kv_post(self, base_widget):
- grid = self.ids.grid
- for i in range(1, 17):
- grid.add_widget(PageButton(text=f'Hymn {i}'))
- class search(Screen):
- pass
- class ContentScreen(Screen):
- pass
- class HymnApp(App):
- def build(self):
- return Builder.load_string(kv)
- HymnApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement