Advertisement
jevixlugya

Untitled

Jun 4th, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.11 KB | None | 0 0
  1. from firebase import firebase
  2. from firebase_admin import db
  3. from kivymd.app import MDApp
  4. from kivymd.uix.card import MDCard
  5. from kivymd.uix.label import MDLabel
  6. from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
  7. from kivy.properties import StringProperty,ObjectProperty
  8. from kivy.core.window import Window
  9. from kivy.lang import Builder
  10. import urlrequest
  11. import webbrowser
  12.  
  13. Window.size = 550, 700
  14. gt = """
  15. ScreenManager:
  16.    StartScreen:
  17.        name: 'start'  # on_enter fires during initialization...
  18.    MainScreen:
  19.        name: 'home'
  20.  
  21. <StartScreen@Screen>:
  22.    BoxLayout:
  23.        orientation:'vertical'
  24.        AsyncImage:
  25.            source:"https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/shoe2-removebg-preview.png?alt=media&token=7658113b-d790-4d68-a356-400093a45ffa"
  26.  
  27.        Button:
  28.            text: 'Go to Home'
  29.            on_release: root.manager.current = 'home'
  30.  
  31. <MainScreen>:
  32.     name:'home'
  33.     MDBoxLayout:
  34.         orientation:'vertical'
  35.         padding:20
  36.         spacing:10
  37.        MDBoxLayout:
  38.            size_hint_y:1/9
  39.             MDLabel:
  40.                 text:"Products;"
  41.                 bold:True
  42.                 adaptive_height:True
  43.                 font_style:'H4'
  44.            MDBoxLayout:
  45.                orientation:'vertical'
  46.                size_hint:.3,.3
  47.                MDSpinner:
  48.                    size_hint: None, None
  49.                    size: dp(36), dp(36)
  50.                    pos_hint: {'center_x': .5, 'center_y': .5}
  51.                    active: True
  52.                    color:app.theme_cls.primary_color
  53.                    #determinate: True                
  54.  
  55.         ScrollView:
  56.             MDList:
  57.                 id:show_card
  58.  
  59. <MarkupLabel>:
  60.    markup: True
  61.    on_ref_press: self.action(args[1])
  62.  
  63. #card i want to  populate to show data
  64. <ShowCard>:
  65.    orientation:'vertical'                                  
  66.    ripple_behavior: True
  67.    size_hint:.8,None
  68.    #radius:36, 36, 00, 00
  69.    style:'outlined'
  70.    height:300
  71.    #on_press:
  72.        #root.go_to_buy_screen()
  73.    #md_bg_color: "darkgrey"
  74.    elevation:5
  75.    MDGridLayout:
  76.        cols:3
  77.        spacing:1
  78.        FitImage:
  79.            source:root.image
  80.            id:product_image
  81.            #size_hint: None, None
  82.                    
  83.        MDSeparator:
  84.            height: "5dp"
  85.            md_bg_color:app.theme_cls.accent_color
  86.            orientation:'vertical'            
  87.        MDBoxLayout:
  88.            orientation:'vertical'
  89.            padding:5
  90.            
  91.            MDLabel:
  92.                text:root.name
  93.                bold:True
  94.                font_size:32
  95.                id:product_name                
  96.                #color:app.theme_cls.primary_color
  97.                font_name:'fonts/Roboto-MediumItalic.ttf'
  98.  
  99.            MDLabel:
  100.                text:root.description
  101.                color:app.theme_cls.accent_color
  102.                font_size:25
  103.                id:product_description
  104.                font_name:'fonts/Roboto-MediumItalic.ttf'
  105.                #bold:True
  106.            MDChip:
  107.                text: root.location
  108.                icon_left: "map-marker"
  109.                id:product_location
  110.  
  111.            MDLabel:
  112.                text: root.price
  113.                color:app.theme_cls.primary_dark
  114.                font_size:32
  115.                bold:True
  116.                id:product_price
  117.  
  118.            MarkupLabel:
  119.                text: f'Contact: [ref=tel:+{root.contact}][u]Call me![/u][/ref]'
  120.                adaptive_height:True
  121.                #color:app.theme_cls.primary_color
  122.                bold:True
  123.                font_size:25
  124.                id:product_contact
  125.  
  126.    MDSeparator:
  127.        height: "5dp"
  128.        md_bg_color:app.theme_cls.accent_color                  
  129. """
  130.  
  131. class Managert(ScreenManager):
  132.     pass
  133.  
  134. class MarkupLabel(MDLabel):
  135.     def action(self, url):
  136.         print(url)
  137.         webbrowser.open(url)
  138.  
  139. class ShowCard(MDCard):
  140.     description = StringProperty()# match the keywords in the product dict
  141.     name = StringProperty()
  142.     price = StringProperty()
  143.     image = StringProperty()
  144.     location=StringProperty()
  145.     contact=ObjectProperty()
  146.  
  147.  
  148. class MainScreen(Screen):
  149.  
  150.     def on_enter(self):
  151.         try:
  152.             # getting data from real-time database
  153.             self.firebase = firebase.FirebaseApplication('https://lexconnectionsapp-default-rtdb.firebaseio.com/', None)
  154.             print('connecting........')
  155.      
  156.             self.result = self.firebase.get('lexconnectionsapp-default-rtdb/products', None)
  157.             print(type(self.result))
  158.             # data i fetched from my database
  159.             self.data = self.result
  160.             products = [item for item in self.data.values()]  # ignore primary key, get the inner dicts
  161.             for product in products:
  162.                 sc = ShowCard(**product)  # same as Showcard(description=product['description'],...)
  163.                 self.ids.show_card.add_widget(sc)
  164.  
  165.         except Exception as e:
  166.             print(f'Error: {e}')
  167.  
  168. class FetchdataApp2(MDApp):
  169.     def build(self):
  170.         return Builder.load_string(gt)
  171.  
  172. FetchdataApp2().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement