]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-13/list_report_colsort.py
don't use invalid wxIconBundles, it results in asserts after recent changes
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-13 / list_report_colsort.py
1 import wx
2 import wx.lib.mixins.listctrl
3 import sys, glob, random
4 import data
5
6 class DemoFrame(wx.Frame, wx.lib.mixins.listctrl.ColumnSorterMixin):
7 def __init__(self):
8 wx.Frame.__init__(self, None, -1,
9 "wx.ListCtrl with ColumnSorterMixin",
10 size=(600,400))
11
12 # load some images into an image list
13 il = wx.ImageList(16,16, True)
14 for name in glob.glob("smicon??.png"):
15 bmp = wx.Bitmap(name, wx.BITMAP_TYPE_PNG)
16 il_max = il.Add(bmp)
17
18 # add some arrows for the column sorter
19 self.up = il.AddWithColourMask(
20 wx.Bitmap("sm_up.bmp", wx.BITMAP_TYPE_BMP), "blue")
21 self.dn = il.AddWithColourMask(
22 wx.Bitmap("sm_down.bmp", wx.BITMAP_TYPE_BMP), "blue")
23
24 # create the list control
25 self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT)
26
27 # assign the image list to it
28 self.list.AssignImageList(il, wx.IMAGE_LIST_SMALL)
29
30 # Add some columns
31 for col, text in enumerate(data.columns):
32 self.list.InsertColumn(col, text)
33
34 # add the rows
35 self.itemDataMap = {}
36 for item in data.rows:
37 index = self.list.InsertStringItem(sys.maxint, item[0])
38 for col, text in enumerate(item[1:]):
39 self.list.SetStringItem(index, col+1, text)
40
41 # give each item a data value, and map it back to the
42 # item values, for the column sorter
43 self.list.SetItemData(index, index)
44 self.itemDataMap[index] = item
45
46 # give each item a random image
47 img = random.randint(0, il_max)
48 self.list.SetItemImage(index, img, img)
49
50 # set the width of the columns in various ways
51 self.list.SetColumnWidth(0, 120)
52 self.list.SetColumnWidth(1, wx.LIST_AUTOSIZE)
53 self.list.SetColumnWidth(2, wx.LIST_AUTOSIZE)
54 self.list.SetColumnWidth(3, wx.LIST_AUTOSIZE_USEHEADER)
55
56 # initialize the column sorter
57 wx.lib.mixins.listctrl.ColumnSorterMixin.__init__(self,
58 len(data.columns))
59
60 def GetListCtrl(self):
61 return self.list
62
63 def GetSortImages(self):
64 return (self.dn, self.up)
65
66
67 app = wx.PySimpleApp()
68 frame = DemoFrame()
69 frame.Show()
70 app.MainLoop()