Advertisement
jevixlugya

Untitled

Nov 17th, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 16.99 KB | None | 0 0
  1. from kivy.core.audio import SoundLoader
  2. from kivy.factory import Factory
  3. from kivy.core.window import Window
  4. from kivy.properties import StringProperty, ObjectProperty,ListProperty
  5. from kivy.uix.label import Label
  6. from kivy.uix.button import Button
  7. from kivy.uix.popup import Popup
  8. from kivy.uix.screenmanager import ScreenManager, Screen,WipeTransition,RiseInTransition
  9. from kivy.uix.widget import Widget
  10. from kivymd.app import MDApp
  11. from kivymd.uix.button import MDFlatButton
  12. from kivymd.uix.dialog import MDDialog
  13. from kivymd.uix.menu import MDDropdownMenu
  14. from kivymd.uix.picker import MDThemePicker
  15. from kivymd.toast import toast
  16. from kivy.animation import Animation
  17. from kivy.clock import Clock
  18. from kivy.uix.recycleview import RecycleView
  19. from kivymd.uix.list import TwoLineAvatarIconListItem
  20. from kivy.uix.behaviors import ToggleButtonBehavior
  21. from kivy.uix.image import Image
  22. from kivy.uix.scrollview import ScrollView
  23. Window.size=470,700
  24. kvm="""
  25. #:import Factory kivy.factory.Factory
  26.  
  27.  
  28. ScreenManager:
  29.    HomeScreen:
  30.  
  31.  
  32. <Searchin>:
  33.    name:'serchscreen'
  34.    MDBoxLayout:
  35.        orientation: 'vertical'
  36.        spacing: 1
  37.        md_bg_color:1,.5,0,.2
  38.        BoxLayout:
  39.            size_hint_y: 1/5
  40.            canvas.before:
  41.                Color:
  42.                    rgba: 0,0,0,1
  43.                Rectangle:
  44.                    pos: self.pos
  45.                    size: self.size[0], 2
  46.            MDIconButton:
  47.                icon: 'home'
  48.                size_hint_y: 1
  49.                on_press:root.manager.current='home'
  50.                font_size:90
  51.                color:app.theme_cls.primary_color
  52.            MDTextField:
  53.                id: Searchtext
  54.                multiline: False
  55.                hint_text:'Nnoonya'
  56.                helper_text_mode: "persistent"
  57.                helper_text: "Search"
  58.                on_text:recycle.search_rv(self.text)
  59.                
  60.  
  61.            MDIconButton:
  62.                icon: 'close'
  63.                size_hint_y:1
  64.                text_color: 1,0,0,1
  65.                on_press:
  66.                    Searchtext.text=''
  67.                    
  68.  
  69.  
  70.        MDBoxLayout:
  71.            orientation: 'vertical'
  72.            md_bg_color:1,.5,0,.2
  73.            padding: 4
  74.            RV:
  75.                viewclass: 'Search_Select_Option'
  76.                data:self.data
  77.                id:recycle
  78.                RecycleBoxLayout:
  79.                    #spacing: 5
  80.                    #padding : 5
  81.                    default_size: None, None
  82.                    default_size_hint: 1, None
  83.                    size_hint_y: None
  84.                    height: self.minimum_height
  85.                    orientation: 'vertical'        
  86.        
  87. <Search_Select_Option>:
  88.    secondary_text:'Ennyimba Za Kkristo by L.S.Jevix software '
  89.    font_size:32
  90.    on_release:app.root.current = self.text
  91.        
  92.    IconRightWidget:
  93.        icon: "book-open-variant"
  94.    ImageLeftWidget
  95.        source:'sda1.jpg'
  96.  
  97.  
  98. <TooltipMDIconButton@MDIconButton+MDTooltip>    
  99.  
  100. <HomeScreen>:
  101.    name:'home'
  102.    canvas.before:
  103.        Rectangle:
  104.            pos: self.pos
  105.            size: self.size
  106.            source: 'sda1.jpg'
  107.  
  108.    BoxLayout:
  109.        orientation: 'vertical'
  110.        size: self.size
  111.        MDToolbar:
  112.            title: 'ENNYIMBA ZA KKRISTO'
  113.            left_action_items: [['sda1.jpg']]
  114.            right_action_items: [['magnify',lambda x:root.searchrecycle(),'search'],['dots-vertical',lambda x: root.on_start(x),'options']]
  115.            elevation: 20
  116.  
  117.  
  118.        Label:
  119.            id: label
  120.            font_size: 70
  121.            text: ''
  122.            size_hint: .2,.5
  123.            color: 1,0,0,1
  124.            pos_hint: {'center_x': .5}
  125.            
  126.  
  127.  
  128.        GridLayout:
  129.            cols: 3
  130.            rows: 4
  131.            padding: 25
  132.            spacing: 10
  133.  
  134.  
  135.            Button:
  136.                text: '1'
  137.                #size_hint: (.2,.2)
  138.                background_color:1,1,1,0
  139.                on_press: root.button_pressed(1)
  140.                font_size: 60
  141.                color: 0,0,0,.5
  142.  
  143.  
  144.            Button:
  145.                text: '2'
  146.                background_color:1,1,1,0
  147.                on_press: root.button_pressed(2)
  148.                font_size: 60
  149.                color: 0,0,0,.5
  150.  
  151.            Button:
  152.                text: '3'
  153.                background_color:1,1,1,0
  154.                on_press: root.button_pressed(3)
  155.                font_size: 60
  156.                color: 0,0,0,.5
  157.            Button:
  158.                text: '4'
  159.                background_color:1,1,1,0
  160.                on_press: root.button_pressed(4)
  161.                font_size: 60
  162.                color: 0,0,0,.5
  163.            Button:
  164.                text: '5'
  165.                background_color:1,1,1,0
  166.                on_press: root.button_pressed(5)
  167.                font_size: 60
  168.                color: 0,0,0,.5
  169.  
  170.            Button:
  171.                text: '6'
  172.                background_color:1,1,1,0
  173.                on_press: root.button_pressed(6)
  174.                font_size: 60
  175.                color: 0,0,0,.5
  176.  
  177.  
  178.            Button:
  179.                text: '7'
  180.                background_color:1,1,1,0
  181.                on_press: root.button_pressed(7)
  182.                font_size: 60
  183.                color: 0,0,0,.5
  184.  
  185.            Button:
  186.                text: '8'
  187.                background_color:1,1,1,0
  188.                on_press: root.button_pressed(8)
  189.                font_size: 60
  190.                color: 0,0,0,.5
  191.  
  192.            Button:
  193.                text: '9'
  194.                background_color:1,1,1,0
  195.                on_press: root.button_pressed(9)
  196.                font_size: 60
  197.                color: 0,0,0,.5
  198.  
  199.            Button:
  200.                text: u'\u00AB'
  201.                background_color:0,0,0,0
  202.                pos_hint: {'center_x': .4}
  203.                on_press: root.remove()
  204.                font_size: 80
  205.                color:1,0,0,1
  206.            Button:
  207.                text: '0'
  208.                background_color:1,1,1,0
  209.                on_press: root.button_pressed(0)
  210.                font_size: 60
  211.                color: 0,0,0,.5
  212.            PageButton:
  213.                on_release: self.go_to_page(self.text)
  214.                text: 'GO'
  215.                background_color:0,0,0,0
  216.                pos_hint: {'center_x': .9}
  217.                font_size: 70
  218.                color: 1,0,0,1
  219.  
  220.  
  221.        MDBottomAppBar:
  222.            MDToolbar:
  223.                type: 'bottom'
  224.                icon: 'share'
  225.                #mode: 'off'
  226.                elevation: 12
  227.                on_action_button: app.bottom()
  228.                    
  229. <Content>:
  230.    name: 'content'
  231.    BoxLayout:
  232.        orientation: 'vertical'
  233.        size: root.width, root.height
  234.        MDToolbar:
  235.            color: .1,1,.1,1
  236.            title: "1.Gw'oli mutukuvu  "
  237.            left_action_items: [['sda1.jpg',lambda x: root.callback(),'home']]
  238.            right_action_items:[['magnify',lambda x:root.searchrecycle()]]            
  239.            elevation: 20
  240.  
  241.        MDBoxLayout:
  242.            orientation:'vertical'
  243.            padding:5
  244.            PlayButton:
  245.                id:play
  246.                size_hint:.05,.05
  247.                adaptive_height:True
  248.                pos_hint:{'center_x':.5,'center_y':.5}
  249.                on_state:
  250.                    scroll.animate_scroll(self.state)            
  251.  
  252.            MDCard:
  253.                orientation:'vertical'
  254.                md_bg_color:1,1,1,1
  255.                elevation:70
  256.                #height:
  257.                padding:5
  258.                spacing:20
  259.                size_hint:1,.5
  260.                radius:10,10
  261.                AnimScrollView:
  262.                    size:self.size
  263.                    id:scroll
  264.                    effect_cls: 'ScrollEffect'
  265.                    size_hint: 1,1
  266.                    bar_width:4
  267.                    bar_color:app.theme_cls.primary_color
  268.                    MDBoxLayout:
  269.                        md_bg_color:app.theme_cls.bg_normal
  270.                        adaptive_height:True
  271.                        orientation:'vertical'
  272.                        size_hint_y:None
  273.                        height:self.minimum_height
  274.                        width:self.minimum_width
  275.                        cols:1
  276.                        padding:17
  277.                        spacing:20
  278.                        MDLabel:
  279.                            text:""
  280.                            id:labelhymn
  281.                            font_size:35
  282.                            font_name:'fonts/popins.ttf'
  283.                            adaptive_height:True
  284.  
  285. """
  286.  
  287. class AnimScrollView(ScrollView):
  288.     def __init__(self, **kwargs):
  289.         super().__init__(**kwargs)
  290.         time=170
  291.         self.anim = Animation(scroll_y=0, duration=time) + Animation(scroll_y=1, duration=5)
  292.         self.anim.repeat = True
  293.  
  294.     def animate_scroll(self, toggle_state):
  295.         if toggle_state == 'down':
  296.             self.anim.start(self)
  297.         else:
  298.             self.anim.stop(self)
  299. class PlayButton(ToggleButtonBehavior, Image):
  300.     def __init__(self, **kwargs):
  301.         super(PlayButton, self).__init__(**kwargs)    
  302.         self.source = 'play icon.png'
  303.         self.background_color=1,1,0,1
  304.  
  305.  
  306.     def on_state(self, widget, value):
  307.         if value == 'down':
  308.             self.source = 'Pause-Button.png'
  309.             self.sound=SoundLoader.load('piano/holy.mp3')
  310.             self.sound.play()
  311.             toast('playing.....')
  312.             self.sound.loop=True
  313.         else:
  314.             self.source = 'play icon.png'
  315.             toast('stoped')
  316.             self.sound.stop()
  317.  
  318. class RV(RecycleView):
  319.     def on_kv_post(self, base_widget):
  320.         self.init_data()
  321.  
  322.     def init_data(self):
  323.         # initialize the data for the recycleview
  324.         self.ennyimba=[
  325.             "Gw'oli Mutukuvu","Ka Tukusuute Omulokozi Waffe ",'Mumaaso ga Yesu','Tusinze Nnyo Erinnya Lye',
  326.             'Tumusinze Mukama Waffe',"Mwe Amawanga Ag'oku Nsi",'Mukama Gwe Kifo kyaffe','Okukaaba Kwange Owulire',
  327.             'Gwe Eyanunula','Jjangu Yesu Obe Mu Nze','Bonna basuute Mukama',"Twebaza gwe omuva byonna","Yesu wasuubiza ffe abantu bo","Ka ntambule naawe Yesu",
  328.             "Yesu alifuga wonna wonna","Nkwetaaga ayi Mukama","Si nze, naye Kristo"
  329.            
  330.            
  331.            
  332.            
  333.            
  334.            
  335.            
  336.         ]
  337.         self.data = [{'text': f'{i}'} for i in self.ennyimba]
  338.  
  339.     def search_rv(self, text):
  340.         if not text:
  341.             self.init_data()
  342.         else:
  343.             self.data = [x for x in self.data if text.capitalize() in x['text']]
  344.        
  345. class Search_Select_Option(TwoLineAvatarIconListItem):
  346.    
  347.     pass
  348.  
  349. class Searchin(Screen,RV):
  350.  
  351.     pass
  352. class ScreenManager(ScreenManager):
  353.     def __init__(self,**kwargs):
  354.         super(screenmanager).__init__(**kwargs)
  355.         self.transition=RiseInTransition()
  356.    
  357.    
  358.  
  359.  
  360. class HomeScreen(Screen):
  361.  
  362.  
  363.     def on_start(self,instance):
  364.  
  365.         self.dropdown_list=[
  366.             {   "viewclass":"OneLineListItem",
  367.                 "text":"contact",
  368.                 "on_release":lambda x ="contact":self.contact_callback()
  369.             },
  370.  
  371.  
  372.             {
  373.                 "viewclass": "OneLineListItem",
  374.                 "text": "Color Theme",
  375.                 "on_release": lambda x="Color Theme": self.themeshow()
  376.  
  377.             },
  378.             {
  379.                 "viewclass": "OneLineListItem",
  380.                 "text": "About",
  381.                 "on_release": lambda x="About": self.about_callback()
  382.  
  383.  
  384.             },            
  385.  
  386.             {
  387.                 "viewclass": "OneLineListItem",
  388.                 "text": "Exite",
  389.                 "on_release": lambda x="Exite": EnnyimbaApp().stop()
  390.             },
  391.  
  392.  
  393.             {
  394.                 "viewclass": "OneLineListItem",
  395.                 "text": "Close",
  396.                 "on_release": lambda x="Close": self.dropdown.dismiss()
  397.             }
  398.  
  399.  
  400.         ]
  401.         self.dropdown=MDDropdownMenu(
  402.             items=self.dropdown_list,
  403.             width_mult=3,
  404.             background_color=(1,.4,0,1),
  405.  
  406.         )
  407.         self.dropdown.caller=instance
  408.        
  409.         self.dropdown.open()
  410.    
  411.  
  412.     def themeshow(self):
  413.         t=MDThemePicker()
  414.         t.open()
  415.  
  416.  
  417.     def contact_callback(self):
  418.         dialog=ObjectProperty(None)
  419.         self.dialog = MDDialog(
  420.             title="Contact:",
  421.             type="custom",
  422.             size_hint=[.4,.3],
  423.             text="Contact the developer:                           "
  424.             " Email: samueljevix234@gmail.com                      "
  425.             " mobile: +256754045576",
  426.             buttons=[
  427.  
  428.                 MDFlatButton(
  429.                     text="OK"
  430.                 ),
  431.             ],
  432.         )
  433.         self.dialog.open()
  434.  
  435.     def about_callback(self):
  436.         #print("about my app")
  437.  
  438.  
  439.         self.dialog = MDDialog(
  440.             title="About:",
  441.             size_hint=[.4, .3],
  442.             type="custom",
  443.             text="This is Ennyimba Za Kkristo "
  444.             " version: 2.0.0"
  445.             " Origin:Uganda(Buganda)"
  446.             " By Lugya samuel jevix.",
  447.             buttons=[
  448.  
  449.                 MDFlatButton(
  450.                     text="OK"
  451.                 ),
  452.             ],
  453.         )
  454.         self.dialog.open()
  455.  
  456.     def theme_callback(self):
  457.         print("theme")
  458.     def button_pressed(self, button):
  459.         gt5 = self.ids.label.text
  460.  
  461.  
  462.  
  463.         if gt5 == '0':
  464.             self.ids.label.text = ''
  465.             self.ids.label.text = f'{button}'
  466.  
  467.         else:
  468.             self.ids.label.text = f'{gt5}'f'{button}'
  469.  
  470.     def remove(self):
  471.          gt5 = self.ids.label.text
  472.          gt5=gt5[:-1]
  473.          self.ids.label.text=gt5
  474.      
  475.     def searchrecycle(self):
  476.         self.manager.current='serchscreen'            
  477.  
  478. class PageButton(Button):
  479.     hymns = {'1': {'text': "Gw'oli mutukuvu.txt", 'audio': 'piano/holy.mp3'},
  480.              '2': {'text': 'convert kivy app.txt', 'audio': 'hymn_01.mp3'},
  481.              '3': {'text': 'hymn_02.txt', 'audio': 'hymn_02.mp3'},
  482.              '4': {'text': 'hymn_03.txt', 'audio': 'hymn_03.mp3'},
  483.              '5': {'text': 'hymn_04.txt', 'audio': 'hymn_04.mp3'},
  484.              '6': {'text': 'hymn_05.txt', 'audio': 'hymn_05.mp3'},
  485.              '7': {'text': 'hymn_06.txt', 'audio': 'hymn_06.mp3'},
  486.              '8': {'text': 'hymn_07.txt', 'audio': 'hymn_07.mp3'},
  487.              '9': {'text': 'hymn_08.txt', 'audio': 'hymn_08.mp3'},
  488.              '10': {'text': 'hymn_09.txt', 'audio': 'hymn_09.mp3'},
  489.              '11': {'text': 'hymn_10.txt', 'audio': 'hymn_10.mp3'},
  490.              '12': {'text': 'hymn_11.txt', 'audio': 'hymn_11.mp3'},
  491.              '13': {'text': 'hymn_12.txt', 'audio': 'hymn_12.mp3'},
  492.              '14': {'text': 'hymn_13.txt', 'audio': 'hymn_13.mp3'},
  493.              '15': {'text': 'hymn_14.txt', 'audio': 'hymn_14.mp3'},
  494.              '16': {'text': 'hymn_15.txt', 'audio': 'hymn_15.mp3'}}
  495.  
  496.     def get_hymn_text(self, page):
  497.         with open(self.hymns[page]['text']) as f:
  498.             return f.read()
  499.  
  500.     def go_to_page(self, page):
  501.         app = MDApp.get_running_app()
  502.         self.manager.get_screen('contents').ids.labelhymn.text = self.get_hymn_text(page)
  503.         self.manager.current = 'contents'
  504.         gt5 = self.ids.label.text
  505.         page = page_name[gt5]
  506.         try:
  507.             pass
  508.  
  509.  
  510.         except:
  511.             self.ids.label.text="Not found"
  512.             self.ids.label.text=""
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519. class Content(Screen):
  520.     def searchrecycle(self):
  521.         self.manager.current='serchscreen'
  522.         if self.ids.play.state=='down':
  523.             self.ids.play.sound.stop()
  524.             self.ids.play.source = 'play icon.png'            
  525.     def callback(self):
  526.         self.manager.current=(str(0))
  527.         if self.ids.play.state=='down':
  528.             self.ids.play.sound.stop()
  529.             self.ids.play.source = 'play icon.png'
  530.                        
  531.  
  532.  
  533. class EnnyimbaApp(MDApp):
  534.     def __init__(self, **kwargs):
  535.         super().__init__(**kwargs)
  536.         self.screens = iter(
  537.             [
  538.                 Content,Searchin
  539.             ])
  540.  
  541.     def build(self):
  542.         self.theme_cls.theme_style = 'Light'
  543.         self.theme_cls.primary_palette="Amber" #['Red', 'Pink', 'Purple', 'DeepPurple', 'Indigo', 'Blue', 'LightBlue', 'Cyan', 'Teal', 'Green', 'LightGreen', 'Lime', '', 'Amber', 'Orange', 'DeepOrange', 'Brown', 'Gray', 'BlueGray']
  544.         self.theme_cls.accent_hue='400'
  545.         self.title='Ennyimbs za Kkristo'
  546.         self.theme_cls.accent_palette='Amber'
  547.         self.icon='sda1.jpg'
  548.         Window.borderless=True
  549.         Builder.load_string(kvm)
  550.  
  551.     def on_start(self):
  552.         Clock.schedule_once(self.load_screens, 1)
  553.  
  554.     def load_screens(self, dt):
  555.         for s in self.screens:
  556.             # instance and add Screen
  557.             self.root.add_widget(s())
  558.             Clock.schedule_once(self.load_screens)
  559.             print(f'Screen {s} loaded')
  560.             return
  561.  
  562.     def bottom(self):
  563.         print('bottom')
  564.        
  565.  
  566. EnnyimbaApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement