Advertisement
jevixlugya

Untitled

Jun 6th, 2023
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. class Homepage(Screen):
  2.     def __init__(self, **kwargs):
  3.         super().__init__(**kwargs)
  4.         self.t = None # used to hold thread    
  5.        
  6.     def on_enter(self,*args):
  7.  
  8.         if self.t:  # only allow 1 thread to be created
  9.             return
  10.         self.t =threading.Thread(target=self.fetch_data)
  11.         self.t.start()
  12.         self.set_animation()
  13.         self.fetch_data()        
  14.          
  15.     def show_products22(self, * args):
  16.         try:
  17.             # getting data from real-time database
  18.             self.firebase = firebase.FirebaseApplication('https://lexconnectionsapp-default-rtdb.firebaseio.com/', None)
  19.             print('connecting........')
  20.      
  21.             self.result = self.firebase.get('lexconnectionsapp-default-rtdb/products', None)
  22.             print(type(self.result))
  23.             # data i fetched from my database
  24.             self.data = self.result
  25.             products = [item for item in self.data.values()]  # ignore primary key, get the inner dicts
  26.             for product in products:
  27.                 sc = ShowCard(**product)  # same as Showcard(description=product['description'],...)
  28.                 self.ids.show_card.add_widget(sc)
  29.  
  30.         except Exception as e:
  31.             print(f'Error: {e}')
  32.     @mainthread                  
  33.     def fetch_data(self):
  34.             #time.sleep(.5)  # to make the threaded task slow, note kivy still responds
  35.         self.show_products22()            
  36.  
  37.  
  38.     def on_leave(self):
  39.         print('closed')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement