class DataDeck(FloatLayout): data = [] data_type_display = ObjectProperty(None) data_type_display_class = None data_type_class_map = [ImageDataDisplay] def __init__(self, data_type, database_name, **kwargs): self._data_type = data_type self.database = UserSession().mongo_client[database_name] self.data_manager = DataManager(self.database, self.create_data_type_display()) self.data_manager.fetch_source_data() super(DataDeck, self).__init__(**kwargs) self.initial_populate() def on_kv_post(self, base_widget): self.initial_populate() def create_data_type_display(self): return self.data_type_class_map[self._data_type](self.database) def initdata(self): self.get_data_batch() self.initial_populate() def get_data_batch(self): self.data_manager.fetch_source_data() def initial_populate(self): for i in range(2): self.add_dataDisplay() def add_dataDisplay(self): #remove from self.data #make sure self.data is always full self.data_display_widget = self.create_data_type_display() data = self.data_manager.pop() self.data_display_widget.setData(data) self.data_display_widget.buildData() if len(self.data_manager) < 3: self.data_manager.fetch_source_data() self.add_widget(self.data_display_widget) def label_data(self, label): self.children[0].label_data(label) self.remove_widget(self.children[0]) self.add_dataDisplay() def fetchSourceData(self): # from the datamanager self.data_manager.fetchSourceData()