-
Notifications
You must be signed in to change notification settings - Fork 1
/
adapters.py
91 lines (72 loc) · 3.06 KB
/
adapters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from kivy.properties import BooleanProperty, DictProperty, ListProperty, NumericProperty, ObjectProperty, OptionProperty, WeakListProperty
from kivy.weakreflist import WeakList
import objgraph, random
class ListViewAdapter(object):
data = ListProperty([])
cached_views = DictProperty({})
list_item = ObjectProperty(None)
selection = WeakListProperty(WeakList())
args_converter = ObjectProperty(None)
selection_mode = OptionProperty('single', options=('None', 'single'))
def __init__(self, **kwargs):
self.register_event_type('on_selection_change')
super(ListViewAdapter, self).__init__(**kwargs)
def on_data(self, instance, value):
instance.delete_cache()
if len(instance.selection) > 0:
instance.selection[:] = []
def on_selection(self, instance, value):
instance.dispatch('on_selection_change')
def delete_cache(self, *args):
self.cached_views.clear()
self.container.canvas.clear()
def get_count(self):
return len(self.data)
def get_data_item(self, index):
if (0 <= index < self.get_count()):
return self.data[index]
def get_view(self, index):
if index in self.cached_views:
return self.cached_views[index]
else:
item_view = self.create_view(index)
if item_view:
self.cached_views[index] = item_view
return item_view
def create_view(self, index):
item = self.get_data_item(index)
if item is not None:
item_args = self.args_converter(index, item)
item_args['index'] = index
return self.list_item(**item_args)
def deselect_all(self, *args):
selection = self.selection
for each_view in xrange(len(selection)):
selection.pop().is_selected = False
def handle_selection(self, view, hold_dispatch=False, *args):
if view in self.selection:
self.deselect_item_view(view)
elif self.selection_mode == 'single':
self.deselect_all()
self.select_item_view(view)
if not hold_dispatch:
self.dispatch('on_selection_change')
def select_item_view(self, view):
view.is_selected = True
self.selection.append(view)
def deselect_item_view(self, view):
view.is_selected = False
self.selection.remove(view)
def on_selection_change(self, *args):
#pass
if self.selection:
#from listscreen import ListScreenItem
objgraph.show_growth()
print '...'
roots = objgraph.get_leaking_objects()
objgraph.show_most_common_types(objects=roots)
print '...'
objgraph.show_refs(roots[:3], refcounts=True, filename='sad.png')
#objgraph.show_chain(objgraph.find_backref_chain(self.selection[0].__self__, objgraph.is_proper_module),filename='chain.png')
#objgraph.show_backrefs(self.selection[0].__self__, filename='sample-backref-graph.png')
print '...'