Created
May 12, 2013 15:37
-
-
Save geojeff/5563943 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def scroll_after_add(self): | |
if not self.scrolling: | |
available_height = self.height | |
index = self._index | |
print 'index', index | |
print 'available_height', available_height | |
while available_height > 0: | |
item_view = self.adapter.get_view(index) | |
if item_view is None: | |
break | |
index += 1 | |
available_height -= item_view.height | |
print 'available_height', available_height | |
if available_height <= 0: | |
self._index += 1 | |
self.scrolling = True | |
self.populate() | |
self.dispatch('on_scroll_complete') | |
def on_scroll_complete(self, *args): | |
self.scrolling = False | |
def data_changed(self, *dt): | |
print 'data_changed callback', dt | |
print self.adapter.data.range_change | |
if self.adapter.data.range_change: | |
first_item_view = self.container.children[-1] | |
last_item_view = self.container.children[0] | |
data_action, (start_index, end_index) = self.adapter.data.range_change | |
change_in_range = False | |
if (first_item_view.index <= start_index <= last_item_view.index | |
or | |
first_item_view.index <= end_index <= last_item_view.index): | |
change_in_range = True | |
if data_action == 'add': | |
self.scroll_after_add() | |
elif data_action == 'delete': | |
cv = self.adapter.cached_views | |
i = start_index | |
j = end_index + 1 | |
slice_length = end_index - start_index | |
deleted_views = [] | |
while j in cv and j < len(self.adapter.data) - slice_length: | |
deleted_views.append(cv[i]) | |
cv[i] = cv[j] | |
cv[i].index = i | |
i += 1 | |
j += 1 | |
if j in cv: | |
while j in cv: | |
del cv[j] | |
j += 1 | |
for deleted_view in deleted_views: | |
if deleted_view in self.adapter.selection: | |
self.adapter.selection.remove(deleted_view) | |
self.adapter.check_for_empty_selection() | |
if change_in_range: | |
self.scrolling = True | |
self.populate() | |
self.dispatch('on_scroll_complete') | |
elif data_action == 'move': | |
pass | |
elif data_action == 'sort': | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment