I'm seeing some strange behavior, and I'd like to find
out if it's a known bug with a known workaround or if
I should try to create a simplified test case.
Environment: Win2K, Python 2.3.2, wxPython 2.5.2.8.
I have a ListCtrl in a window.
Selecting an item in the ListCtrl populates an edit panel.
The window implements a handler for wx.EVT_LIST_ITEM_SELECTED.
Handler pseudocode:
def OnItemSelected( self, evt ):
selectedIdx = evt.GetIndex()
if editPanel.Validate() \
and editPanel.TransferDataFromWindow():
### Switch to new item
### Tried with or without evt.Skip(); makes no difference
### because the problem is in the else: case.
else:
# Don't allow change
# Unselect clicked item
listctrl.SetItemState( selectedIdx, 0, wx.LIST_STATE_SELECTED )
# Reselect original item
wx.CallAfter( selector.SetItemState, self._currentIdx, \
setflags, setmask )
### Tried with or without evt.Skip(); makes no difference
Expected behavior:
When a validation fails the call to editPanel.Validate()
results in a dialog box. As a result of OnItemSelected,
the old item remains selected and the clicked item remains
unselected.
The problem:
If the switch to the new item is by selecting the listctrl
and hitting the up-arrow or down-arrow key, it works fine.
I get an OnItemSelected event for the change followed by
an OnItemSelected event from the wx.CallAfter (reselecting
the original item). E.g., if item 8 is active and fails
validation when up-arrow is pressed:
OnItemSelected item 7 --> Error dialog from validator
OnItemSelected item 8
If the switch to the new item is by mouse-click on the
new listctrl item, I get an *extra* OnItemSelected event
for the requested change. E.g., if item 8 is active
and fails validation when item 7 is clicked on:
OnItemSelected item 7 --> Error dialog from validator
OnItemSelected item 8
OnItemSelected item 7 --> Error dialog from validator
OnItemSelected item 8
So it seems to generate a duplicate OnItemSelected for
the new item when it originates from a mouse click.
The duplicate error dialog is *really* annoying,
and I *don't* want to release my app to customers
without a fix or workaround.
Is this a known problem?
Is there a fix or workaround?
- Sam
···
__________________________________________________________
Spinward Stars, LLC Samuel Reynolds
Software Consulting and Development 303-805-1446
http://SpinwardStars.com/ sam@SpinwardStars.com