]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-13/list_report_virtual.py
2 import sys
, glob
, random
7 A simple data source class that just uses our sample data items.
8 A real data source class would manage fetching items from a
11 def GetColumnHeaders(self
):
17 def GetItem(self
, index
):
18 return data
.rows
[index
]
20 def UpdateCache(self
, start
, end
):
24 class VirtualListCtrl(wx
.ListCtrl
):
26 A generic virtual listctrl that fetches data from a DataSource.
28 def __init__(self
, parent
, dataSource
):
29 wx
.ListCtrl
.__init
__(self
, parent
,
30 style
=wx
.LC_REPORT|wx
.LC_SINGLE_SEL|wx
.LC_VIRTUAL
)
31 self
.dataSource
= dataSource
32 self
.Bind(wx
.EVT_LIST_CACHE_HINT
, self
.DoCacheItems
)
33 self
.SetItemCount(dataSource
.GetCount())
35 columns
= dataSource
.GetColumnHeaders()
36 for col
, text
in enumerate(columns
):
37 self
.InsertColumn(col
, text
)
40 def DoCacheItems(self
, evt
):
41 self
.dataSource
.UpdateCache(
42 evt
.GetCacheFrom(), evt
.GetCacheTo())
44 def OnGetItemText(self
, item
, col
):
45 data
= self
.dataSource
.GetItem(item
)
48 def OnGetItemAttr(self
, item
): return None
49 def OnGetItemImage(self
, item
): return -1
53 class DemoFrame(wx
.Frame
):
55 wx
.Frame
.__init
__(self
, None, -1,
56 "Virtual wx.ListCtrl",
59 self
.list = VirtualListCtrl(self
, DataSource())
63 app
= wx
.PySimpleApp()