]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-13/list_report_virtual.py
don't use invalid wxIconBundles, it results in asserts after recent changes
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-13 / list_report_virtual.py
1 import wx
2 import sys, glob, random
3 import data
4
5 class DataSource:
6 """
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
9 database or similar.
10 """
11 def GetColumnHeaders(self):
12 return data.columns
13
14 def GetCount(self):
15 return len(data.rows)
16
17 def GetItem(self, index):
18 return data.rows[index]
19
20 def UpdateCache(self, start, end):
21 pass
22
23
24 class VirtualListCtrl(wx.ListCtrl):
25 """
26 A generic virtual listctrl that fetches data from a DataSource.
27 """
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())
34
35 columns = dataSource.GetColumnHeaders()
36 for col, text in enumerate(columns):
37 self.InsertColumn(col, text)
38
39
40 def DoCacheItems(self, evt):
41 self.dataSource.UpdateCache(
42 evt.GetCacheFrom(), evt.GetCacheTo())
43
44 def OnGetItemText(self, item, col):
45 data = self.dataSource.GetItem(item)
46 return data[col]
47
48 def OnGetItemAttr(self, item): return None
49 def OnGetItemImage(self, item): return -1
50
51
52
53 class DemoFrame(wx.Frame):
54 def __init__(self):
55 wx.Frame.__init__(self, None, -1,
56 "Virtual wx.ListCtrl",
57 size=(600,400))
58
59 self.list = VirtualListCtrl(self, DataSource())
60
61
62
63 app = wx.PySimpleApp()
64 frame = DemoFrame()
65 frame.Show()
66 app.MainLoop()