]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ListCtrl_edit.py
use size_t for the total size of data instead of wxFileSize_t (msg catalogs can't...
[wxWidgets.git] / wxPython / demo / ListCtrl_edit.py
CommitLineData
15513a80
RD
1#----------------------------------------------------------------------------
2# Name: ListCtrl_edit.py
3# Purpose: Testing editing a ListCtrl
4#
5# Author: Pim van Heuven
6#
7# Created: 2004/10/15
8# Copyright: (c) Pim Van Heuven
9# Licence: wxWindows license
10#----------------------------------------------------------------------------
11
12import sys
13import wx
14import wx.lib.mixins.listctrl as listmix
15
16#---------------------------------------------------------------------------
17
18listctrldata = {
191 : ("Hey!", "You can edit", "me!"),
202 : ("Try changing the contents", "by", "clicking"),
213 : ("in", "a", "cell"),
224 : ("See how the length columns", "change", "?"),
235 : ("You can use", "TAB,", "cursor down,"),
246 : ("and cursor up", "to", "navigate"),
25}
26
27#---------------------------------------------------------------------------
28
29class TestListCtrl(wx.ListCtrl,
30 listmix.ListCtrlAutoWidthMixin,
31 listmix.TextEditMixin):
32
33 def __init__(self, parent, ID, pos=wx.DefaultPosition,
34 size=wx.DefaultSize, style=0):
35 wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
36
37 # Divide remaining space over all columns
38 listmix.ListCtrlAutoWidthMixin.__init__(self, 0, 3)
39 self.Populate()
40 listmix.TextEditMixin.__init__(self)
41
42 def Populate(self):
43 # for normal, simple columns, you can add them like this:
44 self.InsertColumn(0, "Column 1")
45 self.InsertColumn(1, "Column 2")
46 self.InsertColumn(2, "Column 3")
47 self.InsertColumn(3, "Len 1", wx.LIST_FORMAT_RIGHT)
48 self.InsertColumn(4, "Len 2", wx.LIST_FORMAT_RIGHT)
49 self.InsertColumn(5, "Len 3", wx.LIST_FORMAT_RIGHT)
50
51 items = listctrldata.items()
52 for key, data in items:
53 index = self.InsertStringItem(sys.maxint, data[0])
54 self.SetStringItem(index, 0, data[0])
55 self.SetStringItem(index, 1, data[1])
56 self.SetStringItem(index, 2, data[2])
57 self.SetItemData(index, key)
58
59 self.SetColumnWidth(0, wx.LIST_AUTOSIZE)
60 self.SetColumnWidth(1, wx.LIST_AUTOSIZE)
61 self.SetColumnWidth(2, 100)
62
63 self.currentItem = 0
64
65
66 def SetStringItem(self, index, col, data):
67 if col in range(3):
68 wx.ListCtrl.SetStringItem(self, index, col, data)
69 wx.ListCtrl.SetStringItem(self, index, 3+col, str(len(data)))
70 else:
71 try:
72 datalen = int(data)
73 except:
74 return
75
76 wx.ListCtrl.SetStringItem(self, index, col, data)
77
78 data = self.GetItem(index, col-3).GetText()
79 wx.ListCtrl.SetStringItem(self, index, col-3, data[0:datalen])
80
81
82
83
84class TestListCtrlPanel(wx.Panel):
85 def __init__(self, parent, log):
86 wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
87
88 self.log = log
89 tID = wx.NewId()
90
91 self.list = TestListCtrl(self, tID,
92 style=wx.LC_REPORT
93 | wx.BORDER_NONE
94 | wx.LC_SORT_ASCENDING
95 )
96
97 self.Bind(wx.EVT_SIZE, self.OnSize)
98
99
100 def OnSize(self, event):
101 w,h = self.GetClientSizeTuple()
102 self.list.SetDimensions(0, 0, w, h)
103
104
105
106#---------------------------------------------------------------------------
107
108def runTest(frame, nb, log):
109 win = TestListCtrlPanel(nb, log)
110 return win
111
112#---------------------------------------------------------------------------
113
114
115overview = """\
116<html>
117<body>
118
119This demo demonstrates direct editing of all cells of a ListCtrl. To
120enable it just include the <b>TextEditMixin</b>. The ListCtrl can be
121navigated with the TAB and up/down cursor keys.
122
123<p>Another facet of this demo is that the remaining space of the
124ListCtrls is divided over the first three columns. This is achieved
125with the extended syntax of <b>ListCtrlAutoWidthMixin</b>:
126<code>listmix.ListCtrlAutoWidthMixin.__init__(self, startcol, endcol)</code>
127(Look at the general ListCtrl demo for more information about the
128ListCtrlAutoWidthMixin)
129
130<p>Finally, the ListCtrl is automatically scrolled, if needed, when
131TAB is pressed consecutively (Windows only).
132
133</body>
134</html>
135"""
136
137
138if __name__ == '__main__':
139 import sys,os
140 import run
141 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
142