Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Homepage(Screen):
- def __init__(self, **kwargs):
- super().__init__(**kwargs)
- self.t = None # used to hold thread
- def on_enter(self,*args):
- if self.t: # only allow 1 thread to be created
- return
- self.t =threading.Thread(target=self.fetch_data)
- self.t.start()
- self.set_animation()
- self.fetch_data()
- def show_products22(self, * args):
- 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}')
- @mainthread
- def fetch_data(self):
- #time.sleep(.5) # to make the threaded task slow, note kivy still responds
- self.show_products22()
- def on_leave(self):
- print('closed')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement