Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivymd.app import MDApp
- from kivy.lang import Builder
- from kivy.uix.screenmanager import Screen
- from kivy.uix.button import Button
- from kivy.uix.recycleview import RecycleView
- from kivy.factory import Factory
- from kivy.core.audio import SoundLoader
- kv = """
- #:import Factory kivy.factory.Factory
- ScreenManager:
- TableOfContentsScreen:
- ContentScreen:
- search:
- <PageButton>:
- on_release: self.go_to_page(self.text)
- id:pagebutton
- <TableOfContentsScreen>:
- name: 'toc'
- GridLayout:
- id: grid
- rows: 4
- cols: 4
- <search>:
- name:'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'
- on_text:recycle.search_rv(self.text)
- BoxLayout:
- orientation: 'vertical'
- md_bg_color:1,.5,0,.2
- padding: 4
- RV:
- viewclass: 'mybutton'
- data:self.data
- id:recycle
- RecycleBoxLayout:
- #spacing: 5
- #padding : 5
- default_size: None, None
- default_size_hint: 1, None
- size_hint_y: None
- height: self.minimum_height
- orientation: 'vertical'
- <mybutton@Button>:
- on_press:Factory.PageButton().go_to_page2(self.text)
- <ContentScreen>:
- name: 'contents'
- MDBoxLayout:
- orientation: 'vertical'
- #size_hint:self.size
- MDTopAppBar:
- title: 'HYMN'
- #type_height:'large'
- left_action_items: [['arrow-left', lambda x: root.callback()],['sda.png', lambda x: None,]]
- right_action_items: [['magnify',lambda x:root.searchrecycle(),'search']]
- elevation: 1
- md_bg_color:app.theme_cls.accent_color
- specific_text_color:1,1,1,1
- MDFloatLayout:
- Image:
- id:contim
- source:''
- allow_stretch:True,
- keep_ratio:False
- ScrollView:
- size:self.size
- id:scroll
- effect_cls: 'ScrollEffect'
- size_hint: 1,1
- bar_width:4
- bar_color:app.theme_cls.primary_color
- MDBoxLayout:
- adaptive_height:True
- orientation:'vertical'
- size_hint_y:None
- height:self.minimum_height
- width:self.minimum_width
- cols:1
- padding:5
- spacing:20
- MDLabel:
- text:""
- id:label
- #font_size:Factory.Settingsscreen().ids.slid.value
- #color:app.theme_cls.primary_color
- adaptive_height:True
- font_style:'H4'
- #font_name:'fonts/Roboto-BoldItalic.ttf'
- bold:True
- """
- from kivy.animation import Animation
- class PageButton(Button):
- hymns = {
- "Hymn 1": {
- 'tittle':"Gw'oli mutukuvu",
- 'text': "Ennyimbatext/Gw'oli mutukuvu.txt",
- 'image1':'images/2.jpg',
- 'image2':'images/3.jpg',
- 'image3':'images/5.jpg'
- },
- 'Hymn 2': {
- 'text': 'Ennyimbatext/hymn2.txt',
- 'image1': 'images/4.jpg',
- 'image2':'images/david.jpg',
- 'image3':'images/jesus1.jpg' }
- }
- def go_to_page(self,text):
- app = MDApp.get_running_app()
- sm = app.root
- sm.get_screen('contents').ids.label.text = self.get_hymn_text()
- sm.current = 'contents'
- sm.get_screen('contents').ids.contim.source=self.get_image_oftext()#'images/singing angels.jpg'
- def get_hymn_text(self):
- app = MDApp.get_running_app()
- global imageId
- self.imageId=app.root.get_screen('contents').ids.contim
- self.page=self.text
- self.t=self.page
- #global hymns
- with open(self.hymns[f'{self.t}']['text']) as f:
- return f.read()
- def get_image_oftext(self):
- self.page=self.text
- image1= self.hymns[f'{self.page}']['image2']
- print(type(image1))
- print(image1)
- return image1
- def get_image2_oftext(self):
- self.page=self.text
- image2= self.hymns[f'{self.page}']['image2']
- print(image2)
- return image2
- def get_image3_oftext(self):
- self.page=self.text
- image3= self.hymns[f'{self.page}']['image3']
- return image3
- def get_images_oftext(self):
- pass
- #here am trying to animate the images from the dict
- def set_animation(self,*args):
- app = MDApp.get_running_app()
- self.imageId=app.root.get_screen('contents').ids.contim
- anim=Animation(opacity=1,duration=1)
- anim+=Animation(opacity=1,duration=7)
- anim+=Animation(opacity=0,duration=7)
- #self.anim.repeat = True
- anim.start(self.imageId)
- anim.bind(on_complete=self.comp)
- def comp(self,*args):
- app = MDApp.get_running_app()
- self.imageId=app.root.get_screen('contents').ids.contim
- self.imageId.source=self.get_image_oftext()
- anim=Animation(opacity=1,duration=1)
- anim+=Animation(opacity=1,duration=7)
- anim+=Animation(opacity=0,duration=7)
- anim.start(self.imageId)
- anim.bind(on_complete=self.compl)
- def compl(self,*args):
- app = MDApp.get_running_app()
- self.imageId=app.root.get_screen('contents').ids.contim
- self.imageId.source=self.get_image2_oftext()
- anim=Animation(opacity=1,duration=1)
- anim+=Animation(opacity=1,duration=7)
- anim+=Animation(opacity=0,duration=7)
- anim.start(self.imageId)
- #anim.repeat = True
- anim.bind(on_complete=self.compl2)
- def compl2(self,*args):
- app = MDApp.get_running_app()
- self.imageId=app.root.get_screen('contents').ids.contim
- self.imageId.source=self.get_image3_oftext()
- anim=Animation(opacity=1,duration=1)
- anim+=Animation(opacity=1,duration=7)
- anim+=Animation(opacity=0,duration=7)
- anim.start(self.imageId)
- #anim.repeat = True
- self.set_animation()
- 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):
- def on_enter(self):
- Factory.PageButton().set_animation()
- #print(Factory.PageButton().get_image_oftext (self.hymns))
- def callback(self):
- self.manager.current=('toc')
- def play_audio(self):
- print('playing')
- self.sound=SoundLoader.load('10.mp3')
- self.sound.play()
- class RV(RecycleView):
- def on_kv_post(self, base_widget):
- self.init_data()
- def init_data(self):
- # initialize the data for the recycleview
- self.ennyimba=[
- "Hymn 1","hymn 2 ",'hymn 3','hymn 4','hymn 5','hymn 6','hymn 7','hymn 8','hymn 9','hymn 10','hymn 11'
- ]
- self.data = [{'text': f'{i}'} for i in self.ennyimba]
- def search_rv(self, text):
- if not text:
- self.init_data()
- else:
- self.data = [x for x in self.data if text in x['text']]
- class HymnApp(MDApp):
- def build(self):
- return Builder.load_string(kv)
- HymnApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement