In light of the lack of response to my question, I had to
find a way to hack around the inability to veto wxListCtrl
selection. After many strategies, I hit upon the use of
wxCallAfter to reduce the number of invocations of my
function from four to just the two I was after.
For anyone interested, the "idiom" I used is (roughly):
def __init__(self...):
...
self.skip_validation = FALSE
EVT_LIST_ITEM_SELECTED(self, self.listctl.GetId(),
self.OnSelect)
def OnSelect(self, event):
if self.skip_validation:
self.skip_validation = FALSE # reset flag
elif self.notValid(self.ctl):
wxMessageBox(error,...)
def cancel_select():
self.listctl.SetItemState(
self.current_index,
wxLIST_STATE_SELECTED,
wxLIST_STATE_SELECTED)
self.listctl.EnsureVisible(index)
self.ctl.SetFocus()
# Queue reselection of previous item:
wxCallAfter(cancel_select)
self.skip_validation = TRUE
else:
self.current_index = event.GetIndex()
self.skip_validation = FALSE
(what a PAIN.)
If there's a better way, I'd still love to know!
/Will Sadkin
Parlance Corporation
···
-----Original Message-----
From: Will Sadkin
Sent: Thursday, January 09, 2003 4:28 PM
To: 'wxpython-users@lists.wxwindows.org'
Subject: [wxPython-users] vetoing list selectionI have an application that uses a list control to select
objects that are editable in the right side of a panel,
using controls.I need to be able to validate the values in those controls
as a set, and disallow change of selection in the list
unless they are consistent. However, I cannot find a
satisfactory way to do this:EVT_LIST_ITEM_SELECTED does not appear to be vetoable.
Putting validation code in that event handler and then
forcing reselection back to the original selected item
within that handler causes the error to be "detected" 2x,
(causing double popups.) Further, it is then difficult
to set focus back to the offending control.Is there a standard idiom for how to do this properly?
Thanks in advance,
/Will Sadkin
Parlance Corporation---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwindows.org