Advertisement
jevixlugya

Untitled

May 28th, 2023
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.75 KB | None | 0 0
  1. # from firebase import firebase
  2. # from firebase_admin import db
  3. from kivy.network.urlrequest import UrlRequest
  4. import UrlRequest
  5. from kivymd.app import MDApp
  6. from kivymd.uix.card import MDCard
  7. from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
  8. from kivy.properties import StringProperty
  9. from kivy.factory import Factory
  10. from kivy.core.window import Window
  11. from kivy.uix.boxlayout import BoxLayout
  12. from kivymd.uix.bottomsheet import MDCustomBottomSheet
  13. from kivy.lang import Builder
  14.  
  15. Window.size = 400, 700
  16. gt = """
  17. ScreenManager:
  18.    StartScreen:
  19.        name: 'start'  # on_enter fires during initialization...
  20.  
  21.                
  22.    MainScreen:
  23.        name: 'home'
  24.  
  25.  
  26. <StartScreen>:
  27.    Button:
  28.        text: 'Go to Home'
  29.        on_release: root.manager.current = 'home'
  30.  
  31. <ContentCustomSheet>:
  32.    orientation: "vertical"
  33.    id:lay
  34.    size_hint_y: None
  35.    height: "400dp"
  36.  
  37.    MDTopAppBar:
  38.        title: 'Buy Product'
  39.  
  40.    ScrollView:
  41.  
  42.        MDGridLayout:
  43.            cols: 1
  44.            adaptive_height: True
  45.            padding:10
  46.            spacing:10
  47.            MDCard:
  48.                orientation:'vertical'                                  
  49.                #ripple_behavior:True
  50.                size_hint:1,None
  51.                radius:10
  52.                style:'outlined'
  53.                height:200
  54.                md_bg_color: "darkgrey"
  55.                elevation: 25
  56.                FitImage:
  57.                    source:'lex/car.jpg'
  58.  
  59.            MDCard:
  60.                orientation:'vertical'                                  
  61.                #ripple_behavior:True
  62.                size_hint:1,None
  63.                radius:10
  64.                style:'outlined'
  65.                height:200
  66.                md_bg_color: "darkgrey"
  67.                padding:5
  68.                elevation: 25
  69.                MDLabel:
  70.                    text:'description '
  71.                    adaptive_height:True
  72.  
  73.                MDSeparator:
  74.                    height: "2dp"
  75.                    md_bg_color:app.theme_cls.accent_color
  76.  
  77.                 MDGridLayout:
  78.                     cols: 1
  79.                     padding:10
  80.                     adaptive_height: True
  81.                     MDLabel:
  82.                         text:'good product  from America '                    
  83.  
  84.  
  85. <MainScreen>:
  86.     name:'home'
  87.     MDBoxLayout:
  88.         orientation:'vertical'
  89.         padding:10
  90.         spacing:10
  91.         MDLabel:
  92.             text:"Fetched Data"
  93.             bold:True
  94.             adaptive_height:True
  95.             font_style:'H4'
  96.  
  97.         ScrollView:
  98.             MDList:
  99.                 spacing:10
  100.                 id:show_card
  101.  
  102.  
  103. #card i want to  populate to show data
  104. <ShowCard>
  105.    orientation:'vertical'                                  
  106.    #ripple_behavior:True
  107.    size_hint:1,None
  108.    radius:10
  109.    style:'outlined'
  110.    height:200
  111.    elevation: 2
  112.    MDGridLayout:
  113.        cols:2
  114.        spacing:5
  115.        FitImage:
  116.            source: root.image
  117.        MDBoxLayout:
  118.            orientation:'vertical'
  119.  
  120.            MDLabel:
  121.                text:root.description
  122.                bold:True
  123.                color:app.theme_cls.primary_color
  124.                # font_name:'fonts/popins.ttf'
  125.            MDLabel:
  126.                text:root.description    
  127.  
  128.            MDLabel:
  129.                text: root.price
  130.                color:app.theme_cls.primary_color
  131.                # font_name:'fonts/popins.ttf'
  132.  
  133.            MDSeparator:
  134.  
  135.            MDBoxLayout:
  136.                 padding:5
  137.                 spacing:5
  138.                 MDRectangleFlatIconButton:
  139.                     text:'buy'
  140.                     icon:'cart'
  141.                     on_press:root.buy_item()
  142.                     md_bg_color:app.theme_cls.primary_color
  143.                     color:1,0,0,.8
  144.                     theme_text_color: "Custom"
  145.                     text_color: "white"
  146.                     line_color: "red"
  147.                     theme_icon_color: "Custom"
  148.                     icon_color: "orange"
  149.  
  150.                 MDRectangleFlatIconButton:
  151.                     text:'favourite'
  152.                     icon:'heart'
  153.                     md_bg_color:app.theme_cls.primary_color
  154.                     color:1,0,0,.8
  155.                     theme_text_color: "Custom"
  156.                     text_color: "white"
  157.                     line_color: "red"
  158.                     theme_icon_color: "Custom"
  159.                     icon_color: "orange"                   
  160. """
  161.  
  162.  
  163. class Managert(ScreenManager):
  164.     pass
  165.  
  166. class ContentCustomSheet(BoxLayout):
  167.     pass
  168.  
  169. class ShowCard(MDCard):
  170.     description = StringProperty()  # match the keywords in the product dict
  171.     name = StringProperty()
  172.     price = StringProperty()
  173.     image = StringProperty()
  174.     def buy_item(self):
  175.         self.custom_sheet = MDCustomBottomSheet(screen=Factory.ContentCustomSheet())
  176.         self.custom_sheet.open()
  177. class StartScreen(Screen):
  178.     pass
  179. class MainScreen(Screen):
  180.  
  181.     def on_enter(self):
  182.         # getting data from real-time database
  183.         # self.firebase = firebase.FirebaseApplication('https://lexconnectionsapp-default-rtdb.firebaseio.com/', None)
  184.         print('connecting........')
  185.  
  186.         # self.result = self.firebase.get('lexconnectionsapp-default-rtdb/products', None)
  187.         # print((self.result))
  188.         print('show here iam')
  189.         # data i fetched from my database
  190.         self.data = {
  191.             "product2": {
  192.                 "description": "best tv in uganda",
  193.                 "image": "https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/electronics.jpg?alt=media&token=f367e838-64a7-46bf-9134-f9dc4f25cc19",
  194.                 "name": "television",
  195.                 "price": "250,000"
  196.             },
  197.             "product3": {
  198.                 "description": "iphone pro best",
  199.                 "image": "https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/phone.jpg?alt=media&token=e65f6cb9-7aeb-40bd-85e9-bbacf12b56a2",
  200.                 "name": "phones",
  201.                 "price": "1000,000"
  202.             },
  203.             "product5": {
  204.                 "description": "best jobs ever",
  205.                 "image": "https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/jobs.jpg?alt=media&token=47c976fe-7832-41ff-97d9-9f1860613b3e",
  206.                 "name": "jobs",
  207.                 "price": "ugx 200,00"
  208.             },
  209.             "product6": {
  210.                 "description": "best properties ever",
  211.                 "image": "https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/property.jpg?alt=media&token=67c1c6f0-77c6-4113-ac21-89a506489668",
  212.                 "name": "property",
  213.                 "price": "ugx 3000,000"
  214.             },
  215.             "product7": {
  216.                 "description": "best tourism ever",
  217.                 "image": "https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/lion.jpg?alt=media&token=04ec0322-ea87-44fa-a8ae-f409fdaf12e0",
  218.                 "name": "WildLife",
  219.                 "price": "ugx 20,000"
  220.             }                        
  221.         }
  222.  
  223.         products = [item for item in self.data.values()]  # ignore primary key, get the inner dicts
  224.         for product in products:
  225.             sc = ShowCard(**product)  # same as Showcard(description=product['description'],...)
  226.             self.ids.show_card.add_widget(sc)
  227.  
  228.  
  229. class FetchdataApp(MDApp):
  230.     def build(self):
  231.         self.theme_cls.accent_palette = 'Red'
  232.         self.theme_cls.accent_hue = '400'
  233.         self.theme_cls.primary_palette = 'DeepPurple'      
  234.         return Builder.load_string(gt)
  235.  
  236.  
  237. # i was trying to post that data to the database
  238.  
  239. '''firebase=firebase.FirebaseApplication('https://lexconnectionsapp-default-rtdb.firebaseio.com/',None)
  240. #importing data
  241. data={
  242.     'Name':'Ford',
  243.     'image':'gs://lexconnectionsapp.appspot.com/car.jpg',
  244.     "price":'ugx:100,000,000',
  245.     "description":'the car is fantastic'
  246.  
  247.  
  248. }
  249. #post data
  250. firebase.post('lexconnectionsapp-default-rtdb/products',data)'''
  251.  
  252. FetchdataApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement