ListCtrl Edit

Hi,

I have a listCtrl and I need edit only the column 1. I Attach my sample code and the error.

Traceback (most recent call last):
File “list.py”, line 66, in
frame_1 = MyFrame(None, -1, “”)
File “list.py”, line 36, in init
self.lc.OpenEditor(0,0)
File “/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py”, line 573, in OpenEditor
x1 = self.col_locs[col+1] - x0

Anyone help me?

list.py (1.93 KB)

···


SIN ETIQUETAS.[ PUNTO ]
http://hi.im/jyr
http://www.opentumblr.com

Hi Jair,

···

On Nov 22, 12:01 am, Jair Gaxiola <jyr.gaxi...@gmail.com> wrote:

Hi,

I have a listCtrl and I need edit only the column 1. I Attach my sample code
and the error.

Traceback (most recent call last):
File "list.py", line 66, in <module>
frame_1 = MyFrame(None, -1, "")
File "list.py", line 36, in __init__
self.lc.OpenEditor(0,0)
File
"/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py",
line 573, in OpenEditor
x1 = self.col_locs[col+1] - x0

Anyone help me?

The easiest way to do this is to use the TextEditMixin:

class TestListCtrl(wx.ListCtrl,
                   listmix.ListCtrlAutoWidthMixin,
                   listmix.TextEditMixin):

The above code is taken from the wxPython demo.

HTH

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

The edition if it works, as in the demo, I’m showing it in the script attached. What I need is to edit only one column, regardless of which row is.

cheers

···

On Mon, Nov 23, 2009 at 9:26 AM, Mike Driscoll kyosohma@gmail.com wrote:

Hi Jair,

The easiest way to do this is to use the TextEditMixin:

class TestListCtrl(wx.ListCtrl,

               listmix.ListCtrlAutoWidthMixin,

               listmix.TextEditMixin):

The above code is taken from the wxPython demo.


SIN ETIQUETAS.[ PUNTO ]
http://hi.im/jyr
http://www.opentumblr.com

Hi,

···

On Mon, Nov 23, 2009 at 10:40 AM, Jair Gaxiola <jyr.gaxiola@gmail.com> wrote:

On Mon, Nov 23, 2009 at 9:26 AM, Mike Driscoll <kyosohma@gmail.com> wrote:

Hi Jair,

The easiest way to do this is to use the TextEditMixin:

class TestListCtrl(wx.ListCtrl,
listmix.ListCtrlAutoWidthMixin,
listmix.TextEditMixin):

The above code is taken from the wxPython demo.

The edition if it works, as in the demo, I'm showing it in the script
attached. What I need is to edit only one column, regardless of which row
is.

If you look at the code there is a method called OpenEditor that is
added by the mixin. This is a callback method that is invoked when a
cell is clicked on. Override it and check if your the click was in the
column you want to allow editing in. If it is call the superclass
method, if not do nothing.

Cody

OpenEditor not work, show me the error

Traceback (most recent call last):
File "list.py", line 62, in <module>
frame_1 = MyFrame(None, -1, "")
File "list.py", line 32, in __init__
self.lc.OpenEditor(0,0)
File "/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py",
line 573, in OpenEditor
x1 = self.col_locs[col+1] - x0
IndexError: list index out of range

Any sugestions?

···

On Mon, Nov 23, 2009 at 10:43 AM, Cody Precord <codyprecord@gmail.com> wrote:

Hi,

On Mon, Nov 23, 2009 at 10:40 AM, Jair Gaxiola <jyr.gaxiola@gmail.com> wrote:
> On Mon, Nov 23, 2009 at 9:26 AM, Mike Driscoll <kyosohma@gmail.com> wrote:
>>
>> Hi Jair,
>>
>>
>> The easiest way to do this is to use the TextEditMixin:
>>
>> class TestListCtrl(wx.ListCtrl,
>> listmix.ListCtrlAutoWidthMixin,
>> listmix.TextEditMixin):
>>
>> The above code is taken from the wxPython demo.
>
> The edition if it works, as in the demo, I'm showing it in the script
> attached. What I need is to edit only one column, regardless of which row
> is.

If you look at the code there is a method called OpenEditor that is
added by the mixin. This is a callback method that is invoked when a
cell is clicked on. Override it and check if your the click was in the
column you want to allow editing in. If it is call the superclass
method, if not do nothing.

--
SIN ETIQUETAS.[ PUNTO ]
http://hi.im/jyr
http://www.opentumblr.com

Hi,

OpenEditor not work, show me the error

Traceback (most recent call last):
File "list.py", line 62, in <module>
frame_1 = MyFrame(None, -1, "")
File "list.py", line 32, in __init__
self.lc.OpenEditor(0,0)
File "/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py",
line 573, in OpenEditor
x1 = self.col_locs[col+1] - x0
IndexError: list index out of range

Any sugestions?

Obviously not without seeing what your doing...

The error there should be sufficient though. Your trying to open the
editor before any columns/rows have been added to the list. You
shouldn't be needing to call the method though just override it in
your ListCtrl subclass and it will be called automatically by the
framework when a column is clicked on.

Example to enable editing of only the first column:

   def OpenEditor(self, col, row):
        """Disable the editor for the first column"""
        if col == 0:
            self._editing = (col, row)
            listmix.TextEditMixin.OpenEditor(self, col, row)

Cody

···

On Mon, Nov 23, 2009 at 10:50 AM, Jair Gaxiola <jyr.gaxiola@gmail.com> wrote:

On Mon, Nov 23, 2009 at 10:43 AM, Cody Precord <codyprecord@gmail.com> wrote:

Hi

Hi,

OpenEditor not work, show me the error

Traceback (most recent call last):
File "list.py", line 62, in <module>
frame_1 = MyFrame(None, -1, "")
File "list.py", line 32, in __init__
self.lc.OpenEditor(0,0)
File "/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py",
line 573, in OpenEditor
x1 = self.col_locs[col+1] - x0
IndexError: list index out of range

Any sugestions?

Obviously not without seeing what your doing...

The error there should be sufficient though. Your trying to open the
editor before any columns/rows have been added to the list. You
shouldn't be needing to call the method though just override it in
your ListCtrl subclass and it will be called automatically by the
framework when a column is clicked on.

Example to enable editing of only the first column:

def OpenEditor(self, col, row):
"""Disable the editor for the first column"""
if col == 0:
self._editing = (col, row)
listmix.TextEditMixin.OpenEditor(self, col, row)

I try whit my sample attached and not work, show me the error

Traceback (most recent call last):
  File "list.py", line 68, in <module>
    frame_1 = MyFrame(None, -1, "")
  File "list.py", line 32, in __init__
    self.OpenEditor(0,0)
  File "list.py", line 59, in OpenEditor
    self.lc.OpenEditor(col, row)
  File "/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py",
line 573, in OpenEditor
    x1 = self.col_locs[col+1] - x0
IndexError: list index out of range

list.py (2.07 KB)

···

On Mon, Nov 23, 2009 at 10:56 AM, Cody Precord <codyprecord@gmail.com> wrote:

On Mon, Nov 23, 2009 at 10:50 AM, Jair Gaxiola <jyr.gaxiola@gmail.com> wrote:

On Mon, Nov 23, 2009 at 10:43 AM, Cody Precord <codyprecord@gmail.com> wrote:

--
SIN ETIQUETAS.[ PUNTO ]
http://hi.im/jyr
http://www.opentumblr.com

hi,

···

On Mon, Nov 23, 2009 at 11:09 AM, Jair Gaxiola <jyr.gaxiola@gmail.com> wrote:

I try whit my sample attached and not work, show me the error

Traceback (most recent call last):
File "list.py", line 68, in <module>
frame_1 = MyFrame(None, -1, "")
File "list.py", line 32, in __init__
self.OpenEditor(0,0)
File "list.py", line 59, in OpenEditor
self.lc.OpenEditor(col, row)
File "/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py",
line 573, in OpenEditor
x1 = self.col_locs[col+1] - x0
IndexError: list index out of range

Take a closer look at your code, there are some issues. Here are some hints,

1) Look where you defined your OpenEditor method

2) IIRC the TextEdit mixin uses a 1 based index for some reason or another

Cody

Hi

hi,

I try whit my sample attached and not work, show me the error

