The first question is for SO.
When the user clicks on the ListCtrl widget, it generates an EVT_LIST_ITEM_SELECTED event. However, if I want to configure the list before displaying to the user to select multiple elements (by calling Select () in ListCtrl), the widget generates the same event. This event is not handled correctly by my application, as if it were a real user choice.
Since wxPython uses message passing, I can't just set the flag (ignore_selection_events) before I make my programmatic selections and then clear it later. As before, the flag will be cleared before the first handler / callback EVT_LIST_ITEM_SELECTED is launched.
Some solutions I tried and what went wrong:
There is a ListCtrl element that allows you to disable EVT_LIST_ITEM_SELECTED generation. I looked, and I am sure that this does not exist.
I can use wx.Timer to delay the reset of the ignore_selection_event flag since the last time Select () was called. Exact timing is error prone. It may not work (time is too short) or it may lead to the loss of a real user (timer is too long).
It should be possible to use PostEvent or ProcessEvent to force ListCtrl to generate a special ignore_selections event before generating the first EVT_LIST_ITEM_SELECTED, and the other after the last. I tried this, but the callback for the ignore event message is not called in the expected order:
evt = MyEvent(myEVT_TOGGLE_SELECTION_IGNORE)
wx.PostEvent(self.list_ctl, evt)
wx.CallAfter (self.list_ctl.Select, item, 1)
evt = MyEvent(myEVT_TOGGLE_SELECTION_IGNORE)
wx.PostEvent(self.list_ctl, evt)
, , EVT_LIST_ITEM_SELECTED. , , . , wxPython Select(), . , gui . self.list_ctl.Bind(wx.EVT_LIST_ITEM_SELECTED, do_nothing), CallAfter, gui .
, SO!
UPDATE:
! , .
list_ctrl.SetItemState(item_index, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) #works
list_ctrl.SetItemState(item_index, 0xFFFFFFFF, wx.LIST_STATE_SELECTED) #works
list_ctrl.SetItemState(item_index, 1, wx.LIST_STATE_SELECTED) # does NOT work
, , , .