listctrl issues

  1. I am using a listctrl (with the column sorter mixin) to hold a list of input files. The type of data contained in the file is determined automatically and displayed in the third column but can be changed via a pop-up menu. When this happens, I want to change the text in that column (and the corresponding item in the itemDataMap) to reflect the user choice. SetItemText on that column cell does not work - nor does changing the Text attribute directly; in either case, nothing happens and I don’t get an error message. SetStringItem does work, however. Is this a bug, or is the description of these methods in Robin’s book incomplete?

  2. I use the image as a pseudo-button; clicking the image opens a pop-up menu with a list of options to display the file (e.g. open a text editor, graphics viewer, etc.). I would like for left-click to do this; I had thought it would be trivial to determine if the mouse cursor was over the image when clicked, using event.GetPoint() - this certainly works for middle and right clicks. However, there is no left-click event associated with the listctrl, only a selection event. If I use the latter, event.GetPoint() always returns (1,1) [or (0,0) - my memory is hazy] no matter what the position, and thus appears to be completely detached from what the mouse is doing. I ended up having to determine the absolute position of the mouse, the window position, the listctrl location, and finally the image location. This ended up working but it’s a mess. Is there a better way to do this?

All of this is on a Mac running Python 2.6.1 and wxPython 2.8.9.1; I haven’t tested it on Linux yet.

thanks,

Nat

Nathaniel Echols wrote:

1. I am using a listctrl (with the column sorter mixin) to hold a list of input files. The type of data contained in the file is determined automatically and displayed in the third column but can be changed via a pop-up menu. When this happens, I want to change the text in that column (and the corresponding item in the itemDataMap) to reflect the user choice. SetItemText on that column cell does not work - nor does changing the Text attribute directly; in either case, nothing happens and I don't get an error message. SetStringItem does work, however. Is this a bug, or is the description of these methods in Robin's book incomplete?

Try this:

  item = listctrl.GetItem(idx, column)
  item.SetText(newValue)
  listctrl.SetItem(item)

2. I use the image as a pseudo-button; clicking the image opens a pop-up menu with a list of options to display the file (e.g. open a text editor, graphics viewer, etc.). I would like for left-click to do this; I had thought it would be trivial to determine if the mouse cursor was over the image when clicked, using event.GetPoint() - this certainly works for middle and right clicks. However, there is no left-click event associated with the listctrl, only a selection event. If I use the latter, event.GetPoint() always returns (1,1) [or (0,0) - my memory is hazy] no matter what the position, and thus appears to be completely detached from what the mouse is doing. I ended up having to determine the absolute position of the mouse, the window position, the listctrl location, and finally the image location. This ended up working but it's a mess. Is there a better way to do this?

Binding a handler for EVT_LEFT_DOWN to the listctrl should work. You can then use listctrl.HitTest to get the item and info about where the click was located.

···

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