Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from firebase import firebase
- from firebase_admin import db
- from kivymd.app import MDApp
- from kivymd.uix.card import MDCard
- from kivymd.uix.label import MDLabel
- from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
- from kivy.properties import StringProperty,ObjectProperty
- from kivy.core.window import Window
- from kivy.lang import Builder
- import urlrequest
- import webbrowser
- Window.size = 550, 700
- gt = """
- ScreenManager:
- StartScreen:
- name: 'start' # on_enter fires during initialization...
- MainScreen:
- name: 'home'
- <StartScreen@Screen>:
- BoxLayout:
- orientation:'vertical'
- AsyncImage:
- source:"https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/shoe2-removebg-preview.png?alt=media&token=7658113b-d790-4d68-a356-400093a45ffa"
- Button:
- text: 'Go to Home'
- on_release: root.manager.current = 'home'
- <MainScreen>:
- name:'home'
- MDBoxLayout:
- orientation:'vertical'
- padding:20
- spacing:10
- MDBoxLayout:
- size_hint_y:1/9
- MDLabel:
- text:"Products;"
- bold:True
- adaptive_height:True
- font_style:'H4'
- MDBoxLayout:
- orientation:'vertical'
- size_hint:.3,.3
- MDSpinner:
- size_hint: None, None
- size: dp(36), dp(36)
- pos_hint: {'center_x': .5, 'center_y': .5}
- active: True
- color:app.theme_cls.primary_color
- #determinate: True
- ScrollView:
- MDList:
- id:show_card
- <MarkupLabel>:
- markup: True
- on_ref_press: self.action(args[1])
- #card i want to populate to show data
- <ShowCard>:
- orientation:'vertical'
- ripple_behavior: True
- size_hint:.8,None
- #radius:36, 36, 00, 00
- style:'outlined'
- height:300
- #on_press:
- #root.go_to_buy_screen()
- #md_bg_color: "darkgrey"
- elevation:5
- MDGridLayout:
- cols:3
- spacing:1
- FitImage:
- source:root.image
- id:product_image
- #size_hint: None, None
- MDSeparator:
- height: "5dp"
- md_bg_color:app.theme_cls.accent_color
- orientation:'vertical'
- MDBoxLayout:
- orientation:'vertical'
- padding:5
- MDLabel:
- text:root.name
- bold:True
- font_size:32
- id:product_name
- #color:app.theme_cls.primary_color
- font_name:'fonts/Roboto-MediumItalic.ttf'
- MDLabel:
- text:root.description
- color:app.theme_cls.accent_color
- font_size:25
- id:product_description
- font_name:'fonts/Roboto-MediumItalic.ttf'
- #bold:True
- MDChip:
- text: root.location
- icon_left: "map-marker"
- id:product_location
- MDLabel:
- text: root.price
- color:app.theme_cls.primary_dark
- font_size:32
- bold:True
- id:product_price
- MarkupLabel:
- text: f'Contact: [ref=tel:+{root.contact}][u]Call me![/u][/ref]'
- adaptive_height:True
- #color:app.theme_cls.primary_color
- bold:True
- font_size:25
- id:product_contact
- MDSeparator:
- height: "5dp"
- md_bg_color:app.theme_cls.accent_color
- """
- class Managert(ScreenManager):
- pass
- class MarkupLabel(MDLabel):
- def action(self, url):
- print(url)
- webbrowser.open(url)
- class ShowCard(MDCard):
- description = StringProperty()# match the keywords in the product dict
- name = StringProperty()
- price = StringProperty()
- image = StringProperty()
- location=StringProperty()
- contact=ObjectProperty()
- class MainScreen(Screen):
- def on_enter(self):
- try:
- # getting data from real-time database
- self.firebase = firebase.FirebaseApplication('https://lexconnectionsapp-default-rtdb.firebaseio.com/', None)
- print('connecting........')
- self.result = self.firebase.get('lexconnectionsapp-default-rtdb/products', None)
- print(type(self.result))
- # data i fetched from my database
- self.data = self.result
- products = [item for item in self.data.values()] # ignore primary key, get the inner dicts
- for product in products:
- sc = ShowCard(**product) # same as Showcard(description=product['description'],...)
- self.ids.show_card.add_widget(sc)
- except Exception as e:
- print(f'Error: {e}')
- class FetchdataApp2(MDApp):
- def build(self):
- return Builder.load_string(gt)
- FetchdataApp2().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement