]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ListCtrl_edit.py
   1 #---------------------------------------------------------------------------- 
   2 # Name:         ListCtrl_edit.py 
   3 # Purpose:      Testing editing a ListCtrl 
   5 # Author:       Pim van Heuven 
   8 # Copyright:    (c) Pim Van Heuven 
   9 # Licence:      wxWindows license 
  10 #---------------------------------------------------------------------------- 
  14 import  wx
.lib
.mixins
.listctrl  
as  listmix
 
  16 #--------------------------------------------------------------------------- 
  19 1 : ("Hey!", "You can edit", "me!"), 
  20 2 : ("Try changing the contents", "by", "clicking"), 
  21 3 : ("in", "a", "cell"), 
  22 4 : ("See how the length columns", "change", "?"), 
  23 5 : ("You can use", "TAB,", "cursor down,"), 
  24 6 : ("and cursor up", "to", "navigate"), 
  27 #--------------------------------------------------------------------------- 
  29 class TestListCtrl(wx
.ListCtrl
, 
  30                    listmix
.ListCtrlAutoWidthMixin
, 
  31                    listmix
.TextEditMixin
): 
  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
) 
  37         listmix
.ListCtrlAutoWidthMixin
.__init
__(self
) 
  39         listmix
.TextEditMixin
.__init
__(self
) 
  42         # for normal, simple columns, you can add them like this: 
  43         self
.InsertColumn(0, "Column 1") 
  44         self
.InsertColumn(1, "Column 2") 
  45         self
.InsertColumn(2, "Column 3") 
  46         self
.InsertColumn(3, "Len 1", wx
.LIST_FORMAT_RIGHT
) 
  47         self
.InsertColumn(4, "Len 2", wx
.LIST_FORMAT_RIGHT
) 
  48         self
.InsertColumn(5, "Len 3", wx
.LIST_FORMAT_RIGHT
) 
  50         items 
= listctrldata
.items() 
  51         for key
, data 
in items
: 
  52             index 
= self
.InsertStringItem(sys
.maxint
, data
[0]) 
  53             self
.SetStringItem(index
, 0, data
[0]) 
  54             self
.SetStringItem(index
, 1, data
[1]) 
  55             self
.SetStringItem(index
, 2, data
[2]) 
  56             self
.SetItemData(index
, key
) 
  58         self
.SetColumnWidth(0, wx
.LIST_AUTOSIZE
) 
  59         self
.SetColumnWidth(1, wx
.LIST_AUTOSIZE
) 
  60         self
.SetColumnWidth(2, 100) 
  65     def SetStringItem(self
, index
, col
, data
): 
  67             wx
.ListCtrl
.SetStringItem(self
, index
, col
, data
) 
  68             wx
.ListCtrl
.SetStringItem(self
, index
, 3+col
, str(len(data
))) 
  75             wx
.ListCtrl
.SetStringItem(self
, index
, col
, data
) 
  77             data 
= self
.GetItem(index
, col
-3).GetText() 
  78             wx
.ListCtrl
.SetStringItem(self
, index
, col
-3, data
[0:datalen
]) 
  83 class TestListCtrlPanel(wx
.Panel
): 
  84     def __init__(self
, parent
, log
): 
  85         wx
.Panel
.__init
__(self
, parent
, -1, style
=wx
.WANTS_CHARS
) 
  90         self
.list = TestListCtrl(self
, tID
, 
  93                                  | wx
.LC_SORT_ASCENDING
 
  96         self
.Bind(wx
.EVT_SIZE
, self
.OnSize
) 
  99     def OnSize(self
, event
): 
 100         w
,h 
= self
.GetClientSizeTuple() 
 101         self
.list.SetDimensions(0, 0, w
, h
) 
 105 #--------------------------------------------------------------------------- 
 107 def runTest(frame
, nb
, log
): 
 108     win 
= TestListCtrlPanel(nb
, log
) 
 111 #--------------------------------------------------------------------------- 
 118 This demo demonstrates direct editing of all cells of a ListCtrl. To 
 119 enable it just include the <b>TextEditMixin</b>. The ListCtrl can be 
 120 navigated with the TAB and up/down cursor keys. 
 122 <p>Another facet of this demo is that the remaining space of the 
 123 ListCtrls is divided over the first three columns. This is achieved 
 124 with the extended syntax of <b>ListCtrlAutoWidthMixin</b>: 
 125 <code>listmix.ListCtrlAutoWidthMixin.__init__(self, startcol, endcol)</code> 
 126 (Look at the general ListCtrl demo for more information about the 
 127 ListCtrlAutoWidthMixin) 
 129 <p>Finally, the ListCtrl is automatically scrolled, if needed, when 
 130 TAB is pressed consecutively (Windows only). 
 137 if __name__ 
== '__main__': 
 140     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])