Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No text return in ListItem.GetText() #605

Closed
bvrl opened this issue Nov 9, 2017 · 1 comment · Fixed by #621
Closed

No text return in ListItem.GetText() #605

bvrl opened this issue Nov 9, 2017 · 1 comment · Fixed by #621

Comments

@bvrl
Copy link

bvrl commented Nov 9, 2017

Operating system: Windows-7-6.1.7601-SP1
wxPython version: 4.0.0rc1.dev3456+e141c95
Python version: 2.7.13

Description of the problem: I created an Editable ListControl, when edit a field I want to catch the changement string (=text). This is done in a eventhandler OnMixUpdate() triggered by wx.EVT_LIST_END_LABEL_EDIT . With event.GetItem() I access the correct listItem but when I do Getext() it returns an empty string. Also wxPyDeprecationWarning is given on listctrl.py:655

import wx
import wx.lib.mixins.listctrl  as  listmix
import sys
import platform
 
########################################################################
class EditableListCtrl(wx.ListCtrl, listmix.TextEditMixin):
    ''' TextEditMixin allows any column to be edited. '''
 
    #----------------------------------------------------------------------
    def __init__(self, parent, ID=wx.ID_ANY, pos=wx.DefaultPosition,
                 size=wx.DefaultSize, style=0):
        """Constructor"""
        wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
        listmix.TextEditMixin.__init__(self)
 
########################################################################
class MyPanel(wx.Panel):
    """"""
 
    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)
 
        rows = [("Ford", "Taurus", "1996", "Blue"),
                ("Nissan", "370Z", "2010", "Green"),
                ("Porche", "911", "2009", "Red")
                ]
        self.list_ctrl = EditableListCtrl(self, style=wx.LC_REPORT)
 
        self.list_ctrl.InsertColumn(0, "Make")
        self.list_ctrl.InsertColumn(1, "Model")
        self.list_ctrl.InsertColumn(2, "Year")
        self.list_ctrl.InsertColumn(3, "Color")
 
        index = 0
        for row in rows:
            self.list_ctrl.InsertItem(index, row[0])
            self.list_ctrl.SetItem(index, 1, row[1])
            self.list_ctrl.SetItem(index, 2, row[2])
            self.list_ctrl.SetItem(index, 3, row[3])
            index += 1
 
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5)
        self.SetSizer(sizer)
        self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnMixUpdate, self.list_ctrl)
        
    def OnMixUpdate(self, event):
        rowid = event.GetIndex()
        colid = event.GetColumn()
        new_data = event.GetItem()
        #print  event.GetItemData()  #Works perfectly with wxpython 2.9, gives string with last given value.
        print type(new_data)
        print new_data.GetText()   #Problem prints empty string

        olddata=self.list_ctrl.GetItem(itemIdx=rowid, col=colid).GetText()

        print "COL ID:%s\tROW ID:%s\t ROW OLD:%s\t NEW:%s\t"%(colid,rowid,olddata,new_data.GetText())
        event.Skip()  
 
 
########################################################################
class MyFrame(wx.Frame):
    """"""
 
    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, wx.ID_ANY, "Editable List Control")
        panel = MyPanel(self)
        self.Show()
        print sys.version_info
        print platform.platform()
        print 'wxversion: %s'%wx.__version__
    #----------------------------------------------------------------------
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame()
    app.MainLoop()

Output: (I changed 911 to 9110):
sys.version_info(major=2, minor=7, micro=13, releaselevel='final', serial=0)
Windows-7-6.1.7601-SP1
wxversion: 4.0.0rc1.dev3456+e141c95
<class 'wx._core.ListItem'>

COL ID:1 ROW ID:2 ROW OLD:911 NEW:
C:\Python27\lib\site-packages\wx\lib\mixins\listctrl.py:655: wxPyDeprecationWarning: Call to deprecated item. Use SetItem instead.
self.SetStringItem(self.curRow, self.curCol, text)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant