Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # from firebase import firebase
- # from firebase_admin import db
- from kivy.network.urlrequest import UrlRequest
- import UrlRequest
- from kivymd.app import MDApp
- from kivymd.uix.card import MDCard
- from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
- from kivy.properties import StringProperty
- from kivy.factory import Factory
- from kivy.core.window import Window
- from kivy.uix.boxlayout import BoxLayout
- from kivymd.uix.bottomsheet import MDCustomBottomSheet
- from kivy.lang import Builder
- Window.size = 400, 700
- gt = """
- ScreenManager:
- StartScreen:
- name: 'start' # on_enter fires during initialization...
- MainScreen:
- name: 'home'
- <StartScreen>:
- Button:
- text: 'Go to Home'
- on_release: root.manager.current = 'home'
- <ContentCustomSheet>:
- orientation: "vertical"
- id:lay
- size_hint_y: None
- height: "400dp"
- MDTopAppBar:
- title: 'Buy Product'
- ScrollView:
- MDGridLayout:
- cols: 1
- adaptive_height: True
- padding:10
- spacing:10
- MDCard:
- orientation:'vertical'
- #ripple_behavior:True
- size_hint:1,None
- radius:10
- style:'outlined'
- height:200
- md_bg_color: "darkgrey"
- elevation: 25
- FitImage:
- source:'lex/car.jpg'
- MDCard:
- orientation:'vertical'
- #ripple_behavior:True
- size_hint:1,None
- radius:10
- style:'outlined'
- height:200
- md_bg_color: "darkgrey"
- padding:5
- elevation: 25
- MDLabel:
- text:'description '
- adaptive_height:True
- MDSeparator:
- height: "2dp"
- md_bg_color:app.theme_cls.accent_color
- MDGridLayout:
- cols: 1
- padding:10
- adaptive_height: True
- MDLabel:
- text:'good product from America '
- <MainScreen>:
- name:'home'
- MDBoxLayout:
- orientation:'vertical'
- padding:10
- spacing:10
- MDLabel:
- text:"Fetched Data"
- bold:True
- adaptive_height:True
- font_style:'H4'
- ScrollView:
- MDList:
- spacing:10
- id:show_card
- #card i want to populate to show data
- <ShowCard>
- orientation:'vertical'
- #ripple_behavior:True
- size_hint:1,None
- radius:10
- style:'outlined'
- height:200
- elevation: 2
- MDGridLayout:
- cols:2
- spacing:5
- FitImage:
- source: root.image
- MDBoxLayout:
- orientation:'vertical'
- MDLabel:
- text:root.description
- bold:True
- color:app.theme_cls.primary_color
- # font_name:'fonts/popins.ttf'
- MDLabel:
- text:root.description
- MDLabel:
- text: root.price
- color:app.theme_cls.primary_color
- # font_name:'fonts/popins.ttf'
- MDSeparator:
- MDBoxLayout:
- padding:5
- spacing:5
- MDRectangleFlatIconButton:
- text:'buy'
- icon:'cart'
- on_press:root.buy_item()
- md_bg_color:app.theme_cls.primary_color
- color:1,0,0,.8
- theme_text_color: "Custom"
- text_color: "white"
- line_color: "red"
- theme_icon_color: "Custom"
- icon_color: "orange"
- MDRectangleFlatIconButton:
- text:'favourite'
- icon:'heart'
- md_bg_color:app.theme_cls.primary_color
- color:1,0,0,.8
- theme_text_color: "Custom"
- text_color: "white"
- line_color: "red"
- theme_icon_color: "Custom"
- icon_color: "orange"
- """
- class Managert(ScreenManager):
- pass
- class ContentCustomSheet(BoxLayout):
- pass
- class ShowCard(MDCard):
- description = StringProperty() # match the keywords in the product dict
- name = StringProperty()
- price = StringProperty()
- image = StringProperty()
- def buy_item(self):
- self.custom_sheet = MDCustomBottomSheet(screen=Factory.ContentCustomSheet())
- self.custom_sheet.open()
- class StartScreen(Screen):
- pass
- class MainScreen(Screen):
- def on_enter(self):
- # 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((self.result))
- print('show here iam')
- # data i fetched from my database
- self.data = {
- "product2": {
- "description": "best tv in uganda",
- "image": "https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/electronics.jpg?alt=media&token=f367e838-64a7-46bf-9134-f9dc4f25cc19",
- "name": "television",
- "price": "250,000"
- },
- "product3": {
- "description": "iphone pro best",
- "image": "https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/phone.jpg?alt=media&token=e65f6cb9-7aeb-40bd-85e9-bbacf12b56a2",
- "name": "phones",
- "price": "1000,000"
- },
- "product5": {
- "description": "best jobs ever",
- "image": "https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/jobs.jpg?alt=media&token=47c976fe-7832-41ff-97d9-9f1860613b3e",
- "name": "jobs",
- "price": "ugx 200,00"
- },
- "product6": {
- "description": "best properties ever",
- "image": "https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/property.jpg?alt=media&token=67c1c6f0-77c6-4113-ac21-89a506489668",
- "name": "property",
- "price": "ugx 3000,000"
- },
- "product7": {
- "description": "best tourism ever",
- "image": "https://firebasestorage.googleapis.com/v0/b/lexconnectionsapp.appspot.com/o/lion.jpg?alt=media&token=04ec0322-ea87-44fa-a8ae-f409fdaf12e0",
- "name": "WildLife",
- "price": "ugx 20,000"
- }
- }
- 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)
- class FetchdataApp(MDApp):
- def build(self):
- self.theme_cls.accent_palette = 'Red'
- self.theme_cls.accent_hue = '400'
- self.theme_cls.primary_palette = 'DeepPurple'
- return Builder.load_string(gt)
- # i was trying to post that data to the database
- '''firebase=firebase.FirebaseApplication('https://lexconnectionsapp-default-rtdb.firebaseio.com/',None)
- #importing data
- data={
- 'Name':'Ford',
- 'image':'gs://lexconnectionsapp.appspot.com/car.jpg',
- "price":'ugx:100,000,000',
- "description":'the car is fantastic'
- }
- #post data
- firebase.post('lexconnectionsapp-default-rtdb/products',data)'''
- FetchdataApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement