Advertisement
jevixlugya

Untitled

May 17th, 2024
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.02 KB | None | 0 0
  1.  
  2. from kivymd.app import MDApp
  3. from kivy.lang import Builder
  4. from kivy.uix.screenmanager import Screen
  5. from kivy.uix.button import Button
  6. from kivy.uix.recycleview import RecycleView
  7. from kivy.factory import Factory
  8. from kivy.core.audio import SoundLoader
  9.  
  10. kv = """
  11. #:import Factory kivy.factory.Factory
  12.  
  13. ScreenManager:
  14.    TableOfContentsScreen:
  15.    ContentScreen:
  16.    search:
  17.  
  18. <PageButton>:
  19.    on_release: self.go_to_page(self.text)
  20.    id:pagebutton
  21.  
  22. <TableOfContentsScreen>:
  23.    name: 'toc'
  24.    GridLayout:
  25.        id: grid
  26.        rows: 4
  27.        cols: 4
  28. <search>:
  29.    name:'search'
  30.    BoxLayout:
  31.        orientation: 'vertical'
  32.        BoxLayout:
  33.            padding:10
  34.            size_hint_y:1/9
  35.                      
  36.            TextInput:
  37.                multiline:False
  38.                size_hint_y: None
  39.                height: dp(48)
  40.                hint_text:'search hymn'
  41.                on_text:recycle.search_rv(self.text)
  42.        BoxLayout:
  43.            orientation: 'vertical'
  44.            md_bg_color:1,.5,0,.2
  45.            padding: 4
  46.            RV:
  47.                viewclass: 'mybutton'
  48.                data:self.data
  49.                id:recycle
  50.                RecycleBoxLayout:
  51.                    #spacing: 5
  52.                    #padding : 5
  53.                    default_size: None, None
  54.                    default_size_hint: 1, None
  55.                    size_hint_y: None
  56.                    height: self.minimum_height
  57.                    orientation: 'vertical'
  58.  
  59.  
  60. <mybutton@Button>:
  61.    on_press:Factory.PageButton().go_to_page2(self.text)
  62.  
  63. <ContentScreen>:
  64.    name: 'contents'
  65.    MDBoxLayout:
  66.        orientation: 'vertical'
  67.        #size_hint:self.size
  68.        MDTopAppBar:
  69.            title: 'HYMN'
  70.            #type_height:'large'
  71.            left_action_items: [['arrow-left', lambda x: root.callback()],['sda.png', lambda x: None,]]
  72.            right_action_items: [['magnify',lambda x:root.searchrecycle(),'search']]
  73.            elevation: 1
  74.            md_bg_color:app.theme_cls.accent_color
  75.            specific_text_color:1,1,1,1        
  76.  
  77.        MDFloatLayout:
  78.            Image:
  79.                id:contim
  80.                source:''
  81.                allow_stretch:True,
  82.                keep_ratio:False
  83.  
  84.  
  85.            ScrollView:
  86.                size:self.size
  87.                id:scroll
  88.                effect_cls: 'ScrollEffect'
  89.                size_hint: 1,1
  90.                bar_width:4
  91.                bar_color:app.theme_cls.primary_color
  92.                MDBoxLayout:
  93.                    adaptive_height:True
  94.                    orientation:'vertical'
  95.                    size_hint_y:None
  96.                    height:self.minimum_height
  97.                    width:self.minimum_width
  98.                    cols:1
  99.                    padding:5
  100.                    spacing:20
  101.                    MDLabel:
  102.                        text:""
  103.                        id:label
  104.                        #font_size:Factory.Settingsscreen().ids.slid.value
  105.                        #color:app.theme_cls.primary_color
  106.                        adaptive_height:True
  107.                        font_style:'H4'
  108.                        #font_name:'fonts/Roboto-BoldItalic.ttf'
  109.                        bold:True
  110.  
  111.            
  112.            
  113.  
  114.  
  115.    
  116.  
  117. """
  118. from kivy.animation import Animation
  119.  
  120. class PageButton(Button):
  121.     hymns = {
  122.         "Hymn 1": {
  123.             'tittle':"Gw'oli mutukuvu",
  124.             'text': "Ennyimbatext/Gw'oli mutukuvu.txt",
  125.             'image1':'images/2.jpg',
  126.             'image2':'images/3.jpg',
  127.             'image3':'images/5.jpg'
  128.  
  129.             },
  130.  
  131.         'Hymn 2': {
  132.             'text': 'Ennyimbatext/hymn2.txt',
  133.             'image1': 'images/4.jpg',
  134.             'image2':'images/david.jpg',
  135.             'image3':'images/jesus1.jpg' }                              
  136.          }  
  137.     def go_to_page(self,text):
  138.  
  139.         app = MDApp.get_running_app()
  140.         sm = app.root
  141.         sm.get_screen('contents').ids.label.text = self.get_hymn_text()
  142.         sm.current = 'contents'
  143.         sm.get_screen('contents').ids.contim.source=self.get_image_oftext()#'images/singing angels.jpg'
  144.  
  145.     def get_hymn_text(self):
  146.         app = MDApp.get_running_app()
  147.         global imageId
  148.         self.imageId=app.root.get_screen('contents').ids.contim
  149.         self.page=self.text
  150.         self.t=self.page
  151.  
  152.         #global hymns
  153.        
  154.         with open(self.hymns[f'{self.t}']['text']) as f:
  155.             return f.read()
  156.        
  157.     def get_image_oftext(self):
  158.         self.page=self.text
  159.         image1= self.hymns[f'{self.page}']['image2']
  160.         print(type(image1))
  161.         print(image1)
  162.         return image1
  163.  
  164.     def get_image2_oftext(self):
  165.         self.page=self.text
  166.         image2= self.hymns[f'{self.page}']['image2']
  167.         print(image2)
  168.         return image2
  169.  
  170.     def get_image3_oftext(self):
  171.         self.page=self.text
  172.         image3= self.hymns[f'{self.page}']['image3']
  173.         return image3
  174.  
  175.     def get_images_oftext(self):
  176.         pass
  177.        
  178. #here am trying to animate the images from the dict
  179.     def set_animation(self,*args):
  180.         app = MDApp.get_running_app()
  181.         self.imageId=app.root.get_screen('contents').ids.contim
  182.         anim=Animation(opacity=1,duration=1)  
  183.         anim+=Animation(opacity=1,duration=7)
  184.         anim+=Animation(opacity=0,duration=7)
  185.         #self.anim.repeat = True
  186.         anim.start(self.imageId)
  187.         anim.bind(on_complete=self.comp)
  188.        
  189.  
  190.     def comp(self,*args):
  191.         app = MDApp.get_running_app()
  192.         self.imageId=app.root.get_screen('contents').ids.contim
  193.         self.imageId.source=self.get_image_oftext()
  194.         anim=Animation(opacity=1,duration=1)    
  195.         anim+=Animation(opacity=1,duration=7)
  196.         anim+=Animation(opacity=0,duration=7)      
  197.         anim.start(self.imageId)    
  198.         anim.bind(on_complete=self.compl)
  199.  
  200.     def compl(self,*args):
  201.         app = MDApp.get_running_app()
  202.         self.imageId=app.root.get_screen('contents').ids.contim
  203.         self.imageId.source=self.get_image2_oftext()
  204.         anim=Animation(opacity=1,duration=1)    
  205.         anim+=Animation(opacity=1,duration=7)
  206.         anim+=Animation(opacity=0,duration=7)      
  207.         anim.start(self.imageId)    
  208.         #anim.repeat = True
  209.         anim.bind(on_complete=self.compl2)
  210.  
  211.     def compl2(self,*args):
  212.         app = MDApp.get_running_app()
  213.         self.imageId=app.root.get_screen('contents').ids.contim
  214.         self.imageId.source=self.get_image3_oftext()
  215.         anim=Animation(opacity=1,duration=1)    
  216.         anim+=Animation(opacity=1,duration=7)
  217.         anim+=Animation(opacity=0,duration=7)      
  218.         anim.start(self.imageId)    
  219.         #anim.repeat = True
  220.         self.set_animation()
  221.        
  222. class TableOfContentsScreen(Screen):
  223.     def on_kv_post(self, base_widget):
  224.         grid = self.ids.grid
  225.         for i in range(1, 17):
  226.             grid.add_widget(PageButton(text=f'Hymn {i}'))
  227.  
  228. class search(Screen):
  229.     pass
  230. class ContentScreen(Screen):
  231.  
  232.     def on_enter(self):
  233.         Factory.PageButton().set_animation()
  234.         #print(Factory.PageButton().get_image_oftext (self.hymns))
  235.  
  236.     def callback(self):
  237.         self.manager.current=('toc')
  238.  
  239.     def play_audio(self):
  240.         print('playing')
  241.         self.sound=SoundLoader.load('10.mp3')
  242.         self.sound.play()
  243.  
  244. class RV(RecycleView):
  245.     def on_kv_post(self, base_widget):
  246.         self.init_data()
  247.  
  248.     def init_data(self):
  249.         # initialize the data for the recycleview
  250.         self.ennyimba=[
  251.             "Hymn 1","hymn 2 ",'hymn 3','hymn 4','hymn 5','hymn 6','hymn 7','hymn 8','hymn 9','hymn 10','hymn 11'    
  252.         ]
  253.         self.data = [{'text': f'{i}'} for i in self.ennyimba]
  254.  
  255.     def search_rv(self, text):
  256.         if not text:
  257.             self.init_data()
  258.         else:
  259.             self.data = [x for x in self.data if text in x['text']]
  260.  
  261. class HymnApp(MDApp):
  262.     def build(self):
  263.         return Builder.load_string(kv)
  264.  
  265.  
  266. HymnApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement