listCtrl.OpenEditor problem

What I am trying to do is, when a button is pushed, it creates a new
listCtrl and move the cursor to the newly created Ctrl to be able to
edit it. WIth the code I have now, it adds the listCtrl fine, you can
click it edit it what have you but it will not go to it automaticly so
we can edit it without having to click on it. I thought that we could
use OpenEditor() but it gives me and error. I will include a snippet
and the trace:
#this is the function that is called when the button is pushed

def OnAdd(self, evt):
“”" Adds a new record to the window
“”"
newRec = [self.id]

    #insted of adding random data we need to move the focus to the edit field after added
    try:
        for fields in range(0,self.editLst.

GetColumnCount()):

            #add field names into the newly created row

            newRec.append(self.databaseCol_Names[fields+1])
    except:
        print "error caught"
        pass   
   
    #Add our new data to the database.
    self.databaseData.append(newRec)

   
    #Add the data in the columns, IE update the window
    row = self.editLst.InsertStringItem(sys.maxint, newRec[1])
    self.editLst.SetStringItem(row, 1, newRec[2])#row, column, object

    self.editLst.SetItemData(row, newRec[0])
   
    #Upadte the number of records
    self.updateCount(len(self.databaseData))
    [self.id](http://self.id/) = [self.id](http://self.id/) + 1

    self.editLst.OpenEditor(0,0)

Traceback (most recent call last):
File “/Users/shadowghost21/Documents/pythonworkspace/etown/src/etown/python-src/editListWindow.py”, line 83, in OnAdd

self.editLst.OpenEditor(0,0)

File “//usr/local/lib/wxPython-unicode-2.8.9.1/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py”, line 557, in OpenEditor

x0 = self.col_locs[col]

AttributeError: ‘Editlst’ object has no attribute ‘col_locs’

Just trying to figure out how to get this dang thing to do what I want ;p
Thanks guys,

Aaron

What I am trying to do is, when a button is pushed, it creates a new listCtrl and move the cursor to the newly created Ctrl to be able to edit it. WIth the code I have now, it adds the listCtrl fine, you can click it edit it what have you but it will not go to it automaticly so we can edit it without having to click on it. I thought that we could use OpenEditor() but it gives me [an] error.

I work with Aaron, and thought I should clarify -- we're not creating a new ListCtrl, of course, but merely adding a new row to the existing ListCtrl. And none of that is really relevant to the problem, which is this:

We want to programmatically open an editor for a cell, but it doesn't work unless the user has previously edited a cell in the traditional way (by clicking). Otherwise, we get:

Traceback (most recent call last):
  File "/Users/shadowghost21/Documents/pythonworkspace/etown/src/etown/python-src/editListWindow.py", line 83, in OnAdd
    self.editLst.OpenEditor(0,0)
  File "//usr/local/lib/wxPython-unicode-2.8.9.1/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py", line 557, in OpenEditor
    x0 = self.col_locs[col]
AttributeError: 'Editlst' object has no attribute 'col_locs'

Poking through the listctrl.py code, it's not hard to see why this happens: the OnLeftDown code says:

         # the following should really be done in the mixin's init but
         # the wx.ListCtrl demo creates the columns after creating the
         # ListCtrl (generally not a good idea) on the other hand,
         # doing this here handles adjustable column widths

         self.col_locs = [0]
         loc = 0
         for n in range(self.GetColumnCount()):
             loc = loc + self.GetColumnWidth(n)
             self.col_locs.append(loc)

So, someone please answer me my questions three:

1. Is this still a problem in the latest wx (we're using 2.8.4.0)?

2. How can we work around it? (I suspect the answer is "call OnLeftDown", but to do so we'd have to construct a fake event that includes things like a fake position properly within the cell we want to edit, which looks nontrivial.)

3. Assuming the answer to question 1 is "yes," why don't we fix it? A simple and safe (ISTM) fix would be to just move the above code into OpenEditor, and perhaps even throw out the col_locs instance variable and make it local, since it isn't used anywhere else. Opening an editor is a UI action, which means the user is involved, which means that milliseconds don't matter -- and it's hard to imagine that getting those column widths is going to take more than that. Why shouldn't we just do this work in OpenEditor, so that OpenEditor always works?

Thanks,
- Joe

···

On Dec 3, 2008, at 11:59 PM, Aaron Hill wrote:

Joe Strout wrote:

What I am trying to do is, when a button is pushed, it creates a new listCtrl and move the cursor to the newly created Ctrl to be able to edit it. WIth the code I have now, it adds the listCtrl fine, you can click it edit it what have you but it will not go to it automaticly so we can edit it without having to click on it. I thought that we could use OpenEditor() but it gives me [an] error.

I work with Aaron, and thought I should clarify -- we're not creating a new ListCtrl, of course, but merely adding a new row to the existing ListCtrl. And none of that is really relevant to the problem, which is this:

We want to programmatically open an editor for a cell, but it doesn't work unless the user has previously edited a cell in the traditional way (by clicking). Otherwise, we get:

Traceback (most recent call last):
  File "/Users/shadowghost21/Documents/pythonworkspace/etown/src/etown/python-src/editListWindow.py", line 83, in OnAdd
    self.editLst.OpenEditor(0,0)
  File "//usr/local/lib/wxPython-unicode-2.8.9.1/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py", line 557, in OpenEditor
    x0 = self.col_locs[col]
AttributeError: 'Editlst' object has no attribute 'col_locs'

Poking through the listctrl.py code, it's not hard to see why this happens: the OnLeftDown code says:

        # the following should really be done in the mixin's init but
        # the wx.ListCtrl demo creates the columns after creating the
        # ListCtrl (generally not a good idea) on the other hand,
        # doing this here handles adjustable column widths

        self.col_locs = [0]
        loc = 0
        for n in range(self.GetColumnCount()):
            loc = loc + self.GetColumnWidth(n)
            self.col_locs.append(loc)

So, someone please answer me my questions three:

1. Is this still a problem in the latest wx (we're using 2.8.4.0)?

2. How can we work around it? (I suspect the answer is "call OnLeftDown", but to do so we'd have to construct a fake event that includes things like a fake position properly within the cell we want to edit, which looks nontrivial.)

3. Assuming the answer to question 1 is "yes," why don't we fix it? A simple and safe (ISTM) fix would be to just move the above code into OpenEditor, and perhaps even throw out the col_locs instance variable and make it local, since it isn't used anywhere else. Opening an editor is a UI action, which means the user is involved, which means that milliseconds don't matter -- and it's hard to imagine that getting those column widths is going to take more than that. Why shouldn't we just do this work in OpenEditor, so that OpenEditor always works?

Thanks,
- Joe

I'm not entirely sure, but the ObjectListView widget might work better for you. I've been messing with it lately and it seems far more robust than the original ListCtrl. You can check it out here: Features of an ObjectListView — ObjectListView v1.2 documentation

Here's its page on editing cells: Editing Cell Values — ObjectListView v1.2 documentation

The developer seems quite open to feature requests and such as well. As far as I can tell, you can ask for help on it on the dedicated list as well as here.

···

On Dec 3, 2008, at 11:59 PM, Aaron Hill wrote:

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

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Joe Strout wrote:

What I am trying to do is, when a button is pushed, it creates a new listCtrl and move the cursor to the newly created Ctrl to be able to edit it. WIth the code I have now, it adds the listCtrl fine, you can click it edit it what have you but it will not go to it automaticly so we can edit it without having to click on it. I thought that we could use OpenEditor() but it gives me [an] error.

I work with Aaron, and thought I should clarify -- we're not creating a new ListCtrl, of course, but merely adding a new row to the existing ListCtrl. And none of that is really relevant to the problem, which is this:

We want to programmatically open an editor for a cell, but it doesn't work unless the user has previously edited a cell in the traditional way (by clicking). Otherwise, we get:

Traceback (most recent call last):
  File "/Users/shadowghost21/Documents/pythonworkspace/etown/src/etown/python-src/editListWindow.py", line 83, in OnAdd
    self.editLst.OpenEditor(0,0)
  File "//usr/local/lib/wxPython-unicode-2.8.9.1/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx/lib/mixins/listctrl.py", line 557, in OpenEditor
    x0 = self.col_locs[col]
AttributeError: 'Editlst' object has no attribute 'col_locs'

Poking through the listctrl.py code, it's not hard to see why this happens: the OnLeftDown code says:

        # the following should really be done in the mixin's init but
        # the wx.ListCtrl demo creates the columns after creating the
        # ListCtrl (generally not a good idea) on the other hand,
        # doing this here handles adjustable column widths

        self.col_locs = [0]
        loc = 0
        for n in range(self.GetColumnCount()):
            loc = loc + self.GetColumnWidth(n)
            self.col_locs.append(loc)

So, someone please answer me my questions three:

1. Is this still a problem in the latest wx (we're using 2.8.4.0)?

I expect so. Nothing has been done on that class for a while.

2. How can we work around it? (I suspect the answer is "call OnLeftDown", but to do so we'd have to construct a fake event that includes things like a fake position properly within the cell we want to edit, which looks nontrivial.)

3. Assuming the answer to question 1 is "yes," why don't we fix it? A simple and safe (ISTM) fix would be to just move the above code into OpenEditor, and perhaps even throw out the col_locs instance variable and make it local, since it isn't used anywhere else. Opening an editor is a UI action, which means the user is involved, which means that milliseconds don't matter -- and it's hard to imagine that getting those column widths is going to take more than that. Why shouldn't we just do this work in OpenEditor, so that OpenEditor always works?

I think that at one point in time self.col_locs was used elsewhere, and it needed to be updated any time the col widths changed. As that doesn't appear to be the case any longer I have no problem with your proposed change. If you want to go ahead and change it, test it, and submit a patch to me.

···

On Dec 3, 2008, at 11:59 PM, Aaron Hill wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!