]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-13/list_report_colsort.py
2 import wx
.lib
.mixins
.listctrl
3 import sys
, glob
, random
6 class DemoFrame(wx
.Frame
, wx
.lib
.mixins
.listctrl
.ColumnSorterMixin
):
8 wx
.Frame
.__init
__(self
, None, -1,
9 "wx.ListCtrl with ColumnSorterMixin",
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
)
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")
24 # create the list control
25 self
.list = wx
.ListCtrl(self
, -1, style
=wx
.LC_REPORT
)
27 # assign the image list to it
28 self
.list.AssignImageList(il
, wx
.IMAGE_LIST_SMALL
)
31 for col
, text
in enumerate(data
.columns
):
32 self
.list.InsertColumn(col
, text
)
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
)
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
46 # give each item a random image
47 img
= random
.randint(0, il_max
)
48 self
.list.SetItemImage(index
, img
, img
)
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
)
56 # initialize the column sorter
57 wx
.lib
.mixins
.listctrl
.ColumnSorterMixin
.__init
__(self
,
60 def GetListCtrl(self
):
63 def GetSortImages(self
):
64 return (self
.dn
, self
.up
)
67 app
= wx
.PySimpleApp()