Traceback (most recent call last):
File "list.py", line 68, in <module>
frame_1 = MyFrame(None, -1, "")
File "list.py", line 32, in __init__
self.OpenEditor(0,0)
File "list.py", line 59, in OpenEditor
self.lc.OpenEditor(col, row)
File "/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py",
line 573, in OpenEditor
x1 = self.col_locs[col+1] - x0
IndexError: list index out of range

Take a closer look at your code, there are some issues. Here are some hints,

1) Look where you defined your OpenEditor method

2) IIRC the TextEdit mixin uses a 1 based index for some reason or another

I try with new changes at my sample code, but not works. Anyone will
have a small example with TextEditMixin. I have the next error:

Traceback (most recent call last):
  File "list.py", line 70, in <module>
    frame_1 = MyFrame(None, -1, "")
  File "list.py", line 31, in __init__
    self.OpenEditor(0,0)
  File "list.py", line 58, in OpenEditor
    listmix.TextEditMixin.OpenEditor(self.lc, col, row)
  File "/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py",
line 572, in OpenEditor
    x0 = self.col_locs[col]
AttributeError: 'TestListCtrl' object has no attribute 'col_locs'

list.py (2.18 KB)

···

On Mon, Nov 23, 2009 at 12:19 PM, Cody Precord <codyprecord@gmail.com> wrote:

On Mon, Nov 23, 2009 at 11:09 AM, Jair Gaxiola <jyr.gaxiola@gmail.com> wrote:

--
SIN ETIQUETAS.[ PUNTO ]
http://hi.im/jyr
http://www.opentumblr.com

Hi,

Hi
I try with new changes at my sample code, but not works. Anyone will
have a small example with TextEditMixin. I have the next error:

Traceback (most recent call last):
File "list.py", line 70, in <module>
frame_1 = MyFrame(None, -1, "")
File "list.py", line 31, in __init__
self.OpenEditor(0,0)
File "list.py", line 58, in OpenEditor
listmix.TextEditMixin.OpenEditor(self.lc, col, row)
File "/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py",
line 572, in OpenEditor
x0 = self.col_locs[col]
AttributeError: 'TestListCtrl' object has no attribute 'col_locs'

Please read this very carefully, as it will be my last reply to this thread

The OpenEditor method is a callback that is part of the TextEditMixin.
so you need to OVERRIDE this method in your ListCtrl class, not your
frame class.

Ok, now just some general advise, when you get an Exception (as shown
above in your email) try to read it. It usually will tell you exactly
why your code is not working. In this one, the error is saying that
your ListCtrl doesn't have a 'col_locs' attribute. So you should
think, hey I wonder why that is.

Luckily enough if you then look one line up it shows exactly where the
error happened, so why not take a look at that file to see what caused
it, continue upward in the error as necessary.

In this case I would say its a bit of a deficiency in how the
TextEditMixin is implemented, OpenEditor is really only meant to be
called __internally__ by the mixin when you click on a cell in the
list, don't call it directly in your code. If you need to do that you
will need to repeat some of the setup that is done by the mixin's
mouse handler first.

Attached is a modified version of your sample.

list_fixed.py (2.15 KB)

···

On Tue, Nov 24, 2009 at 3:26 PM, Jair Gaxiola <jyr.gaxiola@gmail.com> wrote:

Cody,

Thanks you a lot.

···

On Tue, Nov 24, 2009 at 4:00 PM, Cody Precord <codyprecord@gmail.com> wrote:

Hi,
Please read this very carefully, as it will be my last reply to this thread

The OpenEditor method is a callback that is part of the TextEditMixin.
so you need to OVERRIDE this method in your ListCtrl class, not your
frame class.

Ok, now just some general advise, when you get an Exception (as shown
above in your email) try to read it. It usually will tell you exactly
why your code is not working. In this one, the error is saying that
your ListCtrl doesn't have a 'col_locs' attribute. So you should
think, hey I wonder why that is.

Luckily enough if you then look one line up it shows exactly where the
error happened, so why not take a look at that file to see what caused
it, continue upward in the error as necessary.

In this case I would say its a bit of a deficiency in how the
TextEditMixin is implemented, OpenEditor is really only meant to be
called __internally__ by the mixin when you click on a cell in the
list, don't call it directly in your code. If you need to do that you
will need to repeat some of the setup that is done by the mixin's
mouse handler first.

--
SIN ETIQUETAS.[ PUNTO ]
http://hi.im/jyr
http://www.opentumblr.com