[wxPython-users] wx.ListCtrl - Problem editing
Nicolás Alejo Reynoso
soda at 3dgames.com.ar
Thu Aug 31 23:04:10 PDT 2006
Robin Dunn wrote:
> Nicolás Alejo Reynoso wrote:
>> First of all "Hello list" and second "I'm a Spanish spoken so sorry
>> for my bad english".
>>
>> Well...
>>
>> I've created a wx.ListCtrl with wx.lib.mixins.listctrl.TextEditMixin.
>> The problem when editing a cell is that the change is not showed
>> inmediatly. May be i'm doing something wrong but when i call
>> wx.EVT_LIST_END_LABEL_EDIT to show the content of that row the data
>> stay the same, now when i click and leave the same cell the change is
>> taken.
>
> What do you mean by "call wx.EVT_LIST_END_LABEL_EDIT" ? Perhaps you
> should send a sample app to show us what you are trying to do.
>
I mean when the "Event is activated" by leaving a cell (with a modified
value). In the OnEndEdit() method i print the data contained in that
column to stdout but this return the original data and not the last
change. Now... if i OnEndEdit the same item again the data returned it
is the modified.
Thanks in advance!
PD: I hope to be clear now :)
The sample from the wxPy doc slightly modified:
#--------------------------------------------------------------------------#
import sys
import wx
import wx.lib.mixins.listctrl as listmix
#---------------------------------------------------------------------------
listctrldata = {
1 : ("Hey!", "You can edit", "me!"),
2 : ("Try changing the contents", "by", "clicking"),
3 : ("in", "a", "cell"),
4 : ("See how the length columns", "change", "?"),
5 : ("You can use", "TAB,", "cursor down,"),
6 : ("and cursor up", "to", "navigate"),
}
#---------------------------------------------------------------------------
class TestListCtrl(wx.ListCtrl,
listmix.ListCtrlAutoWidthMixin,
listmix.TextEditMixin):
def __init__(self, parent, ID, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=0):
wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
self.InsertColumn(3, str(self))
self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEndLabelEdit)
listmix.ListCtrlAutoWidthMixin.__init__(self)
self.Populate()
listmix.TextEditMixin.__init__(self)
def Populate(self):
# for normal, simple columns, you can add them like this:
self.InsertColumn(0, "Column 1")
self.InsertColumn(1, "Column 2")
self.InsertColumn(2, "Column 3")
items = listctrldata.items()
for key, data in items:
index = self.InsertStringItem(sys.maxint, data[0])
self.SetStringItem(index, 0, data[0])
self.SetStringItem(index, 1, data[1])
self.SetStringItem(index, 2, data[2])
self.SetItemData(index, key)
self.SetColumnWidth(0, wx.LIST_AUTOSIZE)
self.SetColumnWidth(1, wx.LIST_AUTOSIZE)
self.SetColumnWidth(2, 100)
self.currentItem = 0
def getColumnText(self, index, col):
item = self.GetItem(index, col)
return item.GetText()
def OnEndLabelEdit(self, event):
self.currentItem = event.m_itemIndex
self.RefreshItem(self.currentItem)
print "\nonEndEdit: "
print >> sys.stdout, self.GetItemText(self.currentItem),\
self.getColumnText(self.currentItem, 1),\
self.getColumnText(self.currentItem, 2)
class TestListCtrlPanel(wx.Panel):
def __init__(self, parent, log):
wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
self.log = log
tID = wx.NewId()
self.list = TestListCtrl(self, tID,
style=wx.LC_REPORT
| wx.BORDER_NONE
| wx.LC_SORT_ASCENDING
)
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, event):
w,h = self.GetClientSizeTuple()
self.list.SetDimensions(0, 0, w, h)
def runTest(frame, nb, log):
win = TestListCtrlPanel(nb, log)
return win
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
#--------------------------------------------------------------------------#
More information about the wxpython-users
mailing